katex 0.13.24 → 0.15.1
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 +3 -3
- package/cli.js +17 -46
- package/contrib/copy-tex/README.md +3 -3
- package/contrib/mathtex-script-type/README.md +5 -5
- package/contrib/mhchem/README.md +1 -1
- package/dist/README.md +3 -3
- package/dist/katex.css +1 -1
- package/dist/katex.js +380 -153
- package/dist/katex.min.css +1 -1
- package/dist/katex.min.js +1 -1
- package/dist/katex.mjs +276 -62
- package/katex.js +5 -1
- package/package.json +28 -1
- package/src/MacroExpander.js +3 -7
- package/src/Namespace.js +9 -4
- package/src/Parser.js +21 -0
- package/src/Settings.js +183 -32
- package/src/environments/array.js +72 -18
- package/src/functions/relax.js +17 -0
- package/src/functions.js +1 -0
- package/src/macros.js +1 -1
- package/src/parseNode.js +2 -1
- package/src/parseTree.js +2 -2
package/dist/katex.mjs
CHANGED
|
@@ -260,7 +260,126 @@ var utils = {
|
|
|
260
260
|
};
|
|
261
261
|
|
|
262
262
|
/* eslint no-console:0 */
|
|
263
|
+
// TODO: automatically generate documentation
|
|
264
|
+
// TODO: check all properties on Settings exist
|
|
265
|
+
// TODO: check the type of a property on Settings matches
|
|
266
|
+
var SETTINGS_SCHEMA = {
|
|
267
|
+
displayMode: {
|
|
268
|
+
type: "boolean",
|
|
269
|
+
description: "Render math in display mode, which puts the math in " + "display style (so \\int and \\sum are large, for example), and " + "centers the math on the page on its own line.",
|
|
270
|
+
cli: "-d, --display-mode"
|
|
271
|
+
},
|
|
272
|
+
output: {
|
|
273
|
+
type: {
|
|
274
|
+
enum: ["htmlAndMathml", "html", "mathml"]
|
|
275
|
+
},
|
|
276
|
+
description: "Determines the markup language of the output.",
|
|
277
|
+
cli: "-F, --format <type>"
|
|
278
|
+
},
|
|
279
|
+
leqno: {
|
|
280
|
+
type: "boolean",
|
|
281
|
+
description: "Render display math in leqno style (left-justified tags)."
|
|
282
|
+
},
|
|
283
|
+
fleqn: {
|
|
284
|
+
type: "boolean",
|
|
285
|
+
description: "Render display math flush left."
|
|
286
|
+
},
|
|
287
|
+
throwOnError: {
|
|
288
|
+
type: "boolean",
|
|
289
|
+
default: true,
|
|
290
|
+
cli: "-t, --no-throw-on-error",
|
|
291
|
+
cliDescription: "Render errors (in the color given by --error-color) ins" + "tead of throwing a ParseError exception when encountering an error."
|
|
292
|
+
},
|
|
293
|
+
errorColor: {
|
|
294
|
+
type: "string",
|
|
295
|
+
default: "#cc0000",
|
|
296
|
+
cli: "-c, --error-color <color>",
|
|
297
|
+
cliDescription: "A color string given in the format 'rgb' or 'rrggbb' " + "(no #). This option determines the color of errors rendered by the " + "-t option.",
|
|
298
|
+
cliProcessor: color => "#" + color
|
|
299
|
+
},
|
|
300
|
+
macros: {
|
|
301
|
+
type: "object",
|
|
302
|
+
cli: "-m, --macro <def>",
|
|
303
|
+
cliDescription: "Define custom macro of the form '\\foo:expansion' (use " + "multiple -m arguments for multiple macros).",
|
|
304
|
+
cliDefault: [],
|
|
305
|
+
cliProcessor: (def, defs) => {
|
|
306
|
+
defs.push(def);
|
|
307
|
+
return defs;
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
minRuleThickness: {
|
|
311
|
+
type: "number",
|
|
312
|
+
description: "Specifies a minimum thickness, in ems, for fraction lines," + " `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, " + "`\\hdashline`, `\\underline`, `\\overline`, and the borders of " + "`\\fbox`, `\\boxed`, and `\\fcolorbox`.",
|
|
313
|
+
processor: t => Math.max(0, t),
|
|
314
|
+
cli: "--min-rule-thickness <size>",
|
|
315
|
+
cliProcessor: parseFloat
|
|
316
|
+
},
|
|
317
|
+
colorIsTextColor: {
|
|
318
|
+
type: "boolean",
|
|
319
|
+
description: "Makes \\color behave like LaTeX's 2-argument \\textcolor, " + "instead of LaTeX's one-argument \\color mode change.",
|
|
320
|
+
cli: "-b, --color-is-text-color"
|
|
321
|
+
},
|
|
322
|
+
strict: {
|
|
323
|
+
type: [{
|
|
324
|
+
enum: ["warn", "ignore", "error"]
|
|
325
|
+
}, "boolean", "function"],
|
|
326
|
+
description: "Turn on strict / LaTeX faithfulness mode, which throws an " + "error if the input uses features that are not supported by LaTeX.",
|
|
327
|
+
cli: "-S, --strict",
|
|
328
|
+
cliDefault: false
|
|
329
|
+
},
|
|
330
|
+
trust: {
|
|
331
|
+
type: ["boolean", "function"],
|
|
332
|
+
description: "Trust the input, enabling all HTML features such as \\url.",
|
|
333
|
+
cli: "-T, --trust"
|
|
334
|
+
},
|
|
335
|
+
maxSize: {
|
|
336
|
+
type: "number",
|
|
337
|
+
default: Infinity,
|
|
338
|
+
description: "If non-zero, all user-specified sizes, e.g. in " + "\\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, " + "elements and spaces can be arbitrarily large",
|
|
339
|
+
processor: s => Math.max(0, s),
|
|
340
|
+
cli: "-s, --max-size <n>",
|
|
341
|
+
cliProcessor: parseInt
|
|
342
|
+
},
|
|
343
|
+
maxExpand: {
|
|
344
|
+
type: "number",
|
|
345
|
+
default: 1000,
|
|
346
|
+
description: "Limit the number of macro expansions to the specified " + "number, to prevent e.g. infinite macro loops. If set to Infinity, " + "the macro expander will try to fully expand as in LaTeX.",
|
|
347
|
+
processor: n => Math.max(0, n),
|
|
348
|
+
cli: "-e, --max-expand <n>",
|
|
349
|
+
cliProcessor: n => n === "Infinity" ? Infinity : parseInt(n)
|
|
350
|
+
},
|
|
351
|
+
globalGroup: {
|
|
352
|
+
type: "boolean",
|
|
353
|
+
cli: false
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
function getDefaultValue(schema) {
|
|
358
|
+
if (schema.default) {
|
|
359
|
+
return schema.default;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
var type = schema.type;
|
|
363
|
+
var defaultType = Array.isArray(type) ? type[0] : type;
|
|
364
|
+
|
|
365
|
+
if (typeof defaultType !== 'string') {
|
|
366
|
+
return defaultType.enum[0];
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
switch (defaultType) {
|
|
370
|
+
case 'boolean':
|
|
371
|
+
return false;
|
|
372
|
+
|
|
373
|
+
case 'string':
|
|
374
|
+
return '';
|
|
263
375
|
|
|
376
|
+
case 'number':
|
|
377
|
+
return 0;
|
|
378
|
+
|
|
379
|
+
case 'object':
|
|
380
|
+
return {};
|
|
381
|
+
}
|
|
382
|
+
}
|
|
264
383
|
/**
|
|
265
384
|
* The main Settings object
|
|
266
385
|
*
|
|
@@ -271,6 +390,8 @@ var utils = {
|
|
|
271
390
|
* math (true), meaning that the math starts in \displaystyle
|
|
272
391
|
* and is placed in a block with vertical margin.
|
|
273
392
|
*/
|
|
393
|
+
|
|
394
|
+
|
|
274
395
|
class Settings {
|
|
275
396
|
constructor(options) {
|
|
276
397
|
this.displayMode = void 0;
|
|
@@ -289,20 +410,16 @@ class Settings {
|
|
|
289
410
|
this.globalGroup = void 0;
|
|
290
411
|
// allow null options
|
|
291
412
|
options = options || {};
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
this.trust = utils.deflt(options.trust, false);
|
|
303
|
-
this.maxSize = Math.max(0, utils.deflt(options.maxSize, Infinity));
|
|
304
|
-
this.maxExpand = Math.max(0, utils.deflt(options.maxExpand, 1000));
|
|
305
|
-
this.globalGroup = utils.deflt(options.globalGroup, false);
|
|
413
|
+
|
|
414
|
+
for (var prop in SETTINGS_SCHEMA) {
|
|
415
|
+
if (SETTINGS_SCHEMA.hasOwnProperty(prop)) {
|
|
416
|
+
// $FlowFixMe
|
|
417
|
+
var schema = SETTINGS_SCHEMA[prop]; // TODO: validate options
|
|
418
|
+
// $FlowFixMe
|
|
419
|
+
|
|
420
|
+
this[prop] = options[prop] !== undefined ? schema.processor ? schema.processor(options[prop]) : options[prop] : getDefaultValue(schema);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
306
423
|
}
|
|
307
424
|
/**
|
|
308
425
|
* Report nonstrict (non-LaTeX-compatible) input.
|
|
@@ -9866,6 +9983,17 @@ function defineEnvironment(_ref) {
|
|
|
9866
9983
|
}
|
|
9867
9984
|
}
|
|
9868
9985
|
|
|
9986
|
+
/**
|
|
9987
|
+
* All registered global/built-in macros.
|
|
9988
|
+
* `macros.js` exports this same dictionary again and makes it public.
|
|
9989
|
+
* `Parser.js` requires this dictionary via `macros.js`.
|
|
9990
|
+
*/
|
|
9991
|
+
var _macros = {}; // This function might one day accept an additional argument and do more things.
|
|
9992
|
+
|
|
9993
|
+
function defineMacro(name, body) {
|
|
9994
|
+
_macros[name] = body;
|
|
9995
|
+
}
|
|
9996
|
+
|
|
9869
9997
|
// Helper functions
|
|
9870
9998
|
function getHLines(parser) {
|
|
9871
9999
|
// Return an array. The array length = number of hlines.
|
|
@@ -9890,7 +10018,19 @@ var validateAmsEnvironmentContext = context => {
|
|
|
9890
10018
|
if (!settings.displayMode) {
|
|
9891
10019
|
throw new ParseError("{" + context.envName + "} can be used only in" + " display mode.");
|
|
9892
10020
|
}
|
|
9893
|
-
};
|
|
10021
|
+
}; // autoTag (an argument to parseArray) can be one of three values:
|
|
10022
|
+
// * undefined: Regular (not-top-level) array; no tags on each row
|
|
10023
|
+
// * true: Automatic equation numbering, overridable by \tag
|
|
10024
|
+
// * false: Tags allowed on each row, but no automatic numbering
|
|
10025
|
+
// This function *doesn't* work with the "split" environment name.
|
|
10026
|
+
|
|
10027
|
+
|
|
10028
|
+
function getAutoTag(name) {
|
|
10029
|
+
if (name.indexOf("ed") === -1) {
|
|
10030
|
+
return name.indexOf("*") === -1;
|
|
10031
|
+
} // return undefined;
|
|
10032
|
+
|
|
10033
|
+
}
|
|
9894
10034
|
/**
|
|
9895
10035
|
* Parse the body of the environment, with rows delimited by \\ and
|
|
9896
10036
|
* columns delimited by &, and create a nested list in row-major order
|
|
@@ -9906,7 +10046,7 @@ function parseArray(parser, _ref, style) {
|
|
|
9906
10046
|
cols,
|
|
9907
10047
|
arraystretch,
|
|
9908
10048
|
colSeparationType,
|
|
9909
|
-
|
|
10049
|
+
autoTag,
|
|
9910
10050
|
singleRow,
|
|
9911
10051
|
emptySingleRow,
|
|
9912
10052
|
maxNumCols,
|
|
@@ -9941,7 +10081,29 @@ function parseArray(parser, _ref, style) {
|
|
|
9941
10081
|
var row = [];
|
|
9942
10082
|
var body = [row];
|
|
9943
10083
|
var rowGaps = [];
|
|
9944
|
-
var hLinesBeforeRow = [];
|
|
10084
|
+
var hLinesBeforeRow = [];
|
|
10085
|
+
var tags = autoTag != null ? [] : undefined; // amsmath uses \global\@eqnswtrue and \global\@eqnswfalse to represent
|
|
10086
|
+
// whether this row should have an equation number. Simulate this with
|
|
10087
|
+
// a \@eqnsw macro set to 1 or 0.
|
|
10088
|
+
|
|
10089
|
+
function beginRow() {
|
|
10090
|
+
if (autoTag) {
|
|
10091
|
+
parser.gullet.macros.set("\\@eqnsw", "1", true);
|
|
10092
|
+
}
|
|
10093
|
+
}
|
|
10094
|
+
|
|
10095
|
+
function endRow() {
|
|
10096
|
+
if (tags) {
|
|
10097
|
+
if (parser.gullet.macros.get("\\df@tag")) {
|
|
10098
|
+
tags.push(parser.subparse([new Token("\\df@tag")]));
|
|
10099
|
+
parser.gullet.macros.set("\\df@tag", undefined, true);
|
|
10100
|
+
} else {
|
|
10101
|
+
tags.push(Boolean(autoTag) && parser.gullet.macros.get("\\@eqnsw") === "1");
|
|
10102
|
+
}
|
|
10103
|
+
}
|
|
10104
|
+
}
|
|
10105
|
+
|
|
10106
|
+
beginRow(); // Test for \hline at the top of the array.
|
|
9945
10107
|
|
|
9946
10108
|
hLinesBeforeRow.push(getHLines(parser));
|
|
9947
10109
|
|
|
@@ -9982,10 +10144,11 @@ function parseArray(parser, _ref, style) {
|
|
|
9982
10144
|
|
|
9983
10145
|
parser.consume();
|
|
9984
10146
|
} else if (next === "\\end") {
|
|
9985
|
-
// Arrays terminate newlines with `\crcr` which consumes a `\cr` if
|
|
10147
|
+
endRow(); // Arrays terminate newlines with `\crcr` which consumes a `\cr` if
|
|
9986
10148
|
// the last line is empty. However, AMS environments keep the
|
|
9987
10149
|
// empty row if it's the only one.
|
|
9988
10150
|
// NOTE: Currently, `cell` is the last item added into `row`.
|
|
10151
|
+
|
|
9989
10152
|
if (row.length === 1 && cell.type === "styling" && cell.body[0].body.length === 0 && (body.length > 1 || !emptySingleRow)) {
|
|
9990
10153
|
body.pop();
|
|
9991
10154
|
}
|
|
@@ -10007,11 +10170,13 @@ function parseArray(parser, _ref, style) {
|
|
|
10007
10170
|
size = parser.parseSizeGroup(true);
|
|
10008
10171
|
}
|
|
10009
10172
|
|
|
10010
|
-
rowGaps.push(size ? size.value : null);
|
|
10173
|
+
rowGaps.push(size ? size.value : null);
|
|
10174
|
+
endRow(); // check for \hline(s) following the row separator
|
|
10011
10175
|
|
|
10012
10176
|
hLinesBeforeRow.push(getHLines(parser));
|
|
10013
10177
|
row = [];
|
|
10014
10178
|
body.push(row);
|
|
10179
|
+
beginRow();
|
|
10015
10180
|
} else {
|
|
10016
10181
|
throw new ParseError("Expected & or \\\\ or \\cr or \\end", parser.nextToken);
|
|
10017
10182
|
}
|
|
@@ -10032,7 +10197,7 @@ function parseArray(parser, _ref, style) {
|
|
|
10032
10197
|
hskipBeforeAndAfter,
|
|
10033
10198
|
hLinesBeforeRow,
|
|
10034
10199
|
colSeparationType,
|
|
10035
|
-
|
|
10200
|
+
tags,
|
|
10036
10201
|
leqno
|
|
10037
10202
|
};
|
|
10038
10203
|
} // Decides on a style for cells in an array according to whether the given
|
|
@@ -10170,20 +10335,33 @@ var htmlBuilder$7 = function htmlBuilder(group, options) {
|
|
|
10170
10335
|
var cols = [];
|
|
10171
10336
|
var colSep;
|
|
10172
10337
|
var colDescrNum;
|
|
10173
|
-
var
|
|
10338
|
+
var tagSpans = [];
|
|
10174
10339
|
|
|
10175
|
-
if (group.
|
|
10176
|
-
// An environment with automatic equation numbers.
|
|
10177
|
-
// Create node(s)
|
|
10340
|
+
if (group.tags && group.tags.some(tag => tag)) {
|
|
10341
|
+
// An environment with manual tags and/or automatic equation numbers.
|
|
10342
|
+
// Create node(s), the latter of which trigger CSS counter increment.
|
|
10178
10343
|
for (r = 0; r < nr; ++r) {
|
|
10179
10344
|
var rw = body[r];
|
|
10180
10345
|
var shift = rw.pos - offset;
|
|
10181
|
-
var
|
|
10182
|
-
|
|
10183
|
-
|
|
10184
|
-
|
|
10346
|
+
var tag = group.tags[r];
|
|
10347
|
+
var tagSpan = void 0;
|
|
10348
|
+
|
|
10349
|
+
if (tag === true) {
|
|
10350
|
+
// automatic numbering
|
|
10351
|
+
tagSpan = buildCommon.makeSpan(["eqn-num"], [], options);
|
|
10352
|
+
} else if (tag === false) {
|
|
10353
|
+
// \nonumber/\notag or starred environment
|
|
10354
|
+
tagSpan = buildCommon.makeSpan([], [], options);
|
|
10355
|
+
} else {
|
|
10356
|
+
// manual \tag
|
|
10357
|
+
tagSpan = buildCommon.makeSpan([], buildExpression$1(tag, options, true), options);
|
|
10358
|
+
}
|
|
10359
|
+
|
|
10360
|
+
tagSpan.depth = rw.depth;
|
|
10361
|
+
tagSpan.height = rw.height;
|
|
10362
|
+
tagSpans.push({
|
|
10185
10363
|
type: "elem",
|
|
10186
|
-
elem:
|
|
10364
|
+
elem: tagSpan,
|
|
10187
10365
|
shift
|
|
10188
10366
|
});
|
|
10189
10367
|
}
|
|
@@ -10319,12 +10497,12 @@ var htmlBuilder$7 = function htmlBuilder(group, options) {
|
|
|
10319
10497
|
}, options);
|
|
10320
10498
|
}
|
|
10321
10499
|
|
|
10322
|
-
if (
|
|
10500
|
+
if (tagSpans.length === 0) {
|
|
10323
10501
|
return buildCommon.makeSpan(["mord"], [body], options);
|
|
10324
10502
|
} else {
|
|
10325
10503
|
var eqnNumCol = buildCommon.makeVList({
|
|
10326
10504
|
positionType: "individualShift",
|
|
10327
|
-
children:
|
|
10505
|
+
children: tagSpans
|
|
10328
10506
|
}, options);
|
|
10329
10507
|
eqnNumCol = buildCommon.makeSpan(["tag"], [eqnNumCol], options);
|
|
10330
10508
|
return buildCommon.makeFragment([body, eqnNumCol]);
|
|
@@ -10350,7 +10528,7 @@ var mathmlBuilder$6 = function mathmlBuilder(group, options) {
|
|
|
10350
10528
|
row.push(new mathMLTree.MathNode("mtd", [buildGroup(rw[j], options)]));
|
|
10351
10529
|
}
|
|
10352
10530
|
|
|
10353
|
-
if (group.
|
|
10531
|
+
if (group.tags && group.tags[i]) {
|
|
10354
10532
|
row.unshift(glue);
|
|
10355
10533
|
row.push(glue);
|
|
10356
10534
|
|
|
@@ -10485,13 +10663,14 @@ var alignedHandler = function alignedHandler(context, args) {
|
|
|
10485
10663
|
|
|
10486
10664
|
var cols = [];
|
|
10487
10665
|
var separationType = context.envName.indexOf("at") > -1 ? "alignat" : "align";
|
|
10666
|
+
var isSplit = context.envName === "split";
|
|
10488
10667
|
var res = parseArray(context.parser, {
|
|
10489
10668
|
cols,
|
|
10490
10669
|
addJot: true,
|
|
10491
|
-
|
|
10670
|
+
autoTag: isSplit ? undefined : getAutoTag(context.envName),
|
|
10492
10671
|
emptySingleRow: true,
|
|
10493
10672
|
colSeparationType: separationType,
|
|
10494
|
-
maxNumCols:
|
|
10673
|
+
maxNumCols: isSplit ? 2 : undefined,
|
|
10495
10674
|
leqno: context.parser.settings.leqno
|
|
10496
10675
|
}, "display"); // Determining number of columns.
|
|
10497
10676
|
// 1. If the first argument is given, we use it as a number of columns,
|
|
@@ -10851,7 +11030,7 @@ defineEnvironment({
|
|
|
10851
11030
|
}],
|
|
10852
11031
|
addJot: true,
|
|
10853
11032
|
colSeparationType: "gather",
|
|
10854
|
-
|
|
11033
|
+
autoTag: getAutoTag(context.envName),
|
|
10855
11034
|
emptySingleRow: true,
|
|
10856
11035
|
leqno: context.parser.settings.leqno
|
|
10857
11036
|
};
|
|
@@ -10884,7 +11063,7 @@ defineEnvironment({
|
|
|
10884
11063
|
handler(context) {
|
|
10885
11064
|
validateAmsEnvironmentContext(context);
|
|
10886
11065
|
var res = {
|
|
10887
|
-
|
|
11066
|
+
autoTag: getAutoTag(context.envName),
|
|
10888
11067
|
emptySingleRow: true,
|
|
10889
11068
|
singleRow: true,
|
|
10890
11069
|
maxNumCols: 1,
|
|
@@ -10910,7 +11089,9 @@ defineEnvironment({
|
|
|
10910
11089
|
|
|
10911
11090
|
htmlBuilder: htmlBuilder$7,
|
|
10912
11091
|
mathmlBuilder: mathmlBuilder$6
|
|
10913
|
-
});
|
|
11092
|
+
});
|
|
11093
|
+
defineMacro("\\nonumber", "\\gdef\\@eqnsw{0}");
|
|
11094
|
+
defineMacro("\\notag", "\\nonumber"); // Catch \hline outside array environment
|
|
10914
11095
|
|
|
10915
11096
|
defineFunction({
|
|
10916
11097
|
type: "text",
|
|
@@ -13036,17 +13217,6 @@ defineFunction({
|
|
|
13036
13217
|
mathmlBuilder: mathmlBuilder$1
|
|
13037
13218
|
});
|
|
13038
13219
|
|
|
13039
|
-
/**
|
|
13040
|
-
* All registered global/built-in macros.
|
|
13041
|
-
* `macros.js` exports this same dictionary again and makes it public.
|
|
13042
|
-
* `Parser.js` requires this dictionary via `macros.js`.
|
|
13043
|
-
*/
|
|
13044
|
-
var _macros = {}; // This function might one day accept an additional argument and do more things.
|
|
13045
|
-
|
|
13046
|
-
function defineMacro(name, body) {
|
|
13047
|
-
_macros[name] = body;
|
|
13048
|
-
}
|
|
13049
|
-
|
|
13050
13220
|
// NOTE: Unlike most `htmlBuilder`s, this one handles not only
|
|
13051
13221
|
// "operatorname", but also "supsub" since \operatorname* can
|
|
13052
13222
|
// affect super/subscripting.
|
|
@@ -13427,6 +13597,26 @@ defineFunction({
|
|
|
13427
13597
|
|
|
13428
13598
|
});
|
|
13429
13599
|
|
|
13600
|
+
defineFunction({
|
|
13601
|
+
type: "internal",
|
|
13602
|
+
names: ["\\relax"],
|
|
13603
|
+
props: {
|
|
13604
|
+
numArgs: 0,
|
|
13605
|
+
allowedInText: true
|
|
13606
|
+
},
|
|
13607
|
+
|
|
13608
|
+
handler(_ref) {
|
|
13609
|
+
var {
|
|
13610
|
+
parser
|
|
13611
|
+
} = _ref;
|
|
13612
|
+
return {
|
|
13613
|
+
type: "internal",
|
|
13614
|
+
mode: parser.mode
|
|
13615
|
+
};
|
|
13616
|
+
}
|
|
13617
|
+
|
|
13618
|
+
});
|
|
13619
|
+
|
|
13430
13620
|
defineFunction({
|
|
13431
13621
|
type: "rule",
|
|
13432
13622
|
names: ["\\rule"],
|
|
@@ -14675,7 +14865,7 @@ class Namespace {
|
|
|
14675
14865
|
|
|
14676
14866
|
for (var undef in undefs) {
|
|
14677
14867
|
if (undefs.hasOwnProperty(undef)) {
|
|
14678
|
-
if (undefs[undef]
|
|
14868
|
+
if (undefs[undef] == null) {
|
|
14679
14869
|
delete this.current[undef];
|
|
14680
14870
|
} else {
|
|
14681
14871
|
this.current[undef] = undefs[undef];
|
|
@@ -14725,6 +14915,7 @@ class Namespace {
|
|
|
14725
14915
|
* Local set() sets the current value and (when appropriate) adds an undo
|
|
14726
14916
|
* operation to the undo stack. Global set() may change the undo
|
|
14727
14917
|
* operation at every level, so takes time linear in their number.
|
|
14918
|
+
* A value of undefined means to delete existing definitions.
|
|
14728
14919
|
*/
|
|
14729
14920
|
|
|
14730
14921
|
|
|
@@ -14756,7 +14947,11 @@ class Namespace {
|
|
|
14756
14947
|
}
|
|
14757
14948
|
}
|
|
14758
14949
|
|
|
14759
|
-
|
|
14950
|
+
if (value == null) {
|
|
14951
|
+
delete this.current[name];
|
|
14952
|
+
} else {
|
|
14953
|
+
this.current[name] = value;
|
|
14954
|
+
}
|
|
14760
14955
|
}
|
|
14761
14956
|
|
|
14762
14957
|
}
|
|
@@ -15132,7 +15327,7 @@ defineMacro("\\varOmega", "\\mathit{\\Omega}"); //\newcommand{\substack}[1]{\sub
|
|
|
15132
15327
|
defineMacro("\\substack", "\\begin{subarray}{c}#1\\end{subarray}"); // \renewcommand{\colon}{\nobreak\mskip2mu\mathpunct{}\nonscript
|
|
15133
15328
|
// \mkern-\thinmuskip{:}\mskip6muplus1mu\relax}
|
|
15134
15329
|
|
|
15135
|
-
defineMacro("\\colon", "\\nobreak\\mskip2mu\\mathpunct{}" + "\\mathchoice{\\mkern-3mu}{\\mkern-3mu}{}{}{:}\\mskip6mu"); // \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}
|
|
15330
|
+
defineMacro("\\colon", "\\nobreak\\mskip2mu\\mathpunct{}" + "\\mathchoice{\\mkern-3mu}{\\mkern-3mu}{}{}{:}\\mskip6mu\\relax"); // \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}
|
|
15136
15331
|
|
|
15137
15332
|
defineMacro("\\boxed", "\\fbox{$\\displaystyle{#1}$}"); // \def\iff{\DOTSB\;\Longleftrightarrow\;}
|
|
15138
15333
|
// \def\implies{\DOTSB\;\Longrightarrow\;}
|
|
@@ -15659,8 +15854,6 @@ defineMacro("\\kaGreen", "\\textcolor{##71B307}{#1}");
|
|
|
15659
15854
|
// List of commands that act like macros but aren't defined as a macro,
|
|
15660
15855
|
// function, or symbol. Used in `isDefined`.
|
|
15661
15856
|
var implicitCommands = {
|
|
15662
|
-
"\\relax": true,
|
|
15663
|
-
// MacroExpander.js
|
|
15664
15857
|
"^": true,
|
|
15665
15858
|
// Parser.js
|
|
15666
15859
|
"_": true,
|
|
@@ -16024,15 +16217,13 @@ class MacroExpander {
|
|
|
16024
16217
|
var expanded = this.expandOnce(); // expandOnce returns Token if and only if it's fully expanded.
|
|
16025
16218
|
|
|
16026
16219
|
if (expanded instanceof Token) {
|
|
16027
|
-
// \relax stops the expansion, but shouldn't get returned (a
|
|
16028
|
-
// null return value couldn't get implemented as a function).
|
|
16029
16220
|
// the token after \noexpand is interpreted as if its meaning
|
|
16030
16221
|
// were ‘\relax’
|
|
16031
|
-
if (expanded.
|
|
16032
|
-
|
|
16033
|
-
} else {
|
|
16034
|
-
return this.stack.pop(); // === expanded
|
|
16222
|
+
if (expanded.treatAsRelax) {
|
|
16223
|
+
expanded.text = "\\relax";
|
|
16035
16224
|
}
|
|
16225
|
+
|
|
16226
|
+
return this.stack.pop(); // === expanded
|
|
16036
16227
|
}
|
|
16037
16228
|
} // Flow unable to figure out that this pathway is impossible.
|
|
16038
16229
|
// https://github.com/facebook/flow/issues/4808
|
|
@@ -16698,6 +16889,25 @@ class Parser {
|
|
|
16698
16889
|
this.gullet.endGroups();
|
|
16699
16890
|
}
|
|
16700
16891
|
}
|
|
16892
|
+
/**
|
|
16893
|
+
* Fully parse a separate sequence of tokens as a separate job.
|
|
16894
|
+
* Tokens should be specified in reverse order, as in a MacroDefinition.
|
|
16895
|
+
*/
|
|
16896
|
+
|
|
16897
|
+
|
|
16898
|
+
subparse(tokens) {
|
|
16899
|
+
// Save the next token from the current job.
|
|
16900
|
+
var oldToken = this.nextToken;
|
|
16901
|
+
this.consume(); // Run the new job, terminating it with an excess '}'
|
|
16902
|
+
|
|
16903
|
+
this.gullet.pushToken(new Token("}"));
|
|
16904
|
+
this.gullet.pushTokens(tokens);
|
|
16905
|
+
var parse = this.parseExpression(false);
|
|
16906
|
+
this.expect("}"); // Restore the next token from the current job.
|
|
16907
|
+
|
|
16908
|
+
this.nextToken = oldToken;
|
|
16909
|
+
return parse;
|
|
16910
|
+
}
|
|
16701
16911
|
|
|
16702
16912
|
/**
|
|
16703
16913
|
* Parses an "expression", which is a list of atoms.
|
|
@@ -17639,12 +17849,11 @@ var parseTree = function parseTree(toParse, settings) {
|
|
|
17639
17849
|
throw new ParseError("\\tag works only in display equations");
|
|
17640
17850
|
}
|
|
17641
17851
|
|
|
17642
|
-
parser.gullet.feed("\\df@tag");
|
|
17643
17852
|
tree = [{
|
|
17644
17853
|
type: "tag",
|
|
17645
17854
|
mode: "text",
|
|
17646
17855
|
body: tree,
|
|
17647
|
-
tag: parser.
|
|
17856
|
+
tag: parser.subparse([new Token("\\df@tag")])
|
|
17648
17857
|
}];
|
|
17649
17858
|
}
|
|
17650
17859
|
|
|
@@ -17746,7 +17955,7 @@ var katex = {
|
|
|
17746
17955
|
/**
|
|
17747
17956
|
* Current KaTeX version
|
|
17748
17957
|
*/
|
|
17749
|
-
version: "0.
|
|
17958
|
+
version: "0.15.1",
|
|
17750
17959
|
|
|
17751
17960
|
/**
|
|
17752
17961
|
* Renders the given LaTeX into an HTML+MathML combination, and adds
|
|
@@ -17765,6 +17974,11 @@ var katex = {
|
|
|
17765
17974
|
*/
|
|
17766
17975
|
ParseError,
|
|
17767
17976
|
|
|
17977
|
+
/**
|
|
17978
|
+
* The shema of Settings
|
|
17979
|
+
*/
|
|
17980
|
+
SETTINGS_SCHEMA,
|
|
17981
|
+
|
|
17768
17982
|
/**
|
|
17769
17983
|
* Parses the given LaTeX into KaTeX's internal parse tree structure,
|
|
17770
17984
|
* without rendering to HTML or MathML.
|
package/katex.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import ParseError from "./src/ParseError";
|
|
12
|
-
import Settings from "./src/Settings";
|
|
12
|
+
import Settings, {SETTINGS_SCHEMA} from "./src/Settings";
|
|
13
13
|
|
|
14
14
|
import {buildTree, buildHTMLTree} from "./src/buildTree";
|
|
15
15
|
import parseTree from "./src/parseTree";
|
|
@@ -156,6 +156,10 @@ export default {
|
|
|
156
156
|
* KaTeX error, usually during parsing.
|
|
157
157
|
*/
|
|
158
158
|
ParseError,
|
|
159
|
+
/**
|
|
160
|
+
* The shema of Settings
|
|
161
|
+
*/
|
|
162
|
+
SETTINGS_SCHEMA,
|
|
159
163
|
/**
|
|
160
164
|
* Parses the given LaTeX into KaTeX's internal parse tree structure,
|
|
161
165
|
* without rendering to HTML or MathML.
|
package/package.json
CHANGED
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "katex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.1",
|
|
4
4
|
"description": "Fast math typesetting for the web.",
|
|
5
5
|
"main": "dist/katex.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"require": "./dist/katex.js",
|
|
9
|
+
"import": "./dist/katex.mjs"
|
|
10
|
+
},
|
|
11
|
+
"./contrib/auto-render": {
|
|
12
|
+
"require": "./dist/contrib/auto-render.js",
|
|
13
|
+
"import": "./dist/contrib/auto-render.mjs"
|
|
14
|
+
},
|
|
15
|
+
"./contrib/mhchem": {
|
|
16
|
+
"require": "./dist/contrib/mhchem.js",
|
|
17
|
+
"import": "./dist/contrib/mhchem.mjs"
|
|
18
|
+
},
|
|
19
|
+
"./contrib/copy-tex": {
|
|
20
|
+
"require": "./dist/contrib/copy-tex.js",
|
|
21
|
+
"import": "./dist/contrib/copy-tex.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./contrib/mathtex-script-type": {
|
|
24
|
+
"require": "./dist/contrib/mathtex-script-type.js",
|
|
25
|
+
"import": "./dist/contrib/mathtex-script-type.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./contrib/render-a11y-string": {
|
|
28
|
+
"require": "./dist/contrib/render-a11y-string.js",
|
|
29
|
+
"import": "./dist/contrib/render-a11y-string.mjs"
|
|
30
|
+
},
|
|
31
|
+
"./*": "./*"
|
|
32
|
+
},
|
|
6
33
|
"homepage": "https://katex.org",
|
|
7
34
|
"repository": {
|
|
8
35
|
"type": "git",
|
package/src/MacroExpander.js
CHANGED
|
@@ -20,7 +20,6 @@ import type Settings from "./Settings";
|
|
|
20
20
|
// List of commands that act like macros but aren't defined as a macro,
|
|
21
21
|
// function, or symbol. Used in `isDefined`.
|
|
22
22
|
export const implicitCommands = {
|
|
23
|
-
"\\relax": true, // MacroExpander.js
|
|
24
23
|
"^": true, // Parser.js
|
|
25
24
|
"_": true, // Parser.js
|
|
26
25
|
"\\limits": true, // Parser.js
|
|
@@ -333,15 +332,12 @@ export default class MacroExpander implements MacroContextInterface {
|
|
|
333
332
|
const expanded = this.expandOnce();
|
|
334
333
|
// expandOnce returns Token if and only if it's fully expanded.
|
|
335
334
|
if (expanded instanceof Token) {
|
|
336
|
-
// \relax stops the expansion, but shouldn't get returned (a
|
|
337
|
-
// null return value couldn't get implemented as a function).
|
|
338
335
|
// the token after \noexpand is interpreted as if its meaning
|
|
339
336
|
// were ‘\relax’
|
|
340
|
-
if (expanded.
|
|
341
|
-
|
|
342
|
-
} else {
|
|
343
|
-
return this.stack.pop(); // === expanded
|
|
337
|
+
if (expanded.treatAsRelax) {
|
|
338
|
+
expanded.text = "\\relax";
|
|
344
339
|
}
|
|
340
|
+
return this.stack.pop(); // === expanded
|
|
345
341
|
}
|
|
346
342
|
}
|
|
347
343
|
|
package/src/Namespace.js
CHANGED
|
@@ -15,7 +15,7 @@ export type Mapping<Value> = {[string]: Value};
|
|
|
15
15
|
export default class Namespace<Value> {
|
|
16
16
|
current: Mapping<Value>;
|
|
17
17
|
builtins: Mapping<Value>;
|
|
18
|
-
undefStack: Mapping
|
|
18
|
+
undefStack: Mapping<?Value>[];
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Both arguments are optional. The first argument is an object of
|
|
@@ -48,7 +48,7 @@ export default class Namespace<Value> {
|
|
|
48
48
|
const undefs = this.undefStack.pop();
|
|
49
49
|
for (const undef in undefs) {
|
|
50
50
|
if (undefs.hasOwnProperty(undef)) {
|
|
51
|
-
if (undefs[undef]
|
|
51
|
+
if (undefs[undef] == null) {
|
|
52
52
|
delete this.current[undef];
|
|
53
53
|
} else {
|
|
54
54
|
this.current[undef] = undefs[undef];
|
|
@@ -97,8 +97,9 @@ export default class Namespace<Value> {
|
|
|
97
97
|
* Local set() sets the current value and (when appropriate) adds an undo
|
|
98
98
|
* operation to the undo stack. Global set() may change the undo
|
|
99
99
|
* operation at every level, so takes time linear in their number.
|
|
100
|
+
* A value of undefined means to delete existing definitions.
|
|
100
101
|
*/
|
|
101
|
-
set(name: string, value: Value, global: boolean = false) {
|
|
102
|
+
set(name: string, value: ?Value, global: boolean = false) {
|
|
102
103
|
if (global) {
|
|
103
104
|
// Global set is equivalent to setting in all groups. Simulate this
|
|
104
105
|
// by destroying any undos currently scheduled for this name,
|
|
@@ -119,6 +120,10 @@ export default class Namespace<Value> {
|
|
|
119
120
|
top[name] = this.current[name];
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
|
-
|
|
123
|
+
if (value == null) {
|
|
124
|
+
delete this.current[name];
|
|
125
|
+
} else {
|
|
126
|
+
this.current[name] = value;
|
|
127
|
+
}
|
|
123
128
|
}
|
|
124
129
|
}
|