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.
- package/README.md +1 -1
- package/dist/Temml-Asana.css +16 -1
- package/dist/Temml-Fira.css +16 -1
- package/dist/Temml-Latin-Modern.css +16 -1
- package/dist/Temml-Libertinus.css +16 -1
- package/dist/Temml-Local.css +16 -1
- package/dist/Temml-STIX2.css +16 -1
- package/dist/temml.cjs +473 -283
- package/dist/temml.js +473 -283
- package/dist/temml.min.js +1 -1
- package/dist/temml.mjs +473 -283
- package/dist/temmlPostProcess.js +39 -25
- package/package.json +1 -1
- package/src/Style.js +5 -3
- package/src/buildMathML.js +104 -62
- package/src/domTree.js +34 -0
- package/src/environments/array.js +119 -82
- package/src/environments/cd.js +17 -10
- package/src/functions/arrow.js +11 -3
- package/src/functions/def.js +7 -4
- package/src/functions/delimsizing.js +1 -0
- package/src/functions/font.js +1 -0
- package/src/functions/genfrac.js +13 -4
- package/src/functions/href.js +4 -6
- package/src/functions/label.js +1 -1
- package/src/functions/op.js +0 -7
- package/src/functions/ref.js +3 -5
- package/src/functions/rule.js +2 -0
- package/src/functions/supsub.js +12 -3
- package/src/functions/vcenter.js +30 -0
- package/src/functions.js +1 -0
- package/src/macros.js +4 -2
- package/src/mathMLTree.js +5 -0
- package/src/postProcess.js +39 -25
- package/src/symbols.js +3 -3
- package/src/variant.js +2 -0
@@ -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
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", "
|
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 "\\
|
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
|
*/
|
package/src/postProcess.js
CHANGED
@@ -1,40 +1,49 @@
|
|
1
1
|
/* Temml Post Process
|
2
|
-
*
|
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.
|
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
|
19
|
-
for (
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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", "\\
|
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");
|