Registry / serialization / latex2mathml

latex2mathml

JSON →
library3.81.0pypypi✓ verified 24d ago

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.

pip install latex2mathml
INSTALL
IMPORT
SIG · LATEX2MATHML
L
latex2mathml
serializationpythonv3.81.0
Install
1.6s avg
Import
236ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.81.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.252s · 18.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.220s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

convert
from latex2mathml.converter import convert
import latex2mathml; latex2mathml.convert(latex_input)
The direct import from the top-level 'latex2mathml' package for the 'convert' function was used in older versions (e.g., 1.x) but is now found within the 'converter' submodule.

Convert a simple LaTeX math string to MathML.

from latex2mathml.converter import convert latex_input = r'E = mc^2' mathml_output = convert(latex_input) print(mathml_output)
latex2mathml --version
Debug
Known issues
breakingThe primary `convert` function moved from the top-level `latex2mathml` module to `latex2mathml.converter`. Direct import `from latex2mathml import convert` will fail.
fix
Update imports to `from latex2mathml.converter import convert`.
affects: < 3.0.0 (exact version of change not specified, but observed in difference between v1.1.1 and current usage)
gotchaThe 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>`).
fix
Simplify LaTeX input where possible or consult the project's documentation/examples for supported syntax if encountering conversion issues.
affects: All versions
gotchaThe `\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.
fix
Review the MathML output carefully for `align` environments and consider alternative LaTeX structures if rendering issues occur.
affects: All versions
gotchaMathML 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.
fix
Provide appropriate CSS to specify MathML-compatible fonts (e.g., `STIX-Two-Math`) for web display if targeting browsers with known rendering issues.
affects: All versions (client-side rendering)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'latex2mathml.converter'
The `latex2mathml` library is either not installed or is installed in an environment not accessible by the Python interpreter.
fix
Ensure the library is installed using pip: `pip install latex2mathml`. If using a virtual environment, activate it before installation.
FileNotFoundError: [Errno 2] No such file or directory: '.../latex2mathml/unimathsymbols.txt'
This error typically occurs when an application using `latex2mathml` is packaged with tools like `cx_Freeze` or `PyInstaller`, which fail to include the `unimathsymbols.txt` data file in the executable bundle.
fix
When packaging the application, explicitly include the `unimathsymbols.txt` file (located in the `latex2mathml` installation directory, e.g., `site-packages/latex2mathml/`) in the build configuration (e.g., `include_files` for cx_Freeze or `datas` for PyInstaller), or modify the `symbols_parser.py` file in the `latex2mathml` library to use an absolute path or a path relative to the executable.
ValueError: Invalid LaTeX expression or unsupported command encountered
The input LaTeX string contains syntax that `latex2mathml` cannot parse or includes commands/environments that are not currently supported by the library. The library has specific limitations, such as unsupported newlines outside matrix/align environments or complex sub/superscripts.
fix
Review the LaTeX input for correctness and simplify complex expressions. Refer to the `latex2mathml` documentation for a list of supported LaTeX commands and environments. Adjust the LaTeX string to only use supported features.
Upgrade
Version history
3.81.0latest on PyPI · released Apr 15, 2026
Audit
Dependencies
pythonrequiredRequires Python 3.10 or newer.
Agent activity
7 hits · last 30 days
node
6
Resources
latex2mathml — pip install latex2mathml · libregistry