rapier-math 2.4.0 → 2.6.1
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 +10 -0
- package/LICENSE +10 -3
- package/README.md +4 -5
- package/dist/index.mjs +1 -1
- package/dist/markdown-rules.mjs +47 -0
- package/dist/rapier-math.js +678 -229
- package/docs/api.md +6 -2
- package/docs/font-source.md +37 -29
- package/docs/math-components.json +51 -7
- package/docs/math-resources.json +59 -64
- package/package.json +3 -3
- package/src/math/FONT-LICENSE.txt +9 -2
- package/src/math/build-font.py +61 -65
- package/src/math/classic.js +1 -1
- package/src/math/font.js +23 -487
- package/src/math/layout.js +302 -112
- package/src/math/mathml.js +26 -7
- package/src/math/package-layout.mjs +1 -0
- package/src/math/package-readme.mjs +3 -4
- package/src/math/parser.js +306 -67
- package/src/tools/build-math.mjs +22 -7
- package/tests/adoption.mjs +0 -252
- package/tests/check.mjs +0 -133
- package/tests/semantics.mjs +0 -340
- package/tests/typeset.mjs +0 -172
- package/tests/verify.mjs +0 -49
package/src/math/mathml.js
CHANGED
|
@@ -110,6 +110,7 @@ function mathML(tree, source, safeSource, options = {}) {
|
|
|
110
110
|
const classOf = node => {
|
|
111
111
|
if (!node) return undefined;
|
|
112
112
|
if (node.class) return node.class;
|
|
113
|
+
if (node.type === 'row' && node.group) return 'ord';
|
|
113
114
|
if (node.type === 'scripts' || node.type === 'accent') return classOf(node.base);
|
|
114
115
|
if (node.type === 'style' || node.type === 'link') return classOf(node.body);
|
|
115
116
|
if (node.type === 'row' && node.children.length === 1) return classOf(node.children[0]);
|
|
@@ -118,6 +119,7 @@ function mathML(tree, source, safeSource, options = {}) {
|
|
|
118
119
|
const limitsOf = node => {
|
|
119
120
|
if (!node) return undefined;
|
|
120
121
|
if (node.limits) return node.limits;
|
|
122
|
+
if (node.type === 'row' && node.group) return undefined;
|
|
121
123
|
if (node.type === 'style' || node.type === 'link') return limitsOf(node.body);
|
|
122
124
|
if (node.type === 'row' && node.children.length === 1) return limitsOf(node.children[0]);
|
|
123
125
|
if (node.type === 'accent') return limitsOf(node.base);
|
|
@@ -227,15 +229,21 @@ function mathML(tree, source, safeSource, options = {}) {
|
|
|
227
229
|
open('mtable', {displaystyle: String(cellContext.display), scriptlevel: String(cellContext.level), 'data-math-environment': node.env});
|
|
228
230
|
for (let at = 0; at < rows.length; at++) {
|
|
229
231
|
open('mtr');
|
|
230
|
-
|
|
232
|
+
// \intertext spans the whole row at its left; \multicolumn and \hdotsfor span their columns.
|
|
233
|
+
const intertext = rows[at][0]?.intertext;
|
|
234
|
+
for (let column = 0; column < (intertext ? 1 : columns); column++) {
|
|
231
235
|
if (++metrics.nodes > 100000) fail('resource-limit', 'MathML table cells exceed its work budget.');
|
|
232
|
-
|
|
236
|
+
const cell = rows[at][column];
|
|
237
|
+
if (cell?.covered) continue;
|
|
238
|
+
let align = intertext ? 'l' : cell?.spanAlign || (node.env === 'eqnarray' ? ['r', 'c', 'l'][column % 3] : node.align?.[column] || 'c');
|
|
233
239
|
if (/^multlined?$/.test(node.env) && columns === 1) align = at === 0 ? 'l' : at === rows.length - 1 ? 'r' : 'c';
|
|
234
|
-
|
|
240
|
+
const span = intertext ? columns : cell?.span > 1 ? Math.min(cell.span, columns - column) : 0;
|
|
241
|
+
open('mtd', {...(span > 1 ? {columnspan: String(span)} : {}), style: 'text-align:' + ({l: 'left', r: 'right', c: 'center'}[align] || 'center')});
|
|
235
242
|
open('mrow');
|
|
236
243
|
for (const body of before[column]) emit(body, cellContext, depth + 1);
|
|
237
|
-
if (
|
|
238
|
-
if (
|
|
244
|
+
if (cell?.dots) token('mo', '…', {stretchy: 'false'}, cellContext);
|
|
245
|
+
else if (cell) emit(cell, cellContext, depth + 1);
|
|
246
|
+
if (column + Math.max(1, span) >= columns) for (const body of before[columns]) emit(body, cellContext, depth + 1);
|
|
239
247
|
close('mrow'); close('mtd');
|
|
240
248
|
}
|
|
241
249
|
close('mtr');
|
|
@@ -252,7 +260,8 @@ function mathML(tree, source, safeSource, options = {}) {
|
|
|
252
260
|
active.add(node);
|
|
253
261
|
try {
|
|
254
262
|
switch (node.type) {
|
|
255
|
-
|
|
263
|
+
// A braced group is an ordinary atom in TeX; an operator alone in it takes no spacing of its own.
|
|
264
|
+
case 'row': row(node.children, node.group && node.children.length === 1 ? {...context, ordinary: true} : {...context, ordinary: undefined}, depth); break;
|
|
256
265
|
case 'glyph': {
|
|
257
266
|
const name = kind(node), attributes = {};
|
|
258
267
|
if (name === 'mo') {
|
|
@@ -264,6 +273,9 @@ function mathML(tree, source, safeSource, options = {}) {
|
|
|
264
273
|
if (node.delimiter || node.delimiterSize || node.stretch) attributes.stretchy = 'true';
|
|
265
274
|
else attributes.stretchy = 'false';
|
|
266
275
|
if (node.delimiterSize) attributes.minsize = attributes.maxsize = em(node.delimiterSize);
|
|
276
|
+
else if (node.minWidth) attributes.minsize = em(node.minWidth);
|
|
277
|
+
if (node.class === 'ord' && node.tokenKind === 'mo') attributes.lspace = attributes.rspace = '0em';
|
|
278
|
+
if (context.ordinary) { attributes.lspace = attributes.rspace = '0em'; if (node.limits) attributes.movablelimits = 'false'; }
|
|
267
279
|
}
|
|
268
280
|
atom(node, node.value, name, context, attributes); break;
|
|
269
281
|
}
|
|
@@ -289,6 +301,11 @@ function mathML(tree, source, safeSource, options = {}) {
|
|
|
289
301
|
close(node.index ? 'mroot' : 'msqrt'); break;
|
|
290
302
|
case 'fence':
|
|
291
303
|
open('mrow'); fence(node.left, 'prefix', context, node.size); emit(node.body, inner(context), depth + 1); fence(node.right, 'postfix', context, node.size); close('mrow'); break;
|
|
304
|
+
case 'enclose': {
|
|
305
|
+
warn('semantic-overlay', 'An enclosure uses the MathML 3 menclose extension; hosts implementing only Core may omit its lines.');
|
|
306
|
+
const css = (node.color ? 'color:' + node.color + ';' : '') + (node.background ? 'background:' + node.background + ';' : '');
|
|
307
|
+
open('menclose', {notation: node.notation.join(' '), style: css || undefined}); emit(node.body, context, depth + 1); close('menclose'); break;
|
|
308
|
+
}
|
|
292
309
|
case 'accent': {
|
|
293
310
|
if (node.overlay || node.position === 'through') {
|
|
294
311
|
warn('semantic-overlay', 'An overlay uses the MathML 3 menclose extension; hosts implementing only Core may omit the cancellation or negation mark.');
|
|
@@ -300,8 +317,10 @@ function mathML(tree, source, safeSource, options = {}) {
|
|
|
300
317
|
token('mo', node.value, {stretchy: String(!!node.stretch)}, context); close(name); break;
|
|
301
318
|
}
|
|
302
319
|
case 'overunder': {
|
|
320
|
+
const base = node.minWidth ? {...node.base, minWidth: node.minWidth} : node.base;
|
|
321
|
+
if (!node.over && !node.under) { emit(base, {...context, ordinary: node.unspaced || undefined}, depth + 1); break; }
|
|
303
322
|
const name = node.over && node.under ? 'munderover' : node.under ? 'munder' : 'mover';
|
|
304
|
-
open(name, {accent: node.over ? 'false' : undefined, accentunder: node.under ? 'false' : undefined}); emit(
|
|
323
|
+
open(name, {accent: node.over ? 'false' : undefined, accentunder: node.under ? 'false' : undefined}); emit(base, {...context, movableLimits: false, ordinary: node.unspaced || undefined}, depth + 1);
|
|
305
324
|
if (node.under) emit(node.under, scriptContext(context), depth + 1);
|
|
306
325
|
if (node.over) emit(node.over, scriptContext(context), depth + 1);
|
|
307
326
|
close(name); break;
|
|
@@ -5,6 +5,7 @@ export const MATH_CLASSIC = 'dist/rapier-math.js';
|
|
|
5
5
|
export function mathPackagePath(file) {
|
|
6
6
|
const owners = {
|
|
7
7
|
'math/README.md': 'docs/api.md',
|
|
8
|
+
'math/CHANGELOG.md': 'CHANGELOG.md',
|
|
8
9
|
'math/SEMANTICS.md': 'docs/semantics.md',
|
|
9
10
|
'math/semantic-verify.mjs': 'tests/semantics.mjs',
|
|
10
11
|
'math/accessible.css': 'dist/accessible.css',
|
|
@@ -31,21 +31,20 @@ for host composition. All return synchronously. Type declarations accompany the
|
|
|
31
31
|
- [MathML, accessibility and source contracts](docs/semantics.md)
|
|
32
32
|
- [Runnable examples](examples/README.md)
|
|
33
33
|
- [Font source and regeneration](docs/font-source.md)
|
|
34
|
+
- [Changes](CHANGELOG.md)
|
|
34
35
|
|
|
35
36
|
## Develop
|
|
36
37
|
|
|
37
38
|
The classic script and native entry points live in \`dist/\`. Native entries import the editable
|
|
38
39
|
modules in \`src/math/\` directly, sharing one parser without a duplicate generated renderer. Build
|
|
39
|
-
tools live in \`src/tools/\`. Optional adapters have one source copy in \`dist/\`. Examples
|
|
40
|
+
tools live in \`src/tools/\`. Optional adapters have one source copy in \`dist/\`. Examples and documentation each
|
|
40
41
|
have their own directory. Only the current release is kept in this checkout.
|
|
41
42
|
|
|
42
|
-
From a repository checkout, run \`node tests/check.mjs\` and \`node tests/verify.mjs\` to check the package and rebuild its exact bytes.
|
|
43
43
|
Run \`node src/tools/build-math.mjs --package .\` to regenerate the classic and ESM files from source.
|
|
44
|
-
Optional host checks run with \`node tests/adoption.mjs\` after installing the example dependencies.
|
|
45
44
|
|
|
46
45
|
## License
|
|
47
46
|
|
|
48
|
-
The renderer and adapters are MIT-licensed. Embedded Latin Modern
|
|
47
|
+
The renderer and adapters are MIT-licensed. Embedded Latin Modern outlines and metrics are
|
|
49
48
|
licensed under the GUST Font License. [LICENSE](LICENSE) contains both complete grants.
|
|
50
49
|
[Component provenance](docs/math-components.json) and [source hashes](docs/math-resources.json)
|
|
51
50
|
travel with the package.
|