[{"data":1,"prerenderedAt":144},["ShallowReactive",2],{"blog-post-pandoc-add-table-of-contents":3,"recent-posts":83},{"id":4,"uid":5,"url":6,"type":7,"href":8,"tags":9,"first_publication_date":10,"last_publication_date":10,"slugs":11,"linked_documents":13,"lang":14,"alternate_languages":15,"data":16},"avmFWhEAAC4AkXJ6","pandoc-add-table-of-contents",null,"blog_posts","https:\u002F\u002Fmarks-personal-website.cdn.prismic.io\u002Fapi\u002Fv2\u002Fdocuments\u002Fsearch?ref=av979xIAACoAE1AJ&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22avmFWhEAAC4AkXJ6%22%29+%5D%5D",[],"2026-11-19T22:45:10+0000",[12],"pandoc-how-to-add-a-table-of-contents",[],"en-us",[],{"title":17,"date":23,"description":24,"image":29,"content":39},[18],{"type":19,"text":20,"spans":21,"direction":22},"heading1","Pandoc: How to Add a Table of Contents",[],"ltr","2026-11-19",[25],{"type":26,"text":27,"spans":28,"direction":22},"heading2","Learn how to add a table of contents to a document using Pandoc",[],{"dimensions":30,"alt":20,"copyright":6,"url":33,"id":34,"edit":35},{"width":31,"height":32},1280,720,"https:\u002F\u002Fimages.prismic.io\u002Fmarks-personal-website\u002FxKJKGbosoWUvSqb4_pandoc-add-table-of-contents.png?auto=format,compress","xKJKGbosoWUvSqb4",{"x":36,"y":36,"zoom":37,"background":38},0,1,"transparent",[40,44,48,52,55,58,61,64,67,70,73,76,80],{"type":41,"text":42,"spans":43,"direction":22},"heading3","Install Pandoc and Typst",[],{"type":45,"text":46,"spans":47,"direction":22},"paragraph","Before we start, make sure you have Homebrew installed on your computer and your Markdown file ready in a folder. Install both tools with this command:",[],{"type":49,"text":50,"spans":51,"direction":22},"preformatted","brew install pandoc typst",[],{"type":41,"text":53,"spans":54,"direction":22},"Add the Table of Contents",[],{"type":45,"text":56,"spans":57,"direction":22},"First, open your terminal and navigate to the folder containing your Markdown file. To add a table of contents to a PDF, run this command:",[],{"type":49,"text":59,"spans":60,"direction":22},"pandoc input.md --toc -o output.pdf --pdf-engine=typst",[],{"type":45,"text":62,"spans":63,"direction":22},"Just swap \u003Ccode>input.md\u003C\u002Fcode> with your actual filename. The \u003Ccode>--toc\u003C\u002Fcode> flag adds the table of contents, and \u003Ccode>--pdf-engine=typst\u003C\u002Fcode> tells Pandoc to build the PDF with Typst. This finishes almost instantly, and Pandoc doesn't print anything when it works.",[],{"type":45,"text":65,"spans":66,"direction":22},"To make sure everything worked, run \u003Ccode>open output.pdf\u003C\u002Fcode>. You'll see a \u003Ccode>Contents\u003C\u002Fcode> list at the top with a line for every heading.",[],{"type":41,"text":68,"spans":69,"direction":22},"Number the Sections",[],{"type":45,"text":71,"spans":72,"direction":22},"To number your headings, both in the document and in the table of contents, add the \u003Ccode>-N\u003C\u002Fcode> flag:",[],{"type":49,"text":74,"spans":75,"direction":22},"pandoc input.md --toc -N -o output.pdf --pdf-engine=typst",[],{"type":77,"oembed":78},"embed",{"embed_url":79,"type":77},"",{"type":45,"text":81,"spans":82,"direction":22},"One more tip: if you convert to HTML instead, add \u003Ccode>-s\u003C\u002Fcode> so the output is standalone, otherwise Pandoc leaves the table of contents out. You can also add \u003Ccode>--toc-depth=2\u003C\u002Fcode> to choose how many heading levels show up.",[],{"results":84,"page":37,"results_per_page":142,"results_size":142,"total_results_size":143,"total_pages":37},[85,104,123],{"id":86,"uid":87,"url":6,"type":7,"href":88,"tags":89,"first_publication_date":10,"last_publication_date":10,"slugs":90,"linked_documents":92,"lang":14,"alternate_languages":93,"data":94},"avmFXBEAAC0AkXKG","pandoc-convert-csv-to-markdown","https:\u002F\u002Fmarks-personal-website.cdn.prismic.io\u002Fapi\u002Fv2\u002Fdocuments\u002Fsearch?ref=av979xIAACoAE1AJ&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22avmFXBEAAC0AkXKG%22%29+%5D%5D",[],[91],"pandoc-how-to-convert-csv-to-markdown",[],[],{"image":95,"title":101},{"dimensions":96,"alt":97,"copyright":6,"url":98,"id":99,"edit":100},{"width":31,"height":32},"Pandoc: How to Convert CSV to Markdown","https:\u002F\u002Fimages.prismic.io\u002Fmarks-personal-website\u002FdDE2zaQ1nNI4pvFb_pandoc-convert-csv-to-markdown.png?auto=format,compress","dDE2zaQ1nNI4pvFb",{"x":36,"y":36,"zoom":37,"background":38},[102],{"type":19,"text":97,"spans":103,"direction":22},[],{"id":105,"uid":106,"url":6,"type":7,"href":107,"tags":108,"first_publication_date":10,"last_publication_date":10,"slugs":109,"linked_documents":111,"lang":14,"alternate_languages":112,"data":113},"aviRYBEAACkAkBYS","pandoc-convert-html-to-markdown","https:\u002F\u002Fmarks-personal-website.cdn.prismic.io\u002Fapi\u002Fv2\u002Fdocuments\u002Fsearch?ref=av979xIAACoAE1AJ&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22aviRYBEAACkAkBYS%22%29+%5D%5D",[],[110],"pandoc-how-to-convert-html-to-markdown",[],[],{"image":114,"title":120},{"dimensions":115,"alt":116,"copyright":6,"url":117,"id":118,"edit":119},{"width":31,"height":32},"Pandoc: How to Convert HTML to Markdown","https:\u002F\u002Fimages.prismic.io\u002Fmarks-personal-website\u002F0XaRTeXl-LE8mTSK_pandoc-convert-html-to-markdown.png?auto=format,compress","0XaRTeXl-LE8mTSK",{"x":36,"y":36,"zoom":37,"background":38},[121],{"type":19,"text":116,"spans":122,"direction":22},[],{"id":124,"uid":125,"url":6,"type":7,"href":126,"tags":127,"first_publication_date":10,"last_publication_date":10,"slugs":128,"linked_documents":130,"lang":14,"alternate_languages":131,"data":132},"avmFWREAACgAkXJy","pandoc-convert-epub-to-pdf","https:\u002F\u002Fmarks-personal-website.cdn.prismic.io\u002Fapi\u002Fv2\u002Fdocuments\u002Fsearch?ref=av979xIAACoAE1AJ&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22avmFWREAACgAkXJy%22%29+%5D%5D",[],[129],"pandoc-how-to-convert-epub-to-pdf",[],[],{"image":133,"title":139},{"dimensions":134,"alt":135,"copyright":6,"url":136,"id":137,"edit":138},{"width":31,"height":32},"Pandoc: How to Convert EPUB to PDF","https:\u002F\u002Fimages.prismic.io\u002Fmarks-personal-website\u002FzHtmOvgGFqs9GTF1_pandoc-convert-epub-to-pdf.png?auto=format,compress","zHtmOvgGFqs9GTF1",{"x":36,"y":36,"zoom":37,"background":38},[140],{"type":19,"text":135,"spans":141,"direction":22},[],3,74,1795128335117]