在 iOS 上本地渲染 UILabel/UITextfield 中的 LaTeX 代码

Man*_*nav 6 latex ios swift

我想在我的应用程序中呈现 LaTeX。我试过iOSMathiOSLatex

问题是 iOS Math 不支持带有文本的 Latex ,而 iOS Latex 在 WkWebview 上渲染 Latex 并截取它的屏幕截图并返回图像。

我们有 LaTeX 的原生渲染器(在 iOS 上)吗?

我正在尝试渲染

解这个方程 (\left{\begin{matrix} 3x + 2y - 11 = 0 \ 2x + 3y - 9 = 0 \end{matrix}\right.)

Him*_*tel 4

您可以使用 KatexMathe 视图

你可以下载这个库

示例在这里

//MARK:- IBOutlet

@IBOutlet weak var webViewQuestion: KatexMathView!

override func viewDidLoad() {
    super.viewDidLoad()
    self.webViewQuestion.loadLatex("your string")
}

extension ReadQuestionVC : WKNavigationDelegate {

public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {       
       self.webViewQuestionHC.constant = 10 //Default constant height
       self.setContaintSizeWebView(webView: webViewQuestion, constantSize: self.webViewQuestionHC)

}

func setContaintSizeWebView(webView:WKWebView,constantSize:NSLayoutConstraint){
    webView.evaluateJavaScript("document.readyState", completionHandler: { (complete, error) in
        if complete != nil {
            webView.evaluateJavaScript("Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight)", completionHandler: { (height, error) in
                constantSize.constant = height as! CGFloat
                webView.sizeToFit()
                self.view.layoutIfNeeded()
            })
        }

    })
}
}
Run Code Online (Sandbox Code Playgroud)