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.
@@ -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
- for (let column = 0; column < columns; column++) {
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
- let align = node.env === 'eqnarray' ? ['r', 'c', 'l'][column % 3] : node.align?.[column] || 'c';
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
- open('mtd', {style: 'text-align:' + ({l: 'left', r: 'right', c: 'center'}[align] || 'center')});
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 (rows[at][column]) emit(rows[at][column], cellContext, depth + 1);
238
- if (column === columns - 1) for (const body of before[columns]) emit(body, cellContext, depth + 1);
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
- case 'row': row(node.children, context, depth); break;
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(node.base, {...context, movableLimits: false}, depth + 1);
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, documentation and tests each
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 Math outlines and metrics are
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.