temml 0.12.1 → 0.12.2

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/dist/temml.js CHANGED
@@ -182,6 +182,9 @@ var temml = (function () {
182
182
  return +n.toFixed(4);
183
183
  };
184
184
 
185
+ // Identify short letters. Used for accents and \cancelto.
186
+ const smalls = "acegıȷmnopqrsuvwxyzαγεηικμνοπρςστυχωϕ𝐚𝐜𝐞𝐠𝐦𝐧𝐨𝐩𝐪𝐫𝐬𝐮𝐯𝐰𝐱𝐲𝐳";
187
+
185
188
  /**
186
189
  * This is a module for storing settings passed into Temml. It correctly handles
187
190
  * default settings.
@@ -797,6 +800,8 @@ var temml = (function () {
797
800
  xrightarrow: "\u2192",
798
801
  underbrace: "\u23df",
799
802
  overbrace: "\u23de",
803
+ overbracket: "\u23b4",
804
+ underbracket: "\u23b5",
800
805
  overgroup: "\u23e0",
801
806
  overparen: "⏜",
802
807
  undergroup: "\u23e1",
@@ -2452,9 +2457,6 @@ var temml = (function () {
2452
2457
  return math;
2453
2458
  }
2454
2459
 
2455
- // Identify letters to which we'll attach a combining accent character
2456
- const smalls = "acegıȷmnopqrsuvwxyzαγεηικμνοπρςστυχωϕ𝐚𝐜𝐞𝐠𝐦𝐧𝐨𝐩𝐪𝐫𝐬𝐮𝐯𝐰𝐱𝐲𝐳";
2457
-
2458
2460
  // From the KaTeX font metrics, identify letters whose accents need a italic correction.
2459
2461
  const smallNudge = "DHKLUcegorsuvxyzΠΥΨαδηιμνοτυχϵ";
2460
2462
  const mediumNudge = "BCEGIMNOPQRSTXZlpqtwΓΘΞΣΦΩβεζθξρςφψϑϕϱ";
@@ -4521,6 +4523,7 @@ var temml = (function () {
4521
4523
  const tbl = [];
4522
4524
  const numRows = group.body.length;
4523
4525
  const hlines = group.hLinesBeforeRow;
4526
+ const tagIsPresent = (group.tags && group.tags.some((tag) => tag));
4524
4527
 
4525
4528
  for (let i = 0; i < numRows; i++) {
4526
4529
  const rw = group.body[i];
@@ -4550,7 +4553,7 @@ var temml = (function () {
4550
4553
  for (let k = 0; k < numColumns - rw.length; k++) {
4551
4554
  row.push(new MathNode("mtd", [], [], style));
4552
4555
  }
4553
- if (group.autoTag) {
4556
+ if (tagIsPresent) {
4554
4557
  const tag = group.tags[i];
4555
4558
  let tagElement;
4556
4559
  if (tag === true) { // automatic numbering
@@ -4662,7 +4665,7 @@ var temml = (function () {
4662
4665
  if (j === numCols - 1 && hand === 1) { return "0" }
4663
4666
  if (group.envClasses[0] !== "align") { return sidePadding }
4664
4667
  if (hand === 1) { return "0" }
4665
- if (group.autoTag) {
4668
+ if (tagIsPresent) {
4666
4669
  return (j % 2) ? "1" : "0"
4667
4670
  } else {
4668
4671
  return (j % 2) ? "0" : "1"
@@ -4698,7 +4701,7 @@ var temml = (function () {
4698
4701
  // TODO: Remove -webkit- when Chromium no longer needs it.
4699
4702
  row.children[j].classes = ["tml-" + (j % 2 ? "left" : "right")];
4700
4703
  }
4701
- if (group.autoTag) {
4704
+ if (tagIsPresent) {
4702
4705
  const k = group.leqno ? 0 : row.children.length - 1;
4703
4706
  row.children[k].classes = []; // Default is center.
4704
4707
  }
@@ -4755,7 +4758,7 @@ var temml = (function () {
4755
4758
  row.children[0].style.borderLeft = sep;
4756
4759
  }
4757
4760
  }
4758
- let iCol = group.autoTag ? 0 : -1;
4761
+ let iCol = tagIsPresent ? 0 : -1;
4759
4762
  for (let i = iStart; i < iEnd; i++) {
4760
4763
  if (cols[i].type === "align") {
4761
4764
  const colAlign = alignMap[cols[i].align];
@@ -5281,6 +5284,78 @@ var temml = (function () {
5281
5284
  }
5282
5285
  });
5283
5286
 
5287
+ defineFunction({
5288
+ type: "cancelto",
5289
+ names: ["\\cancelto"],
5290
+ props: {
5291
+ numArgs: 2
5292
+ },
5293
+ handler({ parser }, args) {
5294
+ const to = args[0];
5295
+ const body = args[1];
5296
+ return {
5297
+ type: "cancelto",
5298
+ mode: parser.mode,
5299
+ body,
5300
+ to,
5301
+ isCharacterBox: isCharacterBox(body)
5302
+ };
5303
+ },
5304
+ mathmlBuilder(group, style) {
5305
+ const fromNode = new MathNode(
5306
+ "mrow",
5307
+ [buildGroup$1(group.body, style)],
5308
+ ["ff-narrow"] // A zero-width mrow.
5309
+ );
5310
+ // Write the arrow in a node written after the content.
5311
+ // That way, the arrow will be an overlay on the content.
5312
+ const phantom = new MathNode("mphantom", [buildGroup$1(group.body, style)]);
5313
+ const arrow = new MathNode("mrow", [phantom], ["tml-cancelto"]);
5314
+ if (group.isCharacterBox && smalls.indexOf(group.body.body[0].text) > -1) {
5315
+ arrow.style.left = "0.1em";
5316
+ arrow.style.width = "90%";
5317
+ }
5318
+ const node = new MathNode("mrow", [fromNode, arrow], ["menclose"]);
5319
+ if (!group.isCharacterBox || /[f∫∑]/.test(group.body.body[0].text)) {
5320
+ // Add 0.2em space to right of content to make room for the arrowhead.
5321
+ phantom.style.paddingRight = "0.2em";
5322
+ } else {
5323
+ phantom.style.padding = "0.5ex 0.1em 0 0";
5324
+ const strut = new MathNode('mspace', []);
5325
+ strut.setAttribute('height', "0.85em");
5326
+ fromNode.children.push(strut);
5327
+ }
5328
+
5329
+ // Create the "to" value above and to the right of the arrow.
5330
+ // First, we want a dummy node with the same height as the `from` content.
5331
+ // We'll place the `to` node above the dummy to get the correct vertical alignment.
5332
+ let dummyNode;
5333
+ if (group.isCharacterBox) {
5334
+ dummyNode = new MathNode('mspace', []);
5335
+ dummyNode.setAttribute('height', "1em");
5336
+ } else {
5337
+ // Create a phantom node with the same content as the body.
5338
+ const inner = buildGroup$1(group.body, style);
5339
+ // The phantom node will be zero-width, so it won't affect horizontal spacing.
5340
+ const zeroWidthNode = new MathNode("mpadded", [inner]);
5341
+ zeroWidthNode.setAttribute("width", "0.1px"); // Don't use 0. WebKit would omit it.
5342
+ dummyNode = new MathNode("mphantom", [zeroWidthNode]); // Hide it.
5343
+ }
5344
+ const toNode = buildGroup$1(group.to, style);
5345
+ const zeroWidthToNode = new MathNode("mpadded", [toNode]);
5346
+ if (!group.isCharacterBox || /[f∫∑]/.test(group.body.body[0].text)) {
5347
+ const w = new MathNode("mspace", []);
5348
+ w.setAttribute('width', "0.2em");
5349
+ zeroWidthToNode.children.unshift(w);
5350
+ }
5351
+ zeroWidthToNode.setAttribute("width", "0.1px"); // Don't use 0. WebKit would hide it.
5352
+ const mover = new MathNode("mover", [dummyNode, zeroWidthToNode]);
5353
+ // Fix Firefox positioning.
5354
+ const nudgeLeft = new MathNode('mrow', [], ["ff-nudge-left"]);
5355
+ return newDocumentFragment([makeRow([node, mover]), nudgeLeft])
5356
+ }
5357
+ });
5358
+
5284
5359
  // \@char is an internal function that takes a grouped decimal argument like
5285
5360
  // {123} and converts into symbol with code 123. It is used by the *macro*
5286
5361
  // \char defined in macros.js.
@@ -6207,8 +6282,10 @@ var temml = (function () {
6207
6282
  }
6208
6283
  });
6209
6284
 
6285
+ const boxTags = ["\\boxed", "\\fcolorbox", "\\colorbox"];
6286
+
6210
6287
  const mathmlBuilder$7 = (group, style) => {
6211
- const tag = group.label === "\\boxed" ? "mrow" : "menclose";
6288
+ const tag = boxTags.includes(group.label) ? "mrow" : "menclose";
6212
6289
  const node = new MathNode(tag, [buildGroup$1(group.body, style)]);
6213
6290
  switch (group.label) {
6214
6291
  case "\\overline":
@@ -6235,6 +6312,7 @@ var temml = (function () {
6235
6312
  node.setAttribute("notation", "updiagonalstrike downdiagonalstrike");
6236
6313
  node.classes.push("tml-xcancel");
6237
6314
  break
6315
+ // cancelto is handled in cancelto.js
6238
6316
  case "\\longdiv":
6239
6317
  node.setAttribute("notation", "longdiv");
6240
6318
  node.classes.push("longdiv-top");
@@ -6267,13 +6345,8 @@ var temml = (function () {
6267
6345
  break
6268
6346
  case "\\fcolorbox":
6269
6347
  case "\\colorbox": {
6270
- // <menclose> doesn't have a good notation option for \colorbox.
6271
- // So use <mpadded> instead. Set some attributes that come
6272
- // included with <menclose>.
6273
- //const fboxsep = 3; // 3 pt from LaTeX source2e
6274
- //node.setAttribute("height", `+${2 * fboxsep}pt`)
6275
- //node.setAttribute("voffset", `${fboxsep}pt`)
6276
- node.style.padding = "3pt";
6348
+ // Don't use <menclose>. WebKit would show a radical.
6349
+ node.style.padding = "0.3em"; // 3 pt from LaTeX source2e for a 10pt font
6277
6350
  if (group.label === "\\fcolorbox") {
6278
6351
  node.style.border = "0.0667em solid " + String(group.borderColor);
6279
6352
  }
@@ -7042,16 +7115,16 @@ var temml = (function () {
7042
7115
  ]);
7043
7116
  };
7044
7117
 
7045
- // Horizontal stretchy braces
7118
+ // Horizontal stretchy brackets
7046
7119
  defineFunction({
7047
- type: "horizBrace",
7048
- names: ["\\overbrace", "\\underbrace"],
7120
+ type: "horizBracket",
7121
+ names: ["\\overbrace", "\\underbrace", "\\overbracket", "\\underbracket"],
7049
7122
  props: {
7050
7123
  numArgs: 1
7051
7124
  },
7052
7125
  handler({ parser, funcName }, args) {
7053
7126
  return {
7054
- type: "horizBrace",
7127
+ type: "horizBracket",
7055
7128
  mode: parser.mode,
7056
7129
  label: funcName,
7057
7130
  isOver: /^\\over/.test(funcName),
@@ -8207,7 +8280,8 @@ var temml = (function () {
8207
8280
  "\u2a1a"
8208
8281
  ],
8209
8282
  props: {
8210
- numArgs: 0
8283
+ numArgs: 0,
8284
+ allowedInArgument: true
8211
8285
  },
8212
8286
  handler({ parser, funcName }) {
8213
8287
  let fName = funcName;
@@ -8947,18 +9021,18 @@ var temml = (function () {
8947
9021
  defineFunctionBuilders({
8948
9022
  type: "supsub",
8949
9023
  mathmlBuilder(group, style) {
8950
- // Is the inner group a relevant horizontal brace?
8951
- let isBrace = false;
9024
+ // Is the inner group a relevant horizontal brace or bracket?
9025
+ let isBracket = false;
8952
9026
  let isOver;
8953
9027
  let isSup;
8954
9028
  let appendApplyFunction = false;
8955
9029
  let appendSpace = false;
8956
9030
  let needsLeadingSpace = false;
8957
9031
 
8958
- if (group.base && group.base.type === "horizBrace") {
9032
+ if (group.base && group.base.type === "horizBracket") {
8959
9033
  isSup = !!group.sup;
8960
9034
  if (isSup === group.base.isOver) {
8961
- isBrace = true;
9035
+ isBracket = true;
8962
9036
  isOver = group.base.isOver;
8963
9037
  }
8964
9038
  }
@@ -9006,7 +9080,7 @@ var temml = (function () {
9006
9080
  }
9007
9081
 
9008
9082
  let nodeType;
9009
- if (isBrace) {
9083
+ if (isBracket) {
9010
9084
  nodeType = isOver ? "mover" : "munder";
9011
9085
  } else if (!group.sub) {
9012
9086
  const base = group.base;
@@ -12076,7 +12150,7 @@ var temml = (function () {
12076
12150
  * https://mit-license.org/
12077
12151
  */
12078
12152
 
12079
- const version = "0.12.01";
12153
+ const version = "0.12.02";
12080
12154
 
12081
12155
  function postProcess(block) {
12082
12156
  const labelMap = {};