rapier-math 2.6.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -3
- package/LICENSE +1 -1
- package/README.md +20 -31
- package/dist/accessible.d.ts +2 -2
- package/dist/classic.d.ts +1 -1
- package/dist/combined.d.ts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/integration.d.ts +1 -1
- package/dist/markdown-it.d.ts +2 -0
- package/dist/rapier-math.js +227 -122
- package/dist/rehype.d.ts +1 -1
- package/docs/api.md +10 -8
- package/docs/font-source.md +30 -19
- package/docs/formula-dark.svg +1 -0
- package/docs/formula-light.svg +1 -0
- package/docs/math-components.json +8 -8
- package/docs/math-resources.json +46 -46
- package/docs/semantics.md +6 -3
- package/package.json +1 -1
- package/src/math/FONT-LICENSE.txt +1 -1
- package/src/math/build-font.py +36 -24
- package/src/math/classic.js +1 -1
- package/src/math/font.js +5 -5
- package/src/math/layout.js +68 -84
- package/src/math/mathml.js +53 -7
- package/src/math/package-readme.mjs +20 -31
- package/src/math/parser.js +102 -25
- package/src/tools/build-math.mjs +11 -4
package/src/math/build-font.py
CHANGED
|
@@ -20,6 +20,7 @@ import urllib.request
|
|
|
20
20
|
import zlib
|
|
21
21
|
|
|
22
22
|
from fontTools.pens.svgPathPen import SVGPathPen
|
|
23
|
+
from fontTools.pens.boundsPen import BoundsPen, ControlBoundsPen
|
|
23
24
|
from fontTools.t1Lib import T1Font
|
|
24
25
|
from fontTools.ttLib import TTFont
|
|
25
26
|
|
|
@@ -82,11 +83,11 @@ def extract(font: TTFont):
|
|
|
82
83
|
cmap = font.getBestCmap()
|
|
83
84
|
table = font["MATH"].table
|
|
84
85
|
variants = table.MathVariants
|
|
85
|
-
scripts,
|
|
86
|
+
scripts, dotless = (feature_alternates(font, tag) for tag in ("ssty", "dtls"))
|
|
86
87
|
used = set(cmap.values())
|
|
87
88
|
while True:
|
|
88
89
|
previous = len(used)
|
|
89
|
-
for feature in (scripts,
|
|
90
|
+
for feature in (scripts, dotless):
|
|
90
91
|
for name, alternates in feature.items():
|
|
91
92
|
if name in used:
|
|
92
93
|
used.update(alternates)
|
|
@@ -120,13 +121,11 @@ def extract(font: TTFont):
|
|
|
120
121
|
"xHeight": font["OS/2"].sxHeight,
|
|
121
122
|
"glyphs": glyphs,
|
|
122
123
|
"chars": {cp: ids[name] for cp, name in sorted(cmap.items())},
|
|
123
|
-
"constants": {key: scalar(value) for key, value in vars(table.MathConstants).items() if not key.startswith("_")},
|
|
124
|
+
"constants": {key: scalar(value) for key, value in vars(table.MathConstants).items() if not key.startswith("_") and key not in UNUSED_CONSTANTS},
|
|
124
125
|
"vertical": {},
|
|
125
126
|
"horizontal": {},
|
|
126
127
|
"minConnectorOverlap": variants.MinConnectorOverlap,
|
|
127
|
-
"kern": {},
|
|
128
128
|
"scriptAlternates": {ids[name]: [ids[alternate] for alternate in alternates] for name, alternates in scripts.items() if name in ids},
|
|
129
|
-
"flatAccents": {ids[name]: ids[alternates[0]] for name, alternates in flattened.items() if name in ids},
|
|
130
129
|
"dotless": {ids[name]: ids[alternates[0]] for name, alternates in dotless.items() if name in ids},
|
|
131
130
|
"extendedShapes": {ids[name]: 1 for name in (info.ExtendedShapeCoverage.glyphs if info.ExtendedShapeCoverage else []) if name in ids},
|
|
132
131
|
}
|
|
@@ -144,22 +143,32 @@ def extract(font: TTFont):
|
|
|
144
143
|
"parts": [[ids[p.glyph], p.StartConnectorLength, p.EndConnectorLength, p.FullAdvance, p.PartFlags & 1] for p in assembly.PartRecords],
|
|
145
144
|
}
|
|
146
145
|
data[key][ids[name]] = record
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
146
|
+
# LuaTeX's CFF loader bounds curves by their control points. Keep those semantic vertical boxes separate
|
|
147
|
+
# from the exact ink bounds the outline decoder computes; large operators use them when centering on the axis.
|
|
148
|
+
vertical_ids = set(data["vertical"])
|
|
149
|
+
for record in data["vertical"].values():
|
|
150
|
+
vertical_ids.update(glyph for glyph, _ in record["variants"])
|
|
151
|
+
data["verticalBounds"] = {}
|
|
152
|
+
for glyph in sorted(vertical_ids):
|
|
153
|
+
exact, control = BoundsPen(glyph_set), ControlBoundsPen(glyph_set)
|
|
154
|
+
glyph_set[names[glyph]].draw(exact)
|
|
155
|
+
glyph_set[names[glyph]].draw(control)
|
|
156
|
+
if exact.bounds and control.bounds:
|
|
157
|
+
ink = [math.floor(exact.bounds[1]), math.ceil(exact.bounds[3])]
|
|
158
|
+
box = [round(control.bounds[1]), round(control.bounds[3])]
|
|
159
|
+
if box != ink:
|
|
160
|
+
data["verticalBounds"][glyph] = box
|
|
156
161
|
return data
|
|
157
162
|
|
|
158
163
|
|
|
159
164
|
PAGE_BYTES = 16384
|
|
160
165
|
PAGE_STRIDE = 32768
|
|
161
166
|
PARENT_DEPTH = 4
|
|
162
|
-
|
|
167
|
+
# The pinned font has no MathKernInfo or flac records. These constants have no layout consumer.
|
|
168
|
+
UNUSED_CONSTANTS = {"DelimitedSubFormulaMinHeight", "FlattenedAccentBaseHeight", "StretchStackTopShiftUp",
|
|
169
|
+
"StretchStackBottomShiftDown", "StretchStackGapAboveMin", "StretchStackGapBelowMin",
|
|
170
|
+
"SkewedFractionHorizontalGap", "SkewedFractionVerticalGap"}
|
|
171
|
+
SCALAR_MAPS = ("chars", "dotless", "extendedShapes")
|
|
163
172
|
|
|
164
173
|
|
|
165
174
|
def unsigned(value, target):
|
|
@@ -477,7 +486,7 @@ def main():
|
|
|
477
486
|
parser.add_argument("--license", type=Path, help="Optional pinned GUST Font License; otherwise fetch it")
|
|
478
487
|
parser.add_argument("--lppl", type=Path, help="Optional pinned LPPL 1.3c; otherwise fetch it")
|
|
479
488
|
parser.add_argument("--text-font", type=Path, help="Optional pinned Geist calibration font; otherwise use the editor copy or fetch it")
|
|
480
|
-
parser.add_argument("--mono-font", type=Path, help="Optional pinned Latin Modern Mono font for
|
|
489
|
+
parser.add_argument("--mono-font", type=Path, help="Optional pinned Latin Modern Mono font for text punctuation; otherwise fetch it")
|
|
481
490
|
parser.add_argument("--hook-font", type=Path, help="Optional pinned Latin Modern Math Italic font for its arrow hook; otherwise fetch it")
|
|
482
491
|
parser.add_argument("--out", type=Path, default=Path(__file__).with_name("font.js"))
|
|
483
492
|
args = parser.parse_args()
|
|
@@ -490,16 +499,19 @@ def main():
|
|
|
490
499
|
text_font = TTFont(io.BytesIO(text_bytes))
|
|
491
500
|
mono = TTFont(io.BytesIO(source_bytes(args.mono_font, MONO_URL, MONO_SHA256)))
|
|
492
501
|
data = extract(font)
|
|
493
|
-
#
|
|
502
|
+
# The math font already carries the exact 62 Mono letters and digits. Text punctuation, visible space and
|
|
503
|
+
# sharp s have no mathematical monospace code points; keep their original Mono outlines beside it.
|
|
494
504
|
if mono["head"].unitsPerEm != data["units"]:
|
|
495
505
|
raise ValueError("The monospace outline must share the math font's units")
|
|
496
506
|
mono_glyphs = mono.getGlyphSet()
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
507
|
+
data["styledGlyphs"] = {"monospace": {}}
|
|
508
|
+
for cp in [0xDF, *(cp for cp in range(33, 127) if not chr(cp).isalnum()), 0x2423]:
|
|
509
|
+
name = mono.getBestCmap()[cp]
|
|
510
|
+
path = SVGPathPen(mono_glyphs, ntos=number)
|
|
511
|
+
mono_glyphs[name].draw(path)
|
|
512
|
+
advance = mono["hmtx"].metrics[name][0]
|
|
513
|
+
data["styledGlyphs"]["monospace"][cp] = len(data["glyphs"])
|
|
514
|
+
data["glyphs"].append([advance, 0, advance / 2, path.getCommands()])
|
|
503
515
|
# amsmath's hooked arrow uses the small math-italic hook, not Unicode's taller hooked-arrow glyph.
|
|
504
516
|
with tempfile.NamedTemporaryFile() as source:
|
|
505
517
|
source.write(source_bytes(args.hook_font, HOOK_URL, HOOK_SHA256))
|
|
@@ -516,7 +528,7 @@ def main():
|
|
|
516
528
|
+ mono["name"].getDebugName(0) + "\n\n"
|
|
517
529
|
+ hook["FontInfo"]["Notice"] + "\n\n"
|
|
518
530
|
"Rapier math font data, derived from Latin Modern Math 1.959,\n"
|
|
519
|
-
"
|
|
531
|
+
"text outlines from Latin Modern Mono 2.004, and one arrow hook\n"
|
|
520
532
|
"from Latin Modern Math Italic 10 Regular 2.003.\n"
|
|
521
533
|
"Changes: SVG outline conversion, character and MATH data extraction,\n"
|
|
522
534
|
"optical-form closure and lossless path packing.\n"
|
package/src/math/classic.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
globalThis.RapierMath=Object.freeze({
|
|
3
|
-
version:'
|
|
3
|
+
version:'3.0.0', parse:parseMathTex,
|
|
4
4
|
render:renderMath, renderToString:mathRenderToString,
|
|
5
5
|
fit:mathFit, observe:mathObserve,
|
|
6
6
|
toMathML:mathToMathML, renderWithMathML:mathRenderWithMathML,
|