katex 0.16.18 → 0.16.20
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/contrib/copy-tex/README.md +2 -2
- 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 +13 -10
- package/dist/katex.min.css +1 -1
- package/dist/katex.min.js +1 -1
- package/dist/katex.mjs +13 -10
- package/package.json +1 -1
- package/src/macros.js +16 -9
- package/types/katex.d.ts +38 -1
package/dist/katex.mjs
CHANGED
|
@@ -15375,7 +15375,7 @@ defineMacro("\\char", function (context) {
|
|
|
15375
15375
|
// \renewcommand{\macro}[args]{definition}
|
|
15376
15376
|
// TODO: Optional arguments: \newcommand{\macro}[args][default]{definition}
|
|
15377
15377
|
|
|
15378
|
-
var newcommand = (context, existsOK, nonexistsOK) => {
|
|
15378
|
+
var newcommand = (context, existsOK, nonexistsOK, skipIfExists) => {
|
|
15379
15379
|
var arg = context.consumeArg().tokens;
|
|
15380
15380
|
|
|
15381
15381
|
if (arg.length !== 1) {
|
|
@@ -15412,19 +15412,22 @@ var newcommand = (context, existsOK, nonexistsOK) => {
|
|
|
15412
15412
|
|
|
15413
15413
|
numArgs = parseInt(argText);
|
|
15414
15414
|
arg = context.consumeArg().tokens;
|
|
15415
|
-
}
|
|
15415
|
+
}
|
|
15416
15416
|
|
|
15417
|
+
if (!(exists && skipIfExists)) {
|
|
15418
|
+
// Final arg is the expansion of the macro
|
|
15419
|
+
context.macros.set(name, {
|
|
15420
|
+
tokens: arg,
|
|
15421
|
+
numArgs
|
|
15422
|
+
});
|
|
15423
|
+
}
|
|
15417
15424
|
|
|
15418
|
-
context.macros.set(name, {
|
|
15419
|
-
tokens: arg,
|
|
15420
|
-
numArgs
|
|
15421
|
-
});
|
|
15422
15425
|
return '';
|
|
15423
15426
|
};
|
|
15424
15427
|
|
|
15425
|
-
defineMacro("\\newcommand", context => newcommand(context, false, true));
|
|
15426
|
-
defineMacro("\\renewcommand", context => newcommand(context, true, false));
|
|
15427
|
-
defineMacro("\\providecommand", context => newcommand(context, true, true)); // terminal (console) tools
|
|
15428
|
+
defineMacro("\\newcommand", context => newcommand(context, false, true, false));
|
|
15429
|
+
defineMacro("\\renewcommand", context => newcommand(context, true, false, false));
|
|
15430
|
+
defineMacro("\\providecommand", context => newcommand(context, true, true, true)); // terminal (console) tools
|
|
15428
15431
|
|
|
15429
15432
|
defineMacro("\\message", context => {
|
|
15430
15433
|
var arg = context.consumeArgs(1)[0]; // eslint-disable-next-line no-console
|
|
@@ -18413,7 +18416,7 @@ var renderToHTMLTree = function renderToHTMLTree(expression, options) {
|
|
|
18413
18416
|
}
|
|
18414
18417
|
};
|
|
18415
18418
|
|
|
18416
|
-
var version = "0.16.
|
|
18419
|
+
var version = "0.16.20";
|
|
18417
18420
|
var __domTree = {
|
|
18418
18421
|
Span,
|
|
18419
18422
|
Anchor,
|
package/package.json
CHANGED
package/src/macros.js
CHANGED
|
@@ -146,7 +146,9 @@ defineMacro("\\char", function(context) {
|
|
|
146
146
|
// \newcommand{\macro}[args]{definition}
|
|
147
147
|
// \renewcommand{\macro}[args]{definition}
|
|
148
148
|
// TODO: Optional arguments: \newcommand{\macro}[args][default]{definition}
|
|
149
|
-
const newcommand = (
|
|
149
|
+
const newcommand = (
|
|
150
|
+
context, existsOK: boolean, nonexistsOK: boolean, skipIfExists: boolean
|
|
151
|
+
) => {
|
|
150
152
|
let arg = context.consumeArg().tokens;
|
|
151
153
|
if (arg.length !== 1) {
|
|
152
154
|
throw new ParseError(
|
|
@@ -181,16 +183,21 @@ const newcommand = (context, existsOK: boolean, nonexistsOK: boolean) => {
|
|
|
181
183
|
arg = context.consumeArg().tokens;
|
|
182
184
|
}
|
|
183
185
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
if (!(exists && skipIfExists)) {
|
|
187
|
+
// Final arg is the expansion of the macro
|
|
188
|
+
context.macros.set(name, {
|
|
189
|
+
tokens: arg,
|
|
190
|
+
numArgs,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
189
193
|
return '';
|
|
190
194
|
};
|
|
191
|
-
defineMacro("\\newcommand",
|
|
192
|
-
|
|
193
|
-
defineMacro("\\
|
|
195
|
+
defineMacro("\\newcommand",
|
|
196
|
+
(context) => newcommand(context, false, true, false));
|
|
197
|
+
defineMacro("\\renewcommand",
|
|
198
|
+
(context) => newcommand(context, true, false, false));
|
|
199
|
+
defineMacro("\\providecommand",
|
|
200
|
+
(context) => newcommand(context, true, true, true));
|
|
194
201
|
|
|
195
202
|
// terminal (console) tools
|
|
196
203
|
defineMacro("\\message", (context) => {
|
package/types/katex.d.ts
CHANGED
|
@@ -20,6 +20,43 @@ export type TrustContext =
|
|
|
20
20
|
| { command: "\\htmlStyle", style: string }
|
|
21
21
|
| { command: "\\htmlData", attributes: Record<string, string> }
|
|
22
22
|
|
|
23
|
+
|
|
24
|
+
export type Catcodes = Record<string, number>;
|
|
25
|
+
|
|
26
|
+
export interface Lexer {
|
|
27
|
+
input: string;
|
|
28
|
+
tokenRegex: RegExp;
|
|
29
|
+
settings: Required<KatexOptions>;
|
|
30
|
+
catcodes: Catcodes;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface SourceLocation {
|
|
34
|
+
start: number;
|
|
35
|
+
end: number;
|
|
36
|
+
lexer: Lexer;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface Token {
|
|
40
|
+
text: string;
|
|
41
|
+
loc: SourceLocation | undefined;
|
|
42
|
+
noexpand?: boolean;
|
|
43
|
+
treatAsRelax?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
export type StrictFunction = (
|
|
48
|
+
errorCode:
|
|
49
|
+
| "unknownSymbol"
|
|
50
|
+
| "unicodeTextInMathMode"
|
|
51
|
+
| "mathVsTextUnits"
|
|
52
|
+
| "commentAtEnd"
|
|
53
|
+
| "htmlExtension"
|
|
54
|
+
| "newLineInDisplayMode",
|
|
55
|
+
errorMsg: string,
|
|
56
|
+
token: Token,
|
|
57
|
+
) => boolean | "error" | "warn" | "ignore" | undefined;
|
|
58
|
+
|
|
59
|
+
|
|
23
60
|
/**
|
|
24
61
|
* Options for `katex.render` and `katex.renderToString`.
|
|
25
62
|
* @see https://katex.org/docs/options
|
|
@@ -133,7 +170,7 @@ export interface KatexOptions {
|
|
|
133
170
|
strict?:
|
|
134
171
|
| boolean
|
|
135
172
|
| "ignore" | "warn" | "error"
|
|
136
|
-
|
|
|
173
|
+
| StrictFunction;
|
|
137
174
|
/**
|
|
138
175
|
* If `false` (do not trust input), prevent any commands like
|
|
139
176
|
* `\includegraphics` that could enable adverse behavior, rendering them
|