katex-parser
A Rust port of the KaTeX parser: lexes and parses LaTeX
math expressions with full macro expansion into a typed ParseNode AST, and
renders that AST to Unicode text.
Usage
use ;
// Parse LaTeX into a typed AST.
let nodes = parse?;
// Render the AST as Unicode text.
let text = render;
assert_eq!;
# Ok::
Settings configures display mode, user macros, strictness, trust policy, and a
persistent macro store shared across parses:
use ;
use HashMap;
let mut settings = new;
settings.display_mode = true; // display-style fractions/matrices
settings.macro_store = Some;
settings.global_group = true; // persist \newcommand across parses
parse?;
let nodes = parse?; // \R is still defined
Features
- Typed AST — every construct becomes a
ParseNodevariant (GenFrac,Sqrt,Array,Op,SupSub, …), mirroring KaTeX. - Macro expansion —
\def/\gdef/\edef/\xdef,\newcommand, argument substitution, delimiter arguments,\@ifnextchar,\noexpand. - Environments —
array,matrix,cases,aligned/align,gather,equation,subarray, and commutative-diagramCD. - Unicode rendering backend — block fractions, matrices, boxes, and
commutative diagrams with baseline alignment, plus font mapping
(
\mathbb,\mathbf,\mathcal, …) and Unicode script sub/superscripts. - Zero dependencies.
License
AGPL-3.0. See LICENSE.