You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Equation Number Offset](#equation-number-offset)
18
23
-[Unencode HTML](#🔗-unencode-html)
19
-
-[TeX Options](#♾️-tex-options)
20
24
-[Caching](#🗄️-caching)
21
25
-[Preloading](#🏃♀️-preloading)
26
+
27
+
## ℹ️ About
28
+
29
+
`LaTexSwiftUI` is a package that exposes a view named `LaTeX` that can parse and render TeX and LaTeX equations which contain math-mode marcos.
30
+
31
+
The view utilizes the [MathJaxSwift](https://www.github.com/colinc86/MathJaxSwift) package to render equations with [MathJax](https://www.mathjax.org). Thus, the limitations of the view are heavily influenced by the [limitations](https://docs.mathjax.org/en/v2.7-latest/tex.html#differences) of MathJax.
32
+
33
+
It will
34
+
- render TeX and LaTeX equations (math-mode macros),
35
+
- render the `\text{}` macro within equations,
36
+
- attempt to render block equations as a Tex or LaTeX engine would,
37
+
- and number block equations (if desired).
38
+
39
+
It won't
40
+
- render TeX and LaTeX documents (text-mode macros, with the exception of the rule above).
@@ -62,7 +81,7 @@ Along with supporting the built-in SwiftUI modifies, `LaTeXSwiftUI` defines more
62
81
63
82
#### 🔤 Parsing Mode
64
83
65
-
`LaTexSwiftUI`can parse and render equations (aside from the entire input string) defined with the following terminators.
84
+
Text input can either be completely rendered, or the view can search for top-level equations delimited by the following terminators.
66
85
67
86
| Terminators |
68
87
|-------------|
@@ -72,15 +91,20 @@ Along with supporting the built-in SwiftUI modifies, `LaTeXSwiftUI` defines more
72
91
|`\begin{equation}...\end{equation}`|
73
92
|`\begin{equation*}...\end{equation*}`|
74
93
75
-
Text input can either be completely rendered, or `LaTeXSwiftUI` can search for top-level equations. The default behavior is to only render equations with `onlyEquations`. Use the `parsingMode` modifier to change the default behavior.
94
+
The default behavior is to only render equations with `onlyEquations`. Use the `parsingMode` modifier to change the default behavior.
76
95
77
96
```swift
97
+
// Only parse equations (default)
98
+
LaTeX("Euler's identity is $e^{i\\pi}+1=0$.")
99
+
.font(.system(size: 18))
100
+
.parsingMode(.onlyEquations)
101
+
78
102
// Parse the entire input
79
-
LaTeX("e^{i\\pi}+1=0")
103
+
LaTeX("\\text{Euler's identity is } e^{i\\pi}+1=0\\text{.}")
When an error occurs while parsing the input the view will display the original LaTeX. You can change this behavior by modifying the view's `errorMode`.
104
128
129
+
> Note: when the `rendered` mode is used, MathJax is instructed to load the `noerrors` and `noundefined` packages. In the other two modes, `original` and `error`, these packages are not loaded by MathJax and errors are either displayed in the view, or caught and replaced with the original text.
130
+
105
131
```swift
106
132
// Display the original text instead of the equation
107
133
LaTeX("$\\asdf$")
@@ -144,6 +170,41 @@ LaTeX("The quadratic formula is $$x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}$$ and it h
Input may contain HTML entities such as `<` which will not be parsed by LaTeX as anything meaningful. In this case, you may use the `unencoded` modifier.
@@ -152,25 +213,16 @@ Input may contain HTML entities such as `<` which will not be parsed by LaTeX
`LaTeXSwiftUI` caches its SVG responses from MathJax and the images rendered as a result of the view's environment. If you want to control the cache, then you can access the static `cache` property.
225
+
`LaTeXSwiftUI` caches its SVG responses from MathJax and the images rendered as a result of the view's environment. If you want to control the cache, then you can access the static `dataCache` and `imageCache` properties.
174
226
175
227
The caches are managed automatically, but if, for example, you wanted to clear the cache manually you may do so.
SVGs and images are rendered and cached on demand, but there may be situations where you want to preload the data so that there is minimal lag when the view appears.
190
242
243
+
SVGs and images are rendered as a result of the view's environment, so it is important to call the `preload` method last in the view's modifier chain if you use it.
0 commit comments