Update to README.md and graphic files.
60
EXAMPLES.md
@@ -5,91 +5,104 @@
|
||||
(a_1 + a_2)^2 = a_1^2 + 2a_1a_2 + a_2^2
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Quadratic Formula
|
||||
```LaTeX
|
||||
x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Standard Deviation
|
||||
```LaTeX
|
||||
\sigma = \sqrt{\frac{1}{N}\sum_{i=1}^N (x_i - \mu)^2}
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## De Morgan's laws
|
||||
```LaTeX
|
||||
\neg(P\land Q) \iff (\neg P)\lor(\neg Q)
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Log Change of Base
|
||||
```LaTeX
|
||||
\log_b(x) = \frac{\log_a(x)}{\log_a(b)}
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Cosine addition
|
||||
```LaTeX
|
||||
\cos(\theta + \varphi) = \cos(\theta)\cos(\varphi) - \sin(\theta)\sin(\varphi)
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Limit e^k
|
||||
```LaTeX
|
||||
\lim_{x\to\infty}\left(1 + \frac{k}{x}\right)^x = e^k
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Calculus
|
||||
```LaTeX
|
||||
f(x) = \int\limits_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,\mathrm{d}\xi
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Stirling Numbers of the Second Kind
|
||||
```LaTeX
|
||||
{n \brace k} = \frac{1}{k!}\sum_{j=0}^k (-1)^{k-j}\binom{k}{j}(k-j)^n
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Gaussian Integral
|
||||
```LaTeX
|
||||
\int_{-\infty}^{\infty} \! e^{-x^2} dx = \sqrt{\pi}
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Arithmetic mean, geometric mean inequality
|
||||
```LaTeX
|
||||
\frac{1}{n}\sum_{i=1}^{n}x_i \geq \sqrt[n]{\prod_{i=1}^{n}x_i}
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Cauchy-Schwarz inequality
|
||||
```LaTeX
|
||||
\left(\sum_{k=1}^n a_k b_k \right)^2 \le \left(\sum_{k=1}^n a_k^2\right)\left(\sum_{k=1}^n b_k^2\right)
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Cauchy integral formula
|
||||
```LaTeX
|
||||
f^{(n)}(z_0) = \frac{n!}{2\pi i}\oint_\gamma\frac{f(z)}{(z-z_0)^{n+1}}dz
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Schroedinger's Equation
|
||||
```LaTeX
|
||||
@@ -97,7 +110,8 @@ i\hbar\frac{\partial}{\partial t}\mathbf\Psi(\mathbf{x},t) = -\frac{\hbar}{2m}\n
|
||||
+ V(\mathbf{x})\mathbf\Psi(\mathbf{x},t)
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Lorentz Equations
|
||||
Use the `gather` or `displaylines` environments to center multiple
|
||||
@@ -110,7 +124,8 @@ equations.
|
||||
\end{gather}
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Cross product
|
||||
```LaTeX
|
||||
@@ -121,7 +136,8 @@ equations.
|
||||
\end{vmatrix}
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Maxwell's Equations
|
||||
Use the `aligned`, `eqalign` or `split` environments to align
|
||||
@@ -135,7 +151,8 @@ multiple equations.
|
||||
\end{eqalign}
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Matrix multiplication
|
||||
Supported matrix environments: `matrix`, `pmatrix`, `bmatrix`, `Bmatrix`,
|
||||
@@ -153,7 +170,8 @@ c\alpha + d\gamma & c\beta + d \delta
|
||||
\end{pmatrix}
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Cases
|
||||
```LaTeX
|
||||
@@ -163,7 +181,8 @@ f(x) = \begin{cases}
|
||||
\end{cases}
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Splitting long equations
|
||||
```LaTeX
|
||||
@@ -173,4 +192,5 @@ f(x) = \begin{cases}
|
||||
\left( o_t - \hat{\mu}_m^{(s)} \right) ^T \cal C_m^{(s)-1} \right)
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
54
README.md
@@ -3,7 +3,10 @@
|
||||
`SwiftMath` provides a full Swift implementation of [iosMath](https://travis-ci.org/kostub/iosMath)
|
||||
for displaying beautifully rendered math equations in iOS and MacOS applications. It typesets formulae written
|
||||
using LaTeX in a `UILabel` equivalent class. It uses the same typesetting rules as LaTeX and
|
||||
so the equations are rendered exactly as LaTeX would render them.
|
||||
so the equations are rendered exactly as LaTeX would render them.
|
||||
|
||||
Please also check out [SwiftMathDemo](https://github.com/mgriebling/SwiftMathDemo.git) for examples of how to use `SwiftMath`
|
||||
from SwiftUI.
|
||||
|
||||
`SwiftMath` is similar to [MathJax](https://www.mathjax.org) or
|
||||
[KaTeX](https://github.com/Khan/KaTeX) for the web but for native iOS or MacOS
|
||||
@@ -25,31 +28,35 @@ Here are screenshots of some formulae that were rendered with this library:
|
||||
x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
```LaTeX
|
||||
f(x) = \int\limits_{-\infty}^\infty\!\hat f(\xi)\,e^{2 \pi i \xi x}\,\mathrm{d}\xi
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
```LaTeX
|
||||
\frac{1}{n}\sum_{i=1}^{n}x_i \geq \sqrt[n]{\prod_{i=1}^{n}x_i}
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
```LaTex
|
||||
\frac{1}{\left(\sqrt{\phi \sqrt{5}}-\phi\\right) e^{\frac25 \pi}}
|
||||
= 1+\frac{e^{-2\pi}} {1 +\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\cdots} } } }
|
||||
```
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
More examples are included in [EXAMPLES](EXAMPLES.md)
|
||||
|
||||
## Requirements
|
||||
`SwiftMath` works on iOS 11+ or MacOS 11+. It depends
|
||||
`SwiftMath` works on iOS 11+ or MacOS 12+. It depends
|
||||
on the following Apple frameworks:
|
||||
|
||||
* Foundation.framework
|
||||
@@ -155,7 +162,7 @@ This is a list of formula types that the library currently supports:
|
||||
* Greek alphabet
|
||||
* Combinatorics (\\binom, \\choose etc.)
|
||||
* Geometry symbols (e.g. angle, congruence etc.)
|
||||
* Ratios, proportions, percents
|
||||
* Ratios, proportions, percentages
|
||||
* Math spacing
|
||||
* Overline and underline
|
||||
* Math accents
|
||||
@@ -165,6 +172,18 @@ This is a list of formula types that the library currently supports:
|
||||
* Most commonly used math symbols
|
||||
* Colors
|
||||
|
||||
Note: SwiftMath only supports the commands in LaTeX's math mode. There is
|
||||
also no language support for other than west European langugages and some
|
||||
Cyrillic characters. There would be two ways to support more languages:
|
||||
|
||||
1) Find a math font compatible with `SwiftMath` that contains all the glyphs
|
||||
for that language.
|
||||
2) Add support to `SwiftMath` for standard Unicode fonts that contain all
|
||||
langauge glyphs.
|
||||
|
||||
Of these two, the first is much easier. However, if you want a challenge,
|
||||
try to tackle the second option.
|
||||
|
||||
### Example
|
||||
|
||||
The [SwiftMathDemo](https://github.com/mgriebling/SwiftMathDemo) is a SwiftUI version
|
||||
@@ -194,10 +213,10 @@ label.textAlignment = .center
|
||||
```
|
||||
|
||||
##### Font size
|
||||
The default font-size is 25pt. You can change it as follows:
|
||||
The default font-size is 30pt. You can change it as follows:
|
||||
|
||||
```swift
|
||||
label.fontSize = 30
|
||||
label.fontSize = 25
|
||||
```
|
||||
##### Font
|
||||
The default font is *Latin Modern Math*. This can be changed as:
|
||||
@@ -206,11 +225,18 @@ The default font is *Latin Modern Math*. This can be changed as:
|
||||
label.font = MTFontManager.fontmanager.termesFont(withSize:20)
|
||||
```
|
||||
|
||||
This project has 3 fonts bundled with it, but you can use any OTF math
|
||||
font. Note: I couldn't get the `iosMath` Python script to work. If
|
||||
you do manage to get it working, please let me know.
|
||||
This project has five fonts bundled with it, but you can use any OTF math
|
||||
font. A python script is included that generates the `.plist` files
|
||||
required for an `.otf` font to work with `SwiftMath`. If you generate
|
||||
(and test) any other fonts please contribute them back to this project for
|
||||
others to benefit.
|
||||
|
||||
##### Color
|
||||
Note: The `KpMath-Light` and `KpMath-Sans` fonts current do not correctly
|
||||
render very large radicals correctly. It appears that the font files do
|
||||
not correctly define the offsets required to typeset these glyphs. If
|
||||
anyone can fix this, it would be greatly appreciated.
|
||||
|
||||
##### Text Color
|
||||
The default color of the rendered equation is black. You can change
|
||||
it to any other color as follows:
|
||||
|
||||
@@ -278,3 +304,5 @@ licensed as follows:
|
||||
[GUST Font License](GUST-FONT-LICENSE.txt)
|
||||
* [XITS Math](https://github.com/khaledhosny/xits-math):
|
||||
[Open Font License](OFL.txt)
|
||||
* [KpMath Light/KpMath Sans](http://scripts.sil.org/OFL):
|
||||
[SIL Open Font License](OFL.txt)
|
||||
|
||||
BIN
img/amgm-dark.png
Normal file
|
After Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 9.5 KiB |
BIN
img/calculus-dark.png
Normal file
|
After Width: | Height: | Size: 8.3 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
BIN
img/cases-dark.png
Normal file
|
After Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 9.0 KiB |
BIN
img/cauchyintegral-dark.png
Normal file
|
After Width: | Height: | Size: 9.8 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
BIN
img/cauchyschwarz-dark.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
BIN
img/cross-dark.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
BIN
img/demorgan-dark.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 7.6 KiB |
BIN
img/gaussintegral-dark.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 8.3 KiB |
BIN
img/limit-dark.png
Normal file
|
After Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 8.8 KiB |
BIN
img/log-dark.png
Normal file
|
After Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 9.6 KiB |
BIN
img/long-dark.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
BIN
img/lorentz-dark.png
Normal file
|
After Width: | Height: | Size: 8.3 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
BIN
img/matrixmult-dark.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
BIN
img/maxwell-dark.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
BIN
img/quadratic-dark.png
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 8.3 KiB |
BIN
img/ramanujan-dark.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
BIN
img/schroedinger-dark.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
BIN
img/square-dark.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 7.4 KiB After Width: | Height: | Size: 7.4 KiB |
BIN
img/st-dark.png
Normal file
|
After Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 8.3 KiB |
BIN
img/standard-dark.png
Normal file
|
After Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
BIN
img/stirling-dark.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
BIN
img/trig-dark.png
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |