Skip to content
Talk to an engineerRequest access

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';
  1. Parse — parseLatex(source) turns LaTeX into a tree of nodes, each with its source span, plus diagnostics. It never throws for bad input.
  2. Lay out — layoutFormula(result) sets the tree with TeX’s rules and the font’s OpenType MATH table, and returns a MathLayout: a display list of glyphs, rules, lines, paths and text runs, positioned in em. renderLatex(source) does both steps.
  3. Draw — paint the display list on any canvas. In Flutter, MathPainter does 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 em
toSpeech(result); // "a over b"
toLatex(result); // "\frac{a}{b}"

The version of this package.

const valLatexVersion = '0.1.4';