# Demo for latex2mathml

Pure Python library for LaTeX to MathML conversion

latex2mathml is a pure Python library for LaTeX to MathML conversion. This page is a demo for latex2mathml.

TeX is a typesetting system which was designed to format complex mathematical formulas. MathML, on the other hand, is a mathematical markup language. It is an XML-based format describing mathematical notations.

To install latex2mathml, make sure that you have the latest Python installation, then use pip.

pip install latex2mahtml


Using latex2mathml is very easy. First, import latex2mathml.converter and run latex2mathml.converter.convert(). For example, let us use the following TeX equation:

x=\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}


The following Python code will convert the above equation to MathML:

import latex2mathml.converter

latex_input = r"x=\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}"
mathml_output = latex2mathml.converter.convert(latex_input)
print(mathml_output)


The output of the above code should look like this:

$<mrow> <mi>x</mi> <mo>=</mo> <mfrac> <mrow> <mo>−</mo> <mi>b</mi> <mi>±</mi> <msqrt> <mrow> <msup> <mi>b</mi> <mn>2</mn> </msup> <mo>−</mo> <mn>4</mn> <mi>a</mi> <mi>c</mi> </mrow> </msqrt> </mrow> <mrow> <mn>2</mn> <mi>a</mi> </mrow> </mfrac> </mrow>$


Here is how the equation will look like when presented on HTML pages.

$x=\frac{-b±\sqrt{{b}^{2}-4ac}}{2a}$