32

I would like to specify numbered sections via Pandoc's support for YAML front matter. I know that the flag for the command-line usage is --number-sections, but something like

---
title: Test
number-sections: true
---

doesn't produce the desired result. I know that I am close because you can do this with the geometry package (e.g. geometry: margin=2cm). I wish there was a definitive guide on how Pandoc YAML front matter handling. For example, the following is very useful (avoids templates), but its discoverability is low:

 header-includes: 
 - \usepackage{some latex package}
tlnagy
  • 3,274
  • 4
  • 24
  • 37

2 Answers2

32

In order to turn on numbered-sections in latex output you need to use numbersections in your YAML block. If you ever want to "discover" things like this with pandoc just poke around the templates:

 $ grep -i number default.latex
 $if(numbersections)$
 $ grep -i number default.html*
 $

As you can see this option does not work with html.

Markdown and YAML I tested with:

 ---
 title: Test
 numbersections: true
 ---


 # blah

 Text is here.

 ## Double Blah

 Twice the text is here

If you need it to work with more than beamer,latex,context,opendoc you will need to file a bug at github.

dfc
  • 792
  • 5
  • 16
  • Great tip about poking around in the default templates. I don't know why secnumdepth is getting ignored for me when I do `pandoc -f markdown -S -s --standalone --toc -Vnumbersections -Vsecnumdepth=4 -t latex` but thankfully secnumdepth is manipulable in the template file. – Sridhar Sarnobat Mar 31 '17 at 04:20
  • 3
    @Sridhar-Sarnobat, try `pandoc -f markdown -S -s --standalone --toc -numbersections -Vsecnumdepth=4 -t latex` – chus May 17 '17 at 09:45
  • @chus, according to [pandoc documentation](https://pandoc.org/MANUAL.html), to show section number in pdf output, the correct options in command line is `--number-sections` or simply `-N`. – jdhao Dec 10 '17 at 11:00
  • @jdhao, you are right. Thank you for correcting the options. – chus Dec 11 '17 at 09:22
15

In order to show section number in the produced output pdf, there are two choices.

In YAML front matter

Add the following setting to begin of markdown file

---
numbersections: true
---

In command line

We can also use the command option to generate pdf with numbered section. According to Pandoc documentation, the correct options is --number-sections or simply -N,

pandoc test.md -o test.pdf --number-sections
# pandoc test.md -o test.pdf -N
jdhao
  • 24,001
  • 18
  • 134
  • 273