Warm tip: This article is reproduced from stackoverflow.com, please click
ios latex swift

Renders LaTeX code in UILabel/UITextfield natively on iOS

发布于 2020-04-13 09:26:32

I want to render LaTeX in my application. I have tried iOSMath and iOSLatex.

The problem is iOS Math does not support latex with text while iOS Latex renders latex on a WkWebview and the takes screenshot of it and return an image.

Do we have a native renderer for LaTeX (on iOS)?

I am trying to render

Solve this equation (\left{\begin{matrix} 3x + 2y - 11 = 0 \ 2x + 3y - 9 = 0 \end{matrix}\right.)

Questioner
Manav
Viewed
62
Himanshu Patel 2020-02-17 18:30

You can use KatexMathe View

you can download this library

Example here

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

    })
}
}