If I process this markdown file ('mwe-latex.md'):
---
title: "Minimal Working Example"
header-includes:
- \let\oldsection\section
- \renewcommand{\section}[1]{\clearpage\oldsection{#1}}
---
Text.
with the pandoc command:
pandoc -t latex --latex-engine=xelatex --output=mwe-latex.pdf mwe-latex.mdI get the the error:
! LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.49 \let\oldsection\textbackslash{}s
pandoc: Error producing PDFOn generating latex output with the command:
pandoc -t latex --latex-engine=xelatex --standalone --output=mwe-latex.tex mwe-latex.mdand examining line 49 of the output file it becomes apparent that this line from the header inclusion:
has been munged by pandoc to:
\let\oldsection\textbackslash{}section
and this is causing the processing problem. (Note: changing latex engines makes no difference.)
Once line 49 is edited to resemble the original command from the header inclusion the error disappears.
How can I prevent this latex command in the header inclusion from being munged by pandoc?