I'm trying to convert a Markdown file containing Latin/Cyrillic text and LaTeX math into a PDF using Pandoc. I have inline math delimited by $ ... $
and block math delimited by $$ ... $$
. However, Pandoc is turning all my $
characters into \$
, which causes LaTeX to throw an error because it never properly enters math mode.
Here’s an example snippet of my Markdown:
#### 2.1.1 Tenzori: skalari, vektori, matrice i višeredni tenzori
**Tenzor** (eng. _tensor_) je generalizacija pojma niza brojeva i može se posmatrati kao višedimenzionalni niz.
1. **Skalar** (rang 0): Obični realni ili kompleksni broj. Skalar se može predstaviti kao $ \alpha \in \mathbb{R} $ (ili $ \alpha \in \mathbb{C} $ u slučaju kompleksnih brojeva).
2. **Vektor** (rang 1): Niz brojeva koji tipično reprezentuje neku veličinu sa određenim brojem komponenti. Na primer, vektor dužine $n$ je $ \mathbf{x} \in \mathbb{R}^n $.
3. **Matrica** (rang 2): Dvodimenzionalni niz brojeva ...
4. **Višeredni tenzor** (rang $\geq 3$): ...
But when I run:
pandoc in.md -o out.pdf --pdf-engine=xelatex -V mainfont="DejaVu Serif"
it gives me an error like:
! LaTeX Error: \symbb allowed only in math mode.
l.72 ...predstaviti kao \$ \alpha \in \mathbb
...
Which means that $
was turned into \$
, so I'm never entering math mode.
I want Pandoc to recognize $ ... $
and $$ ... $$
as math delimiters, not turn them into escaped dollar signs. I've tried various combinations like --from=markdown+raw_tex+tex_math_dollars
or --standalone
, but it still ends up escaping my math in some contexts.
Which command line flags or extensions should I use so Pandoc doesn’t escape the $
?
Do I need a special metadata block or a specific yaml
front matter to keep $
intact?
Is there a known bug with certain versions of Pandoc that incorrectly escape $
? I tried looking around but couldn't find anything that aligns with my setup and problem
My environment:
pandoc 3.1.11.1
Features: +server +lua
Scripting engine: Lua 5.4
XeTeX 3.141592653-2.6-0.999996 (TeX Live 2024/nixos)
kpathsea version 6.4.0
(I have all of the tex packages installed from nixos unstable, so they should be the latest versions)
Command used (among others): pandoc in.md -o out.pdf --pdf-engine=xelatex -V mainfont="DejaVu Serif"
Any guidance or workarounds would be greatly appreciated.