Error when using header-includes in front matter
lgarcin opened this issue · comments
I get an error when I try to convert from markdown to pdf with latex commands defined in header-includes in font matter.
File test.md
---
header-includes: |
\newcommand{\Ker}{\mathrm{Ker}}
---
# Title
$\Ker$
Command run
codebraid pandoc --from markdown --to pdf test.md -o test.pdf
Error
! LaTeX Error: Command \Ker already defined.
I don't get any error if I try to convert from markdown to markdown with codebraid or when I convert from markdown to pdf directly with pandoc :
pandoc --from markdown --to pdf test.md -o test.pdf
I believe that direct-to-PDF conversion will internally use --standalone
. It looks like any header-includes get duplicated when the output uses --standalone
(even for markdown to markdown or markdown to latex). This can also happen under some conditions just using pandoc:
pandoc --from markdown --to markdown test.md --standalone
gives
---
header-includes: |
```{=tex}
\newcommand{\Ker}{\mathrm{Ker}}
```
---
```{=tex}
\newcommand{\Ker}{\mathrm{Ker}}
```
Title
=====
$\mathrm{Ker}$
That might be a pandoc bug. If not, I will figure out some way to work around it on the codebraid side.
Using codebraid to convert to an intermediate format like latex or markdown instead of directly to PDF is probably the best workaround for now.
According to jgm/pandoc#4311, pandoc is performing as expected (even if it seems counterintuitive at times), so this will have to be handled within codebraid.
This is fixed now in the dev version on GitHub, and I will release a new version on PyPI soon.