Skip to content

Commit 2eab8a0

Browse files
authored
Merge pull request #1 from colinc86/documentation
Documentation
2 parents 84c686c + 906f5f9 commit 2eab8a0

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

README.md

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,29 @@ A SwiftUI view that renders LaTeX.
66

77
<center><img src="./assets/images/device.png" width="362" height="707"></center>
88

9-
## Installation
9+
## 📖 Contents
10+
11+
- [Installation](#📦-installation)
12+
- [Usage](#⌨️-usage)
13+
- [Modifiers](#⚙️-modifiers)
14+
- [Parsing Mode](#🔤-parsing-mode)
15+
- [Image Rendering Mode](#🌄-image-rendering-mode)
16+
- [Error Mode](#🚨-error-mode)
17+
- [Block Rendering Mode](#🧱-block-rendering-mode)
18+
- [Unencode HTML](#🔗-unencode-html)
19+
- [TeX Options](#♾️-tex-options)
20+
- [Caching](#🗄️-caching)
21+
- [Preloading](#🏃‍♀️-preloading)
22+
23+
## 📦 Installation
1024

1125
Add the dependency to your package manifest file.
1226

1327
```swift
1428
.package(url: "https://github.com/colinc86/LaTeXSwiftUI", branch: "main")
1529
```
1630

17-
## Usage
31+
## ⌨️ Usage
1832

1933
Import the package and use the view.
2034

@@ -32,7 +46,7 @@ struct MyView: View {
3246

3347
> <img src="./assets/images/hello.png" width="85" height="21.5">
3448
35-
### Modifiers
49+
### ⚙️ Modifiers
3650

3751
The `LaTeX` view's body is built up of `Text` views so feel free to use any of the supported modifiers.
3852

@@ -46,23 +60,7 @@ LaTeX("Hello, $\\LaTeX$!")
4660
4761
Along with supporting the built-in SwiftUI modifies, `LaTeXSwiftUI` defines more to let you configure the view.
4862

49-
#### Parsing Mode
50-
51-
Text input can either be completely rendered, or `LaTeXSwiftUI` can search for top-level equations. The default behavior is to only render equations. Use the `parsingMode` modifier to change the default behavior.
52-
53-
```swift
54-
// Only parse the equation
55-
LaTeX("Hello, $\\LaTeX$!")
56-
.parsingMode(.onlyEquations)
57-
58-
// Parse the entire input
59-
LaTeX("e^{i\\pi}+1=0")
60-
.parsingMode(.all)
61-
```
62-
63-
> <img src="./assets/images/euler.png" width="75" height="19.5">
64-
65-
##### Equations
63+
#### 🔤 Parsing Mode
6664

6765
`LaTexSwiftUI` can parse and render equations (aside from the entire input string) defined with the following terminators.
6866

@@ -74,7 +72,17 @@ LaTeX("e^{i\\pi}+1=0")
7472
| `\begin{equation}...\end{equation}` |
7573
| `\begin{equation*}...\end{equation*}` |
7674

77-
#### Image Rendering Mode
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.
76+
77+
```swift
78+
// Parse the entire input
79+
LaTeX("e^{i\\pi}+1=0")
80+
.parsingMode(.all)
81+
```
82+
83+
> <img src="./assets/images/euler.png" width="75" height="19.5">
84+
85+
#### 🌄 Image Rendering Mode
7886

7987
You can specify the rendering mode of the rendered equations so that they either take on the style of the surrounding text or display the style rendered by MathJax. The default behavior is to use the `template` rendering mode so that images match surrounding text.
8088

@@ -90,7 +98,7 @@ LaTeX("Hello, ${\\color{red} \\LaTeX}$!")
9098

9199
> <img src="./assets/images/rendering_mode.png" width="84.5" height="43">
92100
93-
#### Error Mode
101+
#### 🚨 Error Mode
94102

95103
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`.
96104

@@ -110,7 +118,7 @@ LaTeX("$\\asdf$")
110118

111119
> <img src="./assets/images/errors.png" width="199.5" height="55">
112120
113-
#### Block Rendering Mode
121+
#### 🧱 Block Rendering Mode
114122

115123
The typical "LaTeX-ish" way to render the input is with `blockViews`. This mode renders text as usual, and block equations as... blocks; on their own line and centered. MathJax 3 does not support line breaking, so the view places block equations in horizontal scroll views in case the width of the equation is more than the width of the view.
116124

@@ -136,7 +144,7 @@ LaTeX("The quadratic formula is $$x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}$$ and it h
136144

137145
> <img src="./assets/images/blocks.png" width="430" height="350">
138146
139-
#### Unencode HTML
147+
#### 🔗 Unencode HTML
140148

141149
Input may contain HTML entities such as `&lt;` which will not be parsed by LaTeX as anything meaningful. In this case, you may use the `unencoded` modifier.
142150

@@ -151,7 +159,7 @@ LaTeX("$x^2&lt;1$")
151159

152160
> <img src="./assets/images/unencoded.png" width="72.5" height="34">
153161
154-
#### TeX Options
162+
#### ♾️ TeX Options
155163

156164
For more control over the MathJax rendering, you can pass a `TeXInputProcessorOptions` object to the view.
157165

@@ -160,7 +168,7 @@ LaTeX("Hello, $\\LaTeX$!")
160168
.texOptions(TeXInputProcessorOptions(loadPackages: [TeXInputProcessorOptions.Packages.base]))
161169
```
162170

163-
### Caching
171+
### 🗄️ Caching
164172

165173
`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.
166174

@@ -176,9 +184,9 @@ LaTeX.imageCache.removeAll()
176184

177185
`LaTeXSwiftUI` uses the [caching](https://github.com/kean/Nuke/tree/master/Sources/Nuke/Caching) components of the [Nuke](https://github.com/kean/Nuke) package.
178186

179-
### Preloading
187+
### 🏃‍♀️ Preloading
180188

181-
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 no lag when the view appears.
189+
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.
182190

183191
```swift
184192
VStack {

0 commit comments

Comments
 (0)