11

Somewhat similar to How to convert HTML with mathjax into latex using pandoc? but in some sense, the opposite.

If I'm using Pandoc to create MD files with LaTeX, or even just MD files, how can I use Pandoc to convert these to HTML with the correct \(\), \[\] tags for math?

jdhao
  • 24,001
  • 18
  • 134
  • 273
BBischof
  • 310
  • 2
  • 13
  • [Math in Pandoc Markdown](http://pandoc.org/README.html#math) is actually wrapped in dollar signs, not `\(\)` tags. – mb21 May 31 '16 at 18:36
  • @mb21 Yes, I understand that, the issue is when converting to HTML with mathjax I need these tags, not the dollar signs. – BBischof May 31 '16 at 22:58

4 Answers4

18

Following discussion here, I am able to convert test.md (containing LaTeX code) to test.html successfully.

pandoc --toc --standalone --mathjax -f markdown -t html test.md -o test.html

The doc on --mathjaxcan be found here:

Use MathJax to display embedded TeX math in HTML output. TeX math will be put between (...) (for inline math) or [...] (for display math) and wrapped in tags with class math. Then the MathJax JavaScript will render it. The URL should point to the MathJax.js load script. If a URL is not provided, a link to the Cloudflare CDN will be inserted.

The option --standalone is important, without which the LaTeX code can not be rendered correctly.

PS. wrap inline equation like $INLINE EQUATION$ and wrap display equation like $$DISPLAY EQUATION$$.

jdhao
  • 24,001
  • 18
  • 134
  • 273
4

You want to convert from markdown to html with mathjax support?

pandoc --mathjax input.md -o output.html
mb21
  • 34,845
  • 8
  • 116
  • 142
1

Assuming Windows as platform, the following .CMD snippet should do the conversion:

set PATH=%ProgramFiles%\pandoc;%PATH%
set CDN=http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML

set IN=%~s1

if [%2]==[] (
  set OUT=%~sdp1%~n1.html
) else (
  set OUT=%~s2
)

echo Converting markdown to html ...
pandoc.exe -s --mathjax=%CDN% --from=markdown+pipe_tables --to=html --output="%OUT%" %IN%

Consult the pandoc help to tune the commandline parameters.

Axel Kemper
  • 10,544
  • 2
  • 31
  • 54
  • I'm in a unix environment, but I may be able to decipher this. Thanks, I'll update after I see how this goes. – BBischof May 31 '16 at 22:59
  • 1
    Note from the future: cdn.mathjax.org is nearing its end-of-life, check https://www.mathjax.org/cdn-shutting-down/ for migration tips. – Peter Krautzberger Apr 12 '17 at 08:00
0

I just found mathjax-node-page (from html to html) and they are truly self-contained. From my Makefile:

# Convert
pandoc aperture_synthesis.md -t html --self-contained -s --standalone --mathjax -o aperture_synthesis.html
cp aperture_synthesis.html out1.html
# Independentize from MathJax CDN
$$HOME/Program/MathJax/node_modules/mathjax-node-page/bin/mjpage --output CommonHTML < out1.html > aperture_synthesis.html 
Tinmarino
  • 3,693
  • 24
  • 33