5.5 Use a custom Pandoc LaTeX template

Pandoc converts Markdown to LaTeX through a template. The template is a LaTeX file containing Pandoc variables, and Pandoc will replace these variables with their values. Below is a simple template that only contains a single variable $body$:


The value of $body$ is the LaTeX code generated from the body of the Markdown document. For example, if the body text is Hello **world**! in Markdown, the value of $body$ will be Hello \textbf{world}!.

If the LaTeX customization methods in Sections 5.1, 5.2, and 5.4 are not enough for you, you may try to use a custom template instead. A template allows you to use arbitrary LaTeX code in it, hence is much more flexible. To use a template, include the path of the template in the template option of pdf_document, e.g.,

    template: my-template.tex

The default LaTeX template of Pandoc can be found at https://github.com/jgm/pandoc/tree/master/data/templates (named default.latex).

For the full list of Pandoc variables and their meanings, see Pandoc’s manual at https://pandoc.org/MANUAL.html#templates.