Pure Python library for LaTeX to MathML conversion.
Project description
![version](https://img.shields.io/pypi/v/latex2mathml.svg)![license](https://img.shields.io/pypi/l/latex2mathml.svg)![status](https://img.shields.io/pypi/status/latex2mathml.svg)
# latex2mathml
Pure Python library for LaTeX to MathML conversion.
## Usage
```python
import latex2mathml.converter
latex_input = "<your_latex_string>"
mathml_output = latex2mathml.converter.convert(latex_input)
```
## 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 columnalign='right'>
<mi>c</mi>
</mtd>
<mtd columnalign='right'>
<mi>d</mi>
</mtd>
</mtr>
</mtable>
</mrow>
</math>
</pre></td>
</tr>
<tr>
<td valign="top"><pre lang="latex">
A_{m,n} =
\begin{bmatrix}
a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\
a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m,1} & a_{m,2} & \cdots & a_{m,n}
\end{bmatrix}
</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<msub>
<mi>A</mi>
<mrow>
<mi>m</mi>
<mi>,</mi>
<mi>n</mi>
</mrow>
</msub>
<mo>=</mo>
<mo>[</mo>
<mtable>
<mtr>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mn>1</mn>
<mi>,</mi>
<mn>1</mn>
</mrow>
</msub>
</mtd>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mn>1</mn>
<mi>,</mi>
<mn>2</mn>
</mrow>
</msub>
</mtd>
<mtd>
<mo>⋯</mo>
</mtd>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mn>1</mn>
<mi>,</mi>
<mi>n</mi>
</mrow>
</msub>
</mtd>
</mtr>
<mtr>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mn>2</mn>
<mi>,</mi>
<mn>1</mn>
</mrow>
</msub>
</mtd>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mn>2</mn>
<mi>,</mi>
<mn>2</mn>
</mrow>
</msub>
</mtd>
<mtd>
<mo>⋯</mo>
</mtd>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mn>2</mn>
<mi>,</mi>
<mi>n</mi>
</mrow>
</msub>
</mtd>
</mtr>
<mtr>
<mtd>
<mo>⋮</mo>
</mtd>
<mtd>
<mo>⋮</mo>
</mtd>
<mtd>
<mo>⋱</mo>
</mtd>
<mtd>
<mo>⋮</mo>
</mtd>
</mtr>
<mtr>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mi>m</mi>
<mi>,</mi>
<mn>1</mn>
</mrow>
</msub>
</mtd>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mi>m</mi>
<mi>,</mi>
<mn>2</mn>
</mrow>
</msub>
</mtd>
<mtd>
<mo>⋯</mo>
</mtd>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mi>m</mi>
<mi>,</mi>
<mi>n</mi>
</mrow>
</msub>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</math>
</pre></td>
</tr>
</table>
### Unit Test
- [pytest](https://github.com/pytest-dev/pytest)
- [pytest-cov](https://github.com/pytest-dev/pytest-cov)
- [pytest-html](https://github.com/pytest-dev/pytest-html)
### Unit Testing
```bash
pytest -v --show-capture=no --cov="." --cov-report=html --html=result/report.html --self-contained-html tests
```
### References
#### LaTeX
* https://en.wikibooks.org/wiki/LaTeX/Mathematics
* http://artofproblemsolving.com/wiki/index.php?title=Main_Page
* http://milde.users.sourceforge.net/LUCR/Math/
* http://www.forkosh.com/mimetextutorial.html
#### MathML
* http://www.xmlmind.com/tutorials/MathML/
### Author
* [Ronie Martinez](mailto:ronmarti18@gmail.com)
# latex2mathml
Pure Python library for LaTeX to MathML conversion.
## Usage
```python
import latex2mathml.converter
latex_input = "<your_latex_string>"
mathml_output = latex2mathml.converter.convert(latex_input)
```
## 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 columnalign='right'>
<mi>c</mi>
</mtd>
<mtd columnalign='right'>
<mi>d</mi>
</mtd>
</mtr>
</mtable>
</mrow>
</math>
</pre></td>
</tr>
<tr>
<td valign="top"><pre lang="latex">
A_{m,n} =
\begin{bmatrix}
a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\
a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m,1} & a_{m,2} & \cdots & a_{m,n}
\end{bmatrix}
</pre></td>
<td valign="top"><pre lang="html">
<math>
<mrow>
<msub>
<mi>A</mi>
<mrow>
<mi>m</mi>
<mi>,</mi>
<mi>n</mi>
</mrow>
</msub>
<mo>=</mo>
<mo>[</mo>
<mtable>
<mtr>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mn>1</mn>
<mi>,</mi>
<mn>1</mn>
</mrow>
</msub>
</mtd>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mn>1</mn>
<mi>,</mi>
<mn>2</mn>
</mrow>
</msub>
</mtd>
<mtd>
<mo>⋯</mo>
</mtd>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mn>1</mn>
<mi>,</mi>
<mi>n</mi>
</mrow>
</msub>
</mtd>
</mtr>
<mtr>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mn>2</mn>
<mi>,</mi>
<mn>1</mn>
</mrow>
</msub>
</mtd>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mn>2</mn>
<mi>,</mi>
<mn>2</mn>
</mrow>
</msub>
</mtd>
<mtd>
<mo>⋯</mo>
</mtd>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mn>2</mn>
<mi>,</mi>
<mi>n</mi>
</mrow>
</msub>
</mtd>
</mtr>
<mtr>
<mtd>
<mo>⋮</mo>
</mtd>
<mtd>
<mo>⋮</mo>
</mtd>
<mtd>
<mo>⋱</mo>
</mtd>
<mtd>
<mo>⋮</mo>
</mtd>
</mtr>
<mtr>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mi>m</mi>
<mi>,</mi>
<mn>1</mn>
</mrow>
</msub>
</mtd>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mi>m</mi>
<mi>,</mi>
<mn>2</mn>
</mrow>
</msub>
</mtd>
<mtd>
<mo>⋯</mo>
</mtd>
<mtd>
<msub>
<mi>a</mi>
<mrow>
<mi>m</mi>
<mi>,</mi>
<mi>n</mi>
</mrow>
</msub>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</math>
</pre></td>
</tr>
</table>
### Unit Test
- [pytest](https://github.com/pytest-dev/pytest)
- [pytest-cov](https://github.com/pytest-dev/pytest-cov)
- [pytest-html](https://github.com/pytest-dev/pytest-html)
### Unit Testing
```bash
pytest -v --show-capture=no --cov="." --cov-report=html --html=result/report.html --self-contained-html tests
```
### References
#### LaTeX
* https://en.wikibooks.org/wiki/LaTeX/Mathematics
* http://artofproblemsolving.com/wiki/index.php?title=Main_Page
* http://milde.users.sourceforge.net/LUCR/Math/
* http://www.forkosh.com/mimetextutorial.html
#### MathML
* http://www.xmlmind.com/tutorials/MathML/
### Author
* [Ronie Martinez](mailto:ronmarti18@gmail.com)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
latex2mathml-2.1.0.tar.gz
(60.7 kB
view hashes)