Hello, I have the following markdown source, containing some latex macros and I would like to convert it both to html and pdf.
---
title: Hello
---
\DeclareMathOperator*{\E}{\mathbb E}
This is some math: $\E x$
I can convert it to html, using `pandoc hello.md --mathml -s -o out.html`, but conversion to pdf fails (complaining that \DeclareMathOperator can only be used in the preamble):
$ pandoc hello.md -f markdown-latex_macros -s -o out.pdf
Error producing PDF.
! LaTeX Error: Can be used only in preamble.
I can successfully convert the markdown to pdf, by moving the macros to a separate `macros.tex` file and including it with `-H`, however I would like to keep a single input markdown file, which should be converted to both html and pdf.
Having the macros in a separate file would be ideal, so I could avoid duplicating them in each source file.
I also tried to make a lua filter to dynamically include `macros.tex` when converting to html, but it does not seem to work.
mt, contents = pandoc.mediabag.fetch("etc/macros.tex", ".")
macros = pandoc.read(contents).blocks
function Pandoc(doc)
return pandoc.Pandoc(macros .. doc.blocks, doc.meta)
end
Could anyone give me any hints?
Thank you,
Germano