Skip to content
Talk to an engineerRequest access

Supported LaTeX

What val_latex understands — LaTeX and AMS math, environments, chemistry, units, physics, diagrams, text tables and lists, macros and Unicode input.

val_latex reads the LaTeX math that people and models write: the LaTeX kernel and AMS math, the common packages, and the names KaTeX and flutter_math_fork define. LatexCatalog.instance lists every name the parser accepts, read from the same tables the parser uses — in 0.1.4 that is more than 4,400 command names and 88 environments.

final catalog = LatexCatalog.instance;
print(catalog.allCommands.contains(r'\frac')); // true
print(catalog.environments.contains('align')); // true
print(catalog.extension(LatexExtension.physics).contains(r'\dv')); // true
Area Examples
Core LaTeX and AMS math fractions, roots, scripts and limits, accents, \left…\middle…\right, delimiters at every size, every math alphabet (\mathbb, \mathcal, \mathfrak, \mathscr…), \boxed, \cancel, \overbrace
Environments align, gather, multline, split, cases, the matrix family, array with rules and \multicolumn, subequations, CD
Equation numbers automatic numbering in equation, align and the rest, \tag, \notag, \label with \ref/\eqref
Packages mathtools, mhchem (\ce, \pu), siunitx, physics, diffcoeff and derivative, commath, nccmath, empheq, esint, tensor, stmaryrd, wasysym, unicode-math names
Diagrams tikzcd commutative diagrams, CD, and bussproofs prooftree
Text \text with math inside, tabular, tabularx and booktabs rules, itemize, enumerate and description lists
Macros \def, \newcommand, \newenvironment, \NewDocumentCommand, \DeclareMathOperator, \DeclarePairedDelimiter, TeX conditionals and registers
Colour \color, \textcolor, \colorbox; 148 CSS names and xcolor’s dvips names (NavyBlue), \definecolor, mixes (red!30!blue)
Unicode input α, ∑, x², a₁ typed directly

Common package commands such as \abs, \dv, \sfrac, \vv and \celsius work without loading anything, wherever nothing else defines the name (LatexCatalog.instance.fallbacks).

An align environment numbered (1) and tagged (*), then cases for |x| and a 2 by 2 matrix

Two chemical equations, g = 9.81 m s⁻², and an ordinary derivative plus a partial derivative equal to an expectation value

Command sets that change what existing names mean are extensions, chosen with ParseOptions.extensions:

LatexExtension Commands Default
mhchem \ce, \pu on
siunitx \num, \si, \SI, \qty, \unit, \ang, ranges and lists (a subset) on
physics \abs, \norm, \qty, \dv, \pdv, \expval, \mel, \comm, \vb, \grad… (a subset) off

The physics extension is off because, like the LaTeX package, it redefines \div, \Re, \Im and siunitx’s \qty. Its other commands work without it. To turn it on, keep the defaults and add it:

const options = ParseOptions(
extensions: {...LatexExtension.defaults, LatexExtension.physics},
physics: PhysicsOptions(italicDiff: true),
);

PhysicsOptions mirrors the package options: trig (default true), italicDiff (default false) and arrowDel (default false).

A commutative square with arrows f, g, h and k, and a proof tree deriving B from A and A → B

Some tikzcd options are read but not applied; see Limitations.

A booktabs table with a spanning header and a bold cell, and a numbered list of three steps

Text inside a formula is shaped by Flutter’s text engine, so every script your fonts cover shapes correctly; see Styling and fonts. \caption in a table is unnumbered unless you set ParseOptions.captionLabel (for example 'Table').

Define macros in the source with \def, \newcommand, \newenvironment, \NewDocumentCommand, \DeclareMathOperator or \DeclarePairedDelimiter. A definition lasts until the end of its formula. To share definitions across formulas, create one table with newMacroTable(), define into it with \gdef, and pass it to every formula that should see them:

class Formulas extends StatelessWidget {
const Formulas({super.key});
/// One table, passed to every formula that should see the definitions.
static final macros = newMacroTable();
/// Defines the macros once. \gdef is global, so they stay in the table.
static void define() => parseLatex(
r'\gdef\RR{\mathbb{R}} \gdef\norm#1{\left\lVert #1 \right\rVert}',
macros: macros,
);
@override
Widget build(BuildContext context) {
return Column(
children: [
Math.tex(r'f \colon \RR^n \to \RR', displayMode: true, macros: macros),
Math.tex(r'\norm{x + y} \le \norm{x} + \norm{y}', macros: macros),
],
);
}
}

Call Formulas.define() once, for example in main(), before the formulas are built. MathText and MathSpan take macros too. A formula with a shared table is not cached (its parse depends on what was defined before).

For a fixed set, ParseOptions(macros: {r'\RR': r'\mathbb{R}'}) is simpler: the name with its backslash, and the replacement text, with #1…#9 for arguments.

Models write LaTeX that is almost right. Where the intent is clear, val_latex reads it and records a warning instead of failing:

Input Read as Warning
\\frac{a}{b} (backslashes doubled by JSON) \frac{a}{b} doubledBackslashes
a &= b \\ &= c with no environment an aligned block implicitAlignment
x^2' {x^2}' primeAfterSuperscript
a blank line inside math a line break paragraphInMath

Warnings never stop a formula rendering. See Differences from KaTeX for the full list of choices like these.