[Tex/LaTex] Pandoc: How to get numbered LaTeX equations to show up in both PDF and HTML output


To make a numbered equation in Pandoc, I defer to using pure LaTeX:

a^2 + b^2 = c^2

In PDF form, it gives a nice numbered equation, however, this equation doesn't show up at all in the HTML output because the equation is within the \begin environment and is ignored. I would like to keep the numbering in the PDF, but would like the equation to show up in the HTML, with or without the numbering.

Best Answer

An extension exists on github: pandoc-crossref

install it with

cabal update
cabal install pandoc-crossref

or in archlinux using ArchHaskell

pacman -Sy pandoc-crossref

you can use it by doing

$$ math $$ {#eq:label}

and compiling with

pandoc file.md --filter pandoc-crossref -o file.pdf

for more information see the documentation

Alternatively, as described in https://github.com/jgm/pandoc/issues/1938#issuecomment-74011358 you can use --mathjax for HTML rendering

if your equations are in math.txt

$$ a^2 + b^2 = c^2 $$

create a file header

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: "all"} } });

and compile with

pandoc math.txt -t html -s -o test.html --mathjax=https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML -H header 
Related Question