I know that I can use the -H or --include-in-header commands to include a custom preamble in the generated output. The problem is now that Pandoc includes my preamble but puts another preamble in front of it:

  \usepackage[setpagesize=false, % page size defined by xetex
              unicode=false, % unicode breaks when used with xetex
\hypersetup{breaklinks=true, pdfborder={0 0 0}}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em}  % prevent overfull lines

[... my preamble ...]

I know that this is the default LaTeX preamble (default.latex) that Pandoc loads from its templates folder. The same thing happens when I'm using --include-after-body with \end{document}.

This is the command I'm using:

pandoc -o output.tex input.txt --include-before-body=header.tex --include-after-body=footer.tex

As you have discovered, --include-in-header adds text into the preamble specified in Pandoc's LaTeX template. There are a few ways to do what you are trying to do.

  1. If you would like a completely custom preamble, you need to specify a template file using

    pandoc -o output.tex --template=FILE input.txt

    The template can have variables (such as $title$ and, more importantly, $body$) and conditionals. If you would like some inspiration, you could check out the default template using the command

    pandoc -D latex
  2. If you want to use a new template once and for all, you can make one, call it default.latex, and put it in the templates directory (~/.pandoc/templates/ on a unix machine). In this case, you need to specify that you want to use a template by calling

    pandoc -o output.tex --standalone input.txt
  3. If you would rather not deal with templates at all, you can just run

    pandoc -o output.tex input.txt

    and the result will be a bare LaTeX document, that is, without a preamble, \begin{document} or \end{document}. Then you can add a preamble yourself. Note that any metadata (title, author) will be lost when using this method.

Full details on how to make and use templates can be found in Pandoc's excellent man page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.