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.js
CHANGED
@@ -610,6 +610,7 @@ var temml = (function () {
|
|
610
610
|
this.children = children || [];
|
611
611
|
this.classes = classes || [];
|
612
612
|
this.style = style || {}; // Used for <mstyle> elements
|
613
|
+
this.label = "";
|
613
614
|
}
|
614
615
|
|
615
616
|
/**
|
@@ -627,6 +628,10 @@ var temml = (function () {
|
|
627
628
|
return this.attributes[name];
|
628
629
|
}
|
629
630
|
|
631
|
+
setLabel(value) {
|
632
|
+
this.label = value;
|
633
|
+
}
|
634
|
+
|
630
635
|
/**
|
631
636
|
* Converts the math node into a MathML-namespaced DOM element.
|
632
637
|
*/
|
@@ -1543,7 +1548,7 @@ var temml = (function () {
|
|
1543
1548
|
defineSymbol(math, mathord, "\u2aeb", "\\Bot");
|
1544
1549
|
defineSymbol(math, bin, "\u2217", "\u2217", true);
|
1545
1550
|
defineSymbol(math, bin, "+", "+");
|
1546
|
-
defineSymbol(math, bin, "
|
1551
|
+
defineSymbol(math, bin, "\u2217", "*");
|
1547
1552
|
defineSymbol(math, bin, "\u2044", "/", true);
|
1548
1553
|
defineSymbol(math, bin, "\u2044", "\u2044");
|
1549
1554
|
defineSymbol(math, bin, "\u2212", "-", true);
|
@@ -2006,7 +2011,7 @@ var temml = (function () {
|
|
2006
2011
|
}
|
2007
2012
|
block.push(node);
|
2008
2013
|
if (node.type && node.type === "mo" && node.children.length === 1 &&
|
2009
|
-
!Object.
|
2014
|
+
!Object.prototype.hasOwnProperty.call(node.attributes, "movablelimits")) {
|
2010
2015
|
const ch = node.children[0].text;
|
2011
2016
|
if (openDelims.indexOf(ch) > -1) {
|
2012
2017
|
level += 1;
|
@@ -2342,16 +2347,36 @@ var temml = (function () {
|
|
2342
2347
|
return new mathMLTree.MathNode("mtd", [], [], { padding: "0", width: "50%" })
|
2343
2348
|
};
|
2344
2349
|
|
2350
|
+
const labelContainers = ["mrow", "mtd", "mtable", "mtr"];
|
2351
|
+
const getLabel = parent => {
|
2352
|
+
for (const node of parent.children) {
|
2353
|
+
if (node.type && labelContainers.includes(node.type)) {
|
2354
|
+
if (node.classes && node.classes[0] === "tml-label") {
|
2355
|
+
const label = node.label;
|
2356
|
+
return label
|
2357
|
+
} else {
|
2358
|
+
const label = getLabel(node);
|
2359
|
+
if (label) { return label }
|
2360
|
+
}
|
2361
|
+
} else if (!node.type) {
|
2362
|
+
const label = getLabel(node);
|
2363
|
+
if (label) { return label }
|
2364
|
+
}
|
2365
|
+
}
|
2366
|
+
};
|
2367
|
+
|
2345
2368
|
const taggedExpression = (expression, tag, style, leqno) => {
|
2346
2369
|
tag = buildExpressionRow(tag[0].body, style);
|
2347
2370
|
tag = consolidateText(tag);
|
2348
2371
|
tag.classes.push("tml-tag");
|
2349
2372
|
|
2373
|
+
const label = getLabel(expression); // from a \label{} function.
|
2350
2374
|
expression = new mathMLTree.MathNode("mtd", [expression]);
|
2351
2375
|
const rowArray = [glue$1(), expression, glue$1()];
|
2352
2376
|
rowArray[leqno ? 0 : 2].classes.push(leqno ? "tml-left" : "tml-right");
|
2353
2377
|
rowArray[leqno ? 0 : 2].children.push(tag);
|
2354
2378
|
const mtr = new mathMLTree.MathNode("mtr", rowArray, ["tml-tageqn"]);
|
2379
|
+
if (label) { mtr.setAttribute("id", label); }
|
2355
2380
|
const table = new mathMLTree.MathNode("mtable", [mtr]);
|
2356
2381
|
table.style.width = "100%";
|
2357
2382
|
table.setAttribute("displaystyle", "true");
|
@@ -3182,6 +3207,8 @@ var temml = (function () {
|
|
3182
3207
|
type: "array",
|
3183
3208
|
mode: "math",
|
3184
3209
|
body,
|
3210
|
+
tags: null,
|
3211
|
+
labels: new Array(body.length + 1).fill(""),
|
3185
3212
|
envClasses: ["jot", "cd"],
|
3186
3213
|
cols: [],
|
3187
3214
|
hLinesBeforeRow: new Array(body.length + 1).fill([])
|
@@ -4422,6 +4449,75 @@ var temml = (function () {
|
|
4422
4449
|
}
|
4423
4450
|
}
|
4424
4451
|
|
4452
|
+
/**
|
4453
|
+
* Lexing or parsing positional information for error reporting.
|
4454
|
+
* This object is immutable.
|
4455
|
+
*/
|
4456
|
+
class SourceLocation {
|
4457
|
+
constructor(lexer, start, end) {
|
4458
|
+
this.lexer = lexer; // Lexer holding the input string.
|
4459
|
+
this.start = start; // Start offset, zero-based inclusive.
|
4460
|
+
this.end = end; // End offset, zero-based exclusive.
|
4461
|
+
}
|
4462
|
+
|
4463
|
+
/**
|
4464
|
+
* Merges two `SourceLocation`s from location providers, given they are
|
4465
|
+
* provided in order of appearance.
|
4466
|
+
* - Returns the first one's location if only the first is provided.
|
4467
|
+
* - Returns a merged range of the first and the last if both are provided
|
4468
|
+
* and their lexers match.
|
4469
|
+
* - Otherwise, returns null.
|
4470
|
+
*/
|
4471
|
+
static range(first, second) {
|
4472
|
+
if (!second) {
|
4473
|
+
return first && first.loc;
|
4474
|
+
} else if (!first || !first.loc || !second.loc || first.loc.lexer !== second.loc.lexer) {
|
4475
|
+
return null;
|
4476
|
+
} else {
|
4477
|
+
return new SourceLocation(first.loc.lexer, first.loc.start, second.loc.end);
|
4478
|
+
}
|
4479
|
+
}
|
4480
|
+
}
|
4481
|
+
|
4482
|
+
/**
|
4483
|
+
* Interface required to break circular dependency between Token, Lexer, and
|
4484
|
+
* ParseError.
|
4485
|
+
*/
|
4486
|
+
|
4487
|
+
/**
|
4488
|
+
* The resulting token returned from `lex`.
|
4489
|
+
*
|
4490
|
+
* It consists of the token text plus some position information.
|
4491
|
+
* The position information is essentially a range in an input string,
|
4492
|
+
* but instead of referencing the bare input string, we refer to the lexer.
|
4493
|
+
* That way it is possible to attach extra metadata to the input string,
|
4494
|
+
* like for example a file name or similar.
|
4495
|
+
*
|
4496
|
+
* The position information is optional, so it is OK to construct synthetic
|
4497
|
+
* tokens if appropriate. Not providing available position information may
|
4498
|
+
* lead to degraded error reporting, though.
|
4499
|
+
*/
|
4500
|
+
class Token {
|
4501
|
+
constructor(
|
4502
|
+
text, // the text of this token
|
4503
|
+
loc
|
4504
|
+
) {
|
4505
|
+
this.text = text;
|
4506
|
+
this.loc = loc;
|
4507
|
+
}
|
4508
|
+
|
4509
|
+
/**
|
4510
|
+
* Given a pair of tokens (this and endToken), compute a `Token` encompassing
|
4511
|
+
* the whole input range enclosed by these two.
|
4512
|
+
*/
|
4513
|
+
range(
|
4514
|
+
endToken, // last token of the range, inclusive
|
4515
|
+
text // the text of the newly constructed token
|
4516
|
+
) {
|
4517
|
+
return new Token(text, SourceLocation.range(this, endToken));
|
4518
|
+
}
|
4519
|
+
}
|
4520
|
+
|
4425
4521
|
// In TeX, there are actually three sets of dimensions, one for each of
|
4426
4522
|
// textstyle, scriptstyle, and scriptscriptstyle. These are
|
4427
4523
|
// provided in the the arrays below, in that order.
|
@@ -4906,8 +5002,10 @@ var temml = (function () {
|
|
4906
5002
|
if (context.macros.get("\\df@tag")) {
|
4907
5003
|
throw new ParseError("Multiple \\tag");
|
4908
5004
|
}
|
4909
|
-
return "\\
|
5005
|
+
return "\\gdef\\df@tag{\\text{#1}}";
|
4910
5006
|
});
|
5007
|
+
defineMacro("\\notag", "\\nonumber");
|
5008
|
+
defineMacro("\\nonumber", "\\gdef\\@eqnsw{0}");
|
4911
5009
|
|
4912
5010
|
// \renewcommand{\bmod}{\nonscript\mskip-\medmuskip\mkern5mu\mathbin
|
4913
5011
|
// {\operator@font mod}\penalty900
|
@@ -5197,33 +5295,30 @@ var temml = (function () {
|
|
5197
5295
|
return [arraystretch, arraycolsep]
|
5198
5296
|
};
|
5199
5297
|
|
5200
|
-
const
|
5201
|
-
|
5202
|
-
|
5203
|
-
|
5204
|
-
|
5205
|
-
|
5206
|
-
|
5207
|
-
|
5208
|
-
} else {
|
5209
|
-
// \notag. Return an empty span.
|
5210
|
-
tag = new mathMLTree.MathNode("mtext", [], []);
|
5211
|
-
return tag
|
5212
|
-
}
|
5213
|
-
} else if (group.envClasses.includes("multline") &&
|
5214
|
-
((group.leqno && rowNum !== 0) || (!group.leqno && rowNum !== group.body.length - 1))) {
|
5215
|
-
// A multiline that does not receive a tag. Return an empty cell.
|
5216
|
-
tag = new mathMLTree.MathNode("mtext", [], []);
|
5217
|
-
return tag
|
5218
|
-
} else {
|
5219
|
-
// AMS automatcally numbered equaton.
|
5220
|
-
// Insert a class so the element can be populated by a CSS counter.
|
5221
|
-
// WebKit will display the CSS counter only inside a span.
|
5222
|
-
tag = new mathMLTree.MathNode("mtext", [new Span(["tml-eqn"])]);
|
5298
|
+
const checkCellForLabels = cell => {
|
5299
|
+
// Check if the author wrote a \tag{} inside this cell.
|
5300
|
+
let rowLabel = "";
|
5301
|
+
for (let i = 0; i < cell.length; i++) {
|
5302
|
+
if (cell[i].type === "label") {
|
5303
|
+
if (rowLabel) { throw new ParseError(("Multiple \\labels in one row")) }
|
5304
|
+
rowLabel = cell[i].string;
|
5305
|
+
}
|
5223
5306
|
}
|
5224
|
-
return
|
5307
|
+
return rowLabel
|
5225
5308
|
};
|
5226
5309
|
|
5310
|
+
// autoTag (an argument to parseArray) can be one of three values:
|
5311
|
+
// * undefined: Regular (not-top-level) array; no tags on each row
|
5312
|
+
// * true: Automatic equation numbering, overridable by \tag
|
5313
|
+
// * false: Tags allowed on each row, but no automatic numbering
|
5314
|
+
// This function *doesn't* work with the "split" environment name.
|
5315
|
+
function getAutoTag(name) {
|
5316
|
+
if (name.indexOf("ed") === -1) {
|
5317
|
+
return name.indexOf("*") === -1;
|
5318
|
+
}
|
5319
|
+
// return undefined;
|
5320
|
+
}
|
5321
|
+
|
5227
5322
|
/**
|
5228
5323
|
* Parse the body of the environment, with rows delimited by \\ and
|
5229
5324
|
* columns delimited by &, and create a nested list in row-major order
|
@@ -5235,7 +5330,7 @@ var temml = (function () {
|
|
5235
5330
|
{
|
5236
5331
|
cols, // [{ type: string , align: l|c|r|null }]
|
5237
5332
|
envClasses, // align(ed|at|edat) | array | cases | cd | small | multline
|
5238
|
-
|
5333
|
+
autoTag, // boolean
|
5239
5334
|
singleRow, // boolean
|
5240
5335
|
emptySingleRow, // boolean
|
5241
5336
|
maxNumCols, // number
|
@@ -5251,13 +5346,6 @@ var temml = (function () {
|
|
5251
5346
|
// TODO: provide helpful error when \cr is used outside array environment
|
5252
5347
|
parser.gullet.macros.set("\\cr", "\\\\\\relax");
|
5253
5348
|
}
|
5254
|
-
if (addEqnNum) {
|
5255
|
-
parser.gullet.macros.set("\\tag", "\\@ifstar\\envtag@literal\\envtag@paren");
|
5256
|
-
parser.gullet.macros.set("\\envtag@paren", "\\env@tag{{(\\text{#1})}}");
|
5257
|
-
parser.gullet.macros.set("\\envtag@literal", "\\env@tag{\\text{#1}}");
|
5258
|
-
parser.gullet.macros.set("\\notag", "\\env@notag");
|
5259
|
-
parser.gullet.macros.set("\\nonumber", "\\env@notag");
|
5260
|
-
}
|
5261
5349
|
|
5262
5350
|
// Start group for first cell
|
5263
5351
|
parser.gullet.beginGroup();
|
@@ -5265,29 +5353,39 @@ var temml = (function () {
|
|
5265
5353
|
let row = [];
|
5266
5354
|
const body = [row];
|
5267
5355
|
const rowGaps = [];
|
5268
|
-
const
|
5269
|
-
|
5356
|
+
const labels = [];
|
5357
|
+
|
5270
5358
|
const hLinesBeforeRow = [];
|
5271
5359
|
|
5360
|
+
const tags = (autoTag != null ? [] : undefined);
|
5361
|
+
|
5362
|
+
// amsmath uses \global\@eqnswtrue and \global\@eqnswfalse to represent
|
5363
|
+
// whether this row should have an equation number. Simulate this with
|
5364
|
+
// a \@eqnsw macro set to 1 or 0.
|
5365
|
+
function beginRow() {
|
5366
|
+
if (autoTag) {
|
5367
|
+
parser.gullet.macros.set("\\@eqnsw", "1", true);
|
5368
|
+
}
|
5369
|
+
}
|
5370
|
+
function endRow() {
|
5371
|
+
if (tags) {
|
5372
|
+
if (parser.gullet.macros.get("\\df@tag")) {
|
5373
|
+
tags.push(parser.subparse([new Token("\\df@tag")]));
|
5374
|
+
parser.gullet.macros.set("\\df@tag", undefined, true);
|
5375
|
+
} else {
|
5376
|
+
tags.push(Boolean(autoTag) &&
|
5377
|
+
parser.gullet.macros.get("\\@eqnsw") === "1");
|
5378
|
+
}
|
5379
|
+
}
|
5380
|
+
}
|
5381
|
+
beginRow();
|
5382
|
+
|
5272
5383
|
// Test for \hline at the top of the array.
|
5273
5384
|
hLinesBeforeRow.push(getHLines(parser));
|
5274
5385
|
|
5275
5386
|
while (true) {
|
5276
5387
|
// Parse each cell in its own group (namespace)
|
5277
5388
|
let cell = parser.parseExpression(false, singleRow ? "\\end" : "\\\\");
|
5278
|
-
|
5279
|
-
if (addEqnNum && !rowTag) {
|
5280
|
-
// Check if the author wrote a \tag{} inside this cell.
|
5281
|
-
for (let i = 0; i < cell.length; i++) {
|
5282
|
-
if (cell[i].type === "envTag" || cell[i].type === "noTag") {
|
5283
|
-
// Get the contents of the \text{} nested inside the \env@Tag{}
|
5284
|
-
rowTag = cell[i].type === "envTag"
|
5285
|
-
? cell.splice(i, 1)[0].body.body[0]
|
5286
|
-
: { body: null };
|
5287
|
-
break
|
5288
|
-
}
|
5289
|
-
}
|
5290
|
-
}
|
5291
5389
|
parser.gullet.endGroup();
|
5292
5390
|
parser.gullet.beginGroup();
|
5293
5391
|
|
@@ -5316,6 +5414,7 @@ var temml = (function () {
|
|
5316
5414
|
}
|
5317
5415
|
parser.consume();
|
5318
5416
|
} else if (next === "\\end") {
|
5417
|
+
endRow();
|
5319
5418
|
// Arrays terminate newlines with `\crcr` which consumes a `\cr` if
|
5320
5419
|
// the last line is empty. However, AMS environments keep the
|
5321
5420
|
// empty row if it's the only one.
|
@@ -5323,6 +5422,7 @@ var temml = (function () {
|
|
5323
5422
|
if (row.length === 1 && cell.body.length === 0 && (body.length > 1 || !emptySingleRow)) {
|
5324
5423
|
body.pop();
|
5325
5424
|
}
|
5425
|
+
labels.push(checkCellForLabels(cell.body));
|
5326
5426
|
if (hLinesBeforeRow.length < body.length + 1) {
|
5327
5427
|
hLinesBeforeRow.push([]);
|
5328
5428
|
}
|
@@ -5339,15 +5439,16 @@ var temml = (function () {
|
|
5339
5439
|
size = parser.parseSizeGroup(true);
|
5340
5440
|
}
|
5341
5441
|
rowGaps.push(size ? size.value : null);
|
5442
|
+
endRow();
|
5342
5443
|
|
5343
|
-
|
5444
|
+
labels.push(checkCellForLabels(cell.body));
|
5344
5445
|
|
5345
5446
|
// check for \hline(s) following the row separator
|
5346
5447
|
hLinesBeforeRow.push(getHLines(parser));
|
5347
5448
|
|
5348
5449
|
row = [];
|
5349
|
-
rowTag = null;
|
5350
5450
|
body.push(row);
|
5451
|
+
beginRow();
|
5351
5452
|
} else {
|
5352
5453
|
throw new ParseError("Expected & or \\\\ or \\cr or \\end", parser.nextToken);
|
5353
5454
|
}
|
@@ -5358,8 +5459,6 @@ var temml = (function () {
|
|
5358
5459
|
// End array group defining \cr
|
5359
5460
|
parser.gullet.endGroup();
|
5360
5461
|
|
5361
|
-
tags.push(rowTag);
|
5362
|
-
|
5363
5462
|
return {
|
5364
5463
|
type: "array",
|
5365
5464
|
mode: parser.mode,
|
@@ -5368,9 +5467,10 @@ var temml = (function () {
|
|
5368
5467
|
rowGaps,
|
5369
5468
|
hLinesBeforeRow,
|
5370
5469
|
envClasses,
|
5371
|
-
|
5470
|
+
autoTag,
|
5372
5471
|
scriptLevel,
|
5373
5472
|
tags,
|
5473
|
+
labels,
|
5374
5474
|
leqno,
|
5375
5475
|
arraystretch,
|
5376
5476
|
arraycolsep
|
@@ -5427,19 +5527,43 @@ var temml = (function () {
|
|
5427
5527
|
}
|
5428
5528
|
row.push(mtd);
|
5429
5529
|
}
|
5430
|
-
|
5431
|
-
|
5432
|
-
|
5433
|
-
|
5434
|
-
|
5435
|
-
|
5436
|
-
|
5437
|
-
|
5438
|
-
|
5439
|
-
|
5530
|
+
const numColumns = group.body[0].length;
|
5531
|
+
// Fill out a short row with empty <mtd> elements.
|
5532
|
+
for (let k = 0; k < numColumns - rw.length; k++) {
|
5533
|
+
row.push(new mathMLTree.MathNode("mtd", [], style));
|
5534
|
+
}
|
5535
|
+
if (group.autoTag) {
|
5536
|
+
const tag = group.tags[i];
|
5537
|
+
let tagElement;
|
5538
|
+
if (tag === true) { // automatic numbering
|
5539
|
+
tagElement = new mathMLTree.MathNode("mtext", [new Span(["tml-eqn"])]);
|
5540
|
+
} else if (tag === false) {
|
5541
|
+
// \nonumber/\notag or starred environment
|
5542
|
+
tagElement = new mathMLTree.MathNode("mtext", [], []);
|
5543
|
+
} else { // manual \tag
|
5544
|
+
tagElement = buildExpressionRow(tag[0].body, style.withLevel(cellLevel), true);
|
5545
|
+
tagElement = consolidateText(tagElement);
|
5546
|
+
tagElement.classes = ["tml-tag"];
|
5547
|
+
}
|
5548
|
+
if (tagElement) {
|
5549
|
+
row.unshift(glue(group));
|
5550
|
+
row.push(glue(group));
|
5551
|
+
if (group.leqno) {
|
5552
|
+
row[0].children.push(tagElement);
|
5553
|
+
row[0].classes.push("tml-left");
|
5554
|
+
} else {
|
5555
|
+
row[row.length - 1].children.push(tagElement);
|
5556
|
+
row[row.length - 1].classes.push("tml-right");
|
5557
|
+
}
|
5440
5558
|
}
|
5441
5559
|
}
|
5442
5560
|
const mtr = new mathMLTree.MathNode("mtr", row, []);
|
5561
|
+
const label = group.labels.shift();
|
5562
|
+
if (label && group.tags && group.tags[i]) {
|
5563
|
+
mtr.setAttribute("id", label);
|
5564
|
+
if (Array.isArray(group.tags[i])) { mtr.classes.push("tml-tageqn"); }
|
5565
|
+
}
|
5566
|
+
|
5443
5567
|
// Write horizontal rules
|
5444
5568
|
if (i === 0 && hlines[0].length > 0) {
|
5445
5569
|
if (hlines[0].length === 2) {
|
@@ -5463,16 +5587,17 @@ var temml = (function () {
|
|
5463
5587
|
}
|
5464
5588
|
|
5465
5589
|
if (group.envClasses.length > 0) {
|
5466
|
-
let pad = group.envClasses.includes("jot")
|
5467
|
-
? "0.7" // 0.5ex + 0.09em top & bot padding
|
5468
|
-
: group.envClasses.includes("small")
|
5469
|
-
? "0.35"
|
5470
|
-
: "0.5"; // 0.5ex default top & bot padding
|
5471
5590
|
if (group.arraystretch && group.arraystretch !== 1) {
|
5472
5591
|
// In LaTeX, \arraystretch is a factor applied to a 12pt strut height.
|
5473
5592
|
// It defines a baseline to baseline distance.
|
5474
5593
|
// Here, we do an approximation of that approach.
|
5475
|
-
pad = String(1.4 * group.arraystretch - 0.8);
|
5594
|
+
const pad = String(1.4 * group.arraystretch - 0.8) + "ex";
|
5595
|
+
for (let i = 0; i < tbl.length; i++) {
|
5596
|
+
for (let j = 0; j < tbl[i].children.length; j++) {
|
5597
|
+
tbl[i].children[j].style.paddingTop = pad;
|
5598
|
+
tbl[i].children[j].style.paddingBottom = pad;
|
5599
|
+
}
|
5600
|
+
}
|
5476
5601
|
}
|
5477
5602
|
let sidePadding = group.envClasses.includes("abut")
|
5478
5603
|
? "0"
|
@@ -5486,7 +5611,7 @@ var temml = (function () {
|
|
5486
5611
|
let sidePadUnit = "em";
|
5487
5612
|
if (group.arraycolsep) {
|
5488
5613
|
const arraySidePad = calculateSize(group.arraycolsep, style);
|
5489
|
-
sidePadding = arraySidePad.number;
|
5614
|
+
sidePadding = arraySidePad.number.toFixed(4);
|
5490
5615
|
sidePadUnit = arraySidePad.unit;
|
5491
5616
|
}
|
5492
5617
|
|
@@ -5497,18 +5622,18 @@ var temml = (function () {
|
|
5497
5622
|
if (j === numCols - 1 && hand === 1) { return "0" }
|
5498
5623
|
if (group.envClasses[0] !== "align") { return sidePadding }
|
5499
5624
|
if (hand === 1) { return "0" }
|
5500
|
-
if (group.
|
5625
|
+
if (group.autoTag) {
|
5501
5626
|
return (j % 2) ? "1" : "0"
|
5502
5627
|
} else {
|
5503
5628
|
return (j % 2) ? "0" : "1"
|
5504
5629
|
}
|
5505
5630
|
};
|
5506
5631
|
|
5507
|
-
//
|
5632
|
+
// Side padding
|
5508
5633
|
for (let i = 0; i < tbl.length; i++) {
|
5509
5634
|
for (let j = 0; j < tbl[i].children.length; j++) {
|
5510
|
-
tbl[i].children[j].style.
|
5511
|
-
|
5635
|
+
tbl[i].children[j].style.paddingLeft = `${sidePad(j, 0)}${sidePadUnit}`;
|
5636
|
+
tbl[i].children[j].style.paddingRight = `${sidePad(j, 1)}${sidePadUnit}`;
|
5512
5637
|
}
|
5513
5638
|
}
|
5514
5639
|
|
@@ -5522,13 +5647,13 @@ var temml = (function () {
|
|
5522
5647
|
// TODO: Remove -webkit- when Chromium no longer needs it.
|
5523
5648
|
row.children[j].classes = ["tml-" + (j % 2 ? "left" : "right")];
|
5524
5649
|
}
|
5525
|
-
if (group.
|
5650
|
+
if (group.autoTag) {
|
5526
5651
|
const k = group.leqno ? 0 : row.children.length - 1;
|
5527
5652
|
row.children[k].classes = ["tml-" + (group.leqno ? "left" : "right")];
|
5528
5653
|
}
|
5529
5654
|
}
|
5530
5655
|
if (row.children.length > 1 && group.envClasses.includes("cases")) {
|
5531
|
-
row.children[1].style.
|
5656
|
+
row.children[1].style.paddingLeft = "1em";
|
5532
5657
|
}
|
5533
5658
|
|
5534
5659
|
if (group.envClasses.includes("cases") || group.envClasses.includes("subarray")) {
|
@@ -5548,9 +5673,17 @@ var temml = (function () {
|
|
5548
5673
|
}
|
5549
5674
|
|
5550
5675
|
let table = new mathMLTree.MathNode("mtable", tbl);
|
5676
|
+
if (group.envClasses.length > 0) {
|
5677
|
+
// Top & bottom padding
|
5678
|
+
if (group.envClasses.includes("jot")) {
|
5679
|
+
table.classes.push("tml-jot");
|
5680
|
+
} else if (group.envClasses.includes("small")) {
|
5681
|
+
table.classes.push("tml-small");
|
5682
|
+
}
|
5683
|
+
}
|
5551
5684
|
if (group.scriptLevel === "display") { table.setAttribute("displaystyle", "true"); }
|
5552
5685
|
|
5553
|
-
if (group.
|
5686
|
+
if (group.autoTag || group.envClasses.includes("multline")) {
|
5554
5687
|
table.style.width = "100%";
|
5555
5688
|
}
|
5556
5689
|
|
@@ -5580,7 +5713,7 @@ var temml = (function () {
|
|
5580
5713
|
row.children[0].style.borderLeft = sep;
|
5581
5714
|
}
|
5582
5715
|
}
|
5583
|
-
let iCol = group.
|
5716
|
+
let iCol = group.autoTag ? 0 : -1;
|
5584
5717
|
for (let i = iStart; i < iEnd; i++) {
|
5585
5718
|
if (cols[i].type === "align") {
|
5586
5719
|
const colAlign = alignMap[cols[i].align];
|
@@ -5622,7 +5755,7 @@ var temml = (function () {
|
|
5622
5755
|
}
|
5623
5756
|
}
|
5624
5757
|
}
|
5625
|
-
if (group.
|
5758
|
+
if (group.autoTag) {
|
5626
5759
|
// allow for glue cells on each side
|
5627
5760
|
align = "left " + (align.length > 0 ? align : "center ") + "right ";
|
5628
5761
|
}
|
@@ -5646,13 +5779,14 @@ var temml = (function () {
|
|
5646
5779
|
if (context.envName.indexOf("ed") === -1) {
|
5647
5780
|
validateAmsEnvironmentContext(context);
|
5648
5781
|
}
|
5782
|
+
const isSplit = context.envName === "split";
|
5649
5783
|
const cols = [];
|
5650
5784
|
const res = parseArray(
|
5651
5785
|
context.parser,
|
5652
5786
|
{
|
5653
5787
|
cols,
|
5654
|
-
addEqnNum: context.envName === "align" || context.envName === "alignat",
|
5655
5788
|
emptySingleRow: true,
|
5789
|
+
autoTag: isSplit ? undefined : getAutoTag(context.envName),
|
5656
5790
|
envClasses: ["abut", "jot"], // set row spacing & provisional column spacing
|
5657
5791
|
maxNumCols: context.envName === "split" ? 2 : undefined,
|
5658
5792
|
leqno: context.parser.settings.leqno
|
@@ -5974,7 +6108,7 @@ var temml = (function () {
|
|
5974
6108
|
const res = {
|
5975
6109
|
cols: [],
|
5976
6110
|
envClasses: ["abut", "jot"],
|
5977
|
-
|
6111
|
+
autoTag: getAutoTag(context.envName),
|
5978
6112
|
emptySingleRow: true,
|
5979
6113
|
leqno: context.parser.settings.leqno
|
5980
6114
|
};
|
@@ -5992,7 +6126,7 @@ var temml = (function () {
|
|
5992
6126
|
handler(context) {
|
5993
6127
|
validateAmsEnvironmentContext(context);
|
5994
6128
|
const res = {
|
5995
|
-
|
6129
|
+
autoTag: getAutoTag(context.envName),
|
5996
6130
|
emptySingleRow: true,
|
5997
6131
|
singleRow: true,
|
5998
6132
|
maxNumCols: 1,
|
@@ -6013,7 +6147,7 @@ var temml = (function () {
|
|
6013
6147
|
handler(context) {
|
6014
6148
|
validateAmsEnvironmentContext(context);
|
6015
6149
|
const res = {
|
6016
|
-
|
6150
|
+
autoTag: context.envName === "multline",
|
6017
6151
|
maxNumCols: 1,
|
6018
6152
|
envClasses: ["jot", "multline"],
|
6019
6153
|
leqno: context.parser.settings.leqno
|
@@ -7070,7 +7204,7 @@ var temml = (function () {
|
|
7070
7204
|
// Return a no-width, no-ink element with an HTML id.
|
7071
7205
|
const node = new mathMLTree.MathNode("mrow", [], ["tml-label"]);
|
7072
7206
|
if (group.string.length > 0) {
|
7073
|
-
node.
|
7207
|
+
node.setLabel(group.string);
|
7074
7208
|
}
|
7075
7209
|
return node
|
7076
7210
|
}
|
@@ -9333,75 +9467,6 @@ var temml = (function () {
|
|
9333
9467
|
|
9334
9468
|
const functions = _functions;
|
9335
9469
|
|
9336
|
-
/**
|
9337
|
-
* Lexing or parsing positional information for error reporting.
|
9338
|
-
* This object is immutable.
|
9339
|
-
*/
|
9340
|
-
class SourceLocation {
|
9341
|
-
constructor(lexer, start, end) {
|
9342
|
-
this.lexer = lexer; // Lexer holding the input string.
|
9343
|
-
this.start = start; // Start offset, zero-based inclusive.
|
9344
|
-
this.end = end; // End offset, zero-based exclusive.
|
9345
|
-
}
|
9346
|
-
|
9347
|
-
/**
|
9348
|
-
* Merges two `SourceLocation`s from location providers, given they are
|
9349
|
-
* provided in order of appearance.
|
9350
|
-
* - Returns the first one's location if only the first is provided.
|
9351
|
-
* - Returns a merged range of the first and the last if both are provided
|
9352
|
-
* and their lexers match.
|
9353
|
-
* - Otherwise, returns null.
|
9354
|
-
*/
|
9355
|
-
static range(first, second) {
|
9356
|
-
if (!second) {
|
9357
|
-
return first && first.loc;
|
9358
|
-
} else if (!first || !first.loc || !second.loc || first.loc.lexer !== second.loc.lexer) {
|
9359
|
-
return null;
|
9360
|
-
} else {
|
9361
|
-
return new SourceLocation(first.loc.lexer, first.loc.start, second.loc.end);
|
9362
|
-
}
|
9363
|
-
}
|
9364
|
-
}
|
9365
|
-
|
9366
|
-
/**
|
9367
|
-
* Interface required to break circular dependency between Token, Lexer, and
|
9368
|
-
* ParseError.
|
9369
|
-
*/
|
9370
|
-
|
9371
|
-
/**
|
9372
|
-
* The resulting token returned from `lex`.
|
9373
|
-
*
|
9374
|
-
* It consists of the token text plus some position information.
|
9375
|
-
* The position information is essentially a range in an input string,
|
9376
|
-
* but instead of referencing the bare input string, we refer to the lexer.
|
9377
|
-
* That way it is possible to attach extra metadata to the input string,
|
9378
|
-
* like for example a file name or similar.
|
9379
|
-
*
|
9380
|
-
* The position information is optional, so it is OK to construct synthetic
|
9381
|
-
* tokens if appropriate. Not providing available position information may
|
9382
|
-
* lead to degraded error reporting, though.
|
9383
|
-
*/
|
9384
|
-
class Token {
|
9385
|
-
constructor(
|
9386
|
-
text, // the text of this token
|
9387
|
-
loc
|
9388
|
-
) {
|
9389
|
-
this.text = text;
|
9390
|
-
this.loc = loc;
|
9391
|
-
}
|
9392
|
-
|
9393
|
-
/**
|
9394
|
-
* Given a pair of tokens (this and endToken), compute a `Token` encompassing
|
9395
|
-
* the whole input range enclosed by these two.
|
9396
|
-
*/
|
9397
|
-
range(
|
9398
|
-
endToken, // last token of the range, inclusive
|
9399
|
-
text // the text of the newly constructed token
|
9400
|
-
) {
|
9401
|
-
return new Token(text, SourceLocation.range(this, endToken));
|
9402
|
-
}
|
9403
|
-
}
|
9404
|
-
|
9405
9470
|
/**
|
9406
9471
|
* The Lexer class handles tokenizing the input in various ways. Since our
|
9407
9472
|
* parser expects us to be able to backtrack, the lexer allows lexing from any
|
@@ -11699,7 +11764,7 @@ var temml = (function () {
|
|
11699
11764
|
* https://mit-license.org/
|
11700
11765
|
*/
|
11701
11766
|
|
11702
|
-
const version = "0.
|
11767
|
+
const version = "0.11.00";
|
11703
11768
|
|
11704
11769
|
function postProcess(block) {
|
11705
11770
|
const labelMap = {};
|
@@ -11715,15 +11780,15 @@ var temml = (function () {
|
|
11715
11780
|
// No need to write a number into the text content of the element.
|
11716
11781
|
// A CSS counter has done that even if this postProcess() function is not used.
|
11717
11782
|
|
11718
|
-
// Find any \label that refers to an AMS eqn number.
|
11783
|
+
// Find any \label that refers to an AMS automatic eqn number.
|
11719
11784
|
while (true) {
|
11785
|
+
if (parent.tagName === "mtable") { break }
|
11720
11786
|
const labels = parent.getElementsByClassName("tml-label");
|
11721
11787
|
if (labels.length > 0) {
|
11722
|
-
parent.
|
11723
|
-
labelMap[
|
11788
|
+
const id = parent.attributes.id.value;
|
11789
|
+
labelMap[id] = String(i);
|
11724
11790
|
break
|
11725
11791
|
} else {
|
11726
|
-
if (parent.tagName === "mtable") { break }
|
11727
11792
|
parent = parent.parentElement;
|
11728
11793
|
}
|
11729
11794
|
}
|
@@ -11736,7 +11801,8 @@ var temml = (function () {
|
|
11736
11801
|
if (labels.length > 0) {
|
11737
11802
|
const tags = parent.getElementsByClassName("tml-tag");
|
11738
11803
|
if (tags.length > 0) {
|
11739
|
-
|
11804
|
+
const id = parent.attributes.id.value;
|
11805
|
+
labelMap[id] = tags[0].textContent;
|
11740
11806
|
}
|
11741
11807
|
}
|
11742
11808
|
}
|
@@ -11763,6 +11829,267 @@ var temml = (function () {
|
|
11763
11829
|
});
|
11764
11830
|
}
|
11765
11831
|
|
11832
|
+
const findEndOfMath = function(delimiter, text, startIndex) {
|
11833
|
+
// Adapted from
|
11834
|
+
// https://github.com/Khan/perseus/blob/master/src/perseus-markdown.jsx
|
11835
|
+
let index = startIndex;
|
11836
|
+
let braceLevel = 0;
|
11837
|
+
|
11838
|
+
const delimLength = delimiter.length;
|
11839
|
+
|
11840
|
+
while (index < text.length) {
|
11841
|
+
const character = text[index];
|
11842
|
+
|
11843
|
+
if (braceLevel <= 0 && text.slice(index, index + delimLength) === delimiter) {
|
11844
|
+
return index;
|
11845
|
+
} else if (character === "\\") {
|
11846
|
+
index++;
|
11847
|
+
} else if (character === "{") {
|
11848
|
+
braceLevel++;
|
11849
|
+
} else if (character === "}") {
|
11850
|
+
braceLevel--;
|
11851
|
+
}
|
11852
|
+
|
11853
|
+
index++;
|
11854
|
+
}
|
11855
|
+
|
11856
|
+
return -1;
|
11857
|
+
};
|
11858
|
+
|
11859
|
+
const escapeRegex = function(string) {
|
11860
|
+
return string.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
11861
|
+
};
|
11862
|
+
|
11863
|
+
const amsRegex = /^\\(?:begin|(?:eq)?ref){/;
|
11864
|
+
|
11865
|
+
const splitAtDelimiters = function(text, delimiters) {
|
11866
|
+
let index;
|
11867
|
+
const data = [];
|
11868
|
+
|
11869
|
+
const regexLeft = new RegExp(
|
11870
|
+
"(" + delimiters.map((x) => escapeRegex(x.left)).join("|") + ")"
|
11871
|
+
);
|
11872
|
+
|
11873
|
+
while (true) {
|
11874
|
+
index = text.search(regexLeft);
|
11875
|
+
if (index === -1) {
|
11876
|
+
break;
|
11877
|
+
}
|
11878
|
+
if (index > 0) {
|
11879
|
+
data.push({
|
11880
|
+
type: "text",
|
11881
|
+
data: text.slice(0, index)
|
11882
|
+
});
|
11883
|
+
text = text.slice(index); // now text starts with delimiter
|
11884
|
+
}
|
11885
|
+
// ... so this always succeeds:
|
11886
|
+
const i = delimiters.findIndex((delim) => text.startsWith(delim.left));
|
11887
|
+
index = findEndOfMath(delimiters[i].right, text, delimiters[i].left.length);
|
11888
|
+
if (index === -1) {
|
11889
|
+
break;
|
11890
|
+
}
|
11891
|
+
const rawData = text.slice(0, index + delimiters[i].right.length);
|
11892
|
+
const math = amsRegex.test(rawData)
|
11893
|
+
? rawData
|
11894
|
+
: text.slice(delimiters[i].left.length, index);
|
11895
|
+
data.push({
|
11896
|
+
type: "math",
|
11897
|
+
data: math,
|
11898
|
+
rawData,
|
11899
|
+
display: delimiters[i].display
|
11900
|
+
});
|
11901
|
+
text = text.slice(index + delimiters[i].right.length);
|
11902
|
+
}
|
11903
|
+
|
11904
|
+
if (text !== "") {
|
11905
|
+
data.push({
|
11906
|
+
type: "text",
|
11907
|
+
data: text
|
11908
|
+
});
|
11909
|
+
}
|
11910
|
+
|
11911
|
+
return data;
|
11912
|
+
};
|
11913
|
+
|
11914
|
+
const defaultDelimiters = [
|
11915
|
+
{ left: "$$", right: "$$", display: true },
|
11916
|
+
{ left: "\\(", right: "\\)", display: false },
|
11917
|
+
// LaTeX uses $…$, but it ruins the display of normal `$` in text:
|
11918
|
+
// {left: "$", right: "$", display: false},
|
11919
|
+
// $ must come after $$
|
11920
|
+
|
11921
|
+
// Render AMS environments even if outside $$…$$ delimiters.
|
11922
|
+
{ left: "\\begin{equation}", right: "\\end{equation}", display: true },
|
11923
|
+
{ left: "\\begin{equation*}", right: "\\end{equation*}", display: true },
|
11924
|
+
{ left: "\\begin{align}", right: "\\end{align}", display: true },
|
11925
|
+
{ left: "\\begin{align*}", right: "\\end{align*}", display: true },
|
11926
|
+
{ left: "\\begin{alignat}", right: "\\end{alignat}", display: true },
|
11927
|
+
{ left: "\\begin{alignat*}", right: "\\end{alignat*}", display: true },
|
11928
|
+
{ left: "\\begin{gather}", right: "\\end{gather}", display: true },
|
11929
|
+
{ left: "\\begin{gather*}", right: "\\end{gather*}", display: true },
|
11930
|
+
{ left: "\\begin{CD}", right: "\\end{CD}", display: true },
|
11931
|
+
// Ditto \ref & \eqref
|
11932
|
+
{ left: "\\ref{", right: "}", display: false },
|
11933
|
+
{ left: "\\eqref{", right: "}", display: false },
|
11934
|
+
|
11935
|
+
{ left: "\\[", right: "\\]", display: true }
|
11936
|
+
];
|
11937
|
+
|
11938
|
+
const firstDraftDelimiters = {
|
11939
|
+
"$": [
|
11940
|
+
{ left: "$$", right: "$$", display: true },
|
11941
|
+
{ left: "$`", right: "`$", display: false },
|
11942
|
+
{ left: "$", right: "$", display: false }
|
11943
|
+
],
|
11944
|
+
"(": [
|
11945
|
+
{ left: "\\[", right: "\\]", display: true },
|
11946
|
+
{ left: "\\(", right: "\\)", display: false }
|
11947
|
+
]
|
11948
|
+
};
|
11949
|
+
|
11950
|
+
const amsDelimiters = [
|
11951
|
+
{ left: "\\begin{equation}", right: "\\end{equation}", display: true },
|
11952
|
+
{ left: "\\begin{equation*}", right: "\\end{equation*}", display: true },
|
11953
|
+
{ left: "\\begin{align}", right: "\\end{align}", display: true },
|
11954
|
+
{ left: "\\begin{align*}", right: "\\end{align*}", display: true },
|
11955
|
+
{ left: "\\begin{alignat}", right: "\\end{alignat}", display: true },
|
11956
|
+
{ left: "\\begin{alignat*}", right: "\\end{alignat*}", display: true },
|
11957
|
+
{ left: "\\begin{gather}", right: "\\end{gather}", display: true },
|
11958
|
+
{ left: "\\begin{gather*}", right: "\\end{gather*}", display: true },
|
11959
|
+
{ left: "\\begin{CD}", right: "\\end{CD}", display: true },
|
11960
|
+
{ left: "\\ref{", right: "}", display: false },
|
11961
|
+
{ left: "\\eqref{", right: "}", display: false }
|
11962
|
+
];
|
11963
|
+
|
11964
|
+
const delimitersFromKey = key => {
|
11965
|
+
if (key === "$" || key === "(") {
|
11966
|
+
return firstDraftDelimiters[key];
|
11967
|
+
} else if (key === "$+" || key === "(+") {
|
11968
|
+
const firstDraft = firstDraftDelimiters[key.slice(0, 1)];
|
11969
|
+
return firstDraft.concat(amsDelimiters)
|
11970
|
+
} else if (key === "ams") {
|
11971
|
+
return amsDelimiters
|
11972
|
+
} else if (key === "all") {
|
11973
|
+
return (firstDraftDelimiters["("]).concat(firstDraftDelimiters["$"]).concat(amsDelimiters)
|
11974
|
+
} else {
|
11975
|
+
return defaultDelimiters
|
11976
|
+
}
|
11977
|
+
};
|
11978
|
+
|
11979
|
+
/* Note: optionsCopy is mutated by this method. If it is ever exposed in the
|
11980
|
+
* API, we should copy it before mutating.
|
11981
|
+
*/
|
11982
|
+
const renderMathInText = function(text, optionsCopy) {
|
11983
|
+
const data = splitAtDelimiters(text, optionsCopy.delimiters);
|
11984
|
+
if (data.length === 1 && data[0].type === "text") {
|
11985
|
+
// There is no formula in the text.
|
11986
|
+
// Let's return null which means there is no need to replace
|
11987
|
+
// the current text node with a new one.
|
11988
|
+
return null;
|
11989
|
+
}
|
11990
|
+
|
11991
|
+
const fragment = document.createDocumentFragment();
|
11992
|
+
|
11993
|
+
for (let i = 0; i < data.length; i++) {
|
11994
|
+
if (data[i].type === "text") {
|
11995
|
+
fragment.appendChild(document.createTextNode(data[i].data));
|
11996
|
+
} else {
|
11997
|
+
const span = document.createElement("span");
|
11998
|
+
let math = data[i].data;
|
11999
|
+
// Override any display mode defined in the settings with that
|
12000
|
+
// defined by the text itself
|
12001
|
+
optionsCopy.displayMode = data[i].display;
|
12002
|
+
try {
|
12003
|
+
if (optionsCopy.preProcess) {
|
12004
|
+
math = optionsCopy.preProcess(math);
|
12005
|
+
}
|
12006
|
+
// Importing render() from temml.js would be a circular dependency.
|
12007
|
+
// So call the global version.
|
12008
|
+
// eslint-disable-next-line no-undef
|
12009
|
+
temml.render(math, span, optionsCopy);
|
12010
|
+
} catch (e) {
|
12011
|
+
if (!(e instanceof ParseError)) {
|
12012
|
+
throw e;
|
12013
|
+
}
|
12014
|
+
optionsCopy.errorCallback(
|
12015
|
+
"Temml auto-render: Failed to parse `" + data[i].data + "` with ",
|
12016
|
+
e
|
12017
|
+
);
|
12018
|
+
fragment.appendChild(document.createTextNode(data[i].rawData));
|
12019
|
+
continue;
|
12020
|
+
}
|
12021
|
+
fragment.appendChild(span);
|
12022
|
+
}
|
12023
|
+
}
|
12024
|
+
|
12025
|
+
return fragment;
|
12026
|
+
};
|
12027
|
+
|
12028
|
+
const renderElem = function(elem, optionsCopy) {
|
12029
|
+
for (let i = 0; i < elem.childNodes.length; i++) {
|
12030
|
+
const childNode = elem.childNodes[i];
|
12031
|
+
if (childNode.nodeType === 3) {
|
12032
|
+
// Text node
|
12033
|
+
const frag = renderMathInText(childNode.textContent, optionsCopy);
|
12034
|
+
if (frag) {
|
12035
|
+
i += frag.childNodes.length - 1;
|
12036
|
+
elem.replaceChild(frag, childNode);
|
12037
|
+
}
|
12038
|
+
} else if (childNode.nodeType === 1) {
|
12039
|
+
// Element node
|
12040
|
+
const className = " " + childNode.className + " ";
|
12041
|
+
const shouldRender =
|
12042
|
+
optionsCopy.ignoredTags.indexOf(childNode.nodeName.toLowerCase()) === -1 &&
|
12043
|
+
optionsCopy.ignoredClasses.every((x) => className.indexOf(" " + x + " ") === -1);
|
12044
|
+
|
12045
|
+
if (shouldRender) {
|
12046
|
+
renderElem(childNode, optionsCopy);
|
12047
|
+
}
|
12048
|
+
}
|
12049
|
+
// Otherwise, it's something else, and ignore it.
|
12050
|
+
}
|
12051
|
+
};
|
12052
|
+
|
12053
|
+
const renderMathInElement = function(elem, options) {
|
12054
|
+
if (!elem) {
|
12055
|
+
throw new Error("No element provided to render");
|
12056
|
+
}
|
12057
|
+
|
12058
|
+
const optionsCopy = {};
|
12059
|
+
|
12060
|
+
// Object.assign(optionsCopy, option)
|
12061
|
+
for (const option in options) {
|
12062
|
+
if (Object.prototype.hasOwnProperty.call(options, option)) {
|
12063
|
+
optionsCopy[option] = options[option];
|
12064
|
+
}
|
12065
|
+
}
|
12066
|
+
|
12067
|
+
if (optionsCopy.fences) {
|
12068
|
+
optionsCopy.delimiters = delimitersFromKey(optionsCopy.fences);
|
12069
|
+
} else {
|
12070
|
+
optionsCopy.delimiters = optionsCopy.delimiters || defaultDelimiters;
|
12071
|
+
}
|
12072
|
+
optionsCopy.ignoredTags = optionsCopy.ignoredTags || [
|
12073
|
+
"script",
|
12074
|
+
"noscript",
|
12075
|
+
"style",
|
12076
|
+
"textarea",
|
12077
|
+
"pre",
|
12078
|
+
"code",
|
12079
|
+
"option"
|
12080
|
+
];
|
12081
|
+
optionsCopy.ignoredClasses = optionsCopy.ignoredClasses || [];
|
12082
|
+
// eslint-disable-next-line no-console
|
12083
|
+
optionsCopy.errorCallback = optionsCopy.errorCallback || console.error;
|
12084
|
+
|
12085
|
+
// Enable sharing of global macros defined via `\gdef` between different
|
12086
|
+
// math elements within a single call to `renderMathInElement`.
|
12087
|
+
optionsCopy.macros = optionsCopy.macros || {};
|
12088
|
+
|
12089
|
+
renderElem(elem, optionsCopy);
|
12090
|
+
postProcess(elem);
|
12091
|
+
};
|
12092
|
+
|
11766
12093
|
/* eslint no-console:0 */
|
11767
12094
|
/**
|
11768
12095
|
* This is the main entry point for Temml. Here, we expose functions for
|
@@ -11882,7 +12209,7 @@ var temml = (function () {
|
|
11882
12209
|
};
|
11883
12210
|
|
11884
12211
|
/** @type {import('./temml').default} */
|
11885
|
-
var temml = {
|
12212
|
+
var temml$1 = {
|
11886
12213
|
/**
|
11887
12214
|
* Current Temml version
|
11888
12215
|
*/
|
@@ -11897,6 +12224,11 @@ var temml = (function () {
|
|
11897
12224
|
* for sending to the client.
|
11898
12225
|
*/
|
11899
12226
|
renderToString,
|
12227
|
+
/**
|
12228
|
+
* Finds all the math delimiters in a given element of a running HTML document
|
12229
|
+
* and converts the contents of each instance into a <math> element.
|
12230
|
+
*/
|
12231
|
+
renderMathInElement,
|
11900
12232
|
/**
|
11901
12233
|
* Post-process an entire HTML block.
|
11902
12234
|
* Writes AMS auto-numbers and implements \ref{}.
|
@@ -11939,6 +12271,6 @@ var temml = (function () {
|
|
11939
12271
|
__defineMacro: defineMacro
|
11940
12272
|
};
|
11941
12273
|
|
11942
|
-
return temml;
|
12274
|
+
return temml$1;
|
11943
12275
|
|
11944
12276
|
})();
|