# latex2mathml
Pure Python library for LaTeX to MathML conversion
<table>
<tr>
<td>License</td>
<td><img src='https://img.shields.io/pypi/l/latex2mathml.svg' alt="License"></td>
<td>Version</td>
<td><img src='https://img.shields.io/pypi/v/latex2mathml.svg' alt="Version"></td>
</tr>
<tr>
<td>Travis CI</td>
<td><img src='https://travis-ci.org/roniemartinez/latex2mathml.svg?branch=master' alt="Travis CI"></td>
<td>Coverage</td>
<td><img src='https://codecov.io/gh/roniemartinez/latex2mathml/branch/master/graph/badge.svg' alt="CodeCov"></td>
</tr>
<tr>
<td>Supported versions</td>
<td><img src='https://img.shields.io/pypi/pyversions/latex2mathml.svg' alt="Python Versions"></td>
<td>Wheel</td>
<td><img src='https://img.shields.io/pypi/wheel/latex2mathml.svg' alt="Wheel"></td>
</tr>
<tr>
<td>Status</td>
<td><img src='https://img.shields.io/pypi/status/latex2mathml.svg' alt="Status"></td>
<td>Downloads</td>
<td><img src='https://img.shields.io/pypi/dm/latex2mathml.svg' alt="Downloads"></td>
</tr>
</table>
## Support
If you like `latex2mathml` or if it is useful to you, show your support by buying me a coffee.
<a href="https://www.buymeacoffee.com/roniemartinez" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
## Installation
```bash
pip install latex2mathml
```
## Usage
### Python
```python
import latex2mathml.converter
latex_input = "<your_latex_string>"
mathml_output = latex2mathml.converter.convert(latex_input)
```
### Command-line
```shell
% latex2mathml -h
usage: l2m [-h] [-V] [-t TEXT | -f FILE]
Pure Python library for LaTeX to MathML conversion
optional arguments:
-h, --help show this help message and exit
-V, --version Show version
required arguments:
-t TEXT, --text TEXT Text
-f FILE, --file FILE File
```
## Examples
### Identifiers, Numbers and Operators
<table>
<tr>
<th>LaTeX Input</th>
<th>MathML Output</th>
</tr>
<tr>
<td valign="top"><pre lang="latex">x</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<mi>x</mi>
</mrow>
</math>
</pre></td>
</tr>
<tr>
<td valign="top"><pre lang="latex">xyz</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<mi>x</mi>
<mi>y</mi>
<mi>z</mi>
</mrow>
</math>
</pre></td>
</tr>
<tr>
<td valign="top"><pre lang="latex">3</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<mn>3</mn>
</mrow>
</math>
</pre></td>
</tr>
<tr>
<td valign="top"><pre lang="latex">444</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<mn>444</mn>
</mrow>
</math>
</pre></td>
</tr>
<tr>
<td valign="top"><pre lang="latex">12.34</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<mn>12.34</mn>
</mrow>
</math>
</pre></td>
</tr>
<tr>
<td valign="top"><pre lang="latex">12x</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<mn>12</mn>
<mi>x</mi>
</mrow>
</math>
</pre></td>
</tr>
<tr>
<td valign="top"><pre lang="latex">3-2</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<mn>3</mn>
<mo>−</mo>
<mn>2</mn>
</mrow>
</math>
</pre></td>
</tr>
</table>
### Subscripts and Superscripts
<table>
<tr>
<th>LaTeX Input</th>
<th>MathML Output</th>
</tr>
<tr>
<td valign="top"><pre lang="latex">a_b</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<msub>
<mi>a</mi>
<mi>b</mi>
</msub>
</mrow>
</math>
</pre></td>
</tr>
<tr>
<td valign="top"><pre lang="latex">a^b</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<msup>
<mi>a</mi>
<mi>b</mi>
</msup>
</mrow>
</math>
</pre></td>
</tr>
<tr>
<td valign="top"><pre lang="latex">a_b^c</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<msubsup>
<mi>a</mi>
<mi>b</mi>
<mi>c</mi>
</msubsup>
</mrow>
</math>
</pre></td>
</tr>
</table>
### Fractions
<table>
<tr>
<th>LaTeX Input</th>
<th>MathML Output</th>
</tr>
<tr>
<td valign="top"><pre lang="latex">\frac{1}{2}</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<mfrac>
<mrow>
<mn>1</mn>
</mrow>
<mrow>
<mn>2</mn>
</mrow>
</mfrac>
</mrow>
</math>
</pre></td>
</tr>
</table>
### Roots
<table>
<tr>
<th>LaTeX Input</th>
<th>MathML Output</th>
</tr>
<tr>
<td valign="top"><pre lang="latex">\sqrt{2}</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<msqrt>
<mrow>
<mn>2</mn>
</mrow>
</msqrt>
</mrow>
</math>
</pre></td>
</tr>
<tr>
<td valign="top"><pre lang="latex">\sqrt[3]{2}</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<mroot>
<mrow>
<mn>2</mn>
</mrow>
<mrow>
<mn>3</mn>
</mrow>
</mroot>
</mrow>
</math>
</pre></td>
</tr>
</table>
### Matrices
<table>
<tr>
<th>LaTeX Input</th>
<th>MathML Output</th>
</tr>
<tr>
<td valign="top"><pre lang="latex">\begin{matrix}a & b \\ c & d \end{matrix}</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<mtable>
<mtr>
<mtd>
<mi>a</mi>
</mtd>
<mtd>
<mi>b</mi>
</mtd>
</mtr>
<mtr>
<mtd>
<mi>c</mi>
</mtd>
<mtd>
<mi>d</mi>
</mtd>
</mtr>
</mtable>
</mrow>
</math>
</pre></td>
</tr>
<tr>
<td valign="top"><pre lang="latex">\begin{matrix*}[r]a & b \\ c & d \end{matrix*}</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<mtable>
<mtr>
<mtd columnalign='right'>
<mi>a</mi>
</mtd>
<mtd columnalign='right'>
<mi>b</mi>
</mtd>
</mtr>
<mtr>
<mtd columnalig