9

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

B--rian
  • 5,578
  • 10
  • 38
  • 89
Manav
  • 2,284
  • 1
  • 14
  • 27
  • 1
    If you mean by *native* from Apple, then no, Apple does not provide any official public API for LaTex rendering. – Asperi Feb 12 '20 at 17:17
  • By native, I want to say if Latex can be used as attributed string as iOSMath does, but it does not provide support for all latex tokens. – Manav Feb 12 '20 at 20:31
  • I posted a solution that uses iosMath [here](https://stackoverflow.com/questions/53978178/swift-display-latex-math-expressions-inline/57277287#57277287) – Michael Montalbano Aug 19 '22 at 05:19

1 Answers1

4

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

    })
}
}
Himanshu Patel
  • 1,015
  • 8
  • 26