温馨提示:本文翻译自stackoverflow.com,查看原文请点击:swift - Renders LaTeX code in UILabel/UITextfield natively on iOS
ios latex swift

swift - 在iOS上原生呈现UILabel / UITextfield中的LaTeX代码

发布于 2020-04-13 11:09:19

我想在我的应用程序中渲染LaTeX。我已经尝试过iOSMathiOSLatex

问题是iOS Math不支持带有文本的乳胶,而iOS Latex在WkWebview上渲染乳胶并对其进行截图并返回图像。

我们是否有LaTeX的本机渲染器(在iOS上)?

我正在尝试渲染

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

查看更多

提问者
Manav
被浏览
95
Himanshu Patel 2020-02-17 18:30

您可以使用KatexMathe View

你可以下载这个库

这里的例子

//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()
            })
        }

    })
}
}