temml 0.10.32 → 0.10.34

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.
@@ -0,0 +1,30 @@
1
+ import defineFunction from "../defineFunction";
2
+ import mathMLTree from "../mathMLTree";
3
+ import * as mml from "../buildMathML";
4
+
5
+ // \vcenter: Vertically center the argument group on the math axis.
6
+
7
+ defineFunction({
8
+ type: "vcenter",
9
+ names: ["\\vcenter"],
10
+ props: {
11
+ numArgs: 1,
12
+ argTypes: ["original"],
13
+ allowedInText: false
14
+ },
15
+ handler({ parser }, args) {
16
+ return {
17
+ type: "vcenter",
18
+ mode: parser.mode,
19
+ body: args[0]
20
+ };
21
+ },
22
+ mathmlBuilder(group, style) {
23
+ // Use a math table to create vertically centered content.
24
+ const mtd = new mathMLTree.MathNode("mtd", [mml.buildGroup(group.body, style)])
25
+ mtd.style.padding = "0"
26
+ const mtr = new mathMLTree.MathNode("mtr", [mtd])
27
+ return new mathMLTree.MathNode("mtable", [mtr])
28
+ }
29
+ });
30
+
package/src/functions.js CHANGED
@@ -56,4 +56,5 @@ import "./functions/tag";
56
56
  import "./functions/text";
57
57
  // import "./functions/tip";
58
58
  // import "./functions/toggle";
59
+ import "./functions/vcenter";
59
60
  import "./functions/verb";
package/src/macros.js CHANGED
@@ -243,7 +243,7 @@ defineMacro("\\underbar", "\\underline{\\text{#1}}");
243
243
  // \kern6\p@\hbox{.}\hbox{.}\hbox{.}}}
244
244
  // We'll call \varvdots, which gets a glyph from symbols.js.
245
245
  // The zero-width rule gets us an equivalent to the vertical 6pt kern.
246
- defineMacro("\\vdots", "\\TextOrMath{\\textvdots}{{\\varvdots\\rule{0pt}{15pt}}}\\relax");
246
+ defineMacro("\\vdots", "{\\varvdots\\rule{0pt}{15pt}}")
247
247
  defineMacro("\u22ee", "\\vdots");
248
248
 
249
249
  // {array} environment gaps
@@ -463,8 +463,10 @@ defineMacro("\\tag@literal", (context) => {
463
463
  if (context.macros.get("\\df@tag")) {
464
464
  throw new ParseError("Multiple \\tag");
465
465
  }
466
- return "\\def\\df@tag{\\text{#1}}";
466
+ return "\\gdef\\df@tag{\\text{#1}}";
467
467
  });
468
+ defineMacro("\\notag", "\\nonumber");
469
+ defineMacro("\\nonumber", "\\gdef\\@eqnsw{0}")
468
470
 
469
471
  // \renewcommand{\bmod}{\nonscript\mskip-\medmuskip\mkern5mu\mathbin
470
472
  // {\operator@font mod}\penalty900
package/src/mathMLTree.js CHANGED
@@ -25,6 +25,7 @@ export class MathNode {
25
25
  this.children = children || [];
26
26
  this.classes = classes || [];
27
27
  this.style = style || {}; // Used for <mstyle> elements
28
+ this.label = "";
28
29
  }
29
30
 
30
31
  /**
@@ -42,6 +43,10 @@ export class MathNode {
42
43
  return this.attributes[name];
43
44
  }
44
45
 
46
+ setLabel(value) {
47
+ this.label = value
48
+ }
49
+
45
50
  /**
46
51
  * Converts the math node into a MathML-namespaced DOM element.
47
52
  */
@@ -1,40 +1,49 @@
1
1
  /* Temml Post Process
2
- * Perform two tasks not done by Temml when it created each individual Temml <math> element.
3
- * Given a block,
4
- * 1. At each AMS auto-numbered environment, assign an id.
5
- * 2. Populate the text contents of each \ref & \eqref
2
+ * Populate the text contents of each \ref & \eqref
6
3
  *
7
4
  * As with other Temml code, this file is released under terms of the MIT license.
8
5
  * https://mit-license.org/
9
6
  */
10
7
 
11
- export const version = "0.10.32";
8
+ export const version = "0.10.34";
12
9
 
13
10
  export function postProcess(block) {
14
11
  const labelMap = {}
15
12
  let i = 0
16
13
 
17
14
  // Get a collection of the parents of each \tag & auto-numbered equation
18
- const parents = block.getElementsByClassName("tml-tageqn");
19
- for (const parent of parents) {
20
- const eqns = parent.getElementsByClassName("tml-eqn")
21
- if (eqns. length > 0 ) {
22
- // AMS automatically numbered equation.
23
- // Assign an id.
24
- i += 1;
25
- eqns[0].id = "tml-eqn-" + i
26
- // No need to write a number into the text content of the element.
27
- // A CSS counter does that even if this postProcess() function is not used.
15
+ const amsEqns = document.getElementsByClassName('tml-eqn')
16
+ for (let parent of amsEqns) {
17
+ // AMS automatically numbered equation.
18
+ // Assign an id.
19
+ i += 1;
20
+ parent.setAttribute("id", "tml-eqn-" + String(i))
21
+ // No need to write a number into the text content of the element.
22
+ // A CSS counter has done that even if this postProcess() function is not used.
23
+
24
+ // Find any \label that refers to an AMS automatic eqn number.
25
+ while (true) {
26
+ if (parent.tagName === "mtable") { break }
27
+ const labels = parent.getElementsByClassName("tml-label")
28
+ if (labels.length > 0) {
29
+ const id = parent.attributes.id.value
30
+ labelMap[id] = String(i)
31
+ break
32
+ } else {
33
+ parent = parent.parentElement
34
+ }
28
35
  }
29
- // If there is a \label, add it to labelMap
36
+ }
37
+
38
+ // Find \labels associated with \tag
39
+ const taggedEqns = document.getElementsByClassName('tml-tageqn')
40
+ for (const parent of taggedEqns) {
30
41
  const labels = parent.getElementsByClassName("tml-label")
31
- if (labels.length === 0) { continue }
32
- if (eqns.length > 0) {
33
- labelMap[labels[0].id] = String(i)
34
- } else {
42
+ if (labels.length > 0) {
35
43
  const tags = parent.getElementsByClassName("tml-tag")
36
44
  if (tags.length > 0) {
37
- labelMap[labels[0].id] = tags[0].textContent
45
+ const id = parent.attributes.id.value
46
+ labelMap[id] = tags[0].textContent
38
47
  }
39
48
  }
40
49
  }
@@ -42,16 +51,21 @@ export function postProcess(block) {
42
51
  // Populate \ref & \eqref text content
43
52
  const refs = block.getElementsByClassName("tml-ref");
44
53
  [...refs].forEach(ref => {
45
- let str = labelMap[ref.getAttribute("href").slice(1)];
54
+ const attr = ref.getAttribute("href")
55
+ let str = labelMap[attr.slice(1)];
46
56
  if (ref.className.indexOf("tml-eqref") === -1) {
47
57
  // \ref. Omit parens.
48
58
  str = str.replace(/^\(/, "")
49
- str = str.replace(/\($/, "")
50
- } {
59
+ str = str.replace(/\)$/, "")
60
+ } else {
51
61
  // \eqref. Include parens
52
62
  if (str.charAt(0) !== "(") { str = "(" + str }
53
63
  if (str.slice(-1) !== ")") { str = str + ")" }
54
64
  }
55
- ref.textContent = str
65
+ const mtext = document.createElementNS("http://www.w3.org/1998/Math/MathML", "mtext")
66
+ mtext.appendChild(document.createTextNode(str))
67
+ const math = document.createElementNS("http://www.w3.org/1998/Math/MathML", "math")
68
+ math.appendChild(mtext)
69
+ ref.appendChild(math)
56
70
  })
57
71
  }
package/src/symbols.js CHANGED
@@ -670,7 +670,7 @@ defineSymbol(math, mathord, "\u03db", "\\stigma", true);
670
670
  defineSymbol(math, mathord, "\u2aeb", "\\Bot");
671
671
  defineSymbol(math, bin, "\u2217", "\u2217", true);
672
672
  defineSymbol(math, bin, "+", "+");
673
- defineSymbol(math, bin, "*", "*");
673
+ defineSymbol(math, bin, "\u2217", "*");
674
674
  defineSymbol(math, bin, "\u2044", "/", true);
675
675
  defineSymbol(math, bin, "\u2044", "\u2044");
676
676
  defineSymbol(math, bin, "\u2212", "-", true);
@@ -692,7 +692,7 @@ defineSymbol(math, open, "\u27e8", "\\langle", true);
692
692
  defineSymbol(math, open, "\u27ea", "\\lAngle", true);
693
693
  defineSymbol(math, open, "\u2989", "\\llangle", true);
694
694
  defineSymbol(math, open, "|", "\\lvert");
695
- defineSymbol(math, open, "\u2016", "\\lVert");
695
+ defineSymbol(math, open, "\u2016", "\\lVert", true);
696
696
  defineSymbol(math, textord, "!", "\\oc"); // cmll package
697
697
  defineSymbol(math, textord, "?", "\\wn");
698
698
  defineSymbol(math, textord, "\u2193", "\\shpos");
@@ -856,7 +856,7 @@ defineSymbol(math, inner, "\u22f0", "\\iddots", true);
856
856
  defineSymbol(math, inner, "\u22ef", "\\@cdots", true);
857
857
  defineSymbol(math, inner, "\u22f1", "\\ddots", true);
858
858
  defineSymbol(math, textord, "\u22ee", "\\varvdots"); // \vdots is a macro
859
- defineSymbol(text, textord, "\u22ee", "\\textvdots");
859
+ defineSymbol(text, textord, "\u22ee", "\\varvdots");
860
860
  defineSymbol(math, accent, "\u02ca", "\\acute");
861
861
  defineSymbol(math, accent, "\u0060", "\\grave");
862
862
  defineSymbol(math, accent, "\u00a8", "\\ddot");
package/src/variant.js CHANGED
@@ -85,6 +85,8 @@ export const getVariant = function(group, style) {
85
85
  return "script"
86
86
  case "mathsf":
87
87
  return "sans-serif"
88
+ case "mathsfit":
89
+ return "sans-serif-italic"
88
90
  case "mathtt":
89
91
  return "monospace"
90
92
  default: