Skip to main content

ratex 0.0.1 copy "ratex: ^0.0.1" to clipboard
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 (MediaQuery text scaler, overridable via textScaler), and reports its baseline, so inline formulas line up with text in baseline-aligned Rows and WidgetSpans. Reports parse errors (with source spans) through errorBuilder.
  • Accessibility: screen readers announce each formula with a label derived from its LaTeX source (e.g. Mathematical expression: x^2 + y^2); pass semanticLabel for a spoken description such as 'The quadratic formula'.
  • RatexPainter: the underlying CustomPainter, for painting display lists onto your own canvas.
  • Automatic native builds: the ratex_ffi Rust crate is compiled by cargokit during flutter build on 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; see lib/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:

  1. Build the binary: melos run native:build:web (in this repo), or cargo build --release --target wasm32-unknown-unknown in this package's rust/ directory.
  2. Serve ratex_ffi.wasm from your app's web/ directory (files there ship verbatim with a web build), matching the default Ratex.wasmUrl. Or bundle it as an asset and pass wasmAsset: to RatexFlutter.ensureInitialized, or set Ratex.wasmBytes yourself.

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).

0
likes
150
points
681
downloads

Documentation

API reference

Publisher

verified publishermanymath.com

Weekly Downloads

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.

Repository (GitHub)
View/report issues

Topics

#latex #katex #math #rendering #ffi

License

MIT (license)

Dependencies

flutter, ratex_dart

More

Packages that depend on ratex

Packages that implement ratex