diff --git a/EXAMPLES.md b/EXAMPLES.md index 0fd62fa..3dc9e02 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -5,91 +5,104 @@ (a_1 + a_2)^2 = a_1^2 + 2a_1a_2 + a_2^2 ``` -![Square Formula](img/square.png) +![Square Formula](img/square-light.png#gh-light-mode-only) +![Square Formula](img/square-dark.png#gh-dark-mode-only) ## Quadratic Formula ```LaTeX x = \frac{-b \pm \sqrt{b^2-4ac}}{2a} ``` -![Quadratic Formula](img/quadratic.png) +![Quadratic Formula](img/quadratic-light.png#gh-light-mode-only) +![Quadratic Formula](img/quadratic-dark.png#gh-dark-mode-only) ## Standard Deviation ```LaTeX \sigma = \sqrt{\frac{1}{N}\sum_{i=1}^N (x_i - \mu)^2} ``` -![Standard Deviation](img/standard.png) +![Standard Deviation](img/standard-light.png#gh-light-mode-only) +![Standard Deviation](img/standard-dark.png#gh-dark-mode-only) ## De Morgan's laws ```LaTeX \neg(P\land Q) \iff (\neg P)\lor(\neg Q) ``` -![De Morgan](img/demorgan.png) +![De Morgan](img/demorgan-light.png#gh-light-mode-only) +![De Morgan](img/demorgan-dark.png#gh-dark-mode-only) ## Log Change of Base ```LaTeX \log_b(x) = \frac{\log_a(x)}{\log_a(b)} ``` -![Log Base Change](img/log.png) +![Log Base Change](img/log-light.png#gh-light-mode-only) +![Log Base Change](img/log-dark.png#gh-dark-mode-only) ## Cosine addition ```LaTeX \cos(\theta + \varphi) = \cos(\theta)\cos(\varphi) - \sin(\theta)\sin(\varphi) ``` -![Cos Sum](img/trig.png) +![Cos Sum](img/trig-light.png#gh-light-mode-only) +![Cos Sum](img/trig-dark.png#gh-dark-mode-only) ## Limit e^k ```LaTeX \lim_{x\to\infty}\left(1 + \frac{k}{x}\right)^x = e^k ``` -![Limit](img/limit.png) +![Limit](img/limit-light.png#gh-light-mode-only) +![Limit](img/limit-dark.png#gh-dark-mode-only) ## Calculus ```LaTeX f(x) = \int\limits_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,\mathrm{d}\xi ``` -![Calculus](img/calculus.png) +![Calculus](img/calculus-light.png#gh-light-mode-only) +![Calculus](img/calculus-dark.png#gh-dark-mode-only) ## 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 ``` -![Stirling Numbers](img/stirling.png) +![Stirling Numbers](img/stirling-light.png#gh-light-mode-only) +![Stirling Numbers](img/stirling-dark.png#gh-dark-mode-only) ## Gaussian Integral ```LaTeX \int_{-\infty}^{\infty} \! e^{-x^2} dx = \sqrt{\pi} ``` -![Gauss Integral](img/gaussintegral.png) +![Gauss Integral](img/gaussintegral-light.png#gh-light-mode-only) +![Gauss Integral](img/gaussintegral-dark.png#gh-dark-mode-only) ## Arithmetic mean, geometric mean inequality ```LaTeX \frac{1}{n}\sum_{i=1}^{n}x_i \geq \sqrt[n]{\prod_{i=1}^{n}x_i} ``` -![AM-GM](img/amgm.png) +![AM-GM](img/amgm-light.png#gh-light-mode-only) +![AM-GM](img/amgm-dark.png#gh-dark-mode-only) ## 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 Schwarz](img/cauchyschwarz.png) +![Cauchy Schwarz](img/cauchyschwarz-light.png#gh-light-mode-only) +![Cauchy Schwarz](img/cauchyschwarz-dark.png#gh-dark-mode-only) ## Cauchy integral formula ```LaTeX f^{(n)}(z_0) = \frac{n!}{2\pi i}\oint_\gamma\frac{f(z)}{(z-z_0)^{n+1}}dz ``` -![Cauchy Integral](img/cauchyintegral.png) +![Cauchy Integral](img/cauchyintegral-light.png#gh-light-mode-only) +![Cauchy Integral](img/cauchyintegral-dark.png#gh-dark-mode-only) ## 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) ``` -![Schroedinger](img/schroedinger.png) +![Schroedinger](img/schroedinger-light.png#gh-light-mode-only) +![Schroedinger](img/schroedinger-dark.png#gh-dark-mode-only) ## Lorentz Equations Use the `gather` or `displaylines` environments to center multiple @@ -110,7 +124,8 @@ equations. \end{gather} ``` -![Lorentz](img/lorentz.png) +![Lorentz](img/lorentz-light.png#gh-light-mode-only) +![Lorentz](img/lorentz-dark.png#gh-dark-mode-only) ## Cross product ```LaTeX @@ -121,7 +136,8 @@ equations. \end{vmatrix} ``` -![Cross Product](img/cross.png) +![Cross Product](img/cross-light.png#gh-light-mode-only) +![Cross Product](img/cross-dark.png#gh-dark-mode-only) ## Maxwell's Equations Use the `aligned`, `eqalign` or `split` environments to align @@ -135,7 +151,8 @@ multiple equations. \end{eqalign} ``` -![Maxwell's Equations](img/maxwell.png) +![Maxwell's Equations](img/maxwell-light.png#gh-light-mode-only) +![Maxwell's Equations](img/maxwell-dark.png#gh-dark-mode-only) ## Matrix multiplication Supported matrix environments: `matrix`, `pmatrix`, `bmatrix`, `Bmatrix`, @@ -153,7 +170,8 @@ c\alpha + d\gamma & c\beta + d \delta \end{pmatrix} ``` -![Matrix Multiplication](img/matrixmult.png) +![Matrix Multiplication](img/matrixmult-light.png#gh-light-mode-only) +![Matrix Multiplication](img/matrixmult-dark.png#gh-dark-mode-only) ## Cases ```LaTeX @@ -163,7 +181,8 @@ f(x) = \begin{cases} \end{cases} ``` -![Cases](img/cases.png) +![Cases](img/cases-light.png#gh-light-mode-only) +![Cases](img/cases-dark.png#gh-dark-mode-only) ## 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) ``` -![Long equation](img/long.png) +![Long equation](img/long-light.png#gh-light-mode-only) +![Long equation](img/long-dark.png#gh-dark-mode-only) diff --git a/README.md b/README.md index d16b9dd..825bafc 100644 --- a/README.md +++ b/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} ``` -![Quadratic Formula](img/quadratic.png) +![Quadratic Formula](img/quadratic-light.png#gh-light-mode-only) +![Quadratic Formula](img/quadratic-dark.png#gh-dark-mode-only) ```LaTeX f(x) = \int\limits_{-\infty}^\infty\!\hat f(\xi)\,e^{2 \pi i \xi x}\,\mathrm{d}\xi ``` -![Calculus](img/calculus.png) +![Calculus](img/calculus-light.png#gh-light-mode-only) +![Calculus](img/calculus-dark.png#gh-dark-mode-only) ```LaTeX \frac{1}{n}\sum_{i=1}^{n}x_i \geq \sqrt[n]{\prod_{i=1}^{n}x_i} ``` -![AM-GM](img/amgm.png) +![AM-GM](img/amgm-light.png#gh-light-mode-only) +![AM-GM](img/amgm-dark.png#gh-dark-mode-only) ```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} } } } ``` -![Ramanujan Identity](img/ramanujan.png) +![Ramanujan Identity](img/ramanujan-light.png#gh-light-mode-only) +![Ramanujan Identity](img/ramanujan-dark.png#gh-dark-mode-only) 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) diff --git a/img/amgm-dark.png b/img/amgm-dark.png new file mode 100644 index 0000000..6c9b78a Binary files /dev/null and b/img/amgm-dark.png differ diff --git a/img/amgm.png b/img/amgm-light.png similarity index 100% rename from img/amgm.png rename to img/amgm-light.png diff --git a/img/calculus-dark.png b/img/calculus-dark.png new file mode 100644 index 0000000..ce12c11 Binary files /dev/null and b/img/calculus-dark.png differ diff --git a/img/calculus.png b/img/calculus-light.png similarity index 100% rename from img/calculus.png rename to img/calculus-light.png diff --git a/img/cases-dark.png b/img/cases-dark.png new file mode 100644 index 0000000..c6c5f3b Binary files /dev/null and b/img/cases-dark.png differ diff --git a/img/cases.png b/img/cases-light.png similarity index 100% rename from img/cases.png rename to img/cases-light.png diff --git a/img/cauchyintegral-dark.png b/img/cauchyintegral-dark.png new file mode 100644 index 0000000..de428b4 Binary files /dev/null and b/img/cauchyintegral-dark.png differ diff --git a/img/cauchyintegral.png b/img/cauchyintegral-light.png similarity index 100% rename from img/cauchyintegral.png rename to img/cauchyintegral-light.png diff --git a/img/cauchyschwarz-dark.png b/img/cauchyschwarz-dark.png new file mode 100644 index 0000000..b9adabf Binary files /dev/null and b/img/cauchyschwarz-dark.png differ diff --git a/img/cauchyschwarz.png b/img/cauchyschwarz-light.png similarity index 100% rename from img/cauchyschwarz.png rename to img/cauchyschwarz-light.png diff --git a/img/cross-dark.png b/img/cross-dark.png new file mode 100644 index 0000000..2a1f1bf Binary files /dev/null and b/img/cross-dark.png differ diff --git a/img/cross.png b/img/cross-light.png similarity index 100% rename from img/cross.png rename to img/cross-light.png diff --git a/img/demorgan-dark.png b/img/demorgan-dark.png new file mode 100644 index 0000000..7fd0bd8 Binary files /dev/null and b/img/demorgan-dark.png differ diff --git a/img/demorgan.png b/img/demorgan-light.png similarity index 100% rename from img/demorgan.png rename to img/demorgan-light.png diff --git a/img/gaussintegral-dark.png b/img/gaussintegral-dark.png new file mode 100644 index 0000000..4b1672a Binary files /dev/null and b/img/gaussintegral-dark.png differ diff --git a/img/gaussintegral.png b/img/gaussintegral-light.png similarity index 100% rename from img/gaussintegral.png rename to img/gaussintegral-light.png diff --git a/img/limit-dark.png b/img/limit-dark.png new file mode 100644 index 0000000..6193004 Binary files /dev/null and b/img/limit-dark.png differ diff --git a/img/limit.png b/img/limit-light.png similarity index 100% rename from img/limit.png rename to img/limit-light.png diff --git a/img/log-dark.png b/img/log-dark.png new file mode 100644 index 0000000..e9bd2ef Binary files /dev/null and b/img/log-dark.png differ diff --git a/img/log.png b/img/log-light.png similarity index 100% rename from img/log.png rename to img/log-light.png diff --git a/img/long-dark.png b/img/long-dark.png new file mode 100644 index 0000000..ec41875 Binary files /dev/null and b/img/long-dark.png differ diff --git a/img/long.png b/img/long-light.png similarity index 100% rename from img/long.png rename to img/long-light.png diff --git a/img/lorentz-dark.png b/img/lorentz-dark.png new file mode 100644 index 0000000..a7803a2 Binary files /dev/null and b/img/lorentz-dark.png differ diff --git a/img/lorentz.png b/img/lorentz-light.png similarity index 100% rename from img/lorentz.png rename to img/lorentz-light.png diff --git a/img/matrixmult-dark.png b/img/matrixmult-dark.png new file mode 100644 index 0000000..a921c7d Binary files /dev/null and b/img/matrixmult-dark.png differ diff --git a/img/matrixmult.png b/img/matrixmult-light.png similarity index 100% rename from img/matrixmult.png rename to img/matrixmult-light.png diff --git a/img/maxwell-dark.png b/img/maxwell-dark.png new file mode 100644 index 0000000..164d558 Binary files /dev/null and b/img/maxwell-dark.png differ diff --git a/img/maxwell.png b/img/maxwell-light.png similarity index 100% rename from img/maxwell.png rename to img/maxwell-light.png diff --git a/img/quadratic-dark.png b/img/quadratic-dark.png new file mode 100644 index 0000000..8cde5a1 Binary files /dev/null and b/img/quadratic-dark.png differ diff --git a/img/quadratic.png b/img/quadratic-light.png similarity index 100% rename from img/quadratic.png rename to img/quadratic-light.png diff --git a/img/ramanujan-dark.png b/img/ramanujan-dark.png new file mode 100644 index 0000000..a3a6bea Binary files /dev/null and b/img/ramanujan-dark.png differ diff --git a/img/ramanujan.png b/img/ramanujan-light.png similarity index 100% rename from img/ramanujan.png rename to img/ramanujan-light.png diff --git a/img/schroedinger-dark.png b/img/schroedinger-dark.png new file mode 100644 index 0000000..602f022 Binary files /dev/null and b/img/schroedinger-dark.png differ diff --git a/img/schroedinger.png b/img/schroedinger-light.png similarity index 100% rename from img/schroedinger.png rename to img/schroedinger-light.png diff --git a/img/square-dark.png b/img/square-dark.png new file mode 100644 index 0000000..f4e78e1 Binary files /dev/null and b/img/square-dark.png differ diff --git a/img/square.png b/img/square-light.png similarity index 100% rename from img/square.png rename to img/square-light.png diff --git a/img/st-dark.png b/img/st-dark.png new file mode 100644 index 0000000..8aa8379 Binary files /dev/null and b/img/st-dark.png differ diff --git a/img/st.png b/img/st-light.png similarity index 100% rename from img/st.png rename to img/st-light.png diff --git a/img/standard-dark.png b/img/standard-dark.png new file mode 100644 index 0000000..0475f33 Binary files /dev/null and b/img/standard-dark.png differ diff --git a/img/standard.png b/img/standard-light.png similarity index 100% rename from img/standard.png rename to img/standard-light.png diff --git a/img/stirling-dark.png b/img/stirling-dark.png new file mode 100644 index 0000000..1f31040 Binary files /dev/null and b/img/stirling-dark.png differ diff --git a/img/stirling.png b/img/stirling-light.png similarity index 100% rename from img/stirling.png rename to img/stirling-light.png diff --git a/img/trig-dark.png b/img/trig-dark.png new file mode 100644 index 0000000..6e4f143 Binary files /dev/null and b/img/trig-dark.png differ diff --git a/img/trig.png b/img/trig-light.png similarity index 100% rename from img/trig.png rename to img/trig-light.png