Code Monkey home page Code Monkey logo

latex2mathml's Introduction

latex2mathml

Pure Python library for LaTeX to MathML conversion

License Version
Travis CI Coverage
AppVeyor Supported versions
Wheel Implementation
Status Downloads
Show your support

Installation

pip install latex2mathml

Usage

import latex2mathml.converter

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

Examples

Identifiers, Numbers and Operators

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

Subscripts and Superscripts

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

Fractions

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

Roots

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

Matrices

LaTeX Input MathML Output
\begin{matrix}a & b \\ c & d \end{matrix}
<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>
        
\begin{matrix*}[r]a & b \\ c & d \end{matrix*}
<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>
        
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}
        
<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>
        

References

LaTeX

MathML

Continuous Integration

Author

latex2mathml's People

Contributors

roniemartinez avatar johnabell avatar askender avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.