Skip to content
Talk to an engineerRequest access

val_latex

LaTeX math for Dart and Flutter — a pure-Dart TeX engine, and Flutter widgets for formulas, text with formulas in it, and LLM replies while they stream.

MathText(reply, streaming: true)

val_latex renders LaTeX math in Dart and Flutter. It is two packages: a pure-Dart engine that parses formulas and lays them out with TeX’s rules, and a Flutter package that draws them — one formula, a formula inside a paragraph, or a whole reply with $…$ and $$…$$ in it, while it is still arriving.

Terminal window
flutter pub add val_latex_flutter

Then follow Getting started.

Package Use it for
val_latex The engine. Parses LaTeX, lays it out, finds formulas in text, and turns a formula into speech or normalised LaTeX. No Flutter dependency: it runs on the Dart VM, in Flutter, on servers and compiled to JavaScript.
val_latex_flutter The widgets: Math.tex for one formula, MathSpan for math inside Text.rich, MathText for text with formulas in it, MathTheme, and MathPainter for your own canvas. It re-exports val_latex, so one import gives you both.

An inline formula, then a sum in display style with the equation number (1) at the right margin Text with an inline formula, a centred display formula, and prices that stay text An align environment with a number and a tag, cases and a matrix Chemical equations, a quantity with units, and physics derivatives A commutative diagram and a proof tree Arabic notation laid out right to left, with Arabic-Indic digits and Arabic operator names

Each image is rendered from the real package by its screenshot generator (val_latex_flutter/tool/screenshots/), at 18 px in a light Material 3 theme; the page about each feature shows the code behind its picture.

Pure Dart

No WebView, no JavaScript, no platform code. The same engine runs in Flutter on every platform, on a server and on the web.

TeX's layout

Spacing, scripts and limits follow TeX’s rules and the OpenType MATH table of the font. Latin Modern Math is bundled, with STIX Two Math for the symbols it lacks.

Made for model output

Bad input never throws: a mistake is drawn in place and the rest renders. Unfinished input renders as far as it goes while it streams.

Fits the screen

Long display formulas break into lines at relations and operators; what cannot break scrolls, shrinks or clips.

It also does what apps need around a formula: selection that copies LaTeX, taps that report the part tapped, highlights, keyboard navigation, spoken labels for screen readers, theming, right-to-left math, and any OpenType math font.

Both packages are BSD 3-Clause. The bundled fonts keep their own licences: the GUST Font License for Latin Modern, the SIL Open Font License for STIX Two Math.