KaTeX-compatible math rendering for Flutter, on every platform, including
the web. Wraps the pure-Dart ratex package (which drives the
Rust RaTeX engine) and adds:
RatexMath: a widget that lays out a LaTeX formula and paints it with the bundled KaTeX fonts. Inherits the ambient text color; reports parse errors (with source spans) througherrorBuilder.RatexPainter: the underlyingCustomPainter, for painting display lists onto your own canvas.- Automatic native builds: the
ratex_ffiRust crate is compiled by cargokit duringflutter buildon Android, iOS, Linux, macOS, and Windows. Rust is the only extra build-time requirement, and precompiled binaries can remove even that. - Bundled fonts: the KaTeX fonts ship with the package and are
referenced as
packages/ratex_flutter/<family>, so apps need no font configuration. (Fonts are SIL OFL 1.1; seelib/fonts/.)
import 'package:ratex_flutter/ratex_flutter.dart';
// Optional but recommended: eager init in main() so load errors surface
// early and all later renders are synchronous.
await RatexFlutter.ensureInitialized();
// Anywhere in your tree:
RatexMath(r'\frac{-b \pm \sqrt{b^2-4ac}}{2a}', fontSize: 28)The full package:ratex API is re-exported: Ratex.renderDisplayList,
Ratex.renderSvg, custom backends, options, and models.
Flutter web has no dart:ffi, so the same engine runs as WebAssembly:
- Build the binary:
melos run native:build:web(in this repo), orcargo build --release --target wasm32-unknown-unknowninnative/ratex-ffi. - Serve
ratex_ffi.wasmfrom your app'sweb/directory (files there ship verbatim with a web build), matching the defaultRatex.wasmUrl. Or bundle it as an asset and passwasmAsset:toRatexFlutter.ensureInitialized, or setRatex.wasmBytesyourself.
example/ is a formula playground: presets, live LaTeX editing,
font-size slider, display/inline toggle. flutter run on any platform
(see its README for the one-step web setup).