rapier-math 2.7.0 → 3.1.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/README.md +23 -32
- package/dist/accessible.d.ts +2 -2
- package/dist/classic.d.ts +1 -2
- package/dist/cli.mjs +438 -0
- package/dist/combined.d.ts +2 -2
- package/dist/delimiters.mjs +56 -17
- package/dist/index.mjs +1 -1
- package/dist/integration.d.ts +1 -1
- package/dist/markdown-it.d.ts +2 -0
- package/dist/markdown-rules.mjs +22 -5
- package/dist/rapier-math.js +1 -1
- package/dist/rehype.d.ts +1 -1
- package/docs/api.md +53 -49
- package/docs/font-source.md +24 -24
- package/docs/formula-dark.svg +1 -0
- package/docs/formula-light.svg +1 -0
- package/docs/math-components.json +6 -6
- package/docs/math-resources.json +47 -41
- package/docs/semantics.md +39 -36
- package/examples/README.md +7 -7
- package/package.json +6 -3
- package/skills/rapier-math/SKILL.md +60 -0
- package/src/math/classic.js +1 -1
- package/src/math/package-layout.mjs +2 -2
- package/src/math/package-readme.mjs +23 -32
- package/src/tools/build-math.mjs +10 -3
- package/CHANGELOG.md +0 -10
package/docs/math-resources.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
"bundle": "rapier-math-
|
|
2
|
+
"bundle": "rapier-math-3.1.0.js",
|
|
3
3
|
"packageBundle": "dist/rapier-math.js",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.1.0",
|
|
5
5
|
"license": "MIT AND LicenseRef-GUST-Font-License",
|
|
6
6
|
"bytes": 742684,
|
|
7
|
-
"gzipBytes":
|
|
8
|
-
"sha256": "
|
|
9
|
-
"sha384": "
|
|
7
|
+
"gzipBytes": 421701,
|
|
8
|
+
"sha256": "f7513e9078e35bc7fe471960b6a5dc7822d80f7ad35e4321c5d2c131ea6c4ac7",
|
|
9
|
+
"sha384": "ScqVpxxnEv66kw08gHxrm/D7ty17X3GlpuVoZUl5mA1okCGTCMNwUYdkKbqJn3bU",
|
|
10
10
|
"sources": [
|
|
11
11
|
{
|
|
12
12
|
"file": "math/font.js",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"file": "math/classic.js",
|
|
91
91
|
"packageFile": "src/math/classic.js",
|
|
92
92
|
"bytes": 269,
|
|
93
|
-
"sha256": "
|
|
93
|
+
"sha256": "fd1f5b1096dd484b048638fab5ff149edbd9d5f0048cbf645e8b7a9f1ccf3288"
|
|
94
94
|
}
|
|
95
95
|
],
|
|
96
96
|
"recipe": [
|
|
@@ -103,8 +103,8 @@
|
|
|
103
103
|
{
|
|
104
104
|
"file": "math/FONT-SOURCE.md",
|
|
105
105
|
"packageFile": "docs/font-source.md",
|
|
106
|
-
"bytes":
|
|
107
|
-
"sha256": "
|
|
106
|
+
"bytes": 12635,
|
|
107
|
+
"sha256": "18d22cc21724f7d150ea4642dc95a280966392303f1b6f42d7a0f407c0178e98"
|
|
108
108
|
},
|
|
109
109
|
{
|
|
110
110
|
"file": "math/FONT-LICENSE.txt",
|
|
@@ -115,8 +115,8 @@
|
|
|
115
115
|
{
|
|
116
116
|
"file": "tools/build-math.mjs",
|
|
117
117
|
"packageFile": "src/tools/build-math.mjs",
|
|
118
|
-
"bytes":
|
|
119
|
-
"sha256": "
|
|
118
|
+
"bytes": 11626,
|
|
119
|
+
"sha256": "72b44fef13b3109a3e12552e164626aa1dcb64886ec181dd0b62d5c92ec581ea"
|
|
120
120
|
},
|
|
121
121
|
{
|
|
122
122
|
"file": "math/LICENSE-MIT",
|
|
@@ -133,32 +133,38 @@
|
|
|
133
133
|
{
|
|
134
134
|
"file": "math/package-layout.mjs",
|
|
135
135
|
"packageFile": "src/math/package-layout.mjs",
|
|
136
|
-
"bytes":
|
|
137
|
-
"sha256": "
|
|
136
|
+
"bytes": 993,
|
|
137
|
+
"sha256": "b70a8b45112a7e7b3eb8a05a9837de39cbd8a50d7aefd140e91cb2b0e430cb4c"
|
|
138
138
|
},
|
|
139
139
|
{
|
|
140
140
|
"file": "math/package-readme.mjs",
|
|
141
141
|
"packageFile": "src/math/package-readme.mjs",
|
|
142
|
-
"bytes":
|
|
143
|
-
"sha256": "
|
|
142
|
+
"bytes": 2095,
|
|
143
|
+
"sha256": "a72890e98766f6cebbbc860b1e773debd8e9a04dacff1af75e568c84cbdf579a"
|
|
144
144
|
},
|
|
145
145
|
{
|
|
146
146
|
"file": "math/README.md",
|
|
147
147
|
"packageFile": "docs/api.md",
|
|
148
|
-
"bytes":
|
|
149
|
-
"sha256": "
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
"file": "math/CHANGELOG.md",
|
|
153
|
-
"packageFile": "CHANGELOG.md",
|
|
154
|
-
"bytes": 389,
|
|
155
|
-
"sha256": "621ffa760f4ebeb72c7882e46caf8c8cb815abde50cd98d123da5a34ea105397"
|
|
148
|
+
"bytes": 24296,
|
|
149
|
+
"sha256": "fed96a04c7c39a71d814344e922e883a8492394aa8fea6ec58a11b283d2946ad"
|
|
156
150
|
},
|
|
157
151
|
{
|
|
158
152
|
"file": "math/SEMANTICS.md",
|
|
159
153
|
"packageFile": "docs/semantics.md",
|
|
160
|
-
"bytes":
|
|
161
|
-
"sha256": "
|
|
154
|
+
"bytes": 18413,
|
|
155
|
+
"sha256": "ead72ea53908d98dc81dc6f12f87b5e4a9498c8d908f3bcada116e990a9b7f98"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"file": "math/cli.mjs",
|
|
159
|
+
"packageFile": "dist/cli.mjs",
|
|
160
|
+
"bytes": 19282,
|
|
161
|
+
"sha256": "8b8f94baa894fc81a31f833a1e986ec7699d5763b7bbb590961542aee7cfabad"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"file": "math/skills/rapier-math/SKILL.md",
|
|
165
|
+
"packageFile": "skills/rapier-math/SKILL.md",
|
|
166
|
+
"bytes": 4916,
|
|
167
|
+
"sha256": "31a509e5388a15324d98be9b138cef44c53333b8e7280ca97217c393299c4413"
|
|
162
168
|
}
|
|
163
169
|
],
|
|
164
170
|
"components": [
|
|
@@ -206,14 +212,14 @@
|
|
|
206
212
|
{
|
|
207
213
|
"file": "math/delimiters.mjs",
|
|
208
214
|
"packageFile": "dist/delimiters.mjs",
|
|
209
|
-
"bytes":
|
|
210
|
-
"sha256": "
|
|
215
|
+
"bytes": 3283,
|
|
216
|
+
"sha256": "19dc9d5c0ce1051e6e1481e62d28c988c7d8fde1e85d68b6dcc41f8891da0461"
|
|
211
217
|
},
|
|
212
218
|
{
|
|
213
219
|
"file": "math/markdown-rules.mjs",
|
|
214
220
|
"packageFile": "dist/markdown-rules.mjs",
|
|
215
|
-
"bytes":
|
|
216
|
-
"sha256": "
|
|
221
|
+
"bytes": 6749,
|
|
222
|
+
"sha256": "3ef451b770756575674c44b16a27527e75c76a01517f4f6568da109ddee8fe69"
|
|
217
223
|
},
|
|
218
224
|
{
|
|
219
225
|
"file": "math/reuse.mjs",
|
|
@@ -266,14 +272,14 @@
|
|
|
266
272
|
{
|
|
267
273
|
"file": "math/combined.d.ts",
|
|
268
274
|
"packageFile": "dist/combined.d.ts",
|
|
269
|
-
"bytes":
|
|
270
|
-
"sha256": "
|
|
275
|
+
"bytes": 313,
|
|
276
|
+
"sha256": "b48989c14ea7d290add0c98ad1758c223f6d0d6a0049170b4d7cff90d44f9698"
|
|
271
277
|
},
|
|
272
278
|
{
|
|
273
279
|
"file": "math/accessible.d.ts",
|
|
274
280
|
"packageFile": "dist/accessible.d.ts",
|
|
275
|
-
"bytes":
|
|
276
|
-
"sha256": "
|
|
281
|
+
"bytes": 624,
|
|
282
|
+
"sha256": "9cef1d88ea6c2e3c44d3cc439fb49adca42726e3c7abfe5f24a684c02e12e56a"
|
|
277
283
|
},
|
|
278
284
|
{
|
|
279
285
|
"file": "math/index.d.ts",
|
|
@@ -284,8 +290,8 @@
|
|
|
284
290
|
{
|
|
285
291
|
"file": "math/classic.d.ts",
|
|
286
292
|
"packageFile": "dist/classic.d.ts",
|
|
287
|
-
"bytes":
|
|
288
|
-
"sha256": "
|
|
293
|
+
"bytes": 305,
|
|
294
|
+
"sha256": "f1bad476b58469beb7feca3f92f5fc6a6f47b8a31c7031c0d027a843c2276182"
|
|
289
295
|
},
|
|
290
296
|
{
|
|
291
297
|
"file": "math/delimiters.d.ts",
|
|
@@ -296,20 +302,20 @@
|
|
|
296
302
|
{
|
|
297
303
|
"file": "math/integration.d.ts",
|
|
298
304
|
"packageFile": "dist/integration.d.ts",
|
|
299
|
-
"bytes":
|
|
300
|
-
"sha256": "
|
|
305
|
+
"bytes": 1051,
|
|
306
|
+
"sha256": "c606cc0e2c693b42af5131c0fb59e6689ece569b7b51c920fe3e78ed56f6dd8f"
|
|
301
307
|
},
|
|
302
308
|
{
|
|
303
309
|
"file": "math/markdown-it.d.ts",
|
|
304
310
|
"packageFile": "dist/markdown-it.d.ts",
|
|
305
|
-
"bytes":
|
|
306
|
-
"sha256": "
|
|
311
|
+
"bytes": 814,
|
|
312
|
+
"sha256": "55059b5a4228edbfdb125f3e4c28c373bfe3b4feefb853dc34dc2299e05e734e"
|
|
307
313
|
},
|
|
308
314
|
{
|
|
309
315
|
"file": "math/rehype.d.ts",
|
|
310
316
|
"packageFile": "dist/rehype.d.ts",
|
|
311
|
-
"bytes":
|
|
312
|
-
"sha256": "
|
|
317
|
+
"bytes": 561,
|
|
318
|
+
"sha256": "6cd2fc33830af68d4c995124977e64a6c07b073afcb680ab7d1dde96e2d9dc0c"
|
|
313
319
|
},
|
|
314
320
|
{
|
|
315
321
|
"file": "math/stream.d.ts",
|
|
@@ -387,7 +393,7 @@
|
|
|
387
393
|
"file": "math/examples/README.md",
|
|
388
394
|
"packageFile": "examples/README.md",
|
|
389
395
|
"bytes": 2881,
|
|
390
|
-
"sha256": "
|
|
396
|
+
"sha256": "fbe6ff6a4424856a9167f39444aa73ad7272fc01c130160ba68a38724cbd86e9"
|
|
391
397
|
}
|
|
392
398
|
]
|
|
393
399
|
}
|
package/docs/semantics.md
CHANGED
|
@@ -23,16 +23,19 @@ import {renderWithMathML} from 'rapier-math/combined';
|
|
|
23
23
|
const result = renderWithMathML(source, {displayMode: true});
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
Its required `semantics` field contains the same result as `toMathML
|
|
26
|
+
Its required `semantics` field contains the same result as `toMathML`. The combined call admits
|
|
27
27
|
and parses once. SVG errors and semantic status remain independent: MathML can represent a
|
|
28
28
|
Unicode character absent from the embedded SVG font. A successful SVG does not turn a semantic
|
|
29
29
|
refusal into success. `renderToString` returns SVG. The complete classic `RapierMath` object
|
|
30
30
|
also exposes `toMathML` and `renderWithMathML`.
|
|
31
31
|
|
|
32
|
+
`preview` and `caret` apply only to the SVG `render` and `renderToString` methods.
|
|
33
|
+
Combined and accessible rendering use the strict parse and never repair incomplete expressions.
|
|
34
|
+
|
|
32
35
|
The font-free entry exports `parse` for inspection as well. Parse results are ordinary,
|
|
33
36
|
detached data: changing a returned tree has no effect on subsequent renders. There is no
|
|
34
37
|
public API accepting arbitrary or modified trees for serialization. Local macros are
|
|
35
|
-
expanded by the existing parser
|
|
38
|
+
expanded by the existing parser. Their expanded tree is separate from exact authored TeX.
|
|
36
39
|
|
|
37
40
|
| Result field | Meaning |
|
|
38
41
|
| --- | --- |
|
|
@@ -52,24 +55,24 @@ is the portable structural target. Extensions and lossy cases are reported expli
|
|
|
52
55
|
|
|
53
56
|
| TeX/AST family | Mapping and qualification |
|
|
54
57
|
| --- | --- |
|
|
55
|
-
| Rows and groups | `mrow
|
|
56
|
-
| Identifiers and alphabets | `mi
|
|
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
|
|
58
|
-
| Scientific notation | Authored `1.2e-3` remains a number, identifier and signed expression
|
|
59
|
-
| Named operators and text | Standard names and plain `operatorname` use one `mo
|
|
60
|
-
| Fractions | `mfrac`, with numerator then denominator
|
|
58
|
+
| 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`. |
|
|
59
|
+
| 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. |
|
|
60
|
+
| 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. |
|
|
61
|
+
| 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. |
|
|
62
|
+
| 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. |
|
|
63
|
+
| Fractions | `mfrac`, with numerator then denominator. Zero-bar fractions and explicit fences are retained. Continued-fraction numerator alignment is a documented presentation fallback. |
|
|
61
64
|
| Roots | `msqrt` or `mroot`, with radicand before degree. |
|
|
62
|
-
| Scripts and limits | `msub`, `msup`, `msubsup
|
|
65
|
+
| Scripts and limits | `msub`, `msup`, `msubsup`, `munder`, `mover`, `munderover` for applicable explicit/display operator limits. |
|
|
63
66
|
| Fences and accents | Explicit `mo` fences, plus under/over accent relationships. No `mfenced` dependency. |
|
|
64
|
-
| Matrices, aligned equations and cases | `mtable`/`mtr`/`mtd`, the original row/cell order and case/matrix fences. Cell alignment uses fixed CSS. Custom row gaps/baselines are reported as presentation fallback. Array insertion content remains in adjacent cells
|
|
67
|
+
| Matrices, aligned equations and cases | `mtable`/`mtr`/`mtd`, the original row/cell order and case/matrix fences. Cell alignment uses fixed CSS. Custom row gaps/baselines are reported as presentation fallback. Array insertion content remains in adjacent cells. Decorative row/column rules are omitted with a notice. |
|
|
65
68
|
| Styles and spaces | `mstyle`, safe fixed CSS, Unicode alphabets and `mspace`. Text script/fraktur/double-struck requests use a disclosed MathML 3 `mathvariant` extension. |
|
|
66
69
|
| Phantom, smash and raising | `mphantom`/`mpadded`. Overlay-width adjustments retain their content with a fallback notice. Native presentation may differ from SVG. |
|
|
67
70
|
| Cancellation and generic negation overlay | MathML 3 `menclose`, with an explicit extension notice. Core-only hosts may omit the mark. Already-negated Unicode operators stay ordinary `mo`. |
|
|
68
|
-
| Rules | A decorative `mspace` with an explicit presentation notice
|
|
71
|
+
| Rules | A decorative `mspace` with an explicit presentation notice. No additional mathematical relationship is inferred. |
|
|
69
72
|
| Explicit `mmlToken` | The authored admitted `mi`/`mn`/`mo`/`mtext` kind and token text are retained before visual literal lowering. Only the parser's admitted font variant is accepted. |
|
|
70
|
-
| Chemistry, physics and units | Existing fractions, scripts, arrows, fences and rows survive. Origin metadata triggers a domain notice
|
|
73
|
+
| Chemistry, physics and units | Existing fractions, scripts, arrows, fences and rows survive. Origin metadata triggers a domain notice. Chemical elements/bonds/charges, unit identities and specialized physical meaning are not invented. |
|
|
71
74
|
| Tags and labels | Tags remain following authored content with a notice. Labels remain parser-discarded metadata: there is no equation identity, automatic numbering or cross-formula reference support. |
|
|
72
|
-
| HTTP(S) links | A native XHTML `a` inside MathML `mtext`, containing a nested MathML expression. This is a disclosed host integration fallback
|
|
75
|
+
| HTTP(S) links | A native XHTML `a` inside MathML `mtext`, containing a nested MathML expression. This is a disclosed host integration fallback. See the composition contract below. Nested links and links inside phantom content refuse the semantic path. |
|
|
73
76
|
|
|
74
77
|
The parser retains only distinctions with live consumers: explicit token kind/text, operator-name
|
|
75
78
|
origin, and chemistry/physics/units/tag origin. Its visual syntax and SVG layout relationships
|
|
@@ -79,7 +82,7 @@ remain the same. Unsupported commands still produce parser diagnostics.
|
|
|
79
82
|
|
|
80
83
|
The first child of `semantics` is the mathematical expression. For XML-valid source without
|
|
81
84
|
CR, a following `annotation encoding="application/x-tex"` keeps exact authored source
|
|
82
|
-
independently. Escaping includes numeric references for tabs and LF
|
|
85
|
+
independently. Escaping includes numeric references for tabs and LF. BOM and supplementary
|
|
83
86
|
Unicode characters remain intact. The semantic token text is normalized presentation and is
|
|
84
87
|
never described as the original source. The [XML character and newline rules](https://www.w3.org/TR/xml/)
|
|
85
88
|
explain why ordinary escaping alone is insufficient.
|
|
@@ -90,7 +93,7 @@ is a readable alternative, not an exact-source claim. This preserves CRLF throug
|
|
|
90
93
|
HAST-to-HTML-to-HAST pipeline: an HTML stringifier can write a decoded CR literally, which a
|
|
91
94
|
later HTML parser normalizes. The ASCII carrier survives that boundary. CR alone does not
|
|
92
95
|
make an otherwise supported expression a fallback or refusal. Recover exact source from the
|
|
93
|
-
annotation selected by `source.encoding
|
|
96
|
+
annotation selected by `source.encoding`. When only markup remains, prefer its UTF-16
|
|
94
97
|
annotation when present, otherwise its TeX annotation. SVG uses the same carrier for CR-bearing source, preserving exact input through host
|
|
95
98
|
reserialization and later browser fitting. The source is admitted and encoded once per operation.
|
|
96
99
|
|
|
@@ -103,7 +106,7 @@ never becomes an invalid character reference. Invalid characters produced by an
|
|
|
103
106
|
Unicode command likewise refuse while retaining its valid authored command text.
|
|
104
107
|
|
|
105
108
|
Source longer than 1,000,000 UTF-16 code units is refused before scanning, escaping or parsing.
|
|
106
|
-
It is not truncated or embedded
|
|
109
|
+
It is not truncated or embedded. `source.omitted`, the diagnostic's `sourceOmitted`, and
|
|
107
110
|
`data-math-source-omitted` make that explicit. Keep that original input with the host.
|
|
108
111
|
|
|
109
112
|
Existing parser bounds still apply: 100,000 tokens, 50,000 nodes, nesting 192 and 4096 macro
|
|
@@ -113,7 +116,7 @@ repeated insertion content count against the semantic budget. If source carriers
|
|
|
113
116
|
presentation exceed the complete-output bound, the result refuses, retains the admitted
|
|
114
117
|
source carriers and replaces the partial expression with `merror`. SVG retains its existing
|
|
115
118
|
separate limits. Combined accessible HTML has a 40 Mi code-unit bound. All budgets are local
|
|
116
|
-
to one operation
|
|
119
|
+
to one operation. A refusal cannot poison a later render. These bounds do not measure device
|
|
117
120
|
memory or claim constant-size output.
|
|
118
121
|
|
|
119
122
|
## Usable SVG and MathML composition
|
|
@@ -129,14 +132,14 @@ else container.innerHTML = result.html; // only freshly generated output reaches
|
|
|
129
132
|
`renderAccessible` calls `renderWithMathML` once. It returns full standalone `svg`, the
|
|
130
133
|
semantic result, `html`, and `presentation`:
|
|
131
134
|
|
|
132
|
-
- `svg-mathml`: visual SVG is inside an `aria-hidden` wrapper
|
|
135
|
+
- `svg-mathml`: visual SVG is inside an `aria-hidden` wrapper. Native MathML is its clipped
|
|
133
136
|
assistive sibling. There are no authored links in this branch. The semantic tree has no
|
|
134
137
|
image role, raw-TeX aria-label, `aria-hidden`, `display:none` or `visibility:hidden` override.
|
|
135
138
|
- `mathml`: authored links use visible native MathML once. Standalone SVG is still returned
|
|
136
139
|
for consumers choosing that representation, but is not inserted into the combined host.
|
|
137
140
|
Each link uses an HTTP(S) URL, a native HTML anchor, `noopener noreferrer`, and its visible
|
|
138
141
|
content as a nested mathematical expression. The destination title supplies a link-name
|
|
139
|
-
fallback in hosts that do not derive a name from MathML children
|
|
142
|
+
fallback in hosts that do not derive a name from MathML children. It is not generated
|
|
140
143
|
mathematical speech or a claim of a descriptive link purpose. No duplicate or clipped
|
|
141
144
|
focus target is created.
|
|
142
145
|
- `refused`: `html` is empty and `errors` explains the failure. Insert the original source
|
|
@@ -145,23 +148,23 @@ semantic result, `html`, and `presentation`:
|
|
|
145
148
|
This composition supplies one exposed semantic equation surface structurally. Its actual
|
|
146
149
|
announcements and link navigation still require AT acceptance. Putting an interactive link
|
|
147
150
|
under `aria-hidden` violates the [W3C focus rule](https://www.w3.org/WAI/standards-guidelines/act/rules/6cfa84/).
|
|
148
|
-
The published Core target omits native MathML links
|
|
151
|
+
The published Core target omits native MathML links. HTML embedding uses its web integration
|
|
149
152
|
rules. A newer editor draft's MathML anchor does not establish support in a target browser.
|
|
150
|
-
Nested, phantom and empty links refuse
|
|
153
|
+
Nested, phantom and empty links refuse. The serializer also checks explicit transparency
|
|
151
154
|
while allowing an opaque descendant. Unknown or host-specific color names cannot undo an explicitly transparent ancestor. These are structural checks, not a visibility guarantee
|
|
152
155
|
under arbitrary host CSS, colors or backgrounds.
|
|
153
156
|
|
|
154
157
|
The stylesheet must be retained. If it is absent or blocked, both ordinary representations
|
|
155
158
|
can become visible. Hosts that cannot include it can insert `toMathML(source).mathml` visibly
|
|
156
|
-
as their sole representation instead. Native MathML uses the host's mathematical font
|
|
157
|
-
|
|
159
|
+
as their sole representation instead. Native MathML uses the host's mathematical font.
|
|
160
|
+
It does not inherit Rapier's embedded SVG outlines. Linked formulas therefore use native
|
|
158
161
|
typesetting rather than a guarantee of identical SVG appearance.
|
|
159
162
|
|
|
160
163
|
`fit`/`observe` may operate on ordinary combined output because its SVG source carrier remains
|
|
161
|
-
intact
|
|
164
|
+
intact. They adjust only SVG geometry. Linked native MathML has no SVG to fit. Do not change
|
|
162
165
|
source on one side of a combined formula: regenerate the whole result. Stop observations
|
|
163
|
-
before replacement and on unmount
|
|
164
|
-
For SSR, emit the same source/options and stylesheet
|
|
166
|
+
before replacement and on unmount. No semantic timers, IDs or retained formula caches exist.
|
|
167
|
+
For SSR, emit the same source/options and stylesheet. Initial MathML needs no client code.
|
|
165
168
|
|
|
166
169
|
The [accessible browser example](../examples/accessible.html) keeps editable source and generated
|
|
167
170
|
MathML available and demonstrates both representations, replacement and cleanup. The
|
|
@@ -172,19 +175,19 @@ preserving its SVG appearance. Put the anchor outside both composition siblings
|
|
|
172
175
|
an authored link-purpose name, such as `aria-label="Open the derivation"`, or a meaningful
|
|
173
176
|
link title. Native MathML children can leave an otherwise unnamed host link blank in a
|
|
174
177
|
browser's accessibility tree. For accessible output the rehype adapter retains an existing
|
|
175
|
-
`aria-label`, `aria-labelledby` or title
|
|
178
|
+
`aria-label`, `aria-labelledby` or title. Otherwise it supplies the existing destination as
|
|
176
179
|
a title fallback. This preserves the native mathematical subtree without synthesizing
|
|
177
180
|
speech. A URL fallback is not a substitute for the author's meaningful link-purpose name.
|
|
178
181
|
Direct `renderAccessible` users must name any containing host anchor themselves. Do not nest
|
|
179
182
|
an internally linked formula inside another link. The adapters retain the outer host link
|
|
180
183
|
and leave such a formula as source with a `nested-link` diagnostic. Host grammar still applies:
|
|
181
|
-
markdown-it keeps math in link labels literal
|
|
184
|
+
markdown-it keeps math in link labels literal. A remark-math/rehype pipeline can admit it.
|
|
182
185
|
|
|
183
186
|
## Markdown, sanitizer and CSP boundaries
|
|
184
187
|
|
|
185
188
|
The neutral markdown-it and rehype adapters accept `accessible: true`. Include the same CSS.
|
|
186
|
-
Their document output budget counts the complete inserted HTML, including semantic annotations and every cache hit
|
|
187
|
-
|
|
189
|
+
Their document output budget counts the complete inserted HTML, including semantic annotations and every cache hit.
|
|
190
|
+
Semantic refusal leaves source in the host. Original Markdown and diagnostic `mathSource` remain
|
|
188
191
|
the exact fallback authority: HTML text alone can normalize CR or replace invalid Unicode code units. Their parser grammar and lifetime ownership do not
|
|
189
192
|
change. Each inserted occurrence counts against its document's output budget.
|
|
190
193
|
|
|
@@ -197,9 +200,9 @@ authored SVG or HTML. HTML serialization is not a replacement for retaining orig
|
|
|
197
200
|
The example uses an external stylesheet/module and permits generated style attributes. A CSP
|
|
198
201
|
forbidding all inline style attributes cannot reproduce all SVG or MathML presentation. Core
|
|
199
202
|
structure may survive, but that is not a claim of unchanged presentation. The package creates
|
|
200
|
-
no Trusted Types policy
|
|
203
|
+
no Trusted Types policy. String insertion and SVG fitting have the same TrustedHTML limitations
|
|
201
204
|
as the existing browser API. Exact HTTP(S) link destinations carry no fetch authority until
|
|
202
|
-
the person activates them
|
|
205
|
+
the person activates them. No formula rendering request performs a network fetch.
|
|
203
206
|
|
|
204
207
|
## Assistive-technology acceptance
|
|
205
208
|
|
|
@@ -215,7 +218,7 @@ link focus target, link activation and source edit/copy. Repeat after replacemen
|
|
|
215
218
|
These steps are manual acceptance, not an automated pass:
|
|
216
219
|
|
|
217
220
|
- [NVDA's mathematical-content guide](https://download.nvaccess.org/documentation/userGuide.html):
|
|
218
|
-
use the installed provider and recorded browser
|
|
221
|
+
use the installed provider and recorded browser. Enter math from browse mode and inspect
|
|
219
222
|
its nested parts, then return to the surrounding sentence.
|
|
220
223
|
- [JAWS Math Viewer guidance](https://support.freedomscientific.com/SurfsUp/24-MathML.htm):
|
|
221
224
|
enter its viewer, inspect peers and nested structure, return and activate the native link.
|
|
@@ -223,6 +226,6 @@ These steps are manual acceptance, not an automated pass:
|
|
|
223
226
|
explore the expression at different granularities and verify nested math within a link.
|
|
224
227
|
Qualify macOS/Safari separately with its actual VoiceOver controls.
|
|
225
228
|
|
|
226
|
-
Run `node
|
|
227
|
-
|
|
228
|
-
|
|
229
|
+
Run `node examples/semantic.mjs` from the installed package directory to inspect a formula's
|
|
230
|
+
MathML, parse tree, status and work counters. The runtime package has no dependency on Python,
|
|
231
|
+
`lxml` or an XML parser.
|
package/examples/README.md
CHANGED
|
@@ -5,15 +5,15 @@ From a consumer directory, install `rapier-math`, then run
|
|
|
5
5
|
|
|
6
6
|
For Markdown and streaming, also install `markdown-it` and run `markdown.mjs` or `stream.mjs`.
|
|
7
7
|
For unified, install `unified remark-parse remark-math remark-rehype rehype-sanitize rehype-stringify hast-util-from-html`
|
|
8
|
-
and run `unified.mjs`. The remark example uses remark's syntax
|
|
8
|
+
and run `unified.mjs`. The remark example uses remark's syntax. It does not recognize backslash delimiters.
|
|
9
9
|
|
|
10
10
|
Serve the package directory over HTTP and open `examples/browser.html`. Its external module imports the
|
|
11
11
|
installed ESM renderer, fits the output and releases observation before replacement and on page exit.
|
|
12
12
|
Keep both `dist/` and `src/` when serving or copying these native-module examples.
|
|
13
13
|
For a one-file alternative, copy `dist/rapier-math.js`, load it with a classic script tag
|
|
14
|
-
and call `globalThis.RapierMath.renderToString(source)
|
|
14
|
+
and call `globalThis.RapierMath.renderToString(source)`. Do not copy only `dist/index.mjs`.
|
|
15
15
|
Start `new Worker('./worker.mjs', {type: 'module'})` from this directory and post `{id, source}`.
|
|
16
|
-
Use an id owned by the current message and ignore stale replies. Workers render SVG
|
|
16
|
+
Use an id owned by the current message and ignore stale replies. Workers render SVG. They do not call `observe`.
|
|
17
17
|
|
|
18
18
|
`react.tsx` is a small React 19/SSR component to copy into an existing TypeScript application. Install
|
|
19
19
|
`react react-dom` and the development types `@types/react @types/react-dom`. No framework is required by the core.
|
|
@@ -25,14 +25,14 @@ Do not concatenate transport data into HTML. Pass the callback's session through
|
|
|
25
25
|
VFile `data.rapierMathSession` to reuse formulas. On cancellation call `abort`. For replacement, cancel transport
|
|
26
26
|
and use the new handle returned by `stream = stream.reset()`. Each producer captures its own handle, so stale
|
|
27
27
|
writes/finish calls on the old handle refuse. A failed render releases reusable artifacts but keeps accepted
|
|
28
|
-
source for an explicit `finish()` retry
|
|
28
|
+
source for an explicit `finish()` retry. Abort in a final cleanup if the host will not retry.
|
|
29
29
|
|
|
30
30
|
The examples retain the original source as the editable/copyable authority. Markdown hosts can normalize
|
|
31
|
-
newlines or escapes in their syntax nodes
|
|
31
|
+
newlines or escapes in their syntax nodes. An HTML serialization is not an exact source archive.
|
|
32
32
|
|
|
33
33
|
## Structured and accessible formulas
|
|
34
34
|
|
|
35
35
|
Run `node examples/semantic.mjs` for font-free MathML. Serve the package root locally and open
|
|
36
36
|
`examples/accessible.html` for source replacement, generated MathML, cleanup, CSP and the two
|
|
37
|
-
link compositions. The external stylesheet must load. General internal links use native MathML
|
|
38
|
-
|
|
37
|
+
link compositions. The external stylesheet must load. General internal links use native MathML.
|
|
38
|
+
A host link around a complete ordinary formula preserves SVG. See [semantic contracts](../docs/semantics.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rapier-math",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.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",
|
|
@@ -73,14 +73,17 @@
|
|
|
73
73
|
"optional": true
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
|
+
"bin": {
|
|
77
|
+
"rapier-math": "./dist/cli.mjs"
|
|
78
|
+
},
|
|
76
79
|
"files": [
|
|
77
80
|
"dist",
|
|
78
81
|
"src",
|
|
79
82
|
"docs",
|
|
80
83
|
"examples",
|
|
84
|
+
"skills",
|
|
81
85
|
"LICENSE",
|
|
82
|
-
"README.md"
|
|
83
|
-
"CHANGELOG.md"
|
|
86
|
+
"README.md"
|
|
84
87
|
],
|
|
85
88
|
"license": "SEE LICENSE IN LICENSE",
|
|
86
89
|
"author": "Jack Skipworth",
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rapier-math
|
|
3
|
+
description: Typeset TeX math to self-contained SVG or MathML synchronously and offline with npx rapier-math add. Embedded Latin Modern outlines, Markdown and rehype adapters, streaming reuse and responsive browser fitting. Node 22+.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# TeX Math
|
|
7
|
+
|
|
8
|
+
The npm package and command are `rapier-math`. Render TeX formulas synchronously to SVG with embedded Latin Modern outlines or to Presentation MathML with no runtime dependencies, DOM requirement or remote font requests.
|
|
9
|
+
|
|
10
|
+
| Entry | Use |
|
|
11
|
+
| --- | --- |
|
|
12
|
+
| `rapier-math` | `render(tex, options)` (`{svg, width, height, depth, lines, fitted, errors}`), `renderToString(tex, options)`, `parse(tex)`, `fit(container)`, `observe(container)`. |
|
|
13
|
+
| `rapier-math/mathml` | `toMathML(tex, options)` (`{mathml, status, errors, source, metrics}`) and `parse(tex)` with zero font decoding. |
|
|
14
|
+
| `rapier-math/combined` | `renderWithMathML(tex, options)` returning both SVG and MathML from one parse. |
|
|
15
|
+
| `rapier-math/accessible` | `renderAccessible(tex, options)` (`{html, presentation, errors, semantics}`) paired with `rapier-math/accessible.css`. |
|
|
16
|
+
| `rapier-math/markdown-it` | `md.use(rapierMath, options)` for `\(...\)`, `\[...\]` and `$$...$$` (`{singleDollar: true}` opts in `$...$`). |
|
|
17
|
+
| `rapier-math/rehype` | `rehypeRapierMath(options)` placed after `rehype-sanitize` in a `remark-math` + `remark-rehype` pipeline. |
|
|
18
|
+
| `rapier-math/stream` | `createMarkdownStream(renderMarkdown, options)` and `createMathSession(limits)` for streamed model output. |
|
|
19
|
+
| `rapier-math/delimiters` | `createMathMatcher(source, options)` returning exact UTF-16 formula spans in raw text. |
|
|
20
|
+
| `rapier-math/classic` | `dist/rapier-math.js` (`globalThis.RapierMath`), one self-contained browser script with font outlines included. |
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import {render, observe} from 'rapier-math';
|
|
24
|
+
|
|
25
|
+
const source = String.raw`\frac{-b\pm\sqrt{b^2-4ac}}{2a}`;
|
|
26
|
+
const result = render(source, {displayMode: true});
|
|
27
|
+
if (result.errors.length) element.textContent = source;
|
|
28
|
+
else {
|
|
29
|
+
element.innerHTML = result.svg;
|
|
30
|
+
const stop = observe(element); // call stop() before replacing or unmounting
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Keep the original TeX string for editing and copying. Omit `screen` during SSR and initial client hydration so server and client SVG match, then call `observe(container)` after mount to fit wide formulas to narrow columns and snap rules to device pixels. For `markdown-it`, initialize `new MarkdownIt({html: false}).use(rapierMath)`. For `stream`, pass `(text, session) => md.render(text, {rapierMathSession: session})` to `createMarkdownStream`, replace the whole preview whenever `stream.write(chunk)` returns a snapshot, call `stream.finish()` at EOF, and call `stream.abort()` in `finally`.
|
|
35
|
+
|
|
36
|
+
## Mistakes
|
|
37
|
+
|
|
38
|
+
| Wrong | Right |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| `render('$$x^2$$')` | `render('x^2', {displayMode: true})` (formula APIs take raw TeX without Markdown delimiters) |
|
|
41
|
+
| `"\\frac{1}{2}"` unescaped twice | `String.raw`\frac{1}{2}`` in JavaScript source literals |
|
|
42
|
+
| Inserting `result.svg` without checking `result.errors` | Check `result.errors.length === 0` first and write `source` to `textContent` on error |
|
|
43
|
+
| Passing `screen` during SSR | Omit `screen` on server and initial client render, then run `observe(container)` after hydration |
|
|
44
|
+
| Copying `dist/index.mjs` alone into a static site | Copy `dist/rapier-math.js` (`globalThis.RapierMath`) for one file, or bundle/serve `dist/` and `src/` together |
|
|
45
|
+
| Running `rapier-math/rehype` before `rehype-sanitize` | Run `rehype-sanitize` (allowing `language-math`, `math-inline`, `math-display` on `code`) before `rapier-math/rehype` |
|
|
46
|
+
| Appending `stream.write(chunk)` snapshots | Replace the entire preview with `snapshot.html` and finish with `stream.finish()` |
|
|
47
|
+
|
|
48
|
+
## CLI
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
npx rapier-math add
|
|
52
|
+
npx rapier-math add --json
|
|
53
|
+
npx rapier-math remove --json
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`npx rapier-math add` inspects the current folder (or `--path <dir>`), detects `next`, `astro`, `svelte`, `vue`, `react`, `npm` or plain `html` (or accepts an explicit target name or `agents`), installs `rapier-math` (or copies `dist/rapier-math.js` for plain HTML), writes a ready-to-use `<Equation>` component or `typeset` helper, and copies this skill to `.agents/skills/rapier-math/SKILL.md`. `npx rapier-math remove` removes unmodified generated files and preserves files you edited. With `--json`, `add` and `remove` emit one JSON record to stdout.
|
|
57
|
+
|
|
58
|
+
## Refusals
|
|
59
|
+
|
|
60
|
+
Check `result.errors` on `render` (`{code, message, offset, command?, suggestion?, sourceOmitted?}`). Codes include `invalid-tex`, `unsupported-command` (check `suggestion`, such as `\frac` for `\farc`), `unsupported-package`, `invalid-source-character`, `invalid-screen`, `unsafe-url` and `resource-limit`. On `toMathML` and `renderAccessible`, check `semantics.status` (`'complete'`, `'presentation-fallback'` or `'refused'`). CLI setup errors carry `MATH_OPTIONS`, `MATH_SETUP` or `MATH_INSTALL` with `error.hint`.
|
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.1.0', parse:parseMathTex,
|
|
4
4
|
render:renderMath, renderToString:mathRenderToString,
|
|
5
5
|
fit:mathFit, observe:mathObserve,
|
|
6
6
|
toMathML:mathToMathML, renderWithMathML:mathRenderWithMathML,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
export const MATH_CLASSIC = 'dist/rapier-math.js';
|
|
3
|
+
export const MATH_BIN = Object.freeze({'rapier-math': './dist/cli.mjs'});
|
|
3
4
|
|
|
4
5
|
// One public location per authored input. Runtime formats share dist/.
|
|
5
6
|
export function mathPackagePath(file) {
|
|
6
7
|
const owners = {
|
|
7
8
|
'math/README.md': 'docs/api.md',
|
|
8
|
-
'math/CHANGELOG.md': 'CHANGELOG.md',
|
|
9
9
|
'math/SEMANTICS.md': 'docs/semantics.md',
|
|
10
10
|
'math/semantic-verify.mjs': 'tests/semantics.mjs',
|
|
11
11
|
'math/accessible.css': 'dist/accessible.css',
|
|
@@ -16,7 +16,7 @@ export function mathPackagePath(file) {
|
|
|
16
16
|
'math/typeset-verify.mjs': 'tests/typeset.mjs',
|
|
17
17
|
};
|
|
18
18
|
if (owners[file]) return owners[file];
|
|
19
|
-
if (file.startsWith('math/examples/')) return file.slice(5);
|
|
19
|
+
if (file.startsWith('math/examples/') || file.startsWith('math/skills/')) return file.slice(5);
|
|
20
20
|
if (/^math\/(?!package-).+\.(?:mjs|d\.ts)$/.test(file)) return 'dist/' + file.slice(5);
|
|
21
21
|
return 'src/' + file;
|
|
22
22
|
}
|
|
@@ -2,53 +2,44 @@
|
|
|
2
2
|
export function mathReadme(resources) {
|
|
3
3
|
return `# Rapier Math
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Use
|
|
5
|
+
TeX to SVG or MathML, synchronously and offline. Latin Modern outlines are embedded in the SVG, so there are no font requests and no runtime downloads. No dependencies.
|
|
8
6
|
|
|
9
7
|
\`\`\`sh
|
|
10
|
-
|
|
8
|
+
npx rapier-math add
|
|
11
9
|
\`\`\`
|
|
12
10
|
|
|
11
|
+
Installs into npm, plain HTML, React, Vue, Svelte, Astro or Next projects, or run \`npm install rapier-math\`.
|
|
12
|
+
|
|
13
13
|
\`\`\`js
|
|
14
14
|
import {renderToString} from 'rapier-math';
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
const svg = renderToString(String.raw\`\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}\`);
|
|
16
17
|
\`\`\`
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
\`globalThis.RapierMath\`. The native ESM entry is [dist/index.mjs](dist/index.mjs).
|
|
20
|
-
For one-file copying or inline-script embedding, use the classic file above. The native
|
|
21
|
-
ESM entry imports relative \`src/math/\` modules: install/serve the whole package or bundle
|
|
22
|
-
that import; copying only \`dist/index.mjs\` is insufficient. A CDN must retain that graph
|
|
23
|
-
or bundle it. Formula rendering stays synchronous and offline after its chosen script
|
|
24
|
-
or module graph has loaded.
|
|
19
|
+
Try it in [Rapier](https://rapier.website): type \\$x^2\\$.
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
\`rapier-math/combined\` for one-parse SVG and MathML, or \`rapier-math/accessible\` with its stylesheet
|
|
28
|
-
for host composition. All return synchronously. Type declarations accompany the runtime files.
|
|
21
|
+
## Entry points
|
|
29
22
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
23
|
+
| Import | Gives |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| \`rapier-math\` | SVG with the font embedded |
|
|
26
|
+
| \`rapier-math/mathml\` | Native MathML, no font |
|
|
27
|
+
| \`rapier-math/combined\` | SVG and MathML from one parse |
|
|
28
|
+
| \`rapier-math/accessible\` | Accessible output for your own layout, with \`rapier-math/accessible.css\` |
|
|
29
|
+
| \`rapier-math/markdown-it\`, \`rapier-math/rehype\` | Markdown integrations. Your parser stays in charge |
|
|
30
|
+
| \`rapier-math/stream\` | Formulas in streamed text, such as model output |
|
|
31
|
+
| \`rapier-math/classic\` | [${resources.packageBundle}](${resources.packageBundle}): one file, \`globalThis.RapierMath\` |
|
|
35
32
|
|
|
36
|
-
|
|
33
|
+
Types ship with every entry. The classic file is the one to copy or inline: ${resources.bytes.toLocaleString('en-US')} bytes, ${resources.gzipBytes.toLocaleString('en-US')} gzipped, font included. The ES modules import \`src/math/\`, so serve or bundle the whole package rather than copying \`dist/index.mjs\` alone.
|
|
37
34
|
|
|
38
|
-
|
|
39
|
-
modules in \`src/math/\` directly, sharing one parser without a duplicate generated renderer. Build
|
|
40
|
-
tools live in \`src/tools/\`. Optional adapters have one source copy in \`dist/\`. Examples and documentation each
|
|
41
|
-
have their own directory. Only the current release is kept in this checkout.
|
|
35
|
+
[API](docs/api.md) · [MathML and accessibility](docs/semantics.md) · [Examples](examples/README.md) · [Font](docs/font-source.md) · [Changes](https://github.com/jackskip22/rapier-math/releases)
|
|
42
36
|
|
|
43
|
-
|
|
37
|
+
## Build
|
|
44
38
|
|
|
45
|
-
|
|
39
|
+
\`node src/tools/build-math.mjs --package .\` regenerates \`dist/\` from \`src/math/\`.
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
licensed under the GUST Font License. [LICENSE](LICENSE) contains both complete grants.
|
|
49
|
-
[Component provenance](docs/math-components.json) and [source hashes](docs/math-resources.json)
|
|
50
|
-
travel with the package.
|
|
41
|
+
## License
|
|
51
42
|
|
|
52
|
-
|
|
43
|
+
Code: MIT. Embedded Latin Modern outlines and metrics: GUST Font License. Both are in [LICENSE](LICENSE). [Components](docs/math-components.json) and [source hashes](docs/math-resources.json) ship with the package.
|
|
53
44
|
`;
|
|
54
45
|
}
|