Swiftpack.co - nks5117/KatexUtils as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Katex support for iOS
.package(url: "https://github.com/nks5117/KatexUtils.git", from: "0.3.4")


KatexUtils provides a UIView KatexView to render a LaTeX expression for iOS apps using KaTeX. It also provide a wrapper of KaTeX engine called KatexRenderer to access KaTeX's renderToString API.

Version License Platform

Note: KatexUtils is still in development, and the API is not guaranteed to be stable. It's subject to change without warning.


To run the example project, clone the repo, and run pod install from the Example directory first.


Use KatexView to create a UIView that renders a LaTeX formula:

var katexView = KatexView(latex: "a^2 + b^2 = c^2")

Use custom rendering options just like in KaTeX:

var katexView = KatexView(latex: #"c = \pm\sqrt{a^2 + b^2}\in\RR"#,
                          options: [
                            .displayMode: true,
                            .macros: [#"\RR"#: #"\mathbb{R}"#]

KatexView will automaticlly make itself scrollable when it's frame can not contains the whole formula. You can also observe the status property to handle error or do some customize change when rendering is finished successfully:

cancellable = katexView.$status.sink { [weak self] status in
    let MAXWIDTH : CGFloat = 300.0
    let MAXHEIGHT : CGFloat = 100.0
    let contentSize = self?.katexView.intrinsicContentSize

    switch status {
    case .finished:
        self?.katexView.frame =
            CGRect(x: 0,
                   y: 0,
                   width: min(contentSize?.width ?? .infinity, MAXWIDTH),
                   height: min(contentSize?.height  ?? .infinity, MAXHEIGHT))
    case .error(let message):

KatexRenderer use KaTeX to render a LaTeX formula to a HTML string:

let str = KatexRenderer.renderToString(latex: "a^2 + b^2 = c^2", options: [.displayMode : true])

For supported functions, check the document of KaTeX.


  • iOS 13.0
  • Swift 5.3



KatexUtils is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'KatexUtils', '~> 0.3.0'

Installation with Swift Package Manager

Once you have your Swift package set up, adding KatexUtils as a dependency is as easy as adding it to the dependencies value of your Package.swift:

dependencies: [
    .package(url: "https://github.com/nks5117/KatexUtils.git", .upToNextMinor(from: "0.3.0"))


Ni Kesu, 1026001096@qq.com


KatexUtils is available under the MIT license. See the LICENSE file for more info.


Stars: 3
Last commit: 4 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics