Integration
Get started by platform
Every target consumes the same display list from the Rust pipeline. Pick your stack below, then open the full guide on GitHub for versioning, fonts, and native build scripts.
Prefer trying formulas in the browser first? Live demo · Math gallery
Web (WASM)
Rust compiled to WebAssembly; Canvas 2D draws the display list. Use the published npm package and the optional ratex-formula web component.
- Install:
npm install ratex-wasm - Load KaTeX fonts CSS from the package and register the custom element or call the programmatic API.
<link rel="stylesheet" href="node_modules/ratex-wasm/fonts.css" />
<script type="module" src="node_modules/ratex-wasm/dist/ratex-formula.js"></script>
<ratex-formula latex="\frac{-b \pm \sqrt{b^2-4ac}}{2a}" font-size="48"></ratex-formula> iOS (Swift)
Swift / SwiftUI views over the C ABI; CoreGraphics renders the display list. SPM from the GitHub repo.
- In Xcode: File → Add Package Dependencies →
https://github.com/erweixin/RaTeX, select the RaTeX product. - Use
RaTeXFormula/RaTeXView; fonts load from the package on first render.
// SwiftUI
RaTeXFormula(latex: #"\frac{-b \pm \sqrt{b^2-4ac}}{2a}"#, fontSize: 24) Android (Kotlin)
AAR with JNI into the same native library; Canvas draws glyphs and rules. Published to Maven coordinates.
- Add
implementation("io.github.erweixin:ratex-android:…")(see README for current version). - Place
RaTeXViewin XML or Compose and setlatex/fontSizein code.
binding.mathView.latex = """\frac{-b \pm \sqrt{b^2-4ac}}{2a}"""
binding.mathView.fontSize = 24f Flutter (Dart FFI)
Dart FFI to `libratex_ffi`; `CustomPainter` renders the display list. Prebuilt iOS XCFramework + Android `.so` on pub.dev.
- Add
ratex_fluttertopubspec.yamland runflutter pub get. - Use
RaTeXWidget(latex: r'…', fontSize: 28).
RaTeXWidget(
latex: r'\frac{-b \pm \sqrt{b^2-4ac}}{2a}',
fontSize: 28,
onError: (e) => debugPrint('RaTeX: ' + e.toString()),
) React Native
Native views on iOS and Android; JS bundles the UI while Rust handles parse/layout in `.a` / `.so`.
- Install:
npm install ratex-react-nativethencd ios && pod install. - Use
RaTeXView/InlineTeX; fonts ship with the package.
import { RaTeXView } from 'ratex-react-native';
<RaTeXView
latex="\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}"
fontSize={24}
/> Server / CLI (PNG)
Rasterize the same display list to PNG with tiny-skia—CI snapshots, backends, or headless servers—no browser.
- From the repo root, use the
ratex-rendercrate (see README “Render to PNG”). - Pipe LaTeX stdin or pass flags as documented; output is a PNG file or stdout.
echo '\frac{1}{2} + \sqrt{x}' | cargo run --release -p ratex-render Architecture overview
All paths share: lexer → parser → layout → display list. Native UIs and WASM map that list to CoreGraphics, Android Canvas, Flutter Canvas, Skia, or Canvas 2D; the server crate rasterizes with tiny-skia.