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.
Note: KatexUtils is still in development, and the API is not guaranteed to be stable. It’s subject to change without warning.
Example
To run the example project, clone the repo, and run pod install from the Example directory first.
Usage
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 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):
fatalError(message)
default:
return
}
}
KatexRenderer use KaTeX to render a LaTeX formula to a HTML string:
KatexUtils
KatexUtils
provides a UIViewKatexView
to render a LaTeX expression for iOS apps using KaTeX. It also provide a wrapper of KaTeX engine calledKatexRenderer
to access KaTeX’srenderToString
API.Example
To run the example project, clone the repo, and run
pod install
from the Example directory first.Usage
Use
KatexView
to create a UIView that renders a LaTeX formula:Use custom rendering options just like in KaTeX:
KatexView
will automaticlly make itself scrollable when it’s frame can not contains the whole formula. You can also observe thestatus
property to handle error or do some customize change when rendering is finished successfully:KatexRenderer
use KaTeX to render a LaTeX formula to a HTML string:For supported functions, check the document of
KaTeX
.Requirements
Installation
CocoaPods
KatexUtils is available through CocoaPods. To install it, simply add the following line to your Podfile:
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 yourPackage.swift
:Author
Ni Kesu, 1026001096@qq.com
License
KatexUtils is available under the MIT license. See the LICENSE file for more info.