Added fonts and provided previews.

This commit is contained in:
Michael Griebling
2024-10-08 19:35:42 -04:00
parent de4484382d
commit 7799485428
19 changed files with 36580 additions and 14 deletions

View File

@@ -54,6 +54,12 @@ f(x) = \int\limits_{-\infty}^\infty\!\hat f(\xi)\,e^{2 \pi i \xi x}\,\mathrm{d}\
![Ramanujan Identity](img/ramanujan-dark.png#gh-dark-mode-only)
More examples are included in [EXAMPLES](EXAMPLES.md)
## Fonts
Here are previews of the included fonts:
![](img/FontsPreview.png#gh-dark-mode-only)
![](img/FontsPreviewLight.png#gh-light-mode-only)
## Requirements
`SwiftMath` works on iOS 11+ or MacOS 12+. It depends
@@ -170,7 +176,7 @@ This is a list of formula types that the library currently supports:
* Equation alignment
* Change bold, roman, caligraphic and other font styles (\\bf, \\text, etc.)
* Most commonly used math symbols
* Colors
* Colors for both text and background
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
@@ -225,13 +231,15 @@ The default font is *Latin Modern Math*. This can be changed as:
label.font = MTFontManager.fontmanager.termesFont(withSize:20)
```
This project has five fonts bundled with it, but you can use any OTF math
This project has 12 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.
Note: The `KpMath-Light` and `KpMath-Sans` fonts currently incorrectly
Note: The `KpMath-Light`, `KpMath-Sans`, `Asana` fonts currently incorrectly
render very large radicals. It appears that the font files do
not properly define the offsets required to typeset these glyphs. If
anyone can fix this, it would be greatly appreciated.

View File

@@ -11,30 +11,53 @@ import UIKit
import AppKit
#endif
public enum MathFont: String, CaseIterable {
public enum MathFont: String, CaseIterable, Identifiable {
public var id: Self { self } // Makes things simpler for SwiftUI
case latinModernFont = "latinmodern-math"
case kpMathLightFont = "KpMath-Light"
case kpMathSansFont = "KpMath-Sans"
case xitsFont = "xits-math"
case termesFont = "texgyretermes-math"
case asanaFont = "Asana-Math"
case eulerFont = "Euler-Math"
case firaFont = "FiraMath-Regular"
case notoSansFont = "NotoSansMath-Regular"
case libertinusFont = "LibertinusMath-Regular"
case garamondFont = "Garamond-Math"
case leteSansFont = "LeteSansMath"
var fontFamilyName: String {
switch self {
case .latinModernFont: return "Latin Modern Math"
case .kpMathLightFont: return "KpMath"
case .kpMathSansFont: return "KpMath"
case .xitsFont: return "XITS Math"
case .termesFont: return "TeX Gyre Termes Math"
case .latinModernFont: "Latin Modern Math"
case .kpMathLightFont: "KpMath"
case .kpMathSansFont: "KpMath"
case .xitsFont: "XITS Math"
case .termesFont: "TeX Gyre Termes Math"
case .asanaFont: "Asana Math"
case .eulerFont: "Euler Math"
case .firaFont: "Fira Math"
case .notoSansFont: "Noto Sans Math"
case .libertinusFont: "Libertinus Math"
case .garamondFont: "Garamond Math"
case .leteSansFont: "Lete Sans Math"
}
}
var fontName: String {
switch self {
case .latinModernFont: return "LatinModernMath-Regular"
case .kpMathLightFont: return "KpMath-Light"
case .kpMathSansFont: return "KpMath-Sans"
case .xitsFont: return "XITSMath"
case .termesFont: return "TeXGyreTermesMath-Regular"
case .latinModernFont: "LatinModernMath-Regular"
case .kpMathLightFont: "KpMath-Light"
case .kpMathSansFont: "KpMath-Sans"
case .xitsFont: "XITSMath"
case .termesFont: "TeXGyreTermesMath-Regular"
case .asanaFont: "Asana Math"
case .eulerFont: "Euler Math"
case .firaFont: "Fira Math"
case .notoSansFont: "Noto Sans Math"
case .libertinusFont: "Libertinus Math"
case .garamondFont: "Garamond Math"
case .leteSansFont: "Lete Sans Math"
}
}
public func cgFont() -> CGFont {

View File

@@ -56,6 +56,34 @@ public class MTFontManager {
MTFontManager.fontManager.font(withName: "texgyretermes-math", size: size)
}
public func asanaFont(withSize size:CGFloat) -> MTFont? {
MTFontManager.fontManager.font(withName: "Asana-Math", size: size)
}
public func eulerFont(withSize size:CGFloat) -> MTFont? {
MTFontManager.fontManager.font(withName: "Euler-Math", size: size)
}
public func firaRegularFont(withSize size:CGFloat) -> MTFont? {
MTFontManager.fontManager.font(withName: "FiraMath-Regular", size: size)
}
public func notoSansRegularFont(withSize size:CGFloat) -> MTFont? {
MTFontManager.fontManager.font(withName: "NotoSansMath-Regular", size: size)
}
public func libertinusRegularFont(withSize size:CGFloat) -> MTFont? {
MTFontManager.fontManager.font(withName: "LibertinusMath-Regular", size: size)
}
public func garamondMathFont(withSize size:CGFloat) -> MTFont? {
MTFontManager.fontManager.font(withName: "Garamond-Math", size: size)
}
public func leteSansFont(withSize size:CGFloat) -> MTFont? {
MTFontManager.fontManager.font(withName: "LeteSansMath", size: size)
}
public var defaultFont: MTFont? {
MTFontManager.fontManager.latinModernFont(withSize: kDefaultFontSize)
}

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

BIN
img/FontsPreview.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 KiB

BIN
img/FontsPreviewLight.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB