Skip to main content

Pure Python library for LaTeX to MathML conversion.

Project description

versionlicensestatus

latex2mathml

Pure Python library for LaTeX to MathML conversion.

Demo

latex2mathml Demo

Usage

import latex2mathml

latex_input = "<your_latex_string>"
mathml_output = latex2mathml.convert(latex_input)

Examples

Identifiers, Numbers and Operators

LaTeX Input
x
MathML Output
<math>
    <mrow>
        <mi>x</mi>
    </mrow>
</math>
LaTeX Input
xyz
MathML Output
<math>
    <mrow>
        <mi>x</mi>
        <mi>y</mi>
        <mi>z</mi>
    </mrow>
</math>
LaTeX Input
3
MathML Output
<math>
    <mrow>
        <mn>3</mn>
    </mrow>
</math>
LaTeX Input
444
MathML Output
<math>
    <mrow>
        <mn>444</mn>
    </mrow>
</math>
LaTeX Input
12.34
MathML Output
<math>
    <mrow>
        <mn>12.34</mn>
    </mrow>
</math>
LaTeX Input
12x
MathML Output
<math>
    <mrow>
        <mn>12</mn>
        <mi>x</mi>
    </mrow>
</math>
LaTeX Input
3-2
MathML Output
<math>
    <mrow>
        <mn>3</mn>
        <mo>&#x02212;</mo>
        <mn>2</mn>
    </mrow>
</math>

Subscripts and Superscripts

LaTeX Input
a_b
MathML Output
<math>
    <mrow>
        <msub>
            <mi>a</mi>
            <mi>b</mi>
        </msub>
    </mrow>
</math>
LaTeX Input
a^b
MathML Output
<math>
    <mrow>
        <msup>
            <mi>a</mi>
            <mi>b</mi>
        </msup>
    </mrow>
</math>
LaTeX Input
a_b^c
MathML Output
<math>
    <mrow>
        <msubsup>
            <mi>a</mi>
            <mi>b</mi>
            <mi>c</mi>
        </msubsup>
    </mrow>
</math>

Fractions

LaTeX Input
\frac{1}{2}
MathML Output
<math>
    <mrow>
        <mfrac>
            <mrow>
                <mn>1</mn>
            </mrow>
            <mrow>
                <mn>2</mn>
            </mrow>
        </mfrac>
    </mrow>
</math>

Roots

LaTeX Input
\sqrt{2}
MathML Output
<math>
    <mrow>
        <msqrt>
            <mrow>
                <mn>2</mn>
            </mrow>
        </msqrt>
    </mrow>
</math>
LaTeX Input
\sqrt[3]{2}
MathML Output
<math>
    <mrow>
        <mroot>
            <mrow>
                <mn>2</mn>
            </mrow>
            <mrow>
                <mn>3</mn>
            </mrow>
        </mroot>
    </mrow>
</math>

Matrices

LaTeX Input
\begin{matrix}a & b \\ c & d \end{matrix}
MathML Output
<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>
LaTeX Input
\begin{matrix*}[r]a & b \\ c & d \end{matrix*}
MathML Output
<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>
LaTeX Input
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}
MathML Output
<math>
    <mrow>
        <msub>
            <mi>A</mi>
            <mrow>
                <mi>m</mi>
                <mi>,</mi>
                <mi>n</mi>
            </mrow>
        </msub>
        <mo>&#x0003D;</mo>
        <mo>&#x0005B;</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>&#x022EF;</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>&#x022EF;</mo>
                </mtd>
                <mtd>
                    <msub>
                        <mi>a</mi>
                        <mrow>
                            <mn>2</mn>
                            <mi>,</mi>
                            <mi>n</mi>
                        </mrow>
                    </msub>
                </mtd>
            </mtr>
            <mtr>
                <mtd>
                    <mo>&#x022EE;</mo>
                </mtd>
                <mtd>
                    <mo>&#x022EE;</mo>
                </mtd>
                <mtd>
                    <mo>&#x022F1;</mo>
                </mtd>
                <mtd>
                    <mo>&#x022EE;</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>&#x022EF;</mo>
                </mtd>
                <mtd>
                    <msub>
                        <mi>a</mi>
                        <mrow>
                            <mi>m</mi>
                            <mi>,</mi>
                            <mi>n</mi>
                        </mrow>
                    </msub>
                </mtd>
            </mtr>
        </mtable>
        <mo>&#x0005D;</mo>
    </mrow>
</math>

References

LaTeX
MathML

Author

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-1.0.9.zip (63.6 kB view details)

Uploaded Source

File details

Details for the file latex2mathml-1.0.9.zip.

File metadata

  • Download URL: latex2mathml-1.0.9.zip
  • Upload date:
  • Size: 63.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for latex2mathml-1.0.9.zip
Algorithm Hash digest
SHA256 44a85f9e7068cfc9edec19b171b76a34097c0637ba39eda75ed6d1fd030909c6
MD5 423a4915fd3fabaa2cc6d6af629fabe9
BLAKE2b-256 4ac715050078adc4be9930384035677cbe57b6294641e524e3221c05df14dd5b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page