3

I'm trying to convert latex code embedded in an HTML document (Intended to be used with a Javascript shim) into MathML. Pandoc seems like a great tool. Following this example: http://pandoc.org/demos.html,

pandoc input.html -s --latexmathml -o output.html

Produces no change in the file. I even made a barebones blank HTML file with various text expressions to test; no change in the output. What am I missing?

http://math.etsu.edu/LaTeXMathML/ This site, linked to by Pandoc, appears to show documentation for a standalone case, but it uses a JS shim instead of outputting the MathML directly. (I think it has the browser render dynamically-rendered MathML, but doesn't actually output it to the file) It's also missing some basic functionality, like own-line functions with \begin{equation}.

I've spent several hours googling ways to accomplish this. Any ideas? The only fully-working solution I've found is https://www.mathtowebonline.com/ This website. There's also a python module called latex2mathml, but it's also missing large chunks of the spec.

Turtles Are Cute
  • 3,200
  • 6
  • 30
  • 38

1 Answers1

6

You'll need the --mathml flag (not the --latexmathml flag) to generate MathML and the tex_math_dollars extension enabled for reading the math between dollar signs:

$ echo '<p>$$x = 4$$</p>' | pandoc -f html+tex_math_dollars -t html --mathml
<p>
  <math display="block" xmlns="http://www.w3.org/1998/Math/MathML">
    <semantics>
      <mrow><mi>x</mi><mo>=</mo><mn>4</mn></mrow><annotation encoding="application/x-tex">x = 4</annotation>
    </semantics>
  </math>
</p>

Or maybe you're better off using somehting like snuggleTeX or LaTeXMathML.js...

mb21
  • 34,845
  • 8
  • 116
  • 142
  • Another option would be to use [mathjax-node](https://github.com/mathjax/MathJax-node). – Peter Krautzberger Jan 08 '17 at 16:37
  • Thank you. It looks like from the Pandoc docs that it should be able to parse latex to MathML, like in the example I used. The LaTeXMathML.js link is an older version of the one I posted in the Q. (That page links to the newer version near its top). It appears that the best route forward is to use the standalone version of the web program I linked: http://www.mathtoweb.com/cgi-bin/mathtoweb_home.pl. It actually seems quite good, complete, and well-documented! – Turtles Are Cute Jan 11 '17 at 19:59
  • 1
    @TurtlesAreCute it's indeed possible to extract the latex math from html with pandoc, I corrected my answer above. – mb21 Jan 15 '17 at 14:07