rapier-math 2.1.0 → 2.3.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/docs/api.md CHANGED
@@ -287,7 +287,7 @@ evaluation; adding a raw TeX label does not satisfy that requirement.
287
287
 
288
288
  ## Security and deployment
289
289
 
290
- The renderer emits local SVG outlines, never executable HTML, remote font/image fetches or loaded TeX
290
+ The renderer emits local SVG outlines (and plain `text` runs for characters outside the font), never executable HTML, remote font/image fetches or loaded TeX
291
291
  extensions. Authored links permit only HTTP(S) and use `noopener noreferrer`. Insert only the returned
292
292
  SVG, never concatenate TeX or arbitrary HTML into the sink. On failure, use a text node or the framework's
293
293
  escaped text rendering. Formula safety does not sanitize surrounding Markdown.
@@ -311,7 +311,9 @@ Greek and mathematical alphabets, text/color/size/spacing, local macros, and sel
311
311
  Existing supported package names select built-in syntax; there is no external package/file loader.
312
312
  This is not a complete TeX document engine. No automatic numbering or cross-formula reference guarantee.
313
313
  Unsupported commands give diagnostics. Lowercase script/bold-script requests use ordinary-letter fallbacks
314
- where Latin Modern lacks those alphabets. All embedded licensed outlines remain present.
314
+ where Latin Modern lacks those alphabets. All embedded licensed outlines remain present. Letters, digits
315
+ and symbols the font lacks (for example CJK, Cyrillic, Arabic or emoji) are drawn as an SVG `text` run in
316
+ the reader's own serif font, fitted to an estimated width, rather than refused.
315
317
 
316
318
  ## Package and proof
317
319
 
@@ -101,14 +101,20 @@ coordinates if present. Missing italic corrections are zero; missing accent atta
101
101
  Assembly parts retain the OpenType order: bottom to top vertically, left to right horizontally. Latin Modern has
102
102
  no MATH Device adjustments. Hint programs and general text shaping tables are not used by the SVG renderer.
103
103
 
104
- Contour profiles cover 1,187 ASCII alphanumeric, mathematical italic and script glyphs, including optical and
105
- dotless forms. Entry `i + 1` bounds the original contour within `[y0 + i * edgeStep, y0 + (i + 1) * edgeStep]`;
104
+ Contour profiles cover 1,190 ASCII alphanumeric, mathematical italic and script glyphs, with U+210E (the
105
+ italic h) and the optical and dotless forms. Entry `i + 1` bounds the original contour within `[y0 + i * edgeStep, y0 + (i + 1) * edgeStep]`;
106
106
  `null` means no ink. Cubic intersections and horizontal extrema determine the bounds. Values round outward
107
107
  with a small numerical guard. Profiles are derived spacing data; they do not replace outlines or pretend to be
108
108
  an original MATH kern table. Layout compares intersecting strips from both glyphs when placing scripts.
109
109
 
110
- Character mappings, optical substitutions and record offsets occupy a compact index decoded at module load.
111
- Glyph metrics, outlines and contour profiles stay in independent raw DEFLATE pages until requested. Every page
110
+ The asset stores neither bounds nor profiles. The decoder derives both from the outline: bounds with the
111
+ arithmetic of fontTools' `BoundsPen`, profiles with the strip algorithm above, operation for operation in
112
+ IEEE double precision. For this font every derived bound and profile equals the value the 2.2.0 asset stored
113
+ (2.2.0 had no profile for U+210E and its two optical forms).
114
+
115
+ Character mappings, optical substitutions, stretch constructions, the profiled glyph set and record offsets
116
+ occupy a compact index decoded at module load. Glyph metrics and outlines stay in independent raw DEFLATE pages
117
+ until requested. Every page
112
118
  ends at a record boundary and contains at most 16,384 decoded bytes. The complete set of pages travels in the
113
119
  same asset; rare characters, stretch parts and optical forms require no additional download.
114
120
 
@@ -118,19 +124,19 @@ exact differences from an earlier contour with the same structure. Parent chains
118
124
  The generator prefers small coordinate differences as well as short records, because the smallest initial
119
125
  record does not necessarily produce the smallest compressed page. Glyph assembly restores the original
120
126
  absolute `M/L/H/V/C/Z` paths, including contour order; existing outline-part consumers use those commands.
127
+ A contour whose closing curve ends at its start omits that end point; the decoder returns the curve to the start.
121
128
 
122
- Glyph metrics use reversible bearing and half-advance predictors with a median origin per metric field.
123
- They retain the complete original bounds, advance, italic and accent measurements. Signed record integers
129
+ Glyph metrics use a reversible half-advance accent predictor with a median origin per metric field.
130
+ They retain the complete original advance, italic and accent measurements. Signed record integers
124
131
  use zigzag values: values below 240 take one byte, the next 3,840 values take two bytes, and larger values use
125
132
  an escape followed by unsigned LEB128. The coordinate unit is exact; this encoding performs no quantization.
126
133
 
127
- Profiles retain the original left/right strip coordinates and exact differences from matching strip structures.
128
- Identical arrays share storage: all 1,187 glyph-to-profile mappings are represented by 1,080 unique records.
129
134
  The renderer only asks for profiles when side-script placement can use them.
130
135
 
131
- The font owns three bounded least-recently-used caches: eight inflated pages, 256 completed glyph records and
132
- 128 contour profiles. Temporary parent coordinates and page views are discarded after a glyph is assembled;
133
- cached glyphs contain the completed path and metrics. Reusing an evicted record reconstructs the same data.
136
+ Each inflated page, completed glyph record and contour profile stays for the life of the module, so the font
137
+ itself bounds these caches: the pages inflate to about 520 KB. Temporary parent coordinates and page views are
138
+ discarded after a glyph is assembled; cached glyphs keep the completed path and metrics, and profiled glyphs
139
+ also keep the outline segments their profile is derived from.
134
140
  These caches contain font data only. They retain no formula source, parse tree, layout result, SVG element or
135
141
  document. Returned internal records are read-only to consumers.
136
142
 
@@ -2,10 +2,10 @@
2
2
  "spdxVersion": "SPDX-2.3",
3
3
  "dataLicense": "CC0-1.0",
4
4
  "SPDXID": "SPDXRef-DOCUMENT",
5
- "name": "rapier-math-2.1.0",
6
- "documentNamespace": "https://rapier.website/spdx/rapier-math-2.1.0-e1667405881f03e4757563ad9ea34202ba6d3413944b5cc648dc4280b66d567a",
5
+ "name": "rapier-math-2.3.0",
6
+ "documentNamespace": "https://rapier.website/spdx/rapier-math-2.3.0-f5df4637eb2c6fffe325f1f6e9c12132aa4f7741abd24c789fc7ac30c8cf499f",
7
7
  "creationInfo": {
8
- "created": "2026-10-13T12:38:30.961Z",
8
+ "created": "2026-10-15T04:22:09.842Z",
9
9
  "creators": [
10
10
  "Tool: rapier-math-components",
11
11
  "Organization: rapier.website"
@@ -15,17 +15,17 @@
15
15
  {
16
16
  "name": "rapier-math",
17
17
  "SPDXID": "SPDXRef-rapier-math",
18
- "versionInfo": "2.1.0",
18
+ "versionInfo": "2.3.0",
19
19
  "downloadLocation": "NOASSERTION",
20
20
  "filesAnalyzed": false,
21
21
  "licenseConcluded": "MIT AND LicenseRef-GUST-Font-License",
22
22
  "licenseDeclared": "MIT AND LicenseRef-GUST-Font-License",
23
23
  "copyrightText": "NOASSERTION",
24
- "sourceInfo": "Verified current build inputs: math-resources.json (SHA-256 1ccf57bc76f95815cb2b9d40b44505e91cd14abe268d9f93d0ea28fb59308eca).",
24
+ "sourceInfo": "Verified current build inputs: math-resources.json (SHA-256 43190d50be5b14a16f69f889041617766b62eab41b88be177aa3e2b388dc1f94).",
25
25
  "checksums": [
26
26
  {
27
27
  "algorithm": "SHA256",
28
- "checksumValue": "e1667405881f03e4757563ad9ea34202ba6d3413944b5cc648dc4280b66d567a"
28
+ "checksumValue": "f5df4637eb2c6fffe325f1f6e9c12132aa4f7741abd24c789fc7ac30c8cf499f"
29
29
  }
30
30
  ]
31
31
  },
@@ -1,30 +1,30 @@
1
1
  {
2
- "bundle": "rapier-math-2.1.0.js",
2
+ "bundle": "rapier-math-2.3.0.js",
3
3
  "packageBundle": "dist/rapier-math.js",
4
- "version": "2.1.0",
4
+ "version": "2.3.0",
5
5
  "license": "MIT AND LicenseRef-GUST-Font-License",
6
- "bytes": 745053,
7
- "gzipBytes": 451500,
8
- "sha256": "e1667405881f03e4757563ad9ea34202ba6d3413944b5cc648dc4280b66d567a",
9
- "sha384": "3+lJzhwiyTiz1ptqIPqrbS/tkfjIki9QnvSY4kyFBv7MCDiH5LmvNUk8CMlaPg9Z",
6
+ "bytes": 673393,
7
+ "gzipBytes": 399554,
8
+ "sha256": "f5df4637eb2c6fffe325f1f6e9c12132aa4f7741abd24c789fc7ac30c8cf499f",
9
+ "sha384": "ie925auPTOH6Zh27w4EowUzc61aeLAYB+3hxZS59bBrEZ21joUXxNWEPR+GBvVn1",
10
10
  "sources": [
11
11
  {
12
12
  "file": "math/font.js",
13
13
  "packageFile": "src/math/font.js",
14
- "bytes": 558741,
15
- "sha256": "ca92701353de9b79527e133d1b44931dedf2a5e647561d4b80626d86f74e7e8b"
14
+ "bytes": 465845,
15
+ "sha256": "d10ac2bcef6e624c4b052602efbbd70c8c69bd40b7e2c5096526291fcae4f60b"
16
16
  },
17
17
  {
18
18
  "file": "math/symbols.js",
19
19
  "packageFile": "src/math/symbols.js",
20
- "bytes": 8484,
21
- "sha256": "0f711ac551d950ba62acbc5cf84d1362276498fbb7809fad55c97d98be100a95"
20
+ "bytes": 9305,
21
+ "sha256": "b48853a637d57697b58dfec4f728e9d67ca9fa041b5a0ccdb4d513d0dc4b4137"
22
22
  },
23
23
  {
24
24
  "file": "math/parser.js",
25
25
  "packageFile": "src/math/parser.js",
26
- "bytes": 69789,
27
- "sha256": "50d740a6190d3ec3218fcf76a1cd7eb74ef18f638e265c5c591e5e943ea91549"
26
+ "bytes": 84418,
27
+ "sha256": "3b7ccf2c7f32fba45a70408939e4c7d5bf18ee5ee9f3f3109b101e81985d5050"
28
28
  },
29
29
  {
30
30
  "file": "math/source.js",
@@ -41,8 +41,8 @@
41
41
  {
42
42
  "file": "math/layout.js",
43
43
  "packageFile": "src/math/layout.js",
44
- "bytes": 36115,
45
- "sha256": "5662f8fd6dd15e496b755d44fc6c0f81589d1eafd49176522e7b7da887c049c9"
44
+ "bytes": 40185,
45
+ "sha256": "c1425c843f3684e24a530a0bdfbeec65626cd6c41893abc395cc5766e38815c0"
46
46
  },
47
47
  {
48
48
  "file": "math/fallbacks.js",
@@ -53,8 +53,8 @@
53
53
  {
54
54
  "file": "math/responsive.js",
55
55
  "packageFile": "src/math/responsive.js",
56
- "bytes": 13839,
57
- "sha256": "d0cff2fd9a520d30b75b1d49074d93d2500c5f32ca6aaa30239498fe6d860e07"
56
+ "bytes": 14156,
57
+ "sha256": "ee1bc05c23be50380c59eed5f9a51057464991695c030563fca8d64d2230d3ec"
58
58
  },
59
59
  {
60
60
  "file": "math/api.js",
@@ -65,14 +65,14 @@
65
65
  {
66
66
  "file": "math/browser.js",
67
67
  "packageFile": "src/math/browser.js",
68
- "bytes": 10172,
69
- "sha256": "c56a36031169a40bbcbaa6be2b197945b5819ca0446392ae2142255ad2a5baa6"
68
+ "bytes": 10946,
69
+ "sha256": "3c163cbe795a6be2781295b10fc41bd8e94248c3bbee521abff43d03fbefbc5d"
70
70
  },
71
71
  {
72
72
  "file": "math/mathml.js",
73
73
  "packageFile": "src/math/mathml.js",
74
- "bytes": 28871,
75
- "sha256": "b337126ecbcfa078e0bd29ef5e33bce0f2b5f792e02935d29beb50ecdc7bbbeb"
74
+ "bytes": 29496,
75
+ "sha256": "f91054b5cabbb32bce79eea6d60f91a3a513a1613ef587d08a86086a983859a5"
76
76
  },
77
77
  {
78
78
  "file": "math/semantic-api.js",
@@ -90,21 +90,21 @@
90
90
  "file": "math/classic.js",
91
91
  "packageFile": "src/math/classic.js",
92
92
  "bytes": 269,
93
- "sha256": "74b3c1332e179113286465e082d44515876fa784ec1d76142e6660f367a7604b"
93
+ "sha256": "e42b812cf9772909c9178b15a85ac300c5e35ae6f56d66261f24654916442c74"
94
94
  }
95
95
  ],
96
96
  "recipe": [
97
97
  {
98
98
  "file": "math/build-font.py",
99
99
  "packageFile": "src/math/build-font.py",
100
- "bytes": 33369,
101
- "sha256": "d54dba7b83d945da4bdeeac6a262c45d0b8f531c0801114451ac3f3d8dab9d35"
100
+ "bytes": 32576,
101
+ "sha256": "98599660cf23e0ee5e38d35732ff353f634c2d4ce641072b0834089533d94836"
102
102
  },
103
103
  {
104
104
  "file": "math/FONT-SOURCE.md",
105
105
  "packageFile": "docs/font-source.md",
106
- "bytes": 10357,
107
- "sha256": "84ab319b1f9342fa08b421231965dd685063d8fd6bb8a071e1f1c186848dcdd9"
106
+ "bytes": 10739,
107
+ "sha256": "621db58ca1b5fcacb450e8f74dfabc533d6856544cf2abb6333a637636d1e0c9"
108
108
  },
109
109
  {
110
110
  "file": "math/FONT-LICENSE.txt",
@@ -121,8 +121,8 @@
121
121
  {
122
122
  "file": "tools/build-math.mjs",
123
123
  "packageFile": "src/tools/build-math.mjs",
124
- "bytes": 9573,
125
- "sha256": "ef053202ffc95e9ae801be789356775381d18c9ab1ac16aa28ee941294bb328e"
124
+ "bytes": 9577,
125
+ "sha256": "442a21aa7c113f93aa706d52a352cb54cbbf2dac33e68e54bd47dafa6f2830e0"
126
126
  },
127
127
  {
128
128
  "file": "math/LICENSE-MIT",
@@ -163,14 +163,14 @@
163
163
  {
164
164
  "file": "math/README.md",
165
165
  "packageFile": "docs/api.md",
166
- "bytes": 23108,
167
- "sha256": "2b79d323c03ba11e6c051d07f4cd688ec9b1f68479c831f426ec276c36ed7b2c"
166
+ "bytes": 23366,
167
+ "sha256": "d3d7d20900f5d32f89182bc8fead8ef08cb57f1173a0306dfb98fe60afc0fa73"
168
168
  },
169
169
  {
170
170
  "file": "math/SEMANTICS.md",
171
171
  "packageFile": "docs/semantics.md",
172
- "bytes": 18096,
173
- "sha256": "c1b63412b38fc96f3b96161584f01ea0eddd194a98d27cd535a5007ba3936847"
172
+ "bytes": 18282,
173
+ "sha256": "98984313665984aaa29fd816cc7b79691deac7450d5d76b8e7dc0f79b575e2cf"
174
174
  },
175
175
  {
176
176
  "file": "math/semantic-verify.mjs",
package/docs/semantics.md CHANGED
@@ -53,7 +53,7 @@ is the portable structural target. Extensions and lossy cases are reported expli
53
53
  | TeX/AST family | Mapping and qualification |
54
54
  | --- | --- |
55
55
  | Rows and groups | `mrow`; explicit groups stay separate. No inferred multiplication or function application is inserted. Explicit U+2061–U+2064 invisible operators remain `mo`. |
56
- | Identifiers and alphabets | `mi`; Unicode mathematical alphabets reuse the SVG renderer's existing pure mapping. Roman identifiers use `mathvariant="normal"`. |
56
+ | Identifiers and alphabets | `mi`; a single default or italic letter stays plain, so MathML Core italicizes it and assistive technology reads the ordinary letter. Other alphabets reuse the SVG renderer's pure Unicode mapping. Roman identifiers use `mathvariant="normal"`. Text spaces become no-break spaces because MathML trims token whitespace. |
57
57
  | Numbers | `mn` joins Unicode decimal-digit integer/decimal runs within one row and matching style. Unary signs remain `mo`. Explicit groups, spaces and style boundaries stop joining. A final directly scripted digit belongs to the complete preceding numeric token, as in `12^3`; `1{2}^3` stays grouped. Multi-dot runs are not reinterpreted as decimals. |
58
58
  | Scientific notation | Authored `1.2e-3` remains a number, identifier and signed expression; there is no inferred exponent grammar. `1.2\times10^{-3}` preserves its explicit structure. The existing units parser's lowering remains reported as a domain fallback. |
59
59
  | Named operators and text | Standard names and plain `operatorname` use one `mo`; ordinary multi-character text uses `mtext`. Mixed or styled operator-name content retains its nested structure and gets a fallback notice. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapier-math",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "Self-contained offline LaTeX-to-SVG rendering with Latin Modern outlines, optional Markdown integrations and streaming helpers.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
@@ -42,9 +42,10 @@ function mathSnapRule(original, matrix, ratio) {
42
42
  'v' + mathNumber(height) + 'h' + mathNumber(-width) + 'Z'};
43
43
  }
44
44
 
45
- function mathSnapRules(svg) {
46
- const ratio=svg.ownerDocument.defaultView.devicePixelRatio || 1;
47
- for(const rule of svg.querySelectorAll('[data-math-rule],[data-math-line]')) {
45
+ // Every rule is measured before any is rewritten, so the browser lays the page out once, not once per formula.
46
+ function mathSnapRules(svgs) {
47
+ const measured=[];
48
+ for(const svg of svgs)for(const rule of svg.querySelectorAll('[data-math-rule],[data-math-line]')) {
48
49
  let original=mathRuleOriginals.get(rule);
49
50
  if(!original) {
50
51
  const box=rule.getBBox(), axis=rule.getAttribute('data-math-line'), thickness=Number(rule.getAttribute('stroke-width'));
@@ -53,7 +54,10 @@ function mathSnapRules(svg) {
53
54
  if(axis==='vertical') {original.x-=thickness/2;original.width=thickness;}
54
55
  mathRuleOriginals.set(rule,original);
55
56
  }
56
- const snapped=mathSnapRule(original,rule.getScreenCTM(),ratio);
57
+ measured.push([rule,original,rule.getScreenCTM(),svg.ownerDocument.defaultView.devicePixelRatio || 1]);
58
+ }
59
+ for(const [rule,original,matrix,ratio] of measured) {
60
+ const snapped=mathSnapRule(original,matrix,ratio);
57
61
  if(!snapped)continue;
58
62
  let path=snapped.d;
59
63
  if(original.axis==='horizontal') {
@@ -69,13 +73,18 @@ function mathSnapRules(svg) {
69
73
  }
70
74
  }
71
75
 
72
- function mathFitElement(svg, printing = false) {
76
+ // Reads only: the column, font and paper of one formula.
77
+ function mathFitMeasure(svg, printing) {
73
78
  if(!svg.isConnected)return null;
74
- const doc=svg.ownerDocument,view=doc.defaultView,column=mathColumn(svg),style=view.getComputedStyle(column),font=parseFloat(view.getComputedStyle(svg).fontSize);
79
+ const view=svg.ownerDocument.defaultView,column=mathColumn(svg),style=view.getComputedStyle(column),font=parseFloat(view.getComputedStyle(svg).fontSize);
75
80
  const available=column.clientWidth-(parseFloat(style.paddingLeft) || 0)-(parseFloat(style.paddingRight) || 0);
76
- if(!(available>0 && font>0))return column;
77
- const width=Math.max(.1,(available-.25)/font),source=svg.getAttribute('aria-label'),display=svg.getAttribute('data-rapier-math')==='display';
78
- const dark=!printing && mathDarkPaper(svg),ratio=view.devicePixelRatio || 1;
81
+ if(!(available>0 && font>0))return {column};
82
+ return {svg,column,font,width:Math.max(.1,(available-.25)/font),dark:!printing && mathDarkPaper(svg),ratio:view.devicePixelRatio || 1};
83
+ }
84
+
85
+ // Writes only: re-render and restyle one measured formula.
86
+ function mathFitApply({svg,font,width,dark,ratio}, printing) {
87
+ const doc=svg.ownerDocument,view=doc.defaultView,source=svg.getAttribute('aria-label'),display=svg.getAttribute('data-rapier-math')==='display';
79
88
  const screen=printing?undefined:{fontSize:font/mathFontRatio,pixelRatio:ratio,dark};
80
89
  const screenKey=printing?'':mathNumber(font)+'|'+mathNumber(ratio)+'|'+dark;
81
90
  let state=mathBrowserStates.get(svg);
@@ -112,13 +121,19 @@ function mathFitElement(svg, printing = false) {
112
121
  node.setAttribute('fill-opacity','1');node.setAttribute('stroke-opacity','1');
113
122
  }
114
123
  }
115
- if(!printing)mathSnapRules(svg);
116
- return column;
124
+ }
125
+
126
+ // All formulas are measured, then all rewritten, then all rules snapped: three layouts for any number of formulas.
127
+ function mathFitElements(svgs, printing) {
128
+ const measured=svgs.map(svg=>mathFitMeasure(svg,printing)).filter(Boolean),fitted=measured.filter(item=>item.svg);
129
+ for(const item of fitted)mathFitApply(item,printing);
130
+ if(!printing)mathSnapRules(fitted.map(item=>item.svg));
131
+ return measured.map(item=>item.column);
117
132
  }
118
133
 
119
134
  function mathFit(root) {
120
135
  const nodes=mathElements(root);
121
- for(const svg of nodes)mathFitElement(svg,svg.ownerDocument.defaultView.matchMedia('print').matches);
136
+ if(nodes.length)mathFitElements(nodes,nodes[0].ownerDocument.defaultView.matchMedia('print').matches);
122
137
  return nodes.length;
123
138
  }
124
139
 
@@ -129,11 +144,7 @@ function mathObserveDocument(doc) {
129
144
  if(!active)return;
130
145
  if(frame!==null)view.cancelAnimationFrame(frame);
131
146
  frame=null;
132
- const wanted=new Set();
133
- for(const svg of nodes.keys()) {
134
- if(!svg.isConnected || svg.ownerDocument!==doc || !svg.matches(mathSvgSelector))continue;
135
- const column=mathFitElement(svg,printing);if(column)wanted.add(column);
136
- }
147
+ const wanted=new Set(mathFitElements([...nodes.keys()].filter(svg=>svg.isConnected && svg.ownerDocument===doc && svg.matches(mathSvgSelector)),printing));
137
148
  for(const column of columns)if(!wanted.has(column)) {resize.unobserve(column);columns.delete(column);}
138
149
  for(const column of wanted)if(!columns.has(column)) {resize.observe(column);columns.add(column);}
139
150
  };