whatisgithub

What is swatex?

phrasehq/swatex — explained in plain English

Analysis updated 2026-05-18

171SwiftAudience · developerComplexity · 3/5LicenseSetup · easy

In one sentence

A pure Swift library that renders LaTeX math formulas natively on Apple platforms, matching KaTeX's output without a hidden web view.

Mindmap

mindmap
  root((SwaTex))
    What it does
      Native LaTeX rendering
      No web view needed
      Matches KaTeX output
    Tech stack
      Swift
      SwiftUI and UIKit
      CoreGraphics
    Use cases
      Render math in apps
      Editor grade caching
      Export SVG or PNG
    Platforms
      iOS macOS tvOS
      watchOS visionOS
    Audience
      iOS developers
      Apple platform teams

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Render LaTeX math formulas natively in a SwiftUI app without loading a web view.

USE CASE 2

Display math inline inside a custom text editor built with UIKit or AppKit.

USE CASE 3

Export a formula as an SVG string or a PNG image for use elsewhere.

USE CASE 4

Render chemistry equations or proof trees alongside standard math notation.

What is it built with?

SwiftSwiftUIUIKitAppKitCoreGraphics

How does it compare?

phrasehq/swatexarinltte/lattevidelalvaro/inference-school
Stars171174176
LanguageSwiftSwiftSwift
Setup difficultyeasyeasyhard
Complexity3/51/55/5
Audiencedevelopergeneraldeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Requires Xcode 16.3+ and targets recent OS versions like iOS 18 and macOS 15.

Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

So what is it?

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.

Copy-paste prompts

Prompt 1
Show me how to add SwaTex to my Swift Package Manager project and render a formula in SwiftUI.
Prompt 2
Explain how SwaTex's formula cache speeds up rendering during scrolling in an editor.
Prompt 3
Walk me through rendering a chemistry equation with mhchem support in this library.
Prompt 4
Describe the architecture from LaTeX string to display list to rendered output.

Frequently asked questions

What is swatex?

A pure Swift library that renders LaTeX math formulas natively on Apple platforms, matching KaTeX's output without a hidden web view.

What language is swatex written in?

Mainly Swift. The stack also includes Swift, SwiftUI, UIKit.

What license does swatex use?

Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

How hard is swatex to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is swatex for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.