[Tex/LaTex] LaTeX to MathML conversion: tools, limitations, and approaches

mathjaxmathml

As far as I understand there are two ways to display LaTeX on the web:

  • The MathJax JavaScript library, which allows you to embed LaTeX directly within HTML tags, but such LaTeX is converted by MathJax to MathML, an XML format which browsers can understand, unlike LaTeX. The disadvantages of this approach is that MathJax support for LaTeX is limited (and perhaps it would be useful if someone could outline some of its most important limitations).

  • Use a command-line tool to convert LaTeX to MathML (I've found this tool, but wonder if there is a command line tool I can install on Linux or Windows or better on both). Apparently, this solution has fewer limitations. I would like to know what the best tools to use for this conversion are, and whether MathML has any limitations as far as the following go:

    1. the MathML language's ability to encode everything that can be encoded with LaTeX syntax, and

    2. any possible limitations due to incomplete browser support for MathML (judging from this page, Chrome support seems to be severaly limited compared to Firefox, but this also means that if a user of my site is not using Firefox, then they will not be able to see math properly, which is a real drawback!).

Furthermore, if there are any other approaches to displaying math on the web, without resorting to images and PDF files, then I would like to know about them, but I think the alternatives I mentioned are most likely the two and only most viable ones.

Best Answer

LaTeXML provides several tools for converting TeX into XML/HTML/MathML. One of those tools is latexmlmath. For example, on a command line, the input:

latexmlmath '\mathbf{F}_{2}=k \frac{q_{1} q_{2} \hat{\mathbf{r}}_{21}}{r_{21}^{2}}'

has the output:

<?xml version="1.0" encoding="UTF-8"?>
<math xmlns="http://www.w3.org/1998/Math/MathML" alttext="\mathbf{F}_{2}=k\frac{q_{1}q_{2}\hat{\mathbf{r}}_{21}}{r_{21}^{2}}" display="block">
  <mrow>
    <msub>
      <mi>𝐅</mi>
      <mn>2</mn>
    </msub>
    <mo>=</mo>
    <mrow>
      <mi>k</mi>
      <mo>⁢</mo>
      <mfrac>
        <mrow>
          <msub>
            <mi>q</mi>
            <mn>1</mn>
          </msub>
          <mo>⁢</mo>
          <msub>
            <mi>q</mi>
            <mn>2</mn>
          </msub>
          <mo>⁢</mo>
          <msub>
            <mover accent="true">
              <mi>𝐫</mi>
              <mo stretchy="false">^</mo>
            </mover>
            <mn>21</mn>
          </msub>
        </mrow>
        <msubsup>
          <mi>r</mi>
          <mn>21</mn>
          <mn>2</mn>
        </msubsup>
      </mfrac>
    </mrow>
  </mrow>
</math>