Skip to main content

mathra

mathra

Math LaTeX to accessible SVG, without a TeX install, chemistry (chemfig structures, reaction schemes, mechanisms) and commutative diagrams (tikz-cd, xymatrix) included. Every SVG carries the phrase a screen reader says, in 16 languages, and draws with the STIX Two Math font embedded, so it looks the same everywhere. Try it in the browser.

pip install mathra

Wheels for Linux, macOS and Windows, for Python 3.9 and later; nothing else to install.

Usage

import mathra

svg = mathra.tex_to_svg(r"x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}")
open("quadratic.svg", "w", encoding="utf-8").write(svg)

r = mathra.render(r"\frac{3}{4}", locale="fr")
r["speech"]        # 'trois quarts'
r["warnings"]      # [] — broken LaTeX is drawn anyway and reported here (E-REC-*)

mathra.tex_to_svg(r"\sum_{n=1}^{\infty} \frac{1}{n^2}", display=False)   # inline style
mathra.tex_to_svg(r"\vertA\vert", strict=True)                           # ValueError, like TeX
mathra.render("sqrt(x)/2", input="asciimath")["speech"]                   # also input="mathml"
mathra.render(r"\chemfig{H_3C-*6(=-=-=-)}")["speech"]                     # 'structure of C7 H8, with 1 aromatic ring'
tex_to_svg(tex, locale="en", *, display=True, strict=False, input="latex", braille=None, animate=False, steps=False) The SVG as a string.
render(tex, locale="en", *, display=True, strict=False, input="latex", braille=None, animate=False, steps=False) A dict: svg, speech, text, braille, braille_code, tree, applied, warnings.
tex_to_tree(tex, locale="en", *, display=True, strict=False, input="latex", braille=None, animate=False, steps=False) The tree of meaning as JSON.
locales() [{"code": "en", "name": "English"}, …]: en, pt-BR, es, fr, de, it, ru, zh, ja, ko, hi, ar, id, tr, nl, pl.

input is "latex", "mathml" or "asciimath"; MathML passed as LaTeX, starting with <math, is recognized on its own. braille is "cmu" or "nemeth"; by default the locale's (CMU in pt-BR and es, Nemeth elsewhere). Errors are ValueError. Types are included (py.typed).

What it draws

Every image below is an SVG written by mathra, on a white card so it reads well on dark pages.

Quadratic formula
Quadratic formula
Gaussian integral
Gaussian integral
m × n matrix with dots
Matrix with dots
Piecewise definition
Piecewise definition
Chemical equation (mhchem)
Chemistry (\ce)
Quantity with units (siunitx)
Units (\SI)
Maxwell's equations
Maxwell's equations
Caffeine: fused rings (chemfig)
Caffeine (\chemfig)
Pullback with bent arrows (tikz-cd)
Commutative diagram (tikz-cd)
Nitration of benzene: structures, mhchem and conditions on the arrow
Reaction scheme (\schemestart)

Chemistry and diagrams

chemfig works inside any equation: structures (rings, wedges, Lewis marks), reaction schemes (\schemestart … \arrow{->[above][below]} … \schemestop) and mechanism arrows (\chemmove). The speech gives each structure's molecular formula, counted from the drawing. Commutative diagrams come in amscd, tikz-cd and xymatrix. Every construction, drawn live, is in the gallery and the reference.

What the SVG carries

Speech in <title> linked with aria-labelledby, the source equation and the tree of meaning in <metadata>, color from the page (currentColor), size in em, a selectable text layer and ids unique to each equation. The same input always gives the same bytes, in Python and in every other package.

With animate=True the equation writes itself in the browser, with CSS alone: each glyph fades in, each rule grows and each line is drawn, in the order the layout set them, in about three seconds (nothing moves with prefers-reduced-motion); steps=True numbers each element by that order (data-step) with no animation. Both are off by default, and without them the SVG is unchanged byte for byte.

Other math fonts

STIX Two Math is embedded and is the default. Any OpenType math font (an .otf or .ttf with a MATH table, such as Libertinus Math or Fira Math) can be loaded from a path or its bytes:

font = mathra.load_font("LibertinusMath-Regular.otf")  # Font(id=0, name='Libertinus Math')
mathra.tex_to_svg(r"e^{i\pi} + 1 = 0", font=font)

A font without a MATH table raises ValueError. The SVG carries the font's outlines, so check that its license allows that.

The fonts of mathfonts, a catalog of math fonts checked with mathra, load by their name. Nothing is downloaded until you ask; a font is downloaded once, kept in ~/.cache/mathra/fonts ($XDG_CACHE_HOME or $MATHRA_CACHE when set, cache= for another folder, cache=False for none) and refused if it does not match the catalog's sha256:

mathra.catalog_fonts()  # [{'slug': 'euler-math', 'name': 'Euler Math', 'license': 'OFL-1.1', ...}, ...]
font = mathra.load_font_from_catalog("euler-math")
mathra.tex_to_svg(r"e^{i\pi} + 1 = 0", font=font)

All the fonts of the catalog are under licenses that let the SVG carry their outlines (OFL, GUST, Apache-2.0, MIT).

Also for JavaScript, Rust and the terminal

The same core is an npm package (@mathlabs/mathra), a Rust crate and a command-line tool: github.com/matheusmota-dev-br/mathra. Rules, languages and the full list of supported commands are there too.

License

The code is MIT or Apache-2.0; the embedded STIX Two Math font is under the SIL Open Font License 1.1.

Metadata

Release files for mathra 1.10.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mathra 1.10.1
File Size Uploaded Provenance Actions
mathra-1.10.1.tar.gz 1.1 MB With provenance Details for mathra-1.10.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for mathra 1.10.1
File Actions
mathra-1.10.1-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for mathra-1.10.1-cp39-abi3-win_amd64.whl
mathra-1.10.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for mathra-1.10.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
mathra-1.10.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for mathra-1.10.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
mathra-1.10.1-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for mathra-1.10.1-cp39-abi3-macosx_11_0_arm64.whl
mathra-1.10.1-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for mathra-1.10.1-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 9.3 MB

Release files / mathra-1.10.1.tar.gz

Download URL mathra-1.10.1.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
11c216a2a666cb0362de8300dc8cc51d04fcb4ea2323eca0c6c68848e2cac9ab
BLAKE2b-256 checksum
How to use checksums
36497bee37c5aabdf5de231aa9ab7c3c9d626990743953c98dea663627ddec90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

Release files / mathra-1.10.1-cp39-abi3-win_amd64.whl

Download URL mathra-1.10.1-cp39-abi3-win_amd64.whl
Size 1.5 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
1ce0c12a7b04363abeac9cbb7bb176235dd2566fb927f74e684ac3df944c0a23
BLAKE2b-256 checksum
How to use checksums
45c6fa45c1f78f5b37586fb91e4f77d509c49bbdc0b899a396182d9a3175ead5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

Release files / mathra-1.10.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL mathra-1.10.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.7 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
bb332bb9ce80e4f1f4ba831376050924f5bd4d969f63cd6f0ed0042bd25fea0c
BLAKE2b-256 checksum
How to use checksums
d3ce8e3633a0bbcdda83e71be1073786e77e94dc67c0996cc415dd7e4f0237e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

Release files / mathra-1.10.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL mathra-1.10.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 1.7 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
a335bcd00347e6df01bc34cc22ba3002be69c4c8071e1d6d35e9183cd7edf4c6
BLAKE2b-256 checksum
How to use checksums
c6c4c7709c615378e33eab235b35755ad5ae163db244c94befd2f54b1b74db3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

Release files / mathra-1.10.1-cp39-abi3-macosx_11_0_arm64.whl

Download URL mathra-1.10.1-cp39-abi3-macosx_11_0_arm64.whl
Size 1.6 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d4ae7a5ea9afc448636de2fef11f79af2ef3d60f35467fb9c1162b8c4cdfd8e8
BLAKE2b-256 checksum
How to use checksums
ad5cbd4d3ad3602a243a22a83a3557c7414f09ce9994ef1f0f792817cdc8a34f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

Release files / mathra-1.10.1-cp39-abi3-macosx_10_12_x86_64.whl

Download URL mathra-1.10.1-cp39-abi3-macosx_10_12_x86_64.whl
Size 1.6 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
1975adb52fd6bf22aca60c9afec89c14e3f4545540dd84c51756d62ababf66f2
BLAKE2b-256 checksum
How to use checksums
9c07927ef0b8a9e2c776aaab3dfb815d824516c900a10f0952bc83322a35d4cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

Security for mathra 1.10.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for mathra-1.10.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page