gpoore / codebraid

Live code in Pandoc Markdown
BSD 3-Clause "New" or "Revised" License
376 stars 13 forks source link

Error when using header-includes in front matter #20

Closed lgarcin closed 4 years ago

lgarcin commented 4 years ago

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
gpoore commented 4 years ago

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}}

\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.
gpoore commented 4 years ago

According to https://github.com/jgm/pandoc/issues/4311, pandoc is performing as expected (even if it seems counterintuitive at times), so this will have to be handled within codebraid.

gpoore commented 4 years ago

This is fixed now in the dev version on GitHub, and I will release a new version on PyPI soon.