SwaTex
99.9% KaTeX syntax coverage. LaTeX math renderer in pure Swift. No JavaScript, no WebView, no DOM. One Swift core → iOS, macOS, tvOS, watchOS, visionOS. SwiftUI · UIKit/AppKit · SVG · PNG. 3.3× the Rust reference engine. Zero re-rasterization scrolling for block editors. By Phrase (phrase.so).
A pure Swift library that renders LaTeX math formulas natively on Apple platforms, matching KaTeX's output without a hidden web view.
SwaTex is a library that renders LaTeX math formulas, the kind used in scientific papers and textbooks, directly on Apple platforms in pure Swift code. Most tools that display math on the web or in apps do it by loading a browser engine or a JavaScript library behind the scenes, which costs memory and adds a delay before the first formula shows up. SwaTex instead reimplements the same rendering pipeline as KaTeX, a popular JavaScript math renderer, as native Swift, so it runs directly on iOS, macOS, tvOS, watchOS, and visionOS without a hidden web view.
It supports nearly all of KaTeX's formula syntax, covering fractions, radicals, integrals, matrices, accents, and custom macros, along with chemistry notation through the mhchem extension and proof trees used in logic and math papers. The project was built by the team behind an app called Phrase, where it renders math formulas inside the app's AI-generated notes, and it was ported from an earlier Rust version of the same renderer called RaTeX.
Developers install it through Swift Package Manager and can use it a few different ways: as a SwiftUI view that displays a formula inline with surrounding text, as a UIKit or AppKit view meant for use inside text editors, or as a lower-level engine that produces an SVG string or a PNG image directly. The library is designed with editors in mind, meaning it caches the layout of formulas it has already rendered once, so redrawing the same formula again during scrolling is very fast and avoids doing the expensive layout work twice.
The project includes benchmark comparisons against the original Rust engine, showing it renders and lays out formulas faster in most cases while producing pixel-identical output on its test set of formulas. It requires a fairly recent version of Xcode and targets recent versions of Apple's operating systems. One known gap is that it does not support the includegraphics command, matching a restriction KaTeX itself also applies. It is released under the MIT license.
Where it fits
- Render LaTeX math formulas natively in a SwiftUI app without loading a web view.
- Display math inline inside a custom text editor built with UIKit or AppKit.
- Export a formula as an SVG string or a PNG image for use elsewhere.
- Render chemistry equations or proof trees alongside standard math notation.