temml 0.10.31 → 0.10.33
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 +6 -0
- package/dist/Temml-Fira.css +6 -0
- package/dist/Temml-Latin-Modern.css +6 -0
- package/dist/Temml-Libertinus.css +6 -0
- package/dist/Temml-Local.css +6 -0
- package/dist/Temml-STIX2.css +6 -0
- package/dist/temml.cjs +251 -126
- package/dist/temml.js +251 -126
- package/dist/temml.min.js +1 -1
- package/dist/temml.mjs +251 -126
- package/dist/temmlPostProcess.js +37 -24
- package/package.json +1 -1
- package/src/Style.js +5 -3
- package/src/buildMathML.js +84 -62
- package/src/domTree.js +34 -0
- package/src/environments/cd.js +15 -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/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 +1 -1
- package/src/postProcess.js +37 -24
- package/src/symbols.js +2 -1
- package/src/variant.js +2 -0
package/dist/temml.js
CHANGED
@@ -502,6 +502,40 @@ var temml = (function () {
|
|
502
502
|
}
|
503
503
|
};
|
504
504
|
|
505
|
+
// Create an <a href="…"> node.
|
506
|
+
class AnchorNode {
|
507
|
+
constructor(href, classes, children) {
|
508
|
+
this.href = href;
|
509
|
+
this.classes = classes;
|
510
|
+
this.children = children || [];
|
511
|
+
}
|
512
|
+
|
513
|
+
toNode() {
|
514
|
+
const node = document.createElement("a");
|
515
|
+
node.setAttribute("href", this.href);
|
516
|
+
if (this.classes.length > 0) {
|
517
|
+
node.className = createClass(this.classes);
|
518
|
+
}
|
519
|
+
for (let i = 0; i < this.children.length; i++) {
|
520
|
+
node.appendChild(this.children[i].toNode());
|
521
|
+
}
|
522
|
+
return node
|
523
|
+
}
|
524
|
+
|
525
|
+
toMarkup() {
|
526
|
+
let markup = `<a href='${utils.escape(this.href)}'`;
|
527
|
+
if (this.classes.length > 0) {
|
528
|
+
markup += ` class="${utils.escape(createClass(this.classes))}"`;
|
529
|
+
}
|
530
|
+
markup += ">";
|
531
|
+
for (let i = 0; i < this.children.length; i++) {
|
532
|
+
markup += this.children[i].toMarkup();
|
533
|
+
}
|
534
|
+
markup += "</a>";
|
535
|
+
return markup
|
536
|
+
}
|
537
|
+
}
|
538
|
+
|
505
539
|
/*
|
506
540
|
* This node represents an image embed (<img>) element.
|
507
541
|
*/
|
@@ -1531,7 +1565,7 @@ var temml = (function () {
|
|
1531
1565
|
defineSymbol(math, open, "\u27ea", "\\lAngle", true);
|
1532
1566
|
defineSymbol(math, open, "\u2989", "\\llangle", true);
|
1533
1567
|
defineSymbol(math, open, "|", "\\lvert");
|
1534
|
-
defineSymbol(math, open, "\u2016", "\\lVert");
|
1568
|
+
defineSymbol(math, open, "\u2016", "\\lVert", true);
|
1535
1569
|
defineSymbol(math, textord, "!", "\\oc"); // cmll package
|
1536
1570
|
defineSymbol(math, textord, "?", "\\wn");
|
1537
1571
|
defineSymbol(math, textord, "\u2193", "\\shpos");
|
@@ -1695,6 +1729,7 @@ var temml = (function () {
|
|
1695
1729
|
defineSymbol(math, inner, "\u22ef", "\\@cdots", true);
|
1696
1730
|
defineSymbol(math, inner, "\u22f1", "\\ddots", true);
|
1697
1731
|
defineSymbol(math, textord, "\u22ee", "\\varvdots"); // \vdots is a macro
|
1732
|
+
defineSymbol(text, textord, "\u22ee", "\\varvdots");
|
1698
1733
|
defineSymbol(math, accent, "\u02ca", "\\acute");
|
1699
1734
|
defineSymbol(math, accent, "\u0060", "\\grave");
|
1700
1735
|
defineSymbol(math, accent, "\u00a8", "\\ddot");
|
@@ -2147,61 +2182,6 @@ var temml = (function () {
|
|
2147
2182
|
}
|
2148
2183
|
};
|
2149
2184
|
|
2150
|
-
const numberRegEx$1 = /^[0-9]$/;
|
2151
|
-
const isDotOrComma = (node, followingNode) => {
|
2152
|
-
return ((node.type === "textord" && node.text === ".") ||
|
2153
|
-
(node.type === "atom" && node.text === ",")) &&
|
2154
|
-
// Don't consolidate if there is a space after the comma.
|
2155
|
-
node.loc && followingNode.loc && node.loc.end === followingNode.loc.start
|
2156
|
-
};
|
2157
|
-
const consolidateNumbers = expression => {
|
2158
|
-
// Consolidate adjacent numbers. We want to return <mn>1,506.3</mn>,
|
2159
|
-
// not <mn>1</mn><mo>,</mo><mn>5</mn><mn>0</mn><mn>6</mn><mi>.</mi><mn>3</mn>
|
2160
|
-
if (expression.length < 2) { return }
|
2161
|
-
const nums = [];
|
2162
|
-
let inNum = false;
|
2163
|
-
// Find adjacent numerals
|
2164
|
-
for (let i = 0; i < expression.length; i++) {
|
2165
|
-
const node = expression[i];
|
2166
|
-
if (node.type === "textord" && numberRegEx$1.test(node.text)) {
|
2167
|
-
if (!inNum) { nums.push({ start: i }); }
|
2168
|
-
inNum = true;
|
2169
|
-
} else {
|
2170
|
-
if (inNum) { nums[nums.length - 1].end = i - 1; }
|
2171
|
-
inNum = false;
|
2172
|
-
}
|
2173
|
-
}
|
2174
|
-
if (inNum) { nums[nums.length - 1].end = expression.length - 1; }
|
2175
|
-
|
2176
|
-
// Determine if numeral groups are separated by a comma or dot.
|
2177
|
-
for (let i = nums.length - 1; i > 0; i--) {
|
2178
|
-
if (nums[i - 1].end === nums[i].start - 2 &&
|
2179
|
-
isDotOrComma(expression[nums[i].start - 1], expression[nums[i].start])) {
|
2180
|
-
// Merge the two groups.
|
2181
|
-
nums[i - 1].end = nums[i].end;
|
2182
|
-
nums.splice(i, 1);
|
2183
|
-
}
|
2184
|
-
}
|
2185
|
-
|
2186
|
-
// Consolidate the number nodes
|
2187
|
-
for (let i = nums.length - 1; i >= 0; i--) {
|
2188
|
-
for (let j = nums[i].start + 1; j <= nums[i].end; j++) {
|
2189
|
-
expression[nums[i].start].text += expression[j].text;
|
2190
|
-
}
|
2191
|
-
expression.splice(nums[i].start + 1, nums[i].end - nums[i].start);
|
2192
|
-
// Check if the <mn> is followed by a numeric base in a supsub, e.g. the "3" in 123^4
|
2193
|
-
// If so, merge the first <mn> into the base.
|
2194
|
-
if (expression.length > nums[i].start + 1) {
|
2195
|
-
const nextTerm = expression[nums[i].start + 1];
|
2196
|
-
if (nextTerm.type === "supsub" && nextTerm.base && nextTerm.base.type === "textord" &&
|
2197
|
-
numberRegEx$1.test(nextTerm.base.text)) {
|
2198
|
-
nextTerm.base.text = expression[nums[i].start].text + nextTerm.base.text;
|
2199
|
-
expression.splice(nums[i].start, 1);
|
2200
|
-
}
|
2201
|
-
}
|
2202
|
-
}
|
2203
|
-
};
|
2204
|
-
|
2205
2185
|
/**
|
2206
2186
|
* Wrap the given array of nodes in an <mrow> node if needed, i.e.,
|
2207
2187
|
* unless the array has length 1. Always returns a single node.
|
@@ -2224,6 +2204,39 @@ var temml = (function () {
|
|
2224
2204
|
return new mathMLTree.MathNode("mrow", body);
|
2225
2205
|
};
|
2226
2206
|
|
2207
|
+
/**
|
2208
|
+
* Check for <mi>.</mi> which is how a dot renders in MathML,
|
2209
|
+
* or <mo separator="true" lspace="0em" rspace="0em">,</mo>
|
2210
|
+
* which is how a braced comma {,} renders in MathML
|
2211
|
+
*/
|
2212
|
+
function isNumberPunctuation(group) {
|
2213
|
+
if (!group) {
|
2214
|
+
return false
|
2215
|
+
}
|
2216
|
+
if (group.type === 'mi' && group.children.length === 1) {
|
2217
|
+
const child = group.children[0];
|
2218
|
+
return child instanceof TextNode && child.text === '.'
|
2219
|
+
} else if (group.type === "mtext" && group.children.length === 1) {
|
2220
|
+
const child = group.children[0];
|
2221
|
+
return child instanceof TextNode && child.text === '\u2008' // punctuation space
|
2222
|
+
} else if (group.type === 'mo' && group.children.length === 1 &&
|
2223
|
+
group.getAttribute('separator') === 'true' &&
|
2224
|
+
group.getAttribute('lspace') === '0em' &&
|
2225
|
+
group.getAttribute('rspace') === '0em') {
|
2226
|
+
const child = group.children[0];
|
2227
|
+
return child instanceof TextNode && child.text === ','
|
2228
|
+
} else {
|
2229
|
+
return false
|
2230
|
+
}
|
2231
|
+
}
|
2232
|
+
const isComma = (expression, i) => {
|
2233
|
+
const node = expression[i];
|
2234
|
+
const followingNode = expression[i + 1];
|
2235
|
+
return (node.type === "atom" && node.text === ",") &&
|
2236
|
+
// Don't consolidate if there is a space after the comma.
|
2237
|
+
node.loc && followingNode.loc && node.loc.end === followingNode.loc.start
|
2238
|
+
};
|
2239
|
+
|
2227
2240
|
const isRel = item => {
|
2228
2241
|
return (item.type === "atom" && item.family === "rel") ||
|
2229
2242
|
(item.type === "mclass" && item.mclass === "mrel")
|
@@ -2247,11 +2260,16 @@ var temml = (function () {
|
|
2247
2260
|
return [group];
|
2248
2261
|
}
|
2249
2262
|
|
2250
|
-
consolidateNumbers(expression);
|
2251
|
-
|
2252
2263
|
const groups = [];
|
2264
|
+
const groupArray = [];
|
2265
|
+
let lastGroup;
|
2253
2266
|
for (let i = 0; i < expression.length; i++) {
|
2254
|
-
|
2267
|
+
groupArray.push(buildGroup$1(expression[i], style));
|
2268
|
+
}
|
2269
|
+
|
2270
|
+
for (let i = 0; i < groupArray.length; i++) {
|
2271
|
+
const group = groupArray[i];
|
2272
|
+
|
2255
2273
|
// Suppress spacing between adjacent relations
|
2256
2274
|
if (i < expression.length - 1 && isRel(expression[i]) && isRel(expression[i + 1])) {
|
2257
2275
|
group.setAttribute("rspace", "0em");
|
@@ -2259,9 +2277,39 @@ var temml = (function () {
|
|
2259
2277
|
if (i > 0 && isRel(expression[i]) && isRel(expression[i - 1])) {
|
2260
2278
|
group.setAttribute("lspace", "0em");
|
2261
2279
|
}
|
2280
|
+
|
2281
|
+
// Concatenate numbers
|
2282
|
+
if (group.type === 'mn' && lastGroup && lastGroup.type === 'mn') {
|
2283
|
+
// Concatenate <mn>...</mn> followed by <mi>.</mi>
|
2284
|
+
lastGroup.children.push(...group.children);
|
2285
|
+
continue
|
2286
|
+
} else if (isNumberPunctuation(group) && lastGroup && lastGroup.type === 'mn') {
|
2287
|
+
// Concatenate <mn>...</mn> followed by <mi>.</mi>
|
2288
|
+
lastGroup.children.push(...group.children);
|
2289
|
+
continue
|
2290
|
+
} else if (lastGroup && lastGroup.type === "mn" && i < groupArray.length - 1 &&
|
2291
|
+
groupArray[i + 1].type === "mn" && isComma(expression, i)) {
|
2292
|
+
lastGroup.children.push(...group.children);
|
2293
|
+
continue
|
2294
|
+
} else if (group.type === 'mn' && isNumberPunctuation(lastGroup)) {
|
2295
|
+
// Concatenate <mi>.</mi> followed by <mn>...</mn>
|
2296
|
+
group.children = [...lastGroup.children, ...group.children];
|
2297
|
+
groups.pop();
|
2298
|
+
} else if ((group.type === 'msup' || group.type === 'msub') &&
|
2299
|
+
group.children.length >= 1 && lastGroup &&
|
2300
|
+
(lastGroup.type === 'mn' || isNumberPunctuation(lastGroup))) {
|
2301
|
+
// Put preceding <mn>...</mn> or <mi>.</mi> inside base of
|
2302
|
+
// <msup><mn>...base...</mn>...exponent...</msup> (or <msub>)
|
2303
|
+
const base = group.children[0];
|
2304
|
+
if (base instanceof MathNode && base.type === 'mn' && lastGroup) {
|
2305
|
+
base.children = [...lastGroup.children, ...base.children];
|
2306
|
+
groups.pop();
|
2307
|
+
}
|
2308
|
+
}
|
2262
2309
|
groups.push(group);
|
2310
|
+
lastGroup = group;
|
2263
2311
|
}
|
2264
|
-
return groups
|
2312
|
+
return groups
|
2265
2313
|
};
|
2266
2314
|
|
2267
2315
|
/**
|
@@ -2323,6 +2371,11 @@ var temml = (function () {
|
|
2323
2371
|
}
|
2324
2372
|
|
2325
2373
|
const expression = buildExpression(tree, style);
|
2374
|
+
|
2375
|
+
if (expression.length === 1 && expression[0] instanceof AnchorNode) {
|
2376
|
+
return expression[0]
|
2377
|
+
}
|
2378
|
+
|
2326
2379
|
const wrap = (settings.displayMode || settings.annotate) ? "none" : settings.wrap;
|
2327
2380
|
|
2328
2381
|
const n1 = expression.length === 0 ? null : expression[0];
|
@@ -2347,6 +2400,9 @@ var temml = (function () {
|
|
2347
2400
|
if (settings.xml) {
|
2348
2401
|
math.setAttribute("xmlns", "http://www.w3.org/1998/Math/MathML");
|
2349
2402
|
}
|
2403
|
+
if (wrapper.style.width) {
|
2404
|
+
math.style.width = "100%";
|
2405
|
+
}
|
2350
2406
|
if (settings.displayMode) {
|
2351
2407
|
math.setAttribute("display", "block");
|
2352
2408
|
math.style.display = "block math"; // necessary in Chromium.
|
@@ -2678,12 +2734,19 @@ var temml = (function () {
|
|
2678
2734
|
return node
|
2679
2735
|
};
|
2680
2736
|
|
2681
|
-
const paddedNode = (group, lspace = 0.3, rspace = 0) => {
|
2737
|
+
const paddedNode = (group, lspace = 0.3, rspace = 0, mustSmash = false) => {
|
2682
2738
|
if (group == null && rspace === 0) { return padding$2(lspace) }
|
2683
2739
|
const row = group ? [group] : [];
|
2684
2740
|
if (lspace !== 0) { row.unshift(padding$2(lspace)); }
|
2685
2741
|
if (rspace > 0) { row.push(padding$2(rspace)); }
|
2686
|
-
|
2742
|
+
if (mustSmash) {
|
2743
|
+
// Used for the bottom arrow in a {CD} environment
|
2744
|
+
const mpadded = new mathMLTree.MathNode("mpadded", row);
|
2745
|
+
mpadded.setAttribute("height", "0");
|
2746
|
+
return mpadded
|
2747
|
+
} else {
|
2748
|
+
return new mathMLTree.MathNode("mrow", row)
|
2749
|
+
}
|
2687
2750
|
};
|
2688
2751
|
|
2689
2752
|
const labelSize = (size, scriptLevel) => Number(size) / emScale(scriptLevel);
|
@@ -2723,7 +2786,8 @@ var temml = (function () {
|
|
2723
2786
|
(body.body.body || body.body.length > 0));
|
2724
2787
|
if (gotUpper) {
|
2725
2788
|
let label = buildGroup$1(body, labelStyle);
|
2726
|
-
|
2789
|
+
const mustSmash = (fName === "\\\\cdrightarrow" || fName === "\\\\cdleftarrow");
|
2790
|
+
label = paddedNode(label, space, space, mustSmash);
|
2727
2791
|
// Since Firefox does not support minsize, stack a invisible node
|
2728
2792
|
// on top of the label. Its width will serve as a min-width.
|
2729
2793
|
// TODO: Refactor this after Firefox supports minsize.
|
@@ -3146,18 +3210,23 @@ var temml = (function () {
|
|
3146
3210
|
};
|
3147
3211
|
},
|
3148
3212
|
mathmlBuilder(group, style) {
|
3149
|
-
|
3150
|
-
|
3151
|
-
label.setAttribute("width", "0");
|
3152
|
-
if (group.side === "left") {
|
3153
|
-
label.setAttribute("lspace", "-1width");
|
3213
|
+
if (group.label.body.length === 0) {
|
3214
|
+
return new mathMLTree.MathNode("mrow", style) // empty label
|
3154
3215
|
}
|
3155
|
-
//
|
3156
|
-
|
3157
|
-
|
3158
|
-
|
3216
|
+
// Abuse an <mtable> to create vertically centered content.
|
3217
|
+
const mtd = new mathMLTree.MathNode("mtd", [buildGroup$1(group.label, style)]);
|
3218
|
+
mtd.style.padding = "0";
|
3219
|
+
const mtr = new mathMLTree.MathNode("mtr", [mtd]);
|
3220
|
+
const mtable = new mathMLTree.MathNode("mtable", [mtr]);
|
3221
|
+
const label = new mathMLTree.MathNode("mpadded", [mtable]);
|
3222
|
+
// Set the label width to zero so that the arrow will be centered under the corner cell.
|
3223
|
+
label.setAttribute("width", "0");
|
3159
3224
|
label.setAttribute("displaystyle", "false");
|
3160
3225
|
label.setAttribute("scriptlevel", "1");
|
3226
|
+
if (group.side === "left") {
|
3227
|
+
label.style.display = "flex";
|
3228
|
+
label.style.justifyContent = "flex-end";
|
3229
|
+
}
|
3161
3230
|
return label;
|
3162
3231
|
}
|
3163
3232
|
});
|
@@ -3747,10 +3816,13 @@ var temml = (function () {
|
|
3747
3816
|
// replacement text, enclosed in '{' and '}' and properly nested
|
3748
3817
|
const { tokens } = parser.gullet.consumeArg();
|
3749
3818
|
|
3750
|
-
parser.gullet.macros.
|
3751
|
-
|
3752
|
-
|
3753
|
-
|
3819
|
+
if (!(funcName === "\\providecommand" && parser.gullet.macros.has(name))) {
|
3820
|
+
// Ignore \providecommand
|
3821
|
+
parser.gullet.macros.set(
|
3822
|
+
name,
|
3823
|
+
{ tokens, numArgs }
|
3824
|
+
);
|
3825
|
+
}
|
3754
3826
|
|
3755
3827
|
return { type: "internal", mode: parser.mode };
|
3756
3828
|
|
@@ -3844,6 +3916,7 @@ var temml = (function () {
|
|
3844
3916
|
"\\vert",
|
3845
3917
|
"\\|",
|
3846
3918
|
"\\Vert",
|
3919
|
+
"\u2016",
|
3847
3920
|
"\\uparrow",
|
3848
3921
|
"\\Uparrow",
|
3849
3922
|
"\\downarrow",
|
@@ -6162,6 +6235,7 @@ var temml = (function () {
|
|
6162
6235
|
"\\mathfrak",
|
6163
6236
|
"\\mathscr",
|
6164
6237
|
"\\mathsf",
|
6238
|
+
"\\mathsfit",
|
6165
6239
|
"\\mathtt",
|
6166
6240
|
|
6167
6241
|
// aliases
|
@@ -6231,10 +6305,19 @@ var temml = (function () {
|
|
6231
6305
|
? style.withLevel(StyleLevel.SCRIPT)
|
6232
6306
|
: style.withLevel(StyleLevel.SCRIPTSCRIPT);
|
6233
6307
|
|
6234
|
-
|
6235
|
-
|
6236
|
-
|
6237
|
-
|
6308
|
+
// Chromium (wrongly) continues to shrink fractions beyond scriptscriptlevel.
|
6309
|
+
// So we check for levels that Chromium shrinks too small.
|
6310
|
+
// If necessary, set an explicit fraction depth.
|
6311
|
+
const numer = buildGroup$1(group.numer, childOptions);
|
6312
|
+
const denom = buildGroup$1(group.denom, childOptions);
|
6313
|
+
if (style.level === 3) {
|
6314
|
+
numer.style.mathDepth = "2";
|
6315
|
+
numer.setAttribute("scriptlevel", "2");
|
6316
|
+
denom.style.mathDepth = "2";
|
6317
|
+
denom.setAttribute("scriptlevel", "2");
|
6318
|
+
}
|
6319
|
+
|
6320
|
+
let node = new mathMLTree.MathNode("mfrac", [numer, denom]);
|
6238
6321
|
|
6239
6322
|
if (!group.hasBarLine) {
|
6240
6323
|
node.setAttribute("linethickness", "0px");
|
@@ -6627,12 +6710,9 @@ var temml = (function () {
|
|
6627
6710
|
};
|
6628
6711
|
},
|
6629
6712
|
mathmlBuilder: (group, style) => {
|
6630
|
-
|
6631
|
-
|
6632
|
-
|
6633
|
-
}
|
6634
|
-
math.setAttribute("href", group.href);
|
6635
|
-
return math;
|
6713
|
+
const math = new MathNode("math", [buildExpressionRow(group.body, style)]);
|
6714
|
+
const anchorNode = new AnchorNode(group.href, [], [math]);
|
6715
|
+
return anchorNode
|
6636
6716
|
}
|
6637
6717
|
});
|
6638
6718
|
|
@@ -7504,13 +7584,6 @@ var temml = (function () {
|
|
7504
7584
|
node = new MathNode("mo", [makeText(group.name, group.mode)]);
|
7505
7585
|
if (noSuccessor.includes(group.name)) {
|
7506
7586
|
node.setAttribute("largeop", "false");
|
7507
|
-
} else if (group.limits) {
|
7508
|
-
// This is a workaround for a MathML/Chromium bug.
|
7509
|
-
// This is being applied to singleCharBigOps, which are not really stretchy.
|
7510
|
-
// But by setting the stretchy attribute, Chromium will vertically center
|
7511
|
-
// big ops around the math axis. This is needed since STIX TWO does not do so.
|
7512
|
-
// TODO: Remove this hack when MathML & Chromium fix their problem.
|
7513
|
-
node.setAttribute("stretchy", "true");
|
7514
7587
|
} else {
|
7515
7588
|
node.setAttribute("movablelimits", "false");
|
7516
7589
|
}
|
@@ -8145,12 +8218,10 @@ var temml = (function () {
|
|
8145
8218
|
};
|
8146
8219
|
},
|
8147
8220
|
mathmlBuilder(group, style) {
|
8148
|
-
// Create an empty
|
8221
|
+
// Create an empty <a> node. Set a class and an href attribute.
|
8149
8222
|
// The post-processor will populate with the target's tag or equation number.
|
8150
8223
|
const classes = group.funcName === "\\ref" ? ["tml-ref"] : ["tml-ref", "tml-eqref"];
|
8151
|
-
|
8152
|
-
node.setAttribute("href", "#" + group.string);
|
8153
|
-
return node
|
8224
|
+
return new AnchorNode("#" + group.string, classes, null)
|
8154
8225
|
}
|
8155
8226
|
});
|
8156
8227
|
|
@@ -8197,6 +8268,8 @@ var temml = (function () {
|
|
8197
8268
|
props: {
|
8198
8269
|
numArgs: 2,
|
8199
8270
|
numOptionalArgs: 1,
|
8271
|
+
allowedInText: true,
|
8272
|
+
allowedInMath: true,
|
8200
8273
|
argTypes: ["size", "size", "size"]
|
8201
8274
|
},
|
8202
8275
|
handler({ parser }, args, optArgs) {
|
@@ -8489,16 +8562,25 @@ var temml = (function () {
|
|
8489
8562
|
? [buildGroup$1(group.base.body[0], style)]
|
8490
8563
|
: [buildGroup$1(group.base, style)];
|
8491
8564
|
|
8565
|
+
// Note regarding scriptstyle level.
|
8566
|
+
// (Sub|super)scripts should not shrink beyond MathML scriptlevel 2 aka \scriptscriptstyle
|
8567
|
+
// Ref: https://w3c.github.io/mathml-core/#the-displaystyle-and-scriptlevel-attributes
|
8568
|
+
// (BTW, MathML scriptlevel 2 is equal to Temml level 3.)
|
8569
|
+
// But Chromium continues to shrink the (sub|super)scripts. So we explicitly set scriptlevel 2.
|
8570
|
+
|
8492
8571
|
const childStyle = style.inSubOrSup();
|
8493
8572
|
if (group.sub) {
|
8494
|
-
|
8573
|
+
const sub = buildGroup$1(group.sub, childStyle);
|
8574
|
+
if (style.level === 3) { sub.setAttribute("scriptlevel", "2"); }
|
8575
|
+
children.push(sub);
|
8495
8576
|
}
|
8496
8577
|
|
8497
8578
|
if (group.sup) {
|
8498
8579
|
const sup = buildGroup$1(group.sup, childStyle);
|
8580
|
+
if (style.level === 3) { sup.setAttribute("scriptlevel", "2"); }
|
8499
8581
|
const testNode = sup.type === "mrow" ? sup.children[0] : sup;
|
8500
8582
|
if ((testNode && testNode.type === "mo" && testNode.classes.includes("tml-prime"))
|
8501
|
-
&& group.base && group.base.text && group.base.text
|
8583
|
+
&& group.base && group.base.text && "fF".indexOf(group.base.text) > -1) {
|
8502
8584
|
// Chromium does not address italic correction on prime. Prevent f′ from overlapping.
|
8503
8585
|
testNode.classes.push("prime-pad");
|
8504
8586
|
}
|
@@ -8725,6 +8807,8 @@ var temml = (function () {
|
|
8725
8807
|
return "script"
|
8726
8808
|
case "mathsf":
|
8727
8809
|
return "sans-serif"
|
8810
|
+
case "mathsfit":
|
8811
|
+
return "sans-serif-italic"
|
8728
8812
|
case "mathtt":
|
8729
8813
|
return "monospace"
|
8730
8814
|
}
|
@@ -9189,6 +9273,32 @@ var temml = (function () {
|
|
9189
9273
|
}
|
9190
9274
|
});
|
9191
9275
|
|
9276
|
+
// \vcenter: Vertically center the argument group on the math axis.
|
9277
|
+
|
9278
|
+
defineFunction({
|
9279
|
+
type: "vcenter",
|
9280
|
+
names: ["\\vcenter"],
|
9281
|
+
props: {
|
9282
|
+
numArgs: 1,
|
9283
|
+
argTypes: ["original"],
|
9284
|
+
allowedInText: false
|
9285
|
+
},
|
9286
|
+
handler({ parser }, args) {
|
9287
|
+
return {
|
9288
|
+
type: "vcenter",
|
9289
|
+
mode: parser.mode,
|
9290
|
+
body: args[0]
|
9291
|
+
};
|
9292
|
+
},
|
9293
|
+
mathmlBuilder(group, style) {
|
9294
|
+
// Use a math table to create vertically centered content.
|
9295
|
+
const mtd = new mathMLTree.MathNode("mtd", [buildGroup$1(group.body, style)]);
|
9296
|
+
mtd.style.padding = "0";
|
9297
|
+
const mtr = new mathMLTree.MathNode("mtr", [mtd]);
|
9298
|
+
return new mathMLTree.MathNode("mtable", [mtr])
|
9299
|
+
}
|
9300
|
+
});
|
9301
|
+
|
9192
9302
|
defineFunction({
|
9193
9303
|
type: "verb",
|
9194
9304
|
names: ["\\verb"],
|
@@ -11455,9 +11565,11 @@ var temml = (function () {
|
|
11455
11565
|
constructor(data) {
|
11456
11566
|
// Style.level can be 0 | 1 | 2 | 3, which correspond to
|
11457
11567
|
// displaystyle, textstyle, scriptstyle, and scriptscriptstyle.
|
11458
|
-
// style.level does not directly set MathML's script level. MathML does that itself.
|
11459
|
-
//
|
11460
|
-
//
|
11568
|
+
// style.level usually does not directly set MathML's script level. MathML does that itself.
|
11569
|
+
// However, Chromium does not stop shrinking after scriptscriptstyle, so we do explicitly
|
11570
|
+
// set a scriptlevel attribute in those conditions.
|
11571
|
+
// We also use style.level to track math style so that we can get the correct
|
11572
|
+
// scriptlevel when needed in supsub.js, mathchoice.js, or for dimensions in em.
|
11461
11573
|
this.level = data.level;
|
11462
11574
|
this.color = data.color; // string | void
|
11463
11575
|
// A font family applies to a group of fonts (i.e. SansSerif), while a font
|
@@ -11581,39 +11693,47 @@ var temml = (function () {
|
|
11581
11693
|
}
|
11582
11694
|
|
11583
11695
|
/* Temml Post Process
|
11584
|
-
*
|
11585
|
-
* Given a block,
|
11586
|
-
* 1. At each AMS auto-numbered environment, assign an id.
|
11587
|
-
* 2. Populate the text contents of each \ref & \eqref
|
11696
|
+
* Populate the text contents of each \ref & \eqref
|
11588
11697
|
*
|
11589
11698
|
* As with other Temml code, this file is released under terms of the MIT license.
|
11590
11699
|
* https://mit-license.org/
|
11591
11700
|
*/
|
11592
11701
|
|
11593
|
-
const version = "0.10.
|
11702
|
+
const version = "0.10.33";
|
11594
11703
|
|
11595
11704
|
function postProcess(block) {
|
11596
11705
|
const labelMap = {};
|
11597
11706
|
let i = 0;
|
11598
11707
|
|
11599
11708
|
// Get a collection of the parents of each \tag & auto-numbered equation
|
11600
|
-
const
|
11601
|
-
for (
|
11602
|
-
|
11603
|
-
|
11604
|
-
|
11605
|
-
|
11606
|
-
|
11607
|
-
|
11608
|
-
|
11609
|
-
|
11709
|
+
const amsEqns = document.getElementsByClassName('tml-eqn');
|
11710
|
+
for (let parent of amsEqns) {
|
11711
|
+
// AMS automatically numbered equation.
|
11712
|
+
// Assign an id.
|
11713
|
+
i += 1;
|
11714
|
+
parent.setAttribute("id", "tml-eqn-" + String(i));
|
11715
|
+
// No need to write a number into the text content of the element.
|
11716
|
+
// A CSS counter has done that even if this postProcess() function is not used.
|
11717
|
+
|
11718
|
+
// Find any \label that refers to an AMS eqn number.
|
11719
|
+
while (true) {
|
11720
|
+
const labels = parent.getElementsByClassName("tml-label");
|
11721
|
+
if (labels.length > 0) {
|
11722
|
+
parent.setAttribute("id", labels[0].id);
|
11723
|
+
labelMap[labels[0].id] = String(i);
|
11724
|
+
break
|
11725
|
+
} else {
|
11726
|
+
if (parent.tagName === "mtable") { break }
|
11727
|
+
parent = parent.parentElement;
|
11728
|
+
}
|
11610
11729
|
}
|
11611
|
-
|
11730
|
+
}
|
11731
|
+
|
11732
|
+
// Find \labels associated with \tag
|
11733
|
+
const taggedEqns = document.getElementsByClassName('tml-tageqn');
|
11734
|
+
for (const parent of taggedEqns) {
|
11612
11735
|
const labels = parent.getElementsByClassName("tml-label");
|
11613
|
-
if (labels.length
|
11614
|
-
if (eqns.length > 0) {
|
11615
|
-
labelMap[labels[0].id] = String(i);
|
11616
|
-
} else {
|
11736
|
+
if (labels.length > 0) {
|
11617
11737
|
const tags = parent.getElementsByClassName("tml-tag");
|
11618
11738
|
if (tags.length > 0) {
|
11619
11739
|
labelMap[labels[0].id] = tags[0].textContent;
|
@@ -11624,17 +11744,22 @@ var temml = (function () {
|
|
11624
11744
|
// Populate \ref & \eqref text content
|
11625
11745
|
const refs = block.getElementsByClassName("tml-ref");
|
11626
11746
|
[...refs].forEach(ref => {
|
11627
|
-
|
11747
|
+
const attr = ref.getAttribute("href");
|
11748
|
+
let str = labelMap[attr.slice(1)];
|
11628
11749
|
if (ref.className.indexOf("tml-eqref") === -1) {
|
11629
11750
|
// \ref. Omit parens.
|
11630
11751
|
str = str.replace(/^\(/, "");
|
11631
|
-
str = str.replace(/\
|
11632
|
-
}
|
11752
|
+
str = str.replace(/\)$/, "");
|
11753
|
+
} else {
|
11633
11754
|
// \eqref. Include parens
|
11634
11755
|
if (str.charAt(0) !== "(") { str = "(" + str; }
|
11635
11756
|
if (str.slice(-1) !== ")") { str = str + ")"; }
|
11636
11757
|
}
|
11637
|
-
|
11758
|
+
const mtext = document.createElementNS("http://www.w3.org/1998/Math/MathML", "mtext");
|
11759
|
+
mtext.appendChild(document.createTextNode(str));
|
11760
|
+
const math = document.createElementNS("http://www.w3.org/1998/Math/MathML", "math");
|
11761
|
+
math.appendChild(mtext);
|
11762
|
+
ref.appendChild(math);
|
11638
11763
|
});
|
11639
11764
|
}
|
11640
11765
|
|