Rust-LaTeX-Parser
LaTeX math parser for Rust. Takes a string, gives you an AST. No dependencies.
Install
[]
= { = "https://github.com/William-Selna/Rust-LaTeX-Parser" }
Usage
use ;
let tree = parse_equation;
match tree
You get back an EqNode tree. Render it, convert it, inspect it — that part's on you.
What it handles
Fractions (\frac{a}{b}, a/b), roots (\sqrt{x}), super/subscripts, matrices, cases, big operators with limits (\sum, \int, \prod), trig and log functions, accents (\hat, \vec, \bar), \left...\right delimiters, math fonts (\mathbb, \mathcal, etc.), binomials, over/underbraces, stacked relations, and 130+ symbols (Greek, arrows, set theory, relations, the usual).
You can also skip backslashes for common stuff — pi works, sqrt(x) works, int_0^1 works. Parens after barewords act as grouping, so sqrt(x+1) grabs the whole x+1.
The tree
19 variants:
Text // "x", "42", "α"
Space // inserted around operators
Seq // horizontal sequence
Sup
Sub
SupSub
Frac
Sqrt
BigOp
Accent
Limit
TextBlock // \text{...}
MathFont
Delimited
Matrix
Cases
Binom
Brace
StackRel
There's also EqMetrics (width/ascent/descent) if you need it for layout.
Symbol lookup
latex_to_unicode works standalone if you just need that:
use latex_to_unicode;
latex_to_unicode; // Some("α")
latex_to_unicode; // Some("→")
latex_to_unicode; // None
Error handling
It doesn't error. Bad input gives you a best-effort tree — unmatched braces get skipped, unknown commands turn into text nodes. I needed this for a live editor where the input is always half-finished.
Tests
95 tests — parser correctness, adversarial input (deep nesting, emoji, 10k tokens), real-world expressions (quadratic formula, Gaussian integral, Schrodinger, Maxwell), Greek alphabet coverage.
License
MIT