Getting chapters to start on a new page in a pandoc-generated PDF


To make this work with pandoc, you'll need to insert the following into the preamble of the LaTeX document pandoc generates on the way to PDF:


There are several ways to do that. One is to create a custom LaTeX template with these lines in the preamble. You can then use the option --template mytemplate.latex to tell pandoc to use this template. To get the default LaTeX template, which you can modify, do pandoc -D latex > mytemplate.latex.

Another option is to create a small file titlesec.tex with just those two lines. Then call pandoc with the option --include-in-header titlesec.tex to include it in the header, like so:

pandoc --toc --include-in-header titlesec.tex -o output.pdf input1.mkd input2.mkd

What I ended up doing was this:

pandoc --toc -V documentclass=report -o output.pdf inputs*.mkd

This causes the LaTeX 'report' document class to be used (by default, with --chapters, pandoc seems to use the 'book' or 'memoir' class, which are designed for books - different-sized margins one each side to facilitate book-binding, chapters only starting on odd pages, etc.), which puts level 1 headers at the top of pages, but doesn't only put them at the top of odd-numbered pages.

This still inserts 'Chapter X' before each chapter, which is still annoying. I would also quite like to have the Table of Contents start on the same page as the title (this happens with the 'article' document class, but then chapters aren't shunted to the beginning of new pages - they just start wherever). However, I think that getting those would require more knowledge of LaTeX than I have: I'm not going to mark this as the accepted answer, since the ideal answer for this would explain how to work around these two issues.