KatexUtils 0.3.3

KatexUtils 0.3.3

Maintained by Ni Kesu.

  • By
  • nikesu


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


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")

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

_ = 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))

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])


  • iOS 13.0


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

pod 'KatexUtils'


nikesu, [email protected]


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