Pure Python library for LaTeX to MathML conversion
latex2mathml is a pure Python library for converting LaTeX math expressions to MathML. It supports a wide range of LaTeX commands and environments. The current version is 3.79.0 and it maintains an active release cadence, with recent updates.
Warnings
- breaking The primary `convert` function moved from the top-level `latex2mathml` module to `latex2mathml.converter`. Direct import `from latex2mathml import convert` will fail.
- gotcha The library has limitations in supported LaTeX commands, particularly for complex structures. Examples of often unsupported features include newlines (`\\`) outside of matrix/align environments, alignment characters (`&`) outside matrix/align environments, and complicated sub/superscripts (`<mmultiscripts>`).
- gotcha The `\begin{align}` environment is experimentally supported and may produce non-recommended or poorly formatted MathML output, as it is internally implemented using a matrix environment.
- gotcha MathML rendering is highly dependent on the browser and its installed fonts. Chromium-based browsers, in particular, may display MathML incorrectly without specific CSS font configurations (e.g., using STIX fonts). This is a browser limitation, not a library issue.
Install
-
pip install latex2mathml
Imports
- convert
from latex2mathml.converter import convert
Quickstart
from latex2mathml.converter import convert latex_input = r'E = mc^2' mathml_output = convert(latex_input) print(mathml_output)