ratex 0.0.1
ratex: ^0.0.1 copied to clipboard
KaTeX-compatible math rendering for Flutter. Builds the Rust RaTeX engine with cargokit, paints formulas with bundled KaTeX fonts, and runs on the web via WebAssembly.
ratex #
KaTeX-compatible math rendering for Flutter, on every platform, including
the web. Wraps the pure-Dart
ratex_dart 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, scales with the user's text size (MediaQuerytext scaler, overridable viatextScaler), and reports its baseline, so inline formulas line up with text in baseline-alignedRows andWidgetSpans. Reports parse errors (with source spans) througherrorBuilder.- Accessibility: screen readers announce each formula with a label
derived from its LaTeX source (e.g.
Mathematical expression: x^2 + y^2); passsemanticLabelfor a spoken description such as'The quadratic formula'. 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 currently required at build time; precompiled binaries are planned. - Bundled fonts: the KaTeX fonts ship with the package and are
referenced as
packages/ratex/<family>, so apps need no font configuration. (Fonts are SIL OFL 1.1; seelib/fonts/.)
import 'package:ratex/ratex.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_dart API is re-exported: Ratex.renderDisplayList,
Ratex.renderSvg, custom backends, options, and models.
Web #
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-unknownin this package'srust/directory. - 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 #
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).