temml 0.10.33 → 0.11.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.
- 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 +495 -163
- package/dist/temml.d.ts +3 -0
- package/dist/temml.js +495 -163
- package/dist/temml.min.js +1 -1
- package/dist/temml.mjs +495 -163
- package/dist/temmlPostProcess.js +7 -6
- package/package.json +2 -2
- package/src/auto-render.js +263 -0
- package/src/buildMathML.js +20 -0
- package/src/environments/array.js +119 -82
- package/src/environments/cd.js +2 -0
- package/src/functions/label.js +1 -1
- package/src/linebreaking.js +1 -1
- package/src/macros.js +3 -1
- package/src/mathMLTree.js +5 -0
- package/src/postProcess.js +7 -6
- package/src/symbols.js +1 -1
- package/temml.js +6 -0
- package/contrib/auto-render/README.md +0 -89
- package/contrib/auto-render/auto-render.js +0 -128
- package/contrib/auto-render/dist/auto-render.js +0 -214
- package/contrib/auto-render/dist/auto-render.min.js +0 -1
- package/contrib/auto-render/splitAtDelimiters.js +0 -84
- package/contrib/auto-render/test/auto-render-spec.js +0 -234
- package/contrib/auto-render/test/auto-render.js +0 -214
- package/contrib/auto-render/test/test_page.html +0 -59
package/dist/temml.mjs
CHANGED
@@ -607,6 +607,7 @@ class MathNode {
|
|
607
607
|
this.children = children || [];
|
608
608
|
this.classes = classes || [];
|
609
609
|
this.style = style || {}; // Used for <mstyle> elements
|
610
|
+
this.label = "";
|
610
611
|
}
|
611
612
|
|
612
613
|
/**
|
@@ -624,6 +625,10 @@ class MathNode {
|
|
624
625
|
return this.attributes[name];
|
625
626
|
}
|
626
627
|
|
628
|
+
setLabel(value) {
|
629
|
+
this.label = value;
|
630
|
+
}
|
631
|
+
|
627
632
|
/**
|
628
633
|
* Converts the math node into a MathML-namespaced DOM element.
|
629
634
|
*/
|
@@ -1540,7 +1545,7 @@ defineSymbol(math, mathord, "\u03db", "\\stigma", true);
|
|
1540
1545
|
defineSymbol(math, mathord, "\u2aeb", "\\Bot");
|
1541
1546
|
defineSymbol(math, bin, "\u2217", "\u2217", true);
|
1542
1547
|
defineSymbol(math, bin, "+", "+");
|
1543
|
-
defineSymbol(math, bin, "
|
1548
|
+
defineSymbol(math, bin, "\u2217", "*");
|
1544
1549
|
defineSymbol(math, bin, "\u2044", "/", true);
|
1545
1550
|
defineSymbol(math, bin, "\u2044", "\u2044");
|
1546
1551
|
defineSymbol(math, bin, "\u2212", "-", true);
|
@@ -2003,7 +2008,7 @@ function setLineBreaks(expression, wrapMode, isDisplayMode) {
|
|
2003
2008
|
}
|
2004
2009
|
block.push(node);
|
2005
2010
|
if (node.type && node.type === "mo" && node.children.length === 1 &&
|
2006
|
-
!Object.
|
2011
|
+
!Object.prototype.hasOwnProperty.call(node.attributes, "movablelimits")) {
|
2007
2012
|
const ch = node.children[0].text;
|
2008
2013
|
if (openDelims.indexOf(ch) > -1) {
|
2009
2014
|
level += 1;
|
@@ -2339,16 +2344,36 @@ const glue$1 = _ => {
|
|
2339
2344
|
return new mathMLTree.MathNode("mtd", [], [], { padding: "0", width: "50%" })
|
2340
2345
|
};
|
2341
2346
|
|
2347
|
+
const labelContainers = ["mrow", "mtd", "mtable", "mtr"];
|
2348
|
+
const getLabel = parent => {
|
2349
|
+
for (const node of parent.children) {
|
2350
|
+
if (node.type && labelContainers.includes(node.type)) {
|
2351
|
+
if (node.classes && node.classes[0] === "tml-label") {
|
2352
|
+
const label = node.label;
|
2353
|
+
return label
|
2354
|
+
} else {
|
2355
|
+
const label = getLabel(node);
|
2356
|
+
if (label) { return label }
|
2357
|
+
}
|
2358
|
+
} else if (!node.type) {
|
2359
|
+
const label = getLabel(node);
|
2360
|
+
if (label) { return label }
|
2361
|
+
}
|
2362
|
+
}
|
2363
|
+
};
|
2364
|
+
|
2342
2365
|
const taggedExpression = (expression, tag, style, leqno) => {
|
2343
2366
|
tag = buildExpressionRow(tag[0].body, style);
|
2344
2367
|
tag = consolidateText(tag);
|
2345
2368
|
tag.classes.push("tml-tag");
|
2346
2369
|
|
2370
|
+
const label = getLabel(expression); // from a \label{} function.
|
2347
2371
|
expression = new mathMLTree.MathNode("mtd", [expression]);
|
2348
2372
|
const rowArray = [glue$1(), expression, glue$1()];
|
2349
2373
|
rowArray[leqno ? 0 : 2].classes.push(leqno ? "tml-left" : "tml-right");
|
2350
2374
|
rowArray[leqno ? 0 : 2].children.push(tag);
|
2351
2375
|
const mtr = new mathMLTree.MathNode("mtr", rowArray, ["tml-tageqn"]);
|
2376
|
+
if (label) { mtr.setAttribute("id", label); }
|
2352
2377
|
const table = new mathMLTree.MathNode("mtable", [mtr]);
|
2353
2378
|
table.style.width = "100%";
|
2354
2379
|
table.setAttribute("displaystyle", "true");
|
@@ -3179,6 +3204,8 @@ function parseCD(parser) {
|
|
3179
3204
|
type: "array",
|
3180
3205
|
mode: "math",
|
3181
3206
|
body,
|
3207
|
+
tags: null,
|
3208
|
+
labels: new Array(body.length + 1).fill(""),
|
3182
3209
|
envClasses: ["jot", "cd"],
|
3183
3210
|
cols: [],
|
3184
3211
|
hLinesBeforeRow: new Array(body.length + 1).fill([])
|
@@ -4419,6 +4446,75 @@ function defineEnvironment({ type, names, props, handler, mathmlBuilder }) {
|
|
4419
4446
|
}
|
4420
4447
|
}
|
4421
4448
|
|
4449
|
+
/**
|
4450
|
+
* Lexing or parsing positional information for error reporting.
|
4451
|
+
* This object is immutable.
|
4452
|
+
*/
|
4453
|
+
class SourceLocation {
|
4454
|
+
constructor(lexer, start, end) {
|
4455
|
+
this.lexer = lexer; // Lexer holding the input string.
|
4456
|
+
this.start = start; // Start offset, zero-based inclusive.
|
4457
|
+
this.end = end; // End offset, zero-based exclusive.
|
4458
|
+
}
|
4459
|
+
|
4460
|
+
/**
|
4461
|
+
* Merges two `SourceLocation`s from location providers, given they are
|
4462
|
+
* provided in order of appearance.
|
4463
|
+
* - Returns the first one's location if only the first is provided.
|
4464
|
+
* - Returns a merged range of the first and the last if both are provided
|
4465
|
+
* and their lexers match.
|
4466
|
+
* - Otherwise, returns null.
|
4467
|
+
*/
|
4468
|
+
static range(first, second) {
|
4469
|
+
if (!second) {
|
4470
|
+
return first && first.loc;
|
4471
|
+
} else if (!first || !first.loc || !second.loc || first.loc.lexer !== second.loc.lexer) {
|
4472
|
+
return null;
|
4473
|
+
} else {
|
4474
|
+
return new SourceLocation(first.loc.lexer, first.loc.start, second.loc.end);
|
4475
|
+
}
|
4476
|
+
}
|
4477
|
+
}
|
4478
|
+
|
4479
|
+
/**
|
4480
|
+
* Interface required to break circular dependency between Token, Lexer, and
|
4481
|
+
* ParseError.
|
4482
|
+
*/
|
4483
|
+
|
4484
|
+
/**
|
4485
|
+
* The resulting token returned from `lex`.
|
4486
|
+
*
|
4487
|
+
* It consists of the token text plus some position information.
|
4488
|
+
* The position information is essentially a range in an input string,
|
4489
|
+
* but instead of referencing the bare input string, we refer to the lexer.
|
4490
|
+
* That way it is possible to attach extra metadata to the input string,
|
4491
|
+
* like for example a file name or similar.
|
4492
|
+
*
|
4493
|
+
* The position information is optional, so it is OK to construct synthetic
|
4494
|
+
* tokens if appropriate. Not providing available position information may
|
4495
|
+
* lead to degraded error reporting, though.
|
4496
|
+
*/
|
4497
|
+
class Token {
|
4498
|
+
constructor(
|
4499
|
+
text, // the text of this token
|
4500
|
+
loc
|
4501
|
+
) {
|
4502
|
+
this.text = text;
|
4503
|
+
this.loc = loc;
|
4504
|
+
}
|
4505
|
+
|
4506
|
+
/**
|
4507
|
+
* Given a pair of tokens (this and endToken), compute a `Token` encompassing
|
4508
|
+
* the whole input range enclosed by these two.
|
4509
|
+
*/
|
4510
|
+
range(
|
4511
|
+
endToken, // last token of the range, inclusive
|
4512
|
+
text // the text of the newly constructed token
|
4513
|
+
) {
|
4514
|
+
return new Token(text, SourceLocation.range(this, endToken));
|
4515
|
+
}
|
4516
|
+
}
|
4517
|
+
|
4422
4518
|
// In TeX, there are actually three sets of dimensions, one for each of
|
4423
4519
|
// textstyle, scriptstyle, and scriptscriptstyle. These are
|
4424
4520
|
// provided in the the arrays below, in that order.
|
@@ -4903,8 +4999,10 @@ defineMacro("\\tag@literal", (context) => {
|
|
4903
4999
|
if (context.macros.get("\\df@tag")) {
|
4904
5000
|
throw new ParseError("Multiple \\tag");
|
4905
5001
|
}
|
4906
|
-
return "\\
|
5002
|
+
return "\\gdef\\df@tag{\\text{#1}}";
|
4907
5003
|
});
|
5004
|
+
defineMacro("\\notag", "\\nonumber");
|
5005
|
+
defineMacro("\\nonumber", "\\gdef\\@eqnsw{0}");
|
4908
5006
|
|
4909
5007
|
// \renewcommand{\bmod}{\nonscript\mskip-\medmuskip\mkern5mu\mathbin
|
4910
5008
|
// {\operator@font mod}\penalty900
|
@@ -7108,33 +7206,30 @@ const arrayGaps = macros => {
|
|
7108
7206
|
return [arraystretch, arraycolsep]
|
7109
7207
|
};
|
7110
7208
|
|
7111
|
-
const
|
7112
|
-
|
7113
|
-
|
7114
|
-
|
7115
|
-
|
7116
|
-
|
7117
|
-
|
7118
|
-
|
7119
|
-
} else {
|
7120
|
-
// \notag. Return an empty span.
|
7121
|
-
tag = new mathMLTree.MathNode("mtext", [], []);
|
7122
|
-
return tag
|
7123
|
-
}
|
7124
|
-
} else if (group.envClasses.includes("multline") &&
|
7125
|
-
((group.leqno && rowNum !== 0) || (!group.leqno && rowNum !== group.body.length - 1))) {
|
7126
|
-
// A multiline that does not receive a tag. Return an empty cell.
|
7127
|
-
tag = new mathMLTree.MathNode("mtext", [], []);
|
7128
|
-
return tag
|
7129
|
-
} else {
|
7130
|
-
// AMS automatcally numbered equaton.
|
7131
|
-
// Insert a class so the element can be populated by a CSS counter.
|
7132
|
-
// WebKit will display the CSS counter only inside a span.
|
7133
|
-
tag = new mathMLTree.MathNode("mtext", [new Span(["tml-eqn"])]);
|
7209
|
+
const checkCellForLabels = cell => {
|
7210
|
+
// Check if the author wrote a \tag{} inside this cell.
|
7211
|
+
let rowLabel = "";
|
7212
|
+
for (let i = 0; i < cell.length; i++) {
|
7213
|
+
if (cell[i].type === "label") {
|
7214
|
+
if (rowLabel) { throw new ParseError(("Multiple \\labels in one row")) }
|
7215
|
+
rowLabel = cell[i].string;
|
7216
|
+
}
|
7134
7217
|
}
|
7135
|
-
return
|
7218
|
+
return rowLabel
|
7136
7219
|
};
|
7137
7220
|
|
7221
|
+
// autoTag (an argument to parseArray) can be one of three values:
|
7222
|
+
// * undefined: Regular (not-top-level) array; no tags on each row
|
7223
|
+
// * true: Automatic equation numbering, overridable by \tag
|
7224
|
+
// * false: Tags allowed on each row, but no automatic numbering
|
7225
|
+
// This function *doesn't* work with the "split" environment name.
|
7226
|
+
function getAutoTag(name) {
|
7227
|
+
if (name.indexOf("ed") === -1) {
|
7228
|
+
return name.indexOf("*") === -1;
|
7229
|
+
}
|
7230
|
+
// return undefined;
|
7231
|
+
}
|
7232
|
+
|
7138
7233
|
/**
|
7139
7234
|
* Parse the body of the environment, with rows delimited by \\ and
|
7140
7235
|
* columns delimited by &, and create a nested list in row-major order
|
@@ -7146,7 +7241,7 @@ function parseArray(
|
|
7146
7241
|
{
|
7147
7242
|
cols, // [{ type: string , align: l|c|r|null }]
|
7148
7243
|
envClasses, // align(ed|at|edat) | array | cases | cd | small | multline
|
7149
|
-
|
7244
|
+
autoTag, // boolean
|
7150
7245
|
singleRow, // boolean
|
7151
7246
|
emptySingleRow, // boolean
|
7152
7247
|
maxNumCols, // number
|
@@ -7162,13 +7257,6 @@ function parseArray(
|
|
7162
7257
|
// TODO: provide helpful error when \cr is used outside array environment
|
7163
7258
|
parser.gullet.macros.set("\\cr", "\\\\\\relax");
|
7164
7259
|
}
|
7165
|
-
if (addEqnNum) {
|
7166
|
-
parser.gullet.macros.set("\\tag", "\\@ifstar\\envtag@literal\\envtag@paren");
|
7167
|
-
parser.gullet.macros.set("\\envtag@paren", "\\env@tag{{(\\text{#1})}}");
|
7168
|
-
parser.gullet.macros.set("\\envtag@literal", "\\env@tag{\\text{#1}}");
|
7169
|
-
parser.gullet.macros.set("\\notag", "\\env@notag");
|
7170
|
-
parser.gullet.macros.set("\\nonumber", "\\env@notag");
|
7171
|
-
}
|
7172
7260
|
|
7173
7261
|
// Start group for first cell
|
7174
7262
|
parser.gullet.beginGroup();
|
@@ -7176,29 +7264,39 @@ function parseArray(
|
|
7176
7264
|
let row = [];
|
7177
7265
|
const body = [row];
|
7178
7266
|
const rowGaps = [];
|
7179
|
-
const
|
7180
|
-
|
7267
|
+
const labels = [];
|
7268
|
+
|
7181
7269
|
const hLinesBeforeRow = [];
|
7182
7270
|
|
7271
|
+
const tags = (autoTag != null ? [] : undefined);
|
7272
|
+
|
7273
|
+
// amsmath uses \global\@eqnswtrue and \global\@eqnswfalse to represent
|
7274
|
+
// whether this row should have an equation number. Simulate this with
|
7275
|
+
// a \@eqnsw macro set to 1 or 0.
|
7276
|
+
function beginRow() {
|
7277
|
+
if (autoTag) {
|
7278
|
+
parser.gullet.macros.set("\\@eqnsw", "1", true);
|
7279
|
+
}
|
7280
|
+
}
|
7281
|
+
function endRow() {
|
7282
|
+
if (tags) {
|
7283
|
+
if (parser.gullet.macros.get("\\df@tag")) {
|
7284
|
+
tags.push(parser.subparse([new Token("\\df@tag")]));
|
7285
|
+
parser.gullet.macros.set("\\df@tag", undefined, true);
|
7286
|
+
} else {
|
7287
|
+
tags.push(Boolean(autoTag) &&
|
7288
|
+
parser.gullet.macros.get("\\@eqnsw") === "1");
|
7289
|
+
}
|
7290
|
+
}
|
7291
|
+
}
|
7292
|
+
beginRow();
|
7293
|
+
|
7183
7294
|
// Test for \hline at the top of the array.
|
7184
7295
|
hLinesBeforeRow.push(getHLines(parser));
|
7185
7296
|
|
7186
7297
|
while (true) {
|
7187
7298
|
// Parse each cell in its own group (namespace)
|
7188
7299
|
let cell = parser.parseExpression(false, singleRow ? "\\end" : "\\\\");
|
7189
|
-
|
7190
|
-
if (addEqnNum && !rowTag) {
|
7191
|
-
// Check if the author wrote a \tag{} inside this cell.
|
7192
|
-
for (let i = 0; i < cell.length; i++) {
|
7193
|
-
if (cell[i].type === "envTag" || cell[i].type === "noTag") {
|
7194
|
-
// Get the contents of the \text{} nested inside the \env@Tag{}
|
7195
|
-
rowTag = cell[i].type === "envTag"
|
7196
|
-
? cell.splice(i, 1)[0].body.body[0]
|
7197
|
-
: { body: null };
|
7198
|
-
break
|
7199
|
-
}
|
7200
|
-
}
|
7201
|
-
}
|
7202
7300
|
parser.gullet.endGroup();
|
7203
7301
|
parser.gullet.beginGroup();
|
7204
7302
|
|
@@ -7227,6 +7325,7 @@ function parseArray(
|
|
7227
7325
|
}
|
7228
7326
|
parser.consume();
|
7229
7327
|
} else if (next === "\\end") {
|
7328
|
+
endRow();
|
7230
7329
|
// Arrays terminate newlines with `\crcr` which consumes a `\cr` if
|
7231
7330
|
// the last line is empty. However, AMS environments keep the
|
7232
7331
|
// empty row if it's the only one.
|
@@ -7234,6 +7333,7 @@ function parseArray(
|
|
7234
7333
|
if (row.length === 1 && cell.body.length === 0 && (body.length > 1 || !emptySingleRow)) {
|
7235
7334
|
body.pop();
|
7236
7335
|
}
|
7336
|
+
labels.push(checkCellForLabels(cell.body));
|
7237
7337
|
if (hLinesBeforeRow.length < body.length + 1) {
|
7238
7338
|
hLinesBeforeRow.push([]);
|
7239
7339
|
}
|
@@ -7250,15 +7350,16 @@ function parseArray(
|
|
7250
7350
|
size = parser.parseSizeGroup(true);
|
7251
7351
|
}
|
7252
7352
|
rowGaps.push(size ? size.value : null);
|
7353
|
+
endRow();
|
7253
7354
|
|
7254
|
-
|
7355
|
+
labels.push(checkCellForLabels(cell.body));
|
7255
7356
|
|
7256
7357
|
// check for \hline(s) following the row separator
|
7257
7358
|
hLinesBeforeRow.push(getHLines(parser));
|
7258
7359
|
|
7259
7360
|
row = [];
|
7260
|
-
rowTag = null;
|
7261
7361
|
body.push(row);
|
7362
|
+
beginRow();
|
7262
7363
|
} else {
|
7263
7364
|
throw new ParseError("Expected & or \\\\ or \\cr or \\end", parser.nextToken);
|
7264
7365
|
}
|
@@ -7269,8 +7370,6 @@ function parseArray(
|
|
7269
7370
|
// End array group defining \cr
|
7270
7371
|
parser.gullet.endGroup();
|
7271
7372
|
|
7272
|
-
tags.push(rowTag);
|
7273
|
-
|
7274
7373
|
return {
|
7275
7374
|
type: "array",
|
7276
7375
|
mode: parser.mode,
|
@@ -7279,9 +7378,10 @@ function parseArray(
|
|
7279
7378
|
rowGaps,
|
7280
7379
|
hLinesBeforeRow,
|
7281
7380
|
envClasses,
|
7282
|
-
|
7381
|
+
autoTag,
|
7283
7382
|
scriptLevel,
|
7284
7383
|
tags,
|
7384
|
+
labels,
|
7285
7385
|
leqno,
|
7286
7386
|
arraystretch,
|
7287
7387
|
arraycolsep
|
@@ -7338,19 +7438,43 @@ const mathmlBuilder$7 = function(group, style) {
|
|
7338
7438
|
}
|
7339
7439
|
row.push(mtd);
|
7340
7440
|
}
|
7341
|
-
|
7342
|
-
|
7343
|
-
|
7344
|
-
|
7345
|
-
|
7346
|
-
|
7347
|
-
|
7348
|
-
|
7349
|
-
|
7350
|
-
|
7441
|
+
const numColumns = group.body[0].length;
|
7442
|
+
// Fill out a short row with empty <mtd> elements.
|
7443
|
+
for (let k = 0; k < numColumns - rw.length; k++) {
|
7444
|
+
row.push(new mathMLTree.MathNode("mtd", [], style));
|
7445
|
+
}
|
7446
|
+
if (group.autoTag) {
|
7447
|
+
const tag = group.tags[i];
|
7448
|
+
let tagElement;
|
7449
|
+
if (tag === true) { // automatic numbering
|
7450
|
+
tagElement = new mathMLTree.MathNode("mtext", [new Span(["tml-eqn"])]);
|
7451
|
+
} else if (tag === false) {
|
7452
|
+
// \nonumber/\notag or starred environment
|
7453
|
+
tagElement = new mathMLTree.MathNode("mtext", [], []);
|
7454
|
+
} else { // manual \tag
|
7455
|
+
tagElement = buildExpressionRow(tag[0].body, style.withLevel(cellLevel), true);
|
7456
|
+
tagElement = consolidateText(tagElement);
|
7457
|
+
tagElement.classes = ["tml-tag"];
|
7458
|
+
}
|
7459
|
+
if (tagElement) {
|
7460
|
+
row.unshift(glue(group));
|
7461
|
+
row.push(glue(group));
|
7462
|
+
if (group.leqno) {
|
7463
|
+
row[0].children.push(tagElement);
|
7464
|
+
row[0].classes.push("tml-left");
|
7465
|
+
} else {
|
7466
|
+
row[row.length - 1].children.push(tagElement);
|
7467
|
+
row[row.length - 1].classes.push("tml-right");
|
7468
|
+
}
|
7351
7469
|
}
|
7352
7470
|
}
|
7353
7471
|
const mtr = new mathMLTree.MathNode("mtr", row, []);
|
7472
|
+
const label = group.labels.shift();
|
7473
|
+
if (label && group.tags && group.tags[i]) {
|
7474
|
+
mtr.setAttribute("id", label);
|
7475
|
+
if (Array.isArray(group.tags[i])) { mtr.classes.push("tml-tageqn"); }
|
7476
|
+
}
|
7477
|
+
|
7354
7478
|
// Write horizontal rules
|
7355
7479
|
if (i === 0 && hlines[0].length > 0) {
|
7356
7480
|
if (hlines[0].length === 2) {
|
@@ -7374,16 +7498,17 @@ const mathmlBuilder$7 = function(group, style) {
|
|
7374
7498
|
}
|
7375
7499
|
|
7376
7500
|
if (group.envClasses.length > 0) {
|
7377
|
-
let pad = group.envClasses.includes("jot")
|
7378
|
-
? "0.7" // 0.5ex + 0.09em top & bot padding
|
7379
|
-
: group.envClasses.includes("small")
|
7380
|
-
? "0.35"
|
7381
|
-
: "0.5"; // 0.5ex default top & bot padding
|
7382
7501
|
if (group.arraystretch && group.arraystretch !== 1) {
|
7383
7502
|
// In LaTeX, \arraystretch is a factor applied to a 12pt strut height.
|
7384
7503
|
// It defines a baseline to baseline distance.
|
7385
7504
|
// Here, we do an approximation of that approach.
|
7386
|
-
pad = String(1.4 * group.arraystretch - 0.8);
|
7505
|
+
const pad = String(1.4 * group.arraystretch - 0.8) + "ex";
|
7506
|
+
for (let i = 0; i < tbl.length; i++) {
|
7507
|
+
for (let j = 0; j < tbl[i].children.length; j++) {
|
7508
|
+
tbl[i].children[j].style.paddingTop = pad;
|
7509
|
+
tbl[i].children[j].style.paddingBottom = pad;
|
7510
|
+
}
|
7511
|
+
}
|
7387
7512
|
}
|
7388
7513
|
let sidePadding = group.envClasses.includes("abut")
|
7389
7514
|
? "0"
|
@@ -7397,7 +7522,7 @@ const mathmlBuilder$7 = function(group, style) {
|
|
7397
7522
|
let sidePadUnit = "em";
|
7398
7523
|
if (group.arraycolsep) {
|
7399
7524
|
const arraySidePad = calculateSize(group.arraycolsep, style);
|
7400
|
-
sidePadding = arraySidePad.number;
|
7525
|
+
sidePadding = arraySidePad.number.toFixed(4);
|
7401
7526
|
sidePadUnit = arraySidePad.unit;
|
7402
7527
|
}
|
7403
7528
|
|
@@ -7408,18 +7533,18 @@ const mathmlBuilder$7 = function(group, style) {
|
|
7408
7533
|
if (j === numCols - 1 && hand === 1) { return "0" }
|
7409
7534
|
if (group.envClasses[0] !== "align") { return sidePadding }
|
7410
7535
|
if (hand === 1) { return "0" }
|
7411
|
-
if (group.
|
7536
|
+
if (group.autoTag) {
|
7412
7537
|
return (j % 2) ? "1" : "0"
|
7413
7538
|
} else {
|
7414
7539
|
return (j % 2) ? "0" : "1"
|
7415
7540
|
}
|
7416
7541
|
};
|
7417
7542
|
|
7418
|
-
//
|
7543
|
+
// Side padding
|
7419
7544
|
for (let i = 0; i < tbl.length; i++) {
|
7420
7545
|
for (let j = 0; j < tbl[i].children.length; j++) {
|
7421
|
-
tbl[i].children[j].style.
|
7422
|
-
|
7546
|
+
tbl[i].children[j].style.paddingLeft = `${sidePad(j, 0)}${sidePadUnit}`;
|
7547
|
+
tbl[i].children[j].style.paddingRight = `${sidePad(j, 1)}${sidePadUnit}`;
|
7423
7548
|
}
|
7424
7549
|
}
|
7425
7550
|
|
@@ -7433,13 +7558,13 @@ const mathmlBuilder$7 = function(group, style) {
|
|
7433
7558
|
// TODO: Remove -webkit- when Chromium no longer needs it.
|
7434
7559
|
row.children[j].classes = ["tml-" + (j % 2 ? "left" : "right")];
|
7435
7560
|
}
|
7436
|
-
if (group.
|
7561
|
+
if (group.autoTag) {
|
7437
7562
|
const k = group.leqno ? 0 : row.children.length - 1;
|
7438
7563
|
row.children[k].classes = ["tml-" + (group.leqno ? "left" : "right")];
|
7439
7564
|
}
|
7440
7565
|
}
|
7441
7566
|
if (row.children.length > 1 && group.envClasses.includes("cases")) {
|
7442
|
-
row.children[1].style.
|
7567
|
+
row.children[1].style.paddingLeft = "1em";
|
7443
7568
|
}
|
7444
7569
|
|
7445
7570
|
if (group.envClasses.includes("cases") || group.envClasses.includes("subarray")) {
|
@@ -7459,9 +7584,17 @@ const mathmlBuilder$7 = function(group, style) {
|
|
7459
7584
|
}
|
7460
7585
|
|
7461
7586
|
let table = new mathMLTree.MathNode("mtable", tbl);
|
7587
|
+
if (group.envClasses.length > 0) {
|
7588
|
+
// Top & bottom padding
|
7589
|
+
if (group.envClasses.includes("jot")) {
|
7590
|
+
table.classes.push("tml-jot");
|
7591
|
+
} else if (group.envClasses.includes("small")) {
|
7592
|
+
table.classes.push("tml-small");
|
7593
|
+
}
|
7594
|
+
}
|
7462
7595
|
if (group.scriptLevel === "display") { table.setAttribute("displaystyle", "true"); }
|
7463
7596
|
|
7464
|
-
if (group.
|
7597
|
+
if (group.autoTag || group.envClasses.includes("multline")) {
|
7465
7598
|
table.style.width = "100%";
|
7466
7599
|
}
|
7467
7600
|
|
@@ -7491,7 +7624,7 @@ const mathmlBuilder$7 = function(group, style) {
|
|
7491
7624
|
row.children[0].style.borderLeft = sep;
|
7492
7625
|
}
|
7493
7626
|
}
|
7494
|
-
let iCol = group.
|
7627
|
+
let iCol = group.autoTag ? 0 : -1;
|
7495
7628
|
for (let i = iStart; i < iEnd; i++) {
|
7496
7629
|
if (cols[i].type === "align") {
|
7497
7630
|
const colAlign = alignMap[cols[i].align];
|
@@ -7533,7 +7666,7 @@ const mathmlBuilder$7 = function(group, style) {
|
|
7533
7666
|
}
|
7534
7667
|
}
|
7535
7668
|
}
|
7536
|
-
if (group.
|
7669
|
+
if (group.autoTag) {
|
7537
7670
|
// allow for glue cells on each side
|
7538
7671
|
align = "left " + (align.length > 0 ? align : "center ") + "right ";
|
7539
7672
|
}
|
@@ -7557,13 +7690,14 @@ const alignedHandler = function(context, args) {
|
|
7557
7690
|
if (context.envName.indexOf("ed") === -1) {
|
7558
7691
|
validateAmsEnvironmentContext(context);
|
7559
7692
|
}
|
7693
|
+
const isSplit = context.envName === "split";
|
7560
7694
|
const cols = [];
|
7561
7695
|
const res = parseArray(
|
7562
7696
|
context.parser,
|
7563
7697
|
{
|
7564
7698
|
cols,
|
7565
|
-
addEqnNum: context.envName === "align" || context.envName === "alignat",
|
7566
7699
|
emptySingleRow: true,
|
7700
|
+
autoTag: isSplit ? undefined : getAutoTag(context.envName),
|
7567
7701
|
envClasses: ["abut", "jot"], // set row spacing & provisional column spacing
|
7568
7702
|
maxNumCols: context.envName === "split" ? 2 : undefined,
|
7569
7703
|
leqno: context.parser.settings.leqno
|
@@ -7885,7 +8019,7 @@ defineEnvironment({
|
|
7885
8019
|
const res = {
|
7886
8020
|
cols: [],
|
7887
8021
|
envClasses: ["abut", "jot"],
|
7888
|
-
|
8022
|
+
autoTag: getAutoTag(context.envName),
|
7889
8023
|
emptySingleRow: true,
|
7890
8024
|
leqno: context.parser.settings.leqno
|
7891
8025
|
};
|
@@ -7903,7 +8037,7 @@ defineEnvironment({
|
|
7903
8037
|
handler(context) {
|
7904
8038
|
validateAmsEnvironmentContext(context);
|
7905
8039
|
const res = {
|
7906
|
-
|
8040
|
+
autoTag: getAutoTag(context.envName),
|
7907
8041
|
emptySingleRow: true,
|
7908
8042
|
singleRow: true,
|
7909
8043
|
maxNumCols: 1,
|
@@ -7924,7 +8058,7 @@ defineEnvironment({
|
|
7924
8058
|
handler(context) {
|
7925
8059
|
validateAmsEnvironmentContext(context);
|
7926
8060
|
const res = {
|
7927
|
-
|
8061
|
+
autoTag: context.envName === "multline",
|
7928
8062
|
maxNumCols: 1,
|
7929
8063
|
envClasses: ["jot", "multline"],
|
7930
8064
|
leqno: context.parser.settings.leqno
|
@@ -8981,7 +9115,7 @@ defineFunction({
|
|
8981
9115
|
// Return a no-width, no-ink element with an HTML id.
|
8982
9116
|
const node = new mathMLTree.MathNode("mrow", [], ["tml-label"]);
|
8983
9117
|
if (group.string.length > 0) {
|
8984
|
-
node.
|
9118
|
+
node.setLabel(group.string);
|
8985
9119
|
}
|
8986
9120
|
return node
|
8987
9121
|
}
|
@@ -11244,75 +11378,6 @@ const makeVerb = (group) => group.body.replace(/ /g, group.star ? "\u2423" : "\x
|
|
11244
11378
|
|
11245
11379
|
const functions = _functions;
|
11246
11380
|
|
11247
|
-
/**
|
11248
|
-
* Lexing or parsing positional information for error reporting.
|
11249
|
-
* This object is immutable.
|
11250
|
-
*/
|
11251
|
-
class SourceLocation {
|
11252
|
-
constructor(lexer, start, end) {
|
11253
|
-
this.lexer = lexer; // Lexer holding the input string.
|
11254
|
-
this.start = start; // Start offset, zero-based inclusive.
|
11255
|
-
this.end = end; // End offset, zero-based exclusive.
|
11256
|
-
}
|
11257
|
-
|
11258
|
-
/**
|
11259
|
-
* Merges two `SourceLocation`s from location providers, given they are
|
11260
|
-
* provided in order of appearance.
|
11261
|
-
* - Returns the first one's location if only the first is provided.
|
11262
|
-
* - Returns a merged range of the first and the last if both are provided
|
11263
|
-
* and their lexers match.
|
11264
|
-
* - Otherwise, returns null.
|
11265
|
-
*/
|
11266
|
-
static range(first, second) {
|
11267
|
-
if (!second) {
|
11268
|
-
return first && first.loc;
|
11269
|
-
} else if (!first || !first.loc || !second.loc || first.loc.lexer !== second.loc.lexer) {
|
11270
|
-
return null;
|
11271
|
-
} else {
|
11272
|
-
return new SourceLocation(first.loc.lexer, first.loc.start, second.loc.end);
|
11273
|
-
}
|
11274
|
-
}
|
11275
|
-
}
|
11276
|
-
|
11277
|
-
/**
|
11278
|
-
* Interface required to break circular dependency between Token, Lexer, and
|
11279
|
-
* ParseError.
|
11280
|
-
*/
|
11281
|
-
|
11282
|
-
/**
|
11283
|
-
* The resulting token returned from `lex`.
|
11284
|
-
*
|
11285
|
-
* It consists of the token text plus some position information.
|
11286
|
-
* The position information is essentially a range in an input string,
|
11287
|
-
* but instead of referencing the bare input string, we refer to the lexer.
|
11288
|
-
* That way it is possible to attach extra metadata to the input string,
|
11289
|
-
* like for example a file name or similar.
|
11290
|
-
*
|
11291
|
-
* The position information is optional, so it is OK to construct synthetic
|
11292
|
-
* tokens if appropriate. Not providing available position information may
|
11293
|
-
* lead to degraded error reporting, though.
|
11294
|
-
*/
|
11295
|
-
class Token {
|
11296
|
-
constructor(
|
11297
|
-
text, // the text of this token
|
11298
|
-
loc
|
11299
|
-
) {
|
11300
|
-
this.text = text;
|
11301
|
-
this.loc = loc;
|
11302
|
-
}
|
11303
|
-
|
11304
|
-
/**
|
11305
|
-
* Given a pair of tokens (this and endToken), compute a `Token` encompassing
|
11306
|
-
* the whole input range enclosed by these two.
|
11307
|
-
*/
|
11308
|
-
range(
|
11309
|
-
endToken, // last token of the range, inclusive
|
11310
|
-
text // the text of the newly constructed token
|
11311
|
-
) {
|
11312
|
-
return new Token(text, SourceLocation.range(this, endToken));
|
11313
|
-
}
|
11314
|
-
}
|
11315
|
-
|
11316
11381
|
/**
|
11317
11382
|
* The Lexer class handles tokenizing the input in various ways. Since our
|
11318
11383
|
* parser expects us to be able to backtrack, the lexer allows lexing from any
|
@@ -13610,7 +13675,7 @@ class Style {
|
|
13610
13675
|
* https://mit-license.org/
|
13611
13676
|
*/
|
13612
13677
|
|
13613
|
-
const version = "0.
|
13678
|
+
const version = "0.11.00";
|
13614
13679
|
|
13615
13680
|
function postProcess(block) {
|
13616
13681
|
const labelMap = {};
|
@@ -13626,15 +13691,15 @@ function postProcess(block) {
|
|
13626
13691
|
// No need to write a number into the text content of the element.
|
13627
13692
|
// A CSS counter has done that even if this postProcess() function is not used.
|
13628
13693
|
|
13629
|
-
// Find any \label that refers to an AMS eqn number.
|
13694
|
+
// Find any \label that refers to an AMS automatic eqn number.
|
13630
13695
|
while (true) {
|
13696
|
+
if (parent.tagName === "mtable") { break }
|
13631
13697
|
const labels = parent.getElementsByClassName("tml-label");
|
13632
13698
|
if (labels.length > 0) {
|
13633
|
-
parent.
|
13634
|
-
labelMap[
|
13699
|
+
const id = parent.attributes.id.value;
|
13700
|
+
labelMap[id] = String(i);
|
13635
13701
|
break
|
13636
13702
|
} else {
|
13637
|
-
if (parent.tagName === "mtable") { break }
|
13638
13703
|
parent = parent.parentElement;
|
13639
13704
|
}
|
13640
13705
|
}
|
@@ -13647,7 +13712,8 @@ function postProcess(block) {
|
|
13647
13712
|
if (labels.length > 0) {
|
13648
13713
|
const tags = parent.getElementsByClassName("tml-tag");
|
13649
13714
|
if (tags.length > 0) {
|
13650
|
-
|
13715
|
+
const id = parent.attributes.id.value;
|
13716
|
+
labelMap[id] = tags[0].textContent;
|
13651
13717
|
}
|
13652
13718
|
}
|
13653
13719
|
}
|
@@ -13674,6 +13740,267 @@ function postProcess(block) {
|
|
13674
13740
|
});
|
13675
13741
|
}
|
13676
13742
|
|
13743
|
+
const findEndOfMath = function(delimiter, text, startIndex) {
|
13744
|
+
// Adapted from
|
13745
|
+
// https://github.com/Khan/perseus/blob/master/src/perseus-markdown.jsx
|
13746
|
+
let index = startIndex;
|
13747
|
+
let braceLevel = 0;
|
13748
|
+
|
13749
|
+
const delimLength = delimiter.length;
|
13750
|
+
|
13751
|
+
while (index < text.length) {
|
13752
|
+
const character = text[index];
|
13753
|
+
|
13754
|
+
if (braceLevel <= 0 && text.slice(index, index + delimLength) === delimiter) {
|
13755
|
+
return index;
|
13756
|
+
} else if (character === "\\") {
|
13757
|
+
index++;
|
13758
|
+
} else if (character === "{") {
|
13759
|
+
braceLevel++;
|
13760
|
+
} else if (character === "}") {
|
13761
|
+
braceLevel--;
|
13762
|
+
}
|
13763
|
+
|
13764
|
+
index++;
|
13765
|
+
}
|
13766
|
+
|
13767
|
+
return -1;
|
13768
|
+
};
|
13769
|
+
|
13770
|
+
const escapeRegex = function(string) {
|
13771
|
+
return string.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
13772
|
+
};
|
13773
|
+
|
13774
|
+
const amsRegex = /^\\(?:begin|(?:eq)?ref){/;
|
13775
|
+
|
13776
|
+
const splitAtDelimiters = function(text, delimiters) {
|
13777
|
+
let index;
|
13778
|
+
const data = [];
|
13779
|
+
|
13780
|
+
const regexLeft = new RegExp(
|
13781
|
+
"(" + delimiters.map((x) => escapeRegex(x.left)).join("|") + ")"
|
13782
|
+
);
|
13783
|
+
|
13784
|
+
while (true) {
|
13785
|
+
index = text.search(regexLeft);
|
13786
|
+
if (index === -1) {
|
13787
|
+
break;
|
13788
|
+
}
|
13789
|
+
if (index > 0) {
|
13790
|
+
data.push({
|
13791
|
+
type: "text",
|
13792
|
+
data: text.slice(0, index)
|
13793
|
+
});
|
13794
|
+
text = text.slice(index); // now text starts with delimiter
|
13795
|
+
}
|
13796
|
+
// ... so this always succeeds:
|
13797
|
+
const i = delimiters.findIndex((delim) => text.startsWith(delim.left));
|
13798
|
+
index = findEndOfMath(delimiters[i].right, text, delimiters[i].left.length);
|
13799
|
+
if (index === -1) {
|
13800
|
+
break;
|
13801
|
+
}
|
13802
|
+
const rawData = text.slice(0, index + delimiters[i].right.length);
|
13803
|
+
const math = amsRegex.test(rawData)
|
13804
|
+
? rawData
|
13805
|
+
: text.slice(delimiters[i].left.length, index);
|
13806
|
+
data.push({
|
13807
|
+
type: "math",
|
13808
|
+
data: math,
|
13809
|
+
rawData,
|
13810
|
+
display: delimiters[i].display
|
13811
|
+
});
|
13812
|
+
text = text.slice(index + delimiters[i].right.length);
|
13813
|
+
}
|
13814
|
+
|
13815
|
+
if (text !== "") {
|
13816
|
+
data.push({
|
13817
|
+
type: "text",
|
13818
|
+
data: text
|
13819
|
+
});
|
13820
|
+
}
|
13821
|
+
|
13822
|
+
return data;
|
13823
|
+
};
|
13824
|
+
|
13825
|
+
const defaultDelimiters = [
|
13826
|
+
{ left: "$$", right: "$$", display: true },
|
13827
|
+
{ left: "\\(", right: "\\)", display: false },
|
13828
|
+
// LaTeX uses $…$, but it ruins the display of normal `$` in text:
|
13829
|
+
// {left: "$", right: "$", display: false},
|
13830
|
+
// $ must come after $$
|
13831
|
+
|
13832
|
+
// Render AMS environments even if outside $$…$$ delimiters.
|
13833
|
+
{ left: "\\begin{equation}", right: "\\end{equation}", display: true },
|
13834
|
+
{ left: "\\begin{equation*}", right: "\\end{equation*}", display: true },
|
13835
|
+
{ left: "\\begin{align}", right: "\\end{align}", display: true },
|
13836
|
+
{ left: "\\begin{align*}", right: "\\end{align*}", display: true },
|
13837
|
+
{ left: "\\begin{alignat}", right: "\\end{alignat}", display: true },
|
13838
|
+
{ left: "\\begin{alignat*}", right: "\\end{alignat*}", display: true },
|
13839
|
+
{ left: "\\begin{gather}", right: "\\end{gather}", display: true },
|
13840
|
+
{ left: "\\begin{gather*}", right: "\\end{gather*}", display: true },
|
13841
|
+
{ left: "\\begin{CD}", right: "\\end{CD}", display: true },
|
13842
|
+
// Ditto \ref & \eqref
|
13843
|
+
{ left: "\\ref{", right: "}", display: false },
|
13844
|
+
{ left: "\\eqref{", right: "}", display: false },
|
13845
|
+
|
13846
|
+
{ left: "\\[", right: "\\]", display: true }
|
13847
|
+
];
|
13848
|
+
|
13849
|
+
const firstDraftDelimiters = {
|
13850
|
+
"$": [
|
13851
|
+
{ left: "$$", right: "$$", display: true },
|
13852
|
+
{ left: "$`", right: "`$", display: false },
|
13853
|
+
{ left: "$", right: "$", display: false }
|
13854
|
+
],
|
13855
|
+
"(": [
|
13856
|
+
{ left: "\\[", right: "\\]", display: true },
|
13857
|
+
{ left: "\\(", right: "\\)", display: false }
|
13858
|
+
]
|
13859
|
+
};
|
13860
|
+
|
13861
|
+
const amsDelimiters = [
|
13862
|
+
{ left: "\\begin{equation}", right: "\\end{equation}", display: true },
|
13863
|
+
{ left: "\\begin{equation*}", right: "\\end{equation*}", display: true },
|
13864
|
+
{ left: "\\begin{align}", right: "\\end{align}", display: true },
|
13865
|
+
{ left: "\\begin{align*}", right: "\\end{align*}", display: true },
|
13866
|
+
{ left: "\\begin{alignat}", right: "\\end{alignat}", display: true },
|
13867
|
+
{ left: "\\begin{alignat*}", right: "\\end{alignat*}", display: true },
|
13868
|
+
{ left: "\\begin{gather}", right: "\\end{gather}", display: true },
|
13869
|
+
{ left: "\\begin{gather*}", right: "\\end{gather*}", display: true },
|
13870
|
+
{ left: "\\begin{CD}", right: "\\end{CD}", display: true },
|
13871
|
+
{ left: "\\ref{", right: "}", display: false },
|
13872
|
+
{ left: "\\eqref{", right: "}", display: false }
|
13873
|
+
];
|
13874
|
+
|
13875
|
+
const delimitersFromKey = key => {
|
13876
|
+
if (key === "$" || key === "(") {
|
13877
|
+
return firstDraftDelimiters[key];
|
13878
|
+
} else if (key === "$+" || key === "(+") {
|
13879
|
+
const firstDraft = firstDraftDelimiters[key.slice(0, 1)];
|
13880
|
+
return firstDraft.concat(amsDelimiters)
|
13881
|
+
} else if (key === "ams") {
|
13882
|
+
return amsDelimiters
|
13883
|
+
} else if (key === "all") {
|
13884
|
+
return (firstDraftDelimiters["("]).concat(firstDraftDelimiters["$"]).concat(amsDelimiters)
|
13885
|
+
} else {
|
13886
|
+
return defaultDelimiters
|
13887
|
+
}
|
13888
|
+
};
|
13889
|
+
|
13890
|
+
/* Note: optionsCopy is mutated by this method. If it is ever exposed in the
|
13891
|
+
* API, we should copy it before mutating.
|
13892
|
+
*/
|
13893
|
+
const renderMathInText = function(text, optionsCopy) {
|
13894
|
+
const data = splitAtDelimiters(text, optionsCopy.delimiters);
|
13895
|
+
if (data.length === 1 && data[0].type === "text") {
|
13896
|
+
// There is no formula in the text.
|
13897
|
+
// Let's return null which means there is no need to replace
|
13898
|
+
// the current text node with a new one.
|
13899
|
+
return null;
|
13900
|
+
}
|
13901
|
+
|
13902
|
+
const fragment = document.createDocumentFragment();
|
13903
|
+
|
13904
|
+
for (let i = 0; i < data.length; i++) {
|
13905
|
+
if (data[i].type === "text") {
|
13906
|
+
fragment.appendChild(document.createTextNode(data[i].data));
|
13907
|
+
} else {
|
13908
|
+
const span = document.createElement("span");
|
13909
|
+
let math = data[i].data;
|
13910
|
+
// Override any display mode defined in the settings with that
|
13911
|
+
// defined by the text itself
|
13912
|
+
optionsCopy.displayMode = data[i].display;
|
13913
|
+
try {
|
13914
|
+
if (optionsCopy.preProcess) {
|
13915
|
+
math = optionsCopy.preProcess(math);
|
13916
|
+
}
|
13917
|
+
// Importing render() from temml.js would be a circular dependency.
|
13918
|
+
// So call the global version.
|
13919
|
+
// eslint-disable-next-line no-undef
|
13920
|
+
temml.render(math, span, optionsCopy);
|
13921
|
+
} catch (e) {
|
13922
|
+
if (!(e instanceof ParseError)) {
|
13923
|
+
throw e;
|
13924
|
+
}
|
13925
|
+
optionsCopy.errorCallback(
|
13926
|
+
"Temml auto-render: Failed to parse `" + data[i].data + "` with ",
|
13927
|
+
e
|
13928
|
+
);
|
13929
|
+
fragment.appendChild(document.createTextNode(data[i].rawData));
|
13930
|
+
continue;
|
13931
|
+
}
|
13932
|
+
fragment.appendChild(span);
|
13933
|
+
}
|
13934
|
+
}
|
13935
|
+
|
13936
|
+
return fragment;
|
13937
|
+
};
|
13938
|
+
|
13939
|
+
const renderElem = function(elem, optionsCopy) {
|
13940
|
+
for (let i = 0; i < elem.childNodes.length; i++) {
|
13941
|
+
const childNode = elem.childNodes[i];
|
13942
|
+
if (childNode.nodeType === 3) {
|
13943
|
+
// Text node
|
13944
|
+
const frag = renderMathInText(childNode.textContent, optionsCopy);
|
13945
|
+
if (frag) {
|
13946
|
+
i += frag.childNodes.length - 1;
|
13947
|
+
elem.replaceChild(frag, childNode);
|
13948
|
+
}
|
13949
|
+
} else if (childNode.nodeType === 1) {
|
13950
|
+
// Element node
|
13951
|
+
const className = " " + childNode.className + " ";
|
13952
|
+
const shouldRender =
|
13953
|
+
optionsCopy.ignoredTags.indexOf(childNode.nodeName.toLowerCase()) === -1 &&
|
13954
|
+
optionsCopy.ignoredClasses.every((x) => className.indexOf(" " + x + " ") === -1);
|
13955
|
+
|
13956
|
+
if (shouldRender) {
|
13957
|
+
renderElem(childNode, optionsCopy);
|
13958
|
+
}
|
13959
|
+
}
|
13960
|
+
// Otherwise, it's something else, and ignore it.
|
13961
|
+
}
|
13962
|
+
};
|
13963
|
+
|
13964
|
+
const renderMathInElement = function(elem, options) {
|
13965
|
+
if (!elem) {
|
13966
|
+
throw new Error("No element provided to render");
|
13967
|
+
}
|
13968
|
+
|
13969
|
+
const optionsCopy = {};
|
13970
|
+
|
13971
|
+
// Object.assign(optionsCopy, option)
|
13972
|
+
for (const option in options) {
|
13973
|
+
if (Object.prototype.hasOwnProperty.call(options, option)) {
|
13974
|
+
optionsCopy[option] = options[option];
|
13975
|
+
}
|
13976
|
+
}
|
13977
|
+
|
13978
|
+
if (optionsCopy.fences) {
|
13979
|
+
optionsCopy.delimiters = delimitersFromKey(optionsCopy.fences);
|
13980
|
+
} else {
|
13981
|
+
optionsCopy.delimiters = optionsCopy.delimiters || defaultDelimiters;
|
13982
|
+
}
|
13983
|
+
optionsCopy.ignoredTags = optionsCopy.ignoredTags || [
|
13984
|
+
"script",
|
13985
|
+
"noscript",
|
13986
|
+
"style",
|
13987
|
+
"textarea",
|
13988
|
+
"pre",
|
13989
|
+
"code",
|
13990
|
+
"option"
|
13991
|
+
];
|
13992
|
+
optionsCopy.ignoredClasses = optionsCopy.ignoredClasses || [];
|
13993
|
+
// eslint-disable-next-line no-console
|
13994
|
+
optionsCopy.errorCallback = optionsCopy.errorCallback || console.error;
|
13995
|
+
|
13996
|
+
// Enable sharing of global macros defined via `\gdef` between different
|
13997
|
+
// math elements within a single call to `renderMathInElement`.
|
13998
|
+
optionsCopy.macros = optionsCopy.macros || {};
|
13999
|
+
|
14000
|
+
renderElem(elem, optionsCopy);
|
14001
|
+
postProcess(elem);
|
14002
|
+
};
|
14003
|
+
|
13677
14004
|
/* eslint no-console:0 */
|
13678
14005
|
/**
|
13679
14006
|
* This is the main entry point for Temml. Here, we expose functions for
|
@@ -13793,7 +14120,7 @@ const renderToMathMLTree = function(expression, options) {
|
|
13793
14120
|
};
|
13794
14121
|
|
13795
14122
|
/** @type {import('./temml').default} */
|
13796
|
-
var temml = {
|
14123
|
+
var temml$1 = {
|
13797
14124
|
/**
|
13798
14125
|
* Current Temml version
|
13799
14126
|
*/
|
@@ -13808,6 +14135,11 @@ var temml = {
|
|
13808
14135
|
* for sending to the client.
|
13809
14136
|
*/
|
13810
14137
|
renderToString,
|
14138
|
+
/**
|
14139
|
+
* Finds all the math delimiters in a given element of a running HTML document
|
14140
|
+
* and converts the contents of each instance into a <math> element.
|
14141
|
+
*/
|
14142
|
+
renderMathInElement,
|
13811
14143
|
/**
|
13812
14144
|
* Post-process an entire HTML block.
|
13813
14145
|
* Writes AMS auto-numbers and implements \ref{}.
|
@@ -13850,4 +14182,4 @@ var temml = {
|
|
13850
14182
|
__defineMacro: defineMacro
|
13851
14183
|
};
|
13852
14184
|
|
13853
|
-
export { temml as default };
|
14185
|
+
export { temml$1 as default };
|