Or rather in a LaTeX block in the `header-includes` list in the YAML metadata:

---
header-includes:
  - |
    ```{=latex}
    % LaTeX code here!
    ```
---


--
Better --help|less than helpless

Den lör 9 maj 2020 21:44John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> skrev:

Try putting it in

header-includes

in your YAML metadata.

Germano Gabbianelli <tyrion.mx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> 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
>
> --
> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/7ee100cd-c4d9-4e00-9648-7c11675be7dd%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/m2y2q0gaie.fsf%40johnmacfarlane.net.

--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhDWg857-fwrboMYnQCHyJ6ON5tsJJtsfDYp7yh2i0Hcmw%40mail.gmail.com.