katex 0.16.17 → 0.16.19

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/dist/katex.mjs CHANGED
@@ -18413,7 +18413,7 @@ var renderToHTMLTree = function renderToHTMLTree(expression, options) {
18413
18413
  }
18414
18414
  };
18415
18415
 
18416
- var version = "0.16.17";
18416
+ var version = "0.16.19";
18417
18417
  var __domTree = {
18418
18418
  Span,
18419
18419
  Anchor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "katex",
3
- "version": "0.16.17",
3
+ "version": "0.16.19",
4
4
  "description": "Fast math typesetting for the web.",
5
5
  "main": "dist/katex.js",
6
6
  "exports": {
@@ -50,7 +50,8 @@
50
50
  "cli.js",
51
51
  "src/",
52
52
  "contrib/",
53
- "dist/"
53
+ "dist/",
54
+ "types/"
54
55
  ],
55
56
  "license": "MIT",
56
57
  "packageManager": "yarn@4.1.1",
@@ -0,0 +1,258 @@
1
+ // Adapted from
2
+ // - https://katex.org/docs/options
3
+ // - https://katex.org/docs/api
4
+ // - https://katex.org/docs/error
5
+ // for v0.16.11 on 2024/12/01
6
+ // with some references from https://www.npmjs.com/package/@types/katex
7
+
8
+ /**
9
+ * For the `trust` option in `KatexOptions`, a custom function
10
+ * `handler(context)` can be provided to customize behavior depending on the
11
+ * context (command, arguments e.g. a URL, etc.)
12
+ * @see https://katex.org/docs/options
13
+ */
14
+ export type TrustContext =
15
+ | { command: "\\url", url: string, protocol?: string }
16
+ | { command: "\\href", url: string, protocol?: string }
17
+ | { command: "\\includegraphics", url: string, protocol?: string }
18
+ | { command: "\\htmlClass", class: string }
19
+ | { command: "\\htmlId", id: string }
20
+ | { command: "\\htmlStyle", style: string }
21
+ | { command: "\\htmlData", attributes: Record<string, string> }
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
+
60
+ /**
61
+ * Options for `katex.render` and `katex.renderToString`.
62
+ * @see https://katex.org/docs/options
63
+ */
64
+ export interface KatexOptions {
65
+ /**
66
+ * If `true` the math will be rendered in display mode.
67
+ * If `false` the math will be rendered in inline mode.
68
+ * @see https://katex.org/docs/options
69
+ *
70
+ * @default false
71
+ */
72
+ displayMode?: boolean;
73
+ /**
74
+ * Determines the markup language of the output. The valid choices are:
75
+ * - `html`: Outputs KaTeX in HTML only.
76
+ * - `mathml`: Outputs KaTeX in MathML only.
77
+ * - `htmlAndMathml`: Outputs HTML for visual rendering and includes MathML
78
+ * for accessibility.
79
+ *
80
+ * @default "htmlAndMathml"
81
+ */
82
+ output?: "html" | "mathml" | "htmlAndMathml";
83
+ /**
84
+ * If `true`, display math has `\tag`s rendered on the left instead of the
85
+ * right, like `\usepackage[leqno]{amsmath}` in LaTeX.
86
+ *
87
+ * @default false
88
+ */
89
+ leqno?: boolean;
90
+ /**
91
+ * If `true`, display math renders flush left with a `2em` left margin,
92
+ * like `\documentclass[fleqn]` in LaTeX with the `amsmath` package.
93
+ *
94
+ * @default false
95
+ */
96
+ fleqn?: boolean;
97
+ /**
98
+ * If `true`, KaTeX will throw a `ParseError` when it encounters an
99
+ * unsupported command or invalid LaTeX.
100
+ * If `false`, KaTeX will render unsupported commands as text, and render
101
+ * invalid LaTeX as its source code with hover text giving the error, in
102
+ * the color given by `errorColor`.
103
+ *
104
+ * @default true
105
+ */
106
+ throwOnError?: boolean;
107
+ /**
108
+ * A color string given in the format `"#XXX"` or `"#XXXXXX"`. This option
109
+ * determines the color that unsupported commands and invalid LaTeX are
110
+ * rendered in when `throwOnError` is set to `false`.
111
+ *
112
+ * @default "#cc0000"
113
+ */
114
+ errorColor?: string;
115
+ /**
116
+ * A collection of custom macros.
117
+ * @see https://katex.org/docs/options
118
+ */
119
+ macros?: Record<string, string | object | ((macroExpander:object) => string | object)>;
120
+ /**
121
+ * Specifies a minimum thickness, in ems, for fraction lines, `\sqrt` top
122
+ * lines, `{array}` vertical lines, `\hline`, `\hdashline`, `\underline`,
123
+ * `\overline`, and the borders of `\fbox`, `\boxed`, and `\fcolorbox`.
124
+ * The usual value for these items is `0.04`, so for `minRuleThickness`
125
+ * to be effective it should probably take a value slightly above `0.04`,
126
+ * say `0.05` or `0.06`. Negative values will be ignored.
127
+ */
128
+ minRuleThickness?: number;
129
+ /**
130
+ * In early versions of both KaTeX (<0.8.0) and MathJax, the `\color`
131
+ * function expected the content to be a function argument, as in
132
+ * `\color{blue}{hello}`. In current KaTeX, `\color` is a switch, as in
133
+ * `\color{blue}` hello. This matches LaTeX behavior. If you want the old
134
+ * `\color` behavior, set option colorIsTextColor to true.
135
+ */
136
+ colorIsTextColor?: boolean;
137
+ /**
138
+ * All user-specified sizes, e.g. in `\rule{500em}{500em}`, will be capped
139
+ * to `maxSize` ems. If set to `Infinity` (the default), users can make
140
+ * elements and spaces arbitrarily large.
141
+ *
142
+ * @default Infinity
143
+ */
144
+ maxSize?: number;
145
+ /**
146
+ * Limit the number of macro expansions to the specified number, to prevent
147
+ * e.g. infinite macro loops. `\edef` expansion counts all expanded tokens.
148
+ * If set to `Infinity`, the macro expander will try to fully expand as in
149
+ * LaTeX.
150
+ *
151
+ * @default 1000
152
+ */
153
+ maxExpand?: number;
154
+ /**
155
+ * If `false` or `"ignore"`, allow features that make writing LaTeX
156
+ * convenient but are not actually supported by (Xe)LaTeX
157
+ * (similar to MathJax).
158
+ * If `true` or `"error"` (LaTeX faithfulness mode), throw an error for any
159
+ * such transgressions.
160
+ * If `"warn"` (the default), warn about such behavior via `console.warn`.
161
+ * Provide a custom function `handler(errorCode, errorMsg, token)` to
162
+ * customize behavior depending on the type of transgression (summarized by
163
+ * the string code `errorCode` and detailed in `errorMsg`); this function
164
+ * can also return `"ignore"`, `"error"`, or `"warn"` to use a built-in
165
+ * behavior.
166
+ * @see https://katex.org/docs/options
167
+ *
168
+ * @default "warn"
169
+ */
170
+ strict?:
171
+ | boolean
172
+ | "ignore" | "warn" | "error"
173
+ | StrictFunction;
174
+ /**
175
+ * If `false` (do not trust input), prevent any commands like
176
+ * `\includegraphics` that could enable adverse behavior, rendering them
177
+ * instead in `errorColor`.
178
+ * If `true` (trust input), allow all such commands.
179
+ * Provide a custom function `handler(context)` to customize behavior
180
+ * depending on the context (command, arguments e.g. a URL, etc.).
181
+ * @see https://katex.org/docs/options
182
+ *
183
+ * @default false
184
+ */
185
+ trust?: boolean | ((context: TrustContext) => boolean);
186
+ /**
187
+ * Run KaTeX code in the global group. As a consequence, macros defined at
188
+ * the top level by `\def` and `\newcommand` are added to the macros
189
+ * argument and can be used in subsequent render calls. In LaTeX,
190
+ * constructs such as `\begin{equation}` and `$$` create a local group and
191
+ * prevent definitions other than `\gdef` from becoming visible outside of
192
+ * those blocks, so this is KaTeX's default behavior.
193
+ *
194
+ * @default false
195
+ */
196
+ globalGroup?: boolean;
197
+ }
198
+
199
+ /**
200
+ * In-browser rendering
201
+ *
202
+ * Call the `render` function with a TeX expression and a DOM element to
203
+ * render into.
204
+ *
205
+ * @param {string} tex A TeX expression.
206
+ * @param {HTMLElement} element A HTML DOM element.
207
+ * @param {KatexOptions} options An options object.
208
+ * @returns {void}
209
+ * @see https://katex.org/docs/api
210
+ */
211
+ export function render(
212
+ tex: string,
213
+ element: HTMLElement,
214
+ options?: KatexOptions,
215
+ ): void;
216
+
217
+ /**
218
+ * Server-side rendering or rendering to a string
219
+ *
220
+ * Use the `renderToString` function to generate HTML on the server or to
221
+ * generate an HTML string of the rendered math.
222
+ *
223
+ * @param {string} tex A TeX expression.
224
+ * @param {KatexOptions} options An options object.
225
+ * @returns {string} The HTML string of the rendered math.
226
+ * @see https://katex.org/docs/api
227
+ */
228
+ export function renderToString(tex: string, options?: KatexOptions): string;
229
+
230
+ /**
231
+ * If KaTeX encounters an error (invalid or unsupported LaTeX) and
232
+ * `throwOnError` hasn't been set to `false`, then `katex.render` and
233
+ * `katex.renderToString` will throw an exception of type
234
+ * `ParseError`. The message in this error includes some of the LaTeX source
235
+ * code, so needs to be escaped if you want to render it to HTML.
236
+ * @see https://katex.org/docs/error
237
+ */
238
+ export class ParseError implements Error {
239
+ constructor(message: string, token?: object);
240
+ name: "ParseError";
241
+ position: number;
242
+ length: number;
243
+ rawMessage: string;
244
+ message: string;
245
+ }
246
+
247
+ export const version: string;
248
+
249
+ export as namespace katex;
250
+
251
+ declare const katex: {
252
+ version: string;
253
+ render: typeof render;
254
+ renderToString: typeof renderToString;
255
+ ParseError: typeof ParseError;
256
+ };
257
+
258
+ export default katex;