This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
iosMath is a native iOS/macOS Objective-C library that renders LaTeX math equations using CoreText — no WebView required. It implements the TeX typesetting algorithm on top of OpenType math fonts.
Swift Package Manager:
swift build
swift testiOS tests (Xcode):
xcodebuild test -project iosMath.xcodeproj -scheme iosMath -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 16'macOS tests (Xcode):
xcodebuild test -project MacOSMath.xcodeproj -scheme MacOSMath -sdk macosxRun a single test class:
xcodebuild test -project iosMath.xcodeproj -scheme iosMath -sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 16' \
-only-testing:iosMathTests/MTMathListBuilderTestLaTeX string → MTMathListBuilder (parser) → MTMathList (atom tree) → MTTypesetter (layout engine) → MTMathListDisplay (positioned glyphs) → CoreText/CoreGraphics → UIView/NSView
iosMath/lib/ — Parsing and data model:
MTMathListBuilder— Parses LaTeX strings into anMTMathList. This is the entry point for all LaTeX input.MTMathList/MTMathAtom— The intermediate representation. Math is modeled as a linked list of typed atoms (fraction, radical, inner, accent, etc.).MTMathAtomFactory— Maps LaTeX commands (e.g.\sin,\alpha,\frac) to their corresponding atoms and Unicode code points. Also owns the stack-command table that backsMTMathStack(the generic over/under atom used for\overrightarrow,\overbrace, and relatives).
iosMath/render/ — Layout and display:
MTMathUILabel— The public-facingUIView/NSViewsubclass. Users instantiate this and set itslatexproperty.MTTypesetter— The core layout engine (~80KB). Implements TeX's box-and-glue algorithm using the OpenType MATH table metrics. This is the most complex file in the codebase.MTMathListDisplay— A tree of display objects produced byMTTypesetter, each positioned with apositionpoint.draw:renders them via CoreText.MTFont/MTFontManager— Wraps CoreTextCTFont. Three math fonts are bundled: Latin Modern Math, Tex Gyre Termes, XITS Math.MTFontMathTable— Reads the OpenType MATH table from font files (via.plistsidecar files infonts/) to get metrics like italic corrections, kern values, and style script constants.
iosMath/render/internal/ — Private headers not exposed in the public API.
iosMath/render/MTConfig.h — Platform abstraction macros (TARGET_OS_IPHONE) that map UIView/NSView, UIColor/NSColor, UIFont/NSFont, etc. to a single set of macros used throughout the render layer.
Fonts are stored as .otf files under fonts/. Each font has a corresponding .plist file containing the pre-parsed OpenType MATH table data (generated by math_table_to_plist.py). MTFontMathTable reads from these plists at runtime rather than parsing the binary font table directly. When adding a new font, run the Python script to generate its plist.
The same source files compile for both iOS and macOS. Platform differences are handled via MTConfig.h macros and a small set of category files (NSColor+HexString, NSView+backgroundColor, NSBezierPath+addLineToPoint) that exist only for macOS to provide UIKit-compatible APIs.
Defined by iosMath/module.modulemap. Exports: MTMathUILabel, MTMathListDisplay, MTMathList, MTMathListBuilder, MTFont, MTFontManager, MTMathAtomFactory, MTMathListIndex.
Test files are in iosMathTests/:
MTMathListBuilderTest.m— Parser correctness (LaTeX → atom type/value)MTMathListTest.m—MTMathListdata structure behaviorMTTypesetterTest.m— Layout output (position, glyph run) validation
Tests use XCTest. There are no third-party test dependencies.
For a detailed mapping of TeX's Appendix G math typesetting algorithm onto iosMath's pipeline (rule-by-rule implementation status, font-parameter correspondence, known gaps, and an audit checklist), see ALGORITHM.md.