@mathzetta/inlinemath 0.2.0 → 0.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.
Files changed (57) hide show
  1. package/README.md +37 -33
  2. package/dist/cas.external.js +2 -2
  3. package/dist/cas.js +2 -2
  4. package/dist/chunks/calculate-BGMEvf3f.js +2 -0
  5. package/dist/chunks/draw-q86mDDWm.js +2 -0
  6. package/dist/chunks/edit-CTMRUElt.js +2 -0
  7. package/dist/chunks/edit-D2RO7fg0.js +2 -0
  8. package/dist/chunks/html-1wCO6EpZ.js +2 -0
  9. package/dist/chunks/html-D5QiXGXD.js +2 -0
  10. package/dist/chunks/lite-Bo8THzyq.js +2 -0
  11. package/dist/fonts/README-inlinemath-greek.txt +15 -0
  12. package/dist/fonts/fonts.css +19 -1
  13. package/dist/fonts/inlinemath-greek-italic.woff2 +0 -0
  14. package/dist/fonts/inlinemath-greek-regular.woff2 +0 -0
  15. package/dist/inlinemath-cas.external.global.min.js +2 -2
  16. package/dist/inlinemath-cas.global.min.js +2 -2
  17. package/dist/inlinemath-lite-calc.global.min.js +2 -2
  18. package/dist/inlinemath-lite.external.global.min.js +2 -2
  19. package/dist/inlinemath-lite.global.min.js +2 -2
  20. package/dist/inlinemath.css +17 -7
  21. package/dist/inlinemath.external.global.min.js +2 -2
  22. package/dist/inlinemath.external.js +2 -2
  23. package/dist/inlinemath.global.min.js +2 -2
  24. package/dist/inlinemath.js +2 -2
  25. package/dist/lite-calc.js +2 -2
  26. package/dist/lite.external.js +2 -2
  27. package/dist/lite.js +2 -2
  28. package/dist/markdown.external.js +2 -2
  29. package/dist/markdown.js +2 -2
  30. package/fonts/README-inlinemath-greek.txt +15 -0
  31. package/fonts/fonts.css +19 -1
  32. package/fonts/inlinemath-greek-italic.woff2 +0 -0
  33. package/fonts/inlinemath-greek-regular.woff2 +0 -0
  34. package/inlinemath.css +17 -7
  35. package/package.json +6 -6
  36. package/src/cas.d.ts +1 -1
  37. package/src/cas.js +15 -4
  38. package/src/draw.js +13 -9
  39. package/src/edit.js +11 -4
  40. package/src/html.js +1 -1
  41. package/src/index.js +1 -1
  42. package/src/layout.js +89 -32
  43. package/src/lite.js +1 -1
  44. package/src/markdown.d.ts +1 -1
  45. package/src/markdown.js +139 -57
  46. package/src/mathzetta.js +2 -2
  47. package/src/select.js +7 -0
  48. package/src/types.d.ts +12 -10
  49. package/src/variables.js +44 -10
  50. package/src/view.js +69 -18
  51. package/dist/chunks/calculate-Cz87Lt0N.js +0 -2
  52. package/dist/chunks/draw-Bev17BJJ.js +0 -2
  53. package/dist/chunks/edit-C65xXzo8.js +0 -2
  54. package/dist/chunks/edit-M68aRA5o.js +0 -2
  55. package/dist/chunks/html-BimAqn7x.js +0 -2
  56. package/dist/chunks/html-CupluJSh.js +0 -2
  57. package/dist/chunks/lite-3Fb-OHbt.js +0 -2
package/src/layout.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * Every rendered piece is a box { html, h, d }: its markup, and how far it
5
5
  * reaches above (h) and below (d) the baseline, in em of the surrounding
6
6
  * text. Nothing is measured in a browser; the estimates place fractions on
7
- * the maths axis, raise exponents above tall bases and size the integral
7
+ * the math axis, raise exponents above tall bases and size the integral
8
8
  * sign, so the same string is right in Node, in a video frame or on a page.
9
9
  * Delimiters, the radical's bar and borders stretch by themselves with CSS.
10
10
  *
@@ -28,7 +28,7 @@ import { svg } from './glyphs.js';
28
28
  // Metrics, in em. They match inlinemath.css; change both together.
29
29
  const LH = 0.8; // a line of text: height above the baseline (line-height 1)
30
30
  const LD = 0.2; // and depth below it
31
- const AXIS = 0.25; // the maths axis: fraction bars and big operators centre here
31
+ const AXIS = 0.25; // the math axis: fraction bars and big operators center here
32
32
  const RULE = 0.06; // fraction bar, radical bar
33
33
  const GAP = 0.1; // between a fraction bar and its numerator or denominator
34
34
  const SCRIPT = 0.7; // exponent and subscript size; deeper scripts use SCRIPT2
@@ -60,10 +60,14 @@ const NAMED = [...TRIG, ...Object.keys(INVERSE), 'ln', 'det'];
60
60
  const CALLS = { atan2: 'atan2', max: 'max', min: 'min', gcd: 'gcd', mean: 'mean', round: 'round', fixed: 'fixed', expm1: 'expm1', random: 'random' };
61
61
 
62
62
  const GROUPS = { '()': ['(', ')'], '[]': ['[', ']'], '{}': ['{', '}'], '(]': ['(', ']'], '[)': ['[', ')'] };
63
+ const BIG_OPERATORS = ['int', 'lim', '\\sumidx', '\\prodidx']; // a body after them takes in whatever follows
63
64
  const LATEX_SYMBOLS = { '\\partial': '∂', '\\nabla': '∇', '\\ell': 'ℓ', '\\infty': '∞', '\\emptyset': '∅' };
64
65
 
65
66
  /** Custom functions drawn as decorations: \boxed{x} parses as boxed(x). */
66
67
  const ACCENTS = { vec: '→', hat: 'ˆ', widehat: 'ˆ', tilde: '˜', dot: '˙', ddot: '¨' };
68
+ /** One letter as tall as an x: an accent over it sits lower. */
69
+ const SHORT_LETTER = /^[acegmnopqrsuvwxyzαγεημνοπρστυχω]$/;
70
+ const isShortLetter = (node) => node?.type === 'symbol' && SHORT_LETTER.test(GREEK[node.value] ?? node.value);
67
71
  const DECORATIONS = ['boxed', 'overline', 'bar', 'underline', 'cancel', ...Object.keys(ACCENTS)];
68
72
 
69
73
  export const DEFAULTS = {
@@ -168,11 +172,11 @@ class Layout {
168
172
  if (node.type === 'op') attrs += ` data-op="${escape(node.op)}"`;
169
173
  const extra = this.o.attributes ? this.o.attributes(node) || {} : {};
170
174
  for (const [k, v] of Object.entries(extra)) {
171
- if (k !== 'class' && k !== 'style') attrs += ` ${k}="${escape(v)}"`;
175
+ if (k !== 'class' && k !== 'style' && /^[A-Za-z_:][\w:.-]*$/.test(k)) attrs += ` ${k}="${escape(v)}"`; // a name is a name: nothing that could close the tag
172
176
  }
173
177
  const style = [extra.style, this.o.style && this.o.style(node)].filter(Boolean).join(';');
174
178
  const all = b.leaf ? ['n', ...kinds, b.leaf.kind] : ['n', ...kinds];
175
- const cls = all.map((k) => `${this.p}-${k}`).concat(extra.class ? [extra.class] : []).join(' ');
179
+ const cls = all.map((k) => `${this.p}-${k}`).concat(extra.class ? [escape(extra.class)] : []).join(' ');
176
180
  const content = b.leaf ? b.leaf.content : b.html;
177
181
  return { html: `<span class="${cls}"${style ? ` style="${escape(style)}"` : ''}${attrs}>${content}</span>`, h: b.h, d: b.d };
178
182
  }
@@ -192,7 +196,7 @@ class Layout {
192
196
 
193
197
  symbol(v) {
194
198
  if (GREEK[v]) v = GREEK[v];
195
- if (LATEX_SYMBOLS[v]) return this.text('ord', LATEX_SYMBOLS[v]);
199
+ if (LATEX_SYMBOLS[v]) return this.text('ord', LATEX_SYMBOLS[v]); // a null-prototype table: toString is a name
196
200
  if (v === '\\+' || v === '\\-') return this.text('ord', v[1]);
197
201
  if (v === '-∞') return this.text('ord', MINUS + '∞');
198
202
  if (/^[A-Za-z]$/.test(v) || /^[α-ω]$/.test(v)) return this.text('var', v);
@@ -209,7 +213,7 @@ class Layout {
209
213
  operation(node, ctx) {
210
214
  const { op, args } = node;
211
215
  const [a, b] = args;
212
- const r = (n, c = {}) => this.render(n, { ...ctx, ...c, forceParens: c.forceParens || false, before: c.before || false });
216
+ const r = (n, c = {}) => this.render(n, { ...ctx, ...c, forceParens: c.forceParens || false, before: c.before || false, leftFactor: false });
213
217
  const kind = OP_CLASS[op] ?? (/^[a-z0-9]+$/i.test(op) ? op : 'other');
214
218
  const wrap = (content) => this.wrap(node, ['op', `op-${kind}`], content);
215
219
  const side = (child, s) => (needsBrackets(node, child, s) && child.op !== '/' ? this.fence(r(child)) : r(child));
@@ -220,13 +224,23 @@ class Layout {
220
224
  const rows = matrixRows(node); // pmatrix, bmatrix, vmatrix, and [[1, 2], [3, 4]]
221
225
  if (rows) return wrap(this.matrix(node, rows, ctx));
222
226
  if (GROUPS[op]) return wrap(this.fence(this.list(args, ctx), ...GROUPS[op]));
227
+ // a choice of equations or inequalities (a CAS's solutions) reads in words: x = 2 or x = 3
228
+ if ((op === '|' || op === '&') && args.length >= 2 && args.every(isStatement)) {
229
+ // the other word inside keeps its brackets: (x = 1 or x = 2) and y = 3
230
+ const part = (n) => ((n.op === '|' || n.op === '&') && n.op !== op ? this.fence(r(n)) : r(n));
231
+ return wrap(row(args.map((n, i) => (i ? [this.text('conj', op === '|' ? 'or' : 'and'), part(n)] : [part(n)])).flat()));
232
+ }
223
233
  if (RELATIONS[op] && args.length === 2) return wrap(row(side(a, 'left'), this.rel(RELATIONS[op]), side(b, 'right')));
224
234
  if (BINARY[op] && args.length === 2) return wrap(row(side(a, 'left'), this.bin(BINARY[op]), side(b, 'right')));
225
235
 
226
236
  switch (op) {
227
237
  case '+': {
228
238
  // a + (-1·x) and a + (-3) read as a − x and a − 3.
229
- if (isMinusOneTimes(b)) return wrap(row(side(a, 'left'), this.bin(MINUS), this.wrap(b, ['op', 'op-mul'], this.render(b.args[1], ctx))));
239
+ if (isMinusOneTimes(b)) { // bracketed as after any minus: c + (−1)(a + b) is c − (a + b)
240
+ const x = b.args[1];
241
+ const drawn = needsBrackets({ op: '-' }, x, 'right') ? this.fence(r(x)) : r(x);
242
+ return wrap(row(side(a, 'left'), this.bin(MINUS), this.wrap(b, ['op', 'op-mul'], drawn)));
243
+ }
230
244
  if (b.type === 'number' && b.value.startsWith('-')) return wrap(row(side(a, 'left'), this.bin(MINUS), this.wrap(b, ['number'], this.text('num', b.value.slice(1)))));
231
245
  return wrap(row(side(a, 'left'), this.bin('+'), this.signed(b, side(b, 'right'))));
232
246
  }
@@ -238,8 +252,10 @@ class Layout {
238
252
  return wrap(this.fraction(node, ctx));
239
253
  case '^':
240
254
  return wrap(this.power(node, ctx));
241
- case '_':
242
- return wrap(this.script(r(a, { forceParens: true }), null, ctx, r(b, { level: ctx.level + 1 })));
255
+ case '_': { // (a + b)₁ keeps its brackets
256
+ const compound = bracketOp(a) && precedenceOf(bracketOp(a)) < 100;
257
+ return wrap(this.script(compound ? this.fence(r(a)) : r(a, { forceParens: true }), null, ctx, r(b, { level: ctx.level + 1 })));
258
+ }
243
259
  case 'neg':
244
260
  return wrap(row(this.text('sign', MINUS), unaryNeedsBrackets(op, a) ? this.fence(r(a)) : r(a, { before: ctx.before })));
245
261
  case 'pm':
@@ -271,10 +287,11 @@ class Layout {
271
287
  return wrap(this.fence(this.stack(r(a), r(b), false)));
272
288
  case '?:':
273
289
  return wrap(this.o.cases ? this.cases(node, ctx) : row(r(a), this.bin('?'), r(b), this.bin(':'), r(args[2])));
274
- case 'sum':
275
- return wrap(row(args.map((n, i) => (i ? [this.bin('+'), r(n)] : [r(n)])).flat()));
276
- case 'prod':
277
- return wrap(row(args.map((n, i) => (i ? [this.bin('·'), r(n)] : [r(n)])).flat()));
290
+ case 'sum': case 'prod': { // each term bracketed as + and · would bracket it: prod(a + b, c) is (a + b)·c
291
+ const parent = { op: op === 'sum' ? '+' : '*' };
292
+ const term = (n, i) => (needsBrackets(parent, n, i ? 'right' : 'left') ? this.fence(r(n)) : r(n));
293
+ return wrap(row(args.map((n, i) => (i ? [this.bin(op === 'sum' ? '+' : '·'), term(n, i)] : [term(n, i)])).flat()));
294
+ }
278
295
  case 'der':
279
296
  return wrap(this.derivative(node, ctx));
280
297
  case 'int':
@@ -302,15 +319,17 @@ class Layout {
302
319
  /** 2x, x·2, (x+1)(x−2), sin x cos x. */
303
320
  product(node, ctx) {
304
321
  const [a, b] = node.args;
305
- if (isMinusOneTimes(node)) return row(this.text('sign', MINUS), this.render(b, ctx));
322
+ if (isMinusOneTimes(node)) return row(this.text('sign', MINUS), unaryNeedsBrackets('neg', b) ? this.fence(this.render(b, ctx)) : this.render(b, ctx));
306
323
  const sides = bracketedSides(node);
307
- const implicit = isImplicitProduct(a, b, sides);
324
+ if (BIG_OPERATORS.includes(a.op)) sides.left = true; // (∑ i)·x: the sum's body would take in the x
325
+ // a product typed with · or × shows it (MathZetta's node.written); otherwise a sign only where one is needed
326
+ const implicit = !node.written && isImplicitProduct(a, b, sides);
308
327
  // "sin x · y" must keep its brackets: sin(x) y. Before another function it needn't: sin x cos x.
309
328
  const nextIsCall = startsWithCall(b);
310
- const left = sides.left ? this.fence(this.render(a, ctx)) : this.render(a, { ...ctx, before: implicit && !nextIsCall });
329
+ const left = sides.left ? this.fence(this.render(a, ctx)) : this.render(a, { ...ctx, before: implicit && !nextIsCall, leftFactor: true });
311
330
  const right = sides.right ? this.fence(this.render(b, ctx)) : this.render(b, { ...ctx, before: ctx.before });
312
331
  // A thin space before a function name: 2 sin x, x² ln x.
313
- const join = !implicit ? this.bin('·') : box(this.el(nextIsCall ? 'fnspace' : 'times', ''));
332
+ const join = !implicit ? this.bin(node.written === 'cross' ? '×' : '·') : box(this.el(nextIsCall ? 'fnspace' : 'times', ''));
314
333
  return row(left, join, right);
315
334
  }
316
335
 
@@ -336,20 +355,24 @@ class Layout {
336
355
  custom(node, ctx) {
337
356
  const name = customName(node.op);
338
357
  const args = node.args;
339
- if (DECORATIONS.includes(name) && args.length === 1) return this.decorate(name, this.render(args[0], ctx));
358
+ if (DECORATIONS.includes(name) && args.length === 1) return this.decorate(name, this.render(args[0], ctx), args[0]);
340
359
  // f(x), g′(x): a one-letter function is italic like a variable; sgn(x) is upright.
341
360
  const head = /^[A-Za-z]′*(⁻¹)?$/.test(name) ? this.symbol(name) : this.word(name);
342
361
  return row(head, box(this.el('callgap', '')), this.fence(this.list(args, ctx)));
343
362
  }
344
363
 
345
- decorate(name, b) {
364
+ decorate(name, b, base) {
346
365
  switch (name) {
347
366
  case 'boxed': return box(this.el('boxed', b.html), b.h + 0.22, b.d + 0.22);
348
- // a drawn stroke, not a background: Windows high contrast drops backgrounds, and a cancelled term would look kept
367
+ // a drawn stroke, not a background: Windows high contrast drops backgrounds, and a canceled term would look kept
349
368
  case 'cancel': return box(this.el('cancel', b.html + svg('cancel', `${this.p}-cancel-line`)), b.h, b.d);
350
369
  case 'underline': return box(this.el('underline', b.html), b.h, b.d + 0.12);
351
- case 'overline': case 'bar': return box(this.el('over', b.html), b.h + 0.14, b.d);
352
- default: return box(this.el('accent', this.el('accent-mark', ACCENTS[name]) + b.html), b.h + 0.3, b.d);
370
+ case 'overline': case 'bar': return box(this.el(`over${isShortLetter(base) ? ' over-low' : ''}`, b.html), b.h + 0.14, b.d);
371
+ default: {
372
+ // over a letter with no ascender (x, u, α) the mark comes down to the letter's top
373
+ const low = isShortLetter(base);
374
+ return box(this.el(`accent${low ? ' accent-low' : ''}`, this.el(`accent-mark accent-${name}`, ACCENTS[name]) + b.html), b.h + 0.3, b.d);
375
+ }
353
376
  }
354
377
  }
355
378
 
@@ -358,8 +381,14 @@ class Layout {
358
381
  fraction(node, ctx) {
359
382
  const [a, b] = node.args;
360
383
  if (ctx.level > 0 && this.o.scriptFractions === 'slash' && isSimpleArgument(a, true) && isSimpleArgument(b, true)) {
361
- const side = (n) => (n.type === 'op' && !isSimpleArgument(n) ? this.fence(this.render(n, ctx)) : this.render(n, ctx));
362
- return row(side(a), this.text('ord', '/'), side(b));
384
+ const inner = { ...ctx, leftFactor: false };
385
+ // x^{1/(2n)} is not x^{(1/2)n}: a product below the slash keeps its brackets
386
+ const side = (n, below) => (n.type === 'op' && (!isSimpleArgument(n) || (below && n.op === '*' && !isMinusOneTimes(n)))
387
+ ? this.fence(this.render(n, inner)) : this.render(n, inner));
388
+ // a leading minus needs no brackets: e^{−x²/2} reads the same as e^{(−x²)/2}
389
+ const top = a.type === 'op' && a.op === 'neg' ? this.render(a, inner) : side(a, false);
390
+ const slash = row(top, this.text('ord', '/'), side(b, true));
391
+ return ctx.leftFactor ? this.fence(slash) : slash; // and (1/2)n keeps its own
363
392
  }
364
393
  // A fraction inside a fraction, or in running text, is set smaller.
365
394
  const k = ctx.level > 0 || ctx.inFraction || !this.o.display ? 0.8 : 1;
@@ -367,7 +396,7 @@ class Layout {
367
396
  return this.stack(this.render(a, inner), this.render(b, inner), true, k);
368
397
  }
369
398
 
370
- /** One box over another, centred on the axis; with a bar for fractions, without for binomials. */
399
+ /** One box over another, centered on the axis; with a bar for fractions, without for binomials. */
371
400
  stack(num, den, bar = true, k = 1) {
372
401
  const scale = (b) => (k === 1 ? b.html : this.el('scaled', b.html, `font-size:${em(k)}`));
373
402
  const t = bar ? RULE : 0;
@@ -382,7 +411,7 @@ class Layout {
382
411
  /** x², (x+1)³, e^{x²}, sin²x, x₁². */
383
412
  power(node, ctx) {
384
413
  const [a, b] = node.args;
385
- const up = { ...ctx, level: ctx.level + 1, forceParens: false, before: false, inFraction: false };
414
+ const up = { ...ctx, level: ctx.level + 1, forceParens: false, before: false, inFraction: false, leftFactor: false };
386
415
  const exponent = () => this.render(b, up);
387
416
  if (this.o.trigPowers && TRIG.includes(a.op) && isPositiveWhole(b)) {
388
417
  return this.wrap(a, ['op', `op-${a.op}`], this.named(a, ctx, exponent()));
@@ -392,7 +421,8 @@ class Layout {
392
421
  return this.wrap(a, ['op', 'op-subscript'], this.script(this.render(a.args[0], { ...ctx, forceParens: true }), exponent(), ctx, sub));
393
422
  }
394
423
  // (sin x)^{1/2}: a named function keeps its own name outside the brackets only as sin²x.
395
- const fenceBase = needsBrackets(node, a, 'left') || (a.type === 'number' && a.value.startsWith('-')) || a.op === '/' || NAMED.includes(a.op);
424
+ const fenceBase = needsBrackets(node, a, 'left') || (a.type === 'number' && a.value.startsWith('-')) || a.op === '/' || NAMED.includes(a.op)
425
+ || BIG_OPERATORS.includes(a.op); // (∫x dx)², (∑ i)²: the exponent would sit on the body
396
426
  const base = fenceBase ? this.fence(this.render(a, ctx)) : this.render(a, { ...ctx, forceParens: true });
397
427
  return this.script(base, exponent(), ctx);
398
428
  }
@@ -469,6 +499,18 @@ class Layout {
469
499
 
470
500
  /** dy/dx, d²y/dx², and d/dx [f] with the body after the fraction. */
471
501
  derivative(node, ctx) {
502
+ const drawn = this.leibniz(node, ctx);
503
+ const { by, at } = derivativeOrder(node);
504
+ if (!at) return drawn;
505
+ // at a point, der(f, x = a): a bar as tall as the derivative, the point below it (|ₓ₌₂). The x there is a
506
+ // copy, with no id: the variable's id stays on the one in dx; the point (x = a) keeps its own.
507
+ const point = node.args[1];
508
+ const below = this.render({ ...point, args: [{ ...by, id: undefined }, at] }, { ...ctx, level: ctx.level + 1 });
509
+ return this.script(this.fence(drawn, '', '|'), null, ctx, below);
510
+ }
511
+
512
+ /** d/dx f drawn: the fraction, and the body after it (or on top, dy/dx). */
513
+ leibniz(node, ctx) {
472
514
  const { n, body, by, variable } = derivativeOrder(node);
473
515
  const up = { ...ctx, level: ctx.level + 1 };
474
516
  const d = () => this.text('d', 'd');
@@ -504,7 +546,7 @@ class Layout {
504
546
  return row(this.bigSign('int', body, lo, hi, ctx), body, dx);
505
547
  }
506
548
 
507
- /** The ∫ sign, centred on the axis and at least as tall as the integrand, with limits beside it. */
549
+ /** The ∫ sign, centered on the axis and at least as tall as the integrand, with limits beside it. */
508
550
  bigSign(name, body, lo, hi, ctx) {
509
551
  const small = !this.o.display || ctx.level > 0;
510
552
  const half = Math.max(small ? 0.6 : 0.95, Math.max(body.h - AXIS, body.d + AXIS) + 0.12);
@@ -529,7 +571,7 @@ class Layout {
529
571
  const arrow = () => this.rel('→');
530
572
  let under;
531
573
  switch (args.length) {
532
- case 1: return row(this.word('lim'), box(this.el('fnspace', '')), this.render(f, ctx));
574
+ case 1: return row(this.word('lim'), box(this.el('fnspace', '')), this.body(f, ctx));
533
575
  case 2: {
534
576
  const v = firstVariable(f);
535
577
  const approaches = second.type === 'number' || (second.type === 'symbol' && second.value.includes('∞'));
@@ -542,7 +584,7 @@ class Layout {
542
584
  under = row(r(second), arrow(), this.script(r(third), this.wrap(fourth, ['symbol'], this.text('ord', sign)), below));
543
585
  }
544
586
  }
545
- return row(this.under(this.word('lim'), under, ctx), this.render(f, ctx));
587
+ return row(this.under(this.word('lim'), under, ctx), this.body(f, ctx));
546
588
  }
547
589
 
548
590
  /** A word with something set small beneath it, lim over x → 0; the word keeps the baseline. */
@@ -554,12 +596,18 @@ class Layout {
554
596
  }
555
597
 
556
598
  /** ∑ and ∏ with the index below and the end above. */
599
+ /** What a limit, sum or product applies to: a sum or anything looser is bracketed, lim (x + 1) not lim x + 1. */
600
+ body(f, ctx) {
601
+ const op = bracketOp(f);
602
+ return op && precedenceOf(op) < precedenceOf('*') ? this.fence(this.render(f, ctx)) : this.render(f, ctx);
603
+ }
604
+
557
605
  bigOperator(name, args, ctx) {
558
606
  const [f, from, to] = args;
559
607
  const up = { ...ctx, level: ctx.level + 1 };
560
608
  const lo = from ? this.render(from, up) : null;
561
609
  const hi = to ? this.render(to, up) : null;
562
- const body = this.render(f, ctx);
610
+ const body = this.body(f, ctx);
563
611
  if (!this.o.display || ctx.level > 0) {
564
612
  const half = 0.55;
565
613
  const sign = svg(name, `${this.p}-bigsign`, `height:${em(2 * half)};width:${em(0.8)};vertical-align:${em(AXIS - half)}`);
@@ -579,7 +627,7 @@ class Layout {
579
627
  }
580
628
 
581
629
  /**
582
- * A matrix: a grid of entries, centred on the maths axis, in brackets as tall as it is. Each
630
+ * A matrix: a grid of entries, centered on the math axis, in brackets as tall as it is. Each
583
631
  * row that is a list in the tree is an element of its own (display: contents), so a row can
584
632
  * be pointed at like any part.
585
633
  */
@@ -635,6 +683,11 @@ function isSimpleArgument(node, inScript = false) {
635
683
  return false;
636
684
  }
637
685
 
686
+ const STATEMENTS = ['=', '===', '≠', '≠=', '<', '>', '≤', '≥', '≈', '≡', '∈', '∉'];
687
+ /** An equation or inequality, or such statements joined by or / and. */
688
+ const isStatement = (n) => n.type === 'op' && n.args.length >= 2
689
+ && ((n.args.length === 2 && STATEMENTS.includes(n.op)) || ((n.op === '|' || n.op === '&') && n.args.every(isStatement)));
690
+
638
691
  const isShortSymbol = (n) => n.type === 'symbol' && (n.value.length === 1 || /^[α-ωΑ-Ω]$/.test(n.value) || Boolean(GREEK[n.value]));
639
692
  const isPositiveWhole = (n) => n.type === 'number' && /^[1-9]\d*$/.test(n.value) && Number(n.value) < 10;
640
693
 
@@ -647,3 +700,7 @@ function startsWithCall(node) {
647
700
  }
648
701
  return false;
649
702
  }
703
+
704
+ // Lookup tables are keyed by what an expression holds: with no prototype, a name like toString or
705
+ // constructor finds nothing rather than Object's own (and is drawn as the name it is).
706
+ for (const table of [OP_CLASS, RELATIONS, BINARY, INVERSE, CALLS, GROUPS, LATEX_SYMBOLS, ACCENTS]) Object.setPrototypeOf(table, null);
package/src/lite.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * '@mathzetta/inlinemath/lite' — Inline Math's drawing only: `toHTML()` and nothing live. The same layout,
3
- * glyphs, colours, highlights and accessible (spoken) labels as the full build, without the live
3
+ * glyphs, colors, highlights and accessible (spoken) labels as the full build, without the live
4
4
  * view (render, step animation, events), Markdown, the CAS or the calculator.
5
5
  *
6
6
  * import { toHTML } from '@mathzetta/inlinemath/lite';
package/src/markdown.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- // '@mathzetta/inlinemath/markdown' — Markdown with maths. See types.d.ts.
1
+ // '@mathzetta/inlinemath/markdown' — Markdown with math. See types.d.ts.
2
2
  export type { MarkdownOptions, VariableDefinition } from './types.js';
3
3
  export { markdownToHTML, renderMarkdownInto, extractMath, renderMarkdown, createVariables, variables, Variables } from './types.js';