Pandoc: How to Number Sections

Updated

Learn how to number the sections of a document using Pandoc

Pandoc: How to Number Sections

Before we start, make sure you have Pandoc and Typst installed on your computer and your Markdown file ready in a folder. If you don't have them yet, run this command:

brew install pandoc typst

First, open your terminal and navigate to the folder that has your file. To number the headings, run this command:

pandoc input.md -N --pdf-engine=typst -o output.pdf

Just remember to replace input.md with your actual filename. The -N flag turns on section numbering, and --pdf-engine=typst tells Pandoc to use Typst to make the PDF. By default, the headings are numbered like 1, 1.1 and 1.1.1.

If you want a different style, add the section-numbering variable with -V. For example, 1.A.1 gives you numbers for the top level and letters for the next level:

pandoc input.md -N -V section-numbering="1.A.1" --pdf-engine=typst -o output.pdf

You can use 1, a, A, i and I in the pattern. Don't worry if you don't see a success message, Pandoc stays quiet when it works.

To make sure everything worked, run open output.pdf and check the headings.

undefined

One more tip: if you want a heading to stay without a number, like an Introduction, add {.unnumbered} after it in your Markdown file, like # Introduction {.unnumbered}.