The Dart engine
val_latex without Flutter — parse, lay out, find formulas in text, speak them and write them back as LaTeX, on the VM, a server or the web.
val_latex is the engine behind the widgets. It has no Flutter dependency:
it runs on the Dart VM, in an isolate, on a server, in a command-line tool
and compiled to JavaScript. Everything here is also available from
package:val_latex_flutter/val_latex_flutter.dart.
import 'package:val_latex/val_latex.dart';The pipeline
Section titled “The pipeline”- Parse —
parseLatex(source)turns LaTeX into a tree of nodes, each with its source span, plus diagnostics. It never throws for bad input. - Lay out —
layoutFormula(result)sets the tree with TeX’s rules and the font’s OpenTypeMATHtable, and returns aMathLayout: a display list of glyphs, rules, lines, paths and text runs, positioned in em.renderLatex(source)does both steps. - Draw — paint the display list on any canvas. In Flutter,
MathPainterdoes it; elsewhere, read the items yourself.
Next to the pipeline: MathScanner finds formulas in text, toSpeech reads
a formula aloud, toLatex writes it back as normalised LaTeX, and
hitTestLayout maps a point on the layout back to the source.
final result = parseLatex(r'\frac{a}{b}');renderLatex(r'\frac{a}{b}'); // the layout: boxes and glyphs in emtoSpeech(result); // "a over b"toLatex(result); // "\frac{a}{b}"ParsingparseLatex, ParseOptions, diagnostics, macros and extensions.
LayoutrenderLatex, layoutFormula, LayoutOptions, line breaking, fonts and background layout.
Finding math in textMathScanner: $…$, $$…$$, \(…\) and \[…\] in chat and Markdown text.
Speech, LaTeX and hit testingtoSpeech, toLatex, hitTestLayout, selection units and the catalog.
Parse treeEvery node class parseLatex produces, and the values the nodes carry.
Display listEvery display item a layout paints, and the path commands of outlines.
API reference
Section titled “API reference”valLatexVersion
Section titled “valLatexVersion”The version of this package.
const valLatexVersion = '0.1.4';