Back to OSS
Swift Package UI / SwiftUI

swift-latex-view

SwiftUI ネイティブな LaTeX 数式レンダリング。LLM 出力にも堅牢

Swift
swiftuilatexmath

English | 日本語

SwiftLaTeXView

SwiftUI-native LaTeX math rendering for Swift, integrated with DesignSystem. Robust display of LLM output and user-generated content with correct typesetting and automatic theming.

Swift 6.2+ iOS 17+ macOS 14+ License

Features

  • Two-layer architecture: LaTeXCore (interpretation layer, no UI dependency) and SwiftLaTeXView (rendering layer, DesignSystem integration)
  • LLM output support: Detects and normalizes all delimiter styles from OpenAI (\(...\) \[...\]), Claude, and Gemini ($...$ $$...$$)
  • Currency false-positive prevention: Single $ uses conservative Pandoc rules (non-whitespace adjacent, not immediately followed by digit)
  • Streaming support: Auto-completion option for unterminated delimiters (completeUnterminated)
  • Parse-failure fallback: Invalid LaTeX degrades to raw source display in error color — no crashes, no empty views
  • Engine encapsulation: The typesetting engine (SwiftMath) is hidden behind internal import; public API remains stable

Quick Start

import SwiftUI
import SwiftLaTeXView

struct ContentView: View {
    var body: some View {
        VStack {
            // Display math
            LaTeXView(#"x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}"#)

            // Inline math, baseline-aligned with surrounding text
            HStack(alignment: .firstTextBaseline) {
                Text("where")
                LaTeXView(#"a \neq 0"#, mode: .inline)
                Text("holds.")
            }
        }
    }
}

Detecting math in text (LaTeXCore)

import LaTeXCore

let segmenter = MathSegmenter()
let segments = segmenter.segments(in: "The energy is $$E = mc^2$$ as shown.")
// [.text("The energy is "), .math(MathExpression("E = mc^2", mode: .display)), .text(" as shown.")]

// Enable unterminated completion for streaming LLM output
let streaming = MathSegmenter(options: .init(completeUnterminated: true))

Custom styling

struct AccentMathStyle: MathStyle {
    var fontFamily: MathFontFamily { .fira }
    var displayFontSize: CGFloat { 28 }

    func textColor(_ palette: any ColorPalette) -> Color {
        palette.primary
    }
}

LaTeXView(#"e^{i\pi} + 1 = 0"#)
    .mathStyle(AccentMathStyle())

Installation

Swift Package Manager

Add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/no-problem-dev/swift-latex-view.git", from: "0.1.1")
]

Add to your target:

.target(
    name: "YourTarget",
    dependencies: [
        .product(name: "SwiftLaTeXView", package: "swift-latex-view"),
        // LaTeXCore only, for server-side Swift or CLI targets
        .product(name: "LaTeXCore", package: "swift-latex-view")
    ]
)

Architecture

SwiftMath (typesetting engine, hidden behind internal import)
    ↑
LaTeXCore ──── MathExpression / MathSegmenter / validate()
    ↑           (no SwiftUI dependency — usable in server-side Swift)
SwiftLaTeXView ─ LaTeXView / MathStyle / Environment
    ↑           (DesignSystem token integration)
Your App
Delimiter Mode Source
$$...$$ display Claude / Gemini / GitHub
\[...\] display OpenAI
\(...\) inline OpenAI
$...$ inline Claude / Gemini (Pandoc rules)

Testing

# Interpretation layer + engine integration (macOS CLI)
swift test

# UI snapshots (iOS Simulator)
xcodebuild test -scheme swift-latex-view-Package \
  -destination 'platform=iOS Simulator,name=iPhone 17 Pro'

License

MIT

同じカテゴリの OSS — UI / SwiftUI

swift-design-system

Swift Package

SwiftUI 向けの型安全で拡張可能なデザインシステム

Swift
· UI / SwiftUI
swiftuidesign-systemios

swift-ui-routing

Swift Package

SwiftUI 向けの型安全で宣言的なルーティングライブラリ

Swift
· UI / SwiftUI
swiftuiroutingnavigation

swift-statable

Swift Package

AsyncValue パターンで Observable な状態管理を実現する Swift マクロ

Swift
· UI / SwiftUI
swift-macrostate-managementasync

swift-markdown-view

Swift Package

DesignSystem 統合とシンタックスハイライトを備えた SwiftUI ネイティブな Markdown レンダリング

Swift
· UI / SwiftUI
swiftuimarkdownsyntax-highlighting

メモリ & ディスクの二層キャッシュで高速表示する SwiftUI リモート画像

Swift
· UI / SwiftUI
swiftuiimage-cacheasync

Google Slides API の JSON を SwiftUI で描画。A2A アーティファクトのストリーミングに対応

Swift
· UI / SwiftUI
swiftuigoogle-slidesa2a

swift-document-scanner

Swift Package

矩形検出・OCR・カメラ撮影を備えた iOS 向けドキュメントスキャン基盤

Swift
· UI / SwiftUI
iosscannerocr

swift-voice-input

Swift Package

ストリーミング認識とフローティングプレビュー UI を備えたプロトコル指向の音声入力

Swift
· UI / SwiftUI
voicespeechswiftui

© 2026 Kyoichi Taniguchi. All rights reserved.