title: Swift: Display (LaTeX) math expressions inline
body: <p>I would like to display math terms inside a text, in particular in an inline mode, i.e. inside a sentence.</p>
  
  <p>Using LaTeX, this would for example look like:
  "Given a right triangle having catheti of length \(a\) resp. \(b\) and a hypotenuse of length \(c\), we have
  \[a^2 + b^2 = c^2.\]
  This fact is known as the Pythagorean theorem."</p>
  
  <p>Does anybody know how this can be achieved in Swift?</p>
  
  <p>(I know that this example may be achieved in Swift without LaTeX-like tools. However, the expressions in my mind are in fact more complex than in this example, I do need the power of LaTeX.)</p>
  
  <p>The optimal way would be a <code>UITextView</code>-like class which recognizes the math delimiters \(,\) resp. \[,\], recognizes LaTeX code inside these delimiters, and formats the text accordingly.</p>
  
  <p>In the Khan Academy app, this problem seems to be solved as the screenshots in the Apple App Store/Google Play Store show inline (LaTeX) math.</p>
  
  <p>I’ve found the package iosMath which provides a <code>UILabel</code>-like class <code>MTMathUILabel</code>. As this class can display solely formulas, this seems to be not good enough for my purpose, except if there was a method which takes a LaTeX source text such as in the example above, formats expressions such as \(a\) into tiny <code>MTMathUILabel</code>s and sets these labels between the other text components. As I am new to Swift, I do not know whether and how this can be achieved. Moreover, this seems to be very difficult from a typographical point of view as there will surely occur difficulties with line breaks. And there might occur performance issues if there are a large number of such labels on the screen at the same time?</p>
  
  <p>It is possible to achieve what I want using a <code>WKWebView</code> and MathJax or KaTeX, which is also a hack, of course. This leads to other difficulties, e.g. if one wants to set several of these <code>WKWebView</code>s on a screen, e.g. inside <code>UITableViewCell</code>s.</p>