MD with Latex to HTML with MathJax with Pandoc
Asked Answered
O

4

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?

Olson answered 30/5, 2016 at 20:41 Comment(2)
Math in Pandoc Markdown is actually wrapped in dollar signs, not \(\) tags.Hypogastrium
@Hypogastrium Yes, I understand that, the issue is when converting to HTML with mathjax I need these tags, not the dollar signs.Olson
N
20

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$$.

Nadiya answered 11/3, 2019 at 17:5 Comment(1)
You sir, are a great gentleman and scholar. This has so much upgraded the level of output.Magnus
H
4

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

pandoc --mathjax input.md -o output.html
Hypogastrium answered 1/6, 2016 at 8:8 Comment(0)
R
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.

Reno answered 30/5, 2016 at 20:53 Comment(2)
I'm in a unix environment, but I may be able to decipher this. Thanks, I'll update after I see how this goes.Olson
Note from the future: cdn.mathjax.org is nearing its end-of-life, check mathjax.org/cdn-shutting-down for migration tips.Mcdougald
J
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 
Jarietta answered 21/6, 2020 at 6:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.