How to render LaTeX math in Flutter

Updated 2026-11-17

The short answer

Use val_latex_flutter: a pure-Dart TeX engine with Flutter widgets, no WebView and no platform code. Math.tex renders one formula, MathText renders text with $...$ and $$...$$ in it (including while it streams), and MathSpan puts a formula inside Text.rich. If you render whole AI replies, gpt_markdown already uses val_latex for its math.

Install

bash
flutter pub add val_latex_flutter

One formula, text with formulas, a streaming reply

dart
import 'package:val_latex_flutter/val_latex_flutter.dart';

Math.tex(r'x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}', displayMode: true)

MathText(r'Euler wrote $e^{i\pi} + 1 = 0$ in 1748.')

MathText(reply, streaming: true) // a model's reply, as it arrives

Coming from flutter_math_fork

val_latex_flutter ships a compatibility import, so the first step is one line. Move to the native API when you're ready.

dart
// before
import 'package:flutter_math_fork/flutter_math.dart';
// after
import 'package:val_latex_flutter/flutter_math_compat.dart';

Why val_latex

  • Pure Dart: no WebView, no JavaScript, no platform channels.
  • TeX's own layout rules, with Latin Modern Math bundled.
  • Built for AI output: half-written formulas in a streaming reply don't throw; problems become diagnostics.
  • Supports the commands KaTeX and flutter_math_fork define (except flutter_math_fork's \cursor).

Frequently asked

How do I display LaTeX in Flutter?
Add val_latex_flutter and use Math.tex(r'...') for one formula or MathText for text that contains $...$ formulas.
Can I render math without a WebView?
Yes. val_latex is pure Dart and draws with Flutter's own canvas.
How do I render math in a chatbot reply?
Use gpt_markdown for the whole reply; it renders the math with val_latex and the rest of the Markdown around it.
val_latex val_latex docs