Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MD with Latex to HTML with MathJax with Pandoc

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?

like image 955
BBischof Avatar asked May 30 '16 20:05

BBischof


People also ask

Can pandoc convert HTML to markdown?

Pandoc can convert between numerous markup and word processing formats, including, but not limited to, various flavors of Markdown, HTML, LaTeX and Word docx.

How do I convert markdown to PDF with pandoc?

Generating PDF from Markdown with Pandoc There are actually two steps involved in converting a Markdown file to a PDF file: The Markdown source file is converted to a LaTeX source file. Pandoc invokes the pdflatex or xelatex or other TeX command and converts the . tex source file to a PDF file.

Can pandoc convert from PDF?

You can't. You can try opening the PDF in Word or Google Docs and saving in a format from which pandoc can convert directly.

What is the difference between LaTeX and markdown?

LaTeX / TeX markup works great for producing high-quality typesetting for articles, research papers, manuals, books, etc. Markdown works great for distraction-free focus-on-what-you-want-to-say writing. Using tools such as pandoc or kramdown you can (auto-)convert plain text in markdown to LaTeX for further processing.


3 Answers

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

like image 52
jdhao Avatar answered Sep 29 '22 13:09

jdhao


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

pandoc --mathjax input.md -o output.html
like image 31
mb21 Avatar answered Sep 29 '22 15:09

mb21


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.

like image 32
Axel Kemper Avatar answered Sep 29 '22 13:09

Axel Kemper