Math LaTeX to accessible SVG.
No TeX install. JavaScript, Python, Rust or the terminal.
mathra reads the equation (LaTeX, MathML or AsciiMath), builds a tree of meaning and draws it with numbered, tested rules. Every SVG says the equation out loud to screen readers and carries it in braille.
One small library, the same output everywhere: JavaScript, Python, Rust and the terminal.
The SVG's <title> carries the phrase a screen reader says: “1 over 2”, not “image”.
From Português to 日本語. The language changes how numbers are read and written (in pt-BR, 3,14 is one number and \sin is sen) and the language of the speech.
Typos and editor leftovers are fixed and reported as numbered warnings. Strict refuses them, like TeX.
MathML pasted from Word or Google Docs, AsciiMath like sum_(i=1)^n i^2: the same tree of meaning, the same drawing and speech. See the reference.
Every equation also comes out in braille: the CMU for Portuguese and Spanish, Nemeth for English, following their official documents and compared with MathCAT. How far to trust it.
Mean time per equation on the corpus. The same input always writes the same bytes.
Drawn live on this page. Click one to open it in the playground.
mathra next to KaTeX and MathJax on the same equations, including where it loses. Lower is better for time and size.
Loads KaTeX 0.16.22 and MathJax 3.2.2 from jsDelivr and times the three libraries on the 18 gallery equations, on your machine.
\SI, \sen, \divchave).noundefined; KaTeX with throwOnError and mhchem.bench/: cd bench && npm install && npm run compare.Pick your platform. All four packages run the same core, so an equation gives the same SVG, byte for byte, wherever it is converted.
Node, bundlers (Vite, webpack, esbuild) and browsers. Types included.
npm install @mathlabs/mathra
import { init, texToSvg, render } from "@mathlabs/mathra";
await init(); // browsers and bundlers; Node needs nothing
const svg = texToSvg("3,14", { locale: "pt-BR" });
const { speech, braille, warnings } = render("x^2");
render("sqrt(x)/2", { input: "asciimath" }); // or "mathml"
Python 3.9 and later, wheels for Linux, macOS and Windows. Types included.
pip install mathra
import mathra
svg = mathra.tex_to_svg(r"\sin x = 0.5")
r = mathra.render(r"\frac{3}{4}", locale="fr")
r["speech"] # 'trois quarts'
mathra.render("x^2", locale="pt-BR")["braille"] # '⠭⠡⠼⠃'
One binary, SVG to stdout or files; --batch for many at once.
cargo install mathra-cli
mathra 'x \le 2.75' -o inequality.svg
mathra '3,14 + \sin x' --locale pt-BR
mathra 'x = -1' --speech
mathra '\vertA\vert' --explain
mathra 'sum_(i=1)^n i' --from asciimath
mathra '\frac{3}{4}' -l pt-BR --braille
The core itself, for servers and native apps. API docs on docs.rs.
cargo add mathra
let r = mathra::convert("3.14", &mathra::Options::default())?;
println!("{}", r.svg);
println!("{}", r.speech);
<title>, linked with aria-labelledby.<metadata>.currentColor), size in em, baseline aligned with the text around it.By default mathra draws what it can and reports what it fixed, as E-REC-1 to E-REC-10 (spec/tolerance.md). Every rule that shapes the output is numbered in spec/rules.md; the Rules tab shows which ones acted on your equation.
Fractions, roots, scripts and limits, stretchy delimiters, matrices and array, cases and rcases, aligned, accents and braces, \text, alphabets, every amssymb symbol and negation, \cancel, \boxed, \colorbox, siunitx with ranges and lists, mhchem (\ce with labeled arrows, hydrates, isotopes, bonds), physics and braket, tensor indices, \newcommand and friends, amscd diagrams, and the computed \divchave and \contaarmada. Also MathML and AsciiMath as input. Every construction, with its drawing and its braille, is in the reference; the full list is in the README.