Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Latex to MathML in HTML

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.

like image 689
Turtles Are Cute Avatar asked Oct 20 '25 12:10

Turtles Are Cute


1 Answers

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

like image 131
mb21 Avatar answered Oct 23 '25 09:10

mb21



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!