1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import fontMetricsData from "../submodules/katex-fonts/fontMetricsData";
|
8 | import symbols from "./symbols";
|
9 | import utils from "./utils";
|
10 | import {Token} from "./Token";
|
11 | import ParseError from "./ParseError";
|
12 | import type Namespace from "./Namespace";
|
13 |
|
14 | import type {Mode} from "./types";
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | export interface MacroContextInterface {
|
21 | mode: Mode;
|
22 |
|
23 | |
24 |
|
25 |
|
26 | macros: Namespace<MacroDefinition>;
|
27 |
|
28 | |
29 |
|
30 |
|
31 |
|
32 | future(): Token;
|
33 |
|
34 | |
35 |
|
36 |
|
37 | popToken(): Token;
|
38 |
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 | expandAfterFuture(): Token;
|
45 |
|
46 | |
47 |
|
48 |
|
49 | expandNextToken(): Token;
|
50 |
|
51 | |
52 |
|
53 |
|
54 |
|
55 | expandMacro(name: string): Token[] | void;
|
56 |
|
57 | |
58 |
|
59 |
|
60 |
|
61 | expandMacroAsText(name: string): string | void;
|
62 |
|
63 | |
64 |
|
65 |
|
66 |
|
67 | consumeArgs(numArgs: number): Token[][];
|
68 |
|
69 | |
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | isDefined(name: string): boolean;
|
76 | }
|
77 |
|
78 |
|
79 | export type MacroExpansion = {tokens: Token[], numArgs: number};
|
80 |
|
81 | export type MacroDefinition = string | MacroExpansion |
|
82 | (MacroContextInterface => (string | MacroExpansion));
|
83 | export type MacroMap = {[string]: MacroDefinition};
|
84 |
|
85 | const builtinMacros: MacroMap = {};
|
86 | export default builtinMacros;
|
87 |
|
88 |
|
89 | export function defineMacro(name: string, body: MacroDefinition) {
|
90 | builtinMacros[name] = body;
|
91 | }
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | defineMacro("\\@firstoftwo", function(context) {
|
99 | const args = context.consumeArgs(2);
|
100 | return {tokens: args[0], numArgs: 0};
|
101 | });
|
102 |
|
103 |
|
104 |
|
105 | defineMacro("\\@secondoftwo", function(context) {
|
106 | const args = context.consumeArgs(2);
|
107 | return {tokens: args[1], numArgs: 0};
|
108 | });
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | defineMacro("\\@ifnextchar", function(context) {
|
114 | const args = context.consumeArgs(3);
|
115 | const nextToken = context.future();
|
116 | if (args[0].length === 1 && args[0][0].text === nextToken.text) {
|
117 | return {tokens: args[1], numArgs: 0};
|
118 | } else {
|
119 | return {tokens: args[2], numArgs: 0};
|
120 | }
|
121 | });
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 | defineMacro("\\@ifstar", "\\@ifnextchar *{\\@firstoftwo{#1}}");
|
128 |
|
129 |
|
130 | defineMacro("\\TextOrMath", function(context) {
|
131 | const args = context.consumeArgs(2);
|
132 | if (context.mode === 'text') {
|
133 | return {tokens: args[0], numArgs: 0};
|
134 | } else {
|
135 | return {tokens: args[1], numArgs: 0};
|
136 | }
|
137 | });
|
138 |
|
139 |
|
140 | const digitToNumber = {
|
141 | "0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8,
|
142 | "9": 9, "a": 10, "A": 10, "b": 11, "B": 11, "c": 12, "C": 12,
|
143 | "d": 13, "D": 13, "e": 14, "E": 14, "f": 15, "F": 15,
|
144 | };
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 | defineMacro("\\char", function(context) {
|
156 | let token = context.popToken();
|
157 | let base;
|
158 | let number = '';
|
159 | if (token.text === "'") {
|
160 | base = 8;
|
161 | token = context.popToken();
|
162 | } else if (token.text === '"') {
|
163 | base = 16;
|
164 | token = context.popToken();
|
165 | } else if (token.text === "`") {
|
166 | token = context.popToken();
|
167 | if (token.text[0] === "\\") {
|
168 | number = token.text.charCodeAt(1);
|
169 | } else if (token.text === "EOF") {
|
170 | throw new ParseError("\\char` missing argument");
|
171 | } else {
|
172 | number = token.text.charCodeAt(0);
|
173 | }
|
174 | } else {
|
175 | base = 10;
|
176 | }
|
177 | if (base) {
|
178 |
|
179 | number = digitToNumber[token.text];
|
180 | if (number == null || number >= base) {
|
181 | throw new ParseError(`Invalid base-${base} digit ${token.text}`);
|
182 | }
|
183 | let digit;
|
184 | while ((digit = digitToNumber[context.future().text]) != null &&
|
185 | digit < base) {
|
186 | number *= base;
|
187 | number += digit;
|
188 | context.popToken();
|
189 | }
|
190 | }
|
191 | return `\\@char{${number}}`;
|
192 | });
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | const def = (context, global: boolean) => {
|
201 | let arg = context.consumeArgs(1)[0];
|
202 | if (arg.length !== 1) {
|
203 | throw new ParseError("\\gdef's first argument must be a macro name");
|
204 | }
|
205 | const name = arg[0].text;
|
206 |
|
207 | let numArgs = 0;
|
208 | arg = context.consumeArgs(1)[0];
|
209 | while (arg.length === 1 && arg[0].text === "#") {
|
210 | arg = context.consumeArgs(1)[0];
|
211 | if (arg.length !== 1) {
|
212 | throw new ParseError(`Invalid argument number length "${arg.length}"`);
|
213 | }
|
214 | if (!(/^[1-9]$/.test(arg[0].text))) {
|
215 | throw new ParseError(`Invalid argument number "${arg[0].text}"`);
|
216 | }
|
217 | numArgs++;
|
218 | if (parseInt(arg[0].text) !== numArgs) {
|
219 | throw new ParseError(`Argument number "${arg[0].text}" out of order`);
|
220 | }
|
221 | arg = context.consumeArgs(1)[0];
|
222 | }
|
223 |
|
224 | context.macros.set(name, {
|
225 | tokens: arg,
|
226 | numArgs,
|
227 | }, global);
|
228 | return '';
|
229 | };
|
230 | defineMacro("\\gdef", (context) => def(context, true));
|
231 | defineMacro("\\def", (context) => def(context, false));
|
232 | defineMacro("\\global", (context) => {
|
233 | const next = context.consumeArgs(1)[0];
|
234 | if (next.length !== 1) {
|
235 | throw new ParseError("Invalid command after \\global");
|
236 | }
|
237 | const command = next[0].text;
|
238 |
|
239 | if (command === "\\def") {
|
240 |
|
241 | return def(context, true);
|
242 | } else {
|
243 | throw new ParseError(`Invalid command '${command}' after \\global`);
|
244 | }
|
245 | });
|
246 |
|
247 |
|
248 |
|
249 |
|
250 | const newcommand = (context, existsOK: boolean, nonexistsOK: boolean) => {
|
251 | let arg = context.consumeArgs(1)[0];
|
252 | if (arg.length !== 1) {
|
253 | throw new ParseError(
|
254 | "\\newcommand's first argument must be a macro name");
|
255 | }
|
256 | const name = arg[0].text;
|
257 |
|
258 | const exists = context.isDefined(name);
|
259 | if (exists && !existsOK) {
|
260 | throw new ParseError(`\\newcommand{${name}} attempting to redefine ` +
|
261 | `${name}; use \\renewcommand`);
|
262 | }
|
263 | if (!exists && !nonexistsOK) {
|
264 | throw new ParseError(`\\renewcommand{${name}} when command ${name} ` +
|
265 | `does not yet exist; use \\newcommand`);
|
266 | }
|
267 |
|
268 | let numArgs = 0;
|
269 | arg = context.consumeArgs(1)[0];
|
270 | if (arg.length === 1 && arg[0].text === "[") {
|
271 | let argText = '';
|
272 | let token = context.expandNextToken();
|
273 | while (token.text !== "]" && token.text !== "EOF") {
|
274 |
|
275 | argText += token.text;
|
276 | token = context.expandNextToken();
|
277 | }
|
278 | if (!argText.match(/^\s*[0-9]+\s*$/)) {
|
279 | throw new ParseError(`Invalid number of arguments: ${argText}`);
|
280 | }
|
281 | numArgs = parseInt(argText);
|
282 | arg = context.consumeArgs(1)[0];
|
283 | }
|
284 |
|
285 |
|
286 | context.macros.set(name, {
|
287 | tokens: arg,
|
288 | numArgs,
|
289 | });
|
290 | return '';
|
291 | };
|
292 | defineMacro("\\newcommand", (context) => newcommand(context, false, true));
|
293 | defineMacro("\\renewcommand", (context) => newcommand(context, true, false));
|
294 | defineMacro("\\providecommand", (context) => newcommand(context, true, true));
|
295 |
|
296 |
|
297 |
|
298 |
|
299 | defineMacro("\\bgroup", "{");
|
300 | defineMacro("\\egroup", "}");
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 | defineMacro("\\lq", "`");
|
308 | defineMacro("\\rq", "'");
|
309 | defineMacro("\\aa", "\\r a");
|
310 | defineMacro("\\AA", "\\r A");
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 | defineMacro("\\textcopyright", "\\html@mathml{\\textcircled{c}}{\\char`©}");
|
319 | defineMacro("\\copyright",
|
320 | "\\TextOrMath{\\textcopyright}{\\text{\\textcopyright}}");
|
321 | defineMacro("\\textregistered",
|
322 | "\\html@mathml{\\textcircled{\\scriptsize R}}{\\char`®}");
|
323 |
|
324 |
|
325 | defineMacro("\u212C", "\\mathscr{B}");
|
326 | defineMacro("\u2130", "\\mathscr{E}");
|
327 | defineMacro("\u2131", "\\mathscr{F}");
|
328 | defineMacro("\u210B", "\\mathscr{H}");
|
329 | defineMacro("\u2110", "\\mathscr{I}");
|
330 | defineMacro("\u2112", "\\mathscr{L}");
|
331 | defineMacro("\u2133", "\\mathscr{M}");
|
332 | defineMacro("\u211B", "\\mathscr{R}");
|
333 | defineMacro("\u212D", "\\mathfrak{C}");
|
334 | defineMacro("\u210C", "\\mathfrak{H}");
|
335 | defineMacro("\u2128", "\\mathfrak{Z}");
|
336 |
|
337 |
|
338 | defineMacro("\\Bbbk", "\\Bbb{k}");
|
339 |
|
340 |
|
341 |
|
342 |
|
343 | defineMacro("\u00b7", "\\cdotp");
|
344 |
|
345 |
|
346 | defineMacro("\\llap", "\\mathllap{\\textrm{#1}}");
|
347 | defineMacro("\\rlap", "\\mathrlap{\\textrm{#1}}");
|
348 | defineMacro("\\clap", "\\mathclap{\\textrm{#1}}");
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 | defineMacro("\\not", '\\html@mathml{\\mathrel{\\mathrlap\\@not}}{\\char"338}');
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 | defineMacro("\\neq", "\\html@mathml{\\mathrel{\\not=}}{\\mathrel{\\char`≠}}");
|
363 | defineMacro("\\ne", "\\neq");
|
364 | defineMacro("\u2260", "\\neq");
|
365 | defineMacro("\\notin", "\\html@mathml{\\mathrel{{\\in}\\mathllap{/\\mskip1mu}}}"
|
366 | + "{\\mathrel{\\char`∉}}");
|
367 | defineMacro("\u2209", "\\notin");
|
368 |
|
369 |
|
370 | defineMacro("\u2258", "\\html@mathml{" +
|
371 | "\\mathrel{=\\kern{-1em}\\raisebox{0.4em}{$\\scriptsize\\frown$}}" +
|
372 | "}{\\mathrel{\\char`\u2258}}");
|
373 | defineMacro("\u2259",
|
374 | "\\html@mathml{\\stackrel{\\tiny\\wedge}{=}}{\\mathrel{\\char`\u2258}}");
|
375 | defineMacro("\u225A",
|
376 | "\\html@mathml{\\stackrel{\\tiny\\vee}{=}}{\\mathrel{\\char`\u225A}}");
|
377 | defineMacro("\u225B",
|
378 | "\\html@mathml{\\stackrel{\\scriptsize\\star}{=}}" +
|
379 | "{\\mathrel{\\char`\u225B}}");
|
380 | defineMacro("\u225D",
|
381 | "\\html@mathml{\\stackrel{\\tiny\\mathrm{def}}{=}}" +
|
382 | "{\\mathrel{\\char`\u225D}}");
|
383 | defineMacro("\u225E",
|
384 | "\\html@mathml{\\stackrel{\\tiny\\mathrm{m}}{=}}" +
|
385 | "{\\mathrel{\\char`\u225E}}");
|
386 | defineMacro("\u225F",
|
387 | "\\html@mathml{\\stackrel{\\tiny?}{=}}{\\mathrel{\\char`\u225F}}");
|
388 |
|
389 |
|
390 | defineMacro("\u27C2", "\\perp");
|
391 | defineMacro("\u203C", "\\mathclose{!\\mkern-0.8mu!}");
|
392 | defineMacro("\u220C", "\\notni");
|
393 | defineMacro("\u231C", "\\ulcorner");
|
394 | defineMacro("\u231D", "\\urcorner");
|
395 | defineMacro("\u231E", "\\llcorner");
|
396 | defineMacro("\u231F", "\\lrcorner");
|
397 | defineMacro("\u00A9", "\\copyright");
|
398 | defineMacro("\u00AE", "\\textregistered");
|
399 | defineMacro("\uFE0F", "\\textregistered");
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 | defineMacro("\\vdots", "\\mathord{\\varvdots\\rule{0pt}{15pt}}");
|
409 | defineMacro("\u22ee", "\\vdots");
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 | defineMacro("\\varGamma", "\\mathit{\\Gamma}");
|
418 | defineMacro("\\varDelta", "\\mathit{\\Delta}");
|
419 | defineMacro("\\varTheta", "\\mathit{\\Theta}");
|
420 | defineMacro("\\varLambda", "\\mathit{\\Lambda}");
|
421 | defineMacro("\\varXi", "\\mathit{\\Xi}");
|
422 | defineMacro("\\varPi", "\\mathit{\\Pi}");
|
423 | defineMacro("\\varSigma", "\\mathit{\\Sigma}");
|
424 | defineMacro("\\varUpsilon", "\\mathit{\\Upsilon}");
|
425 | defineMacro("\\varPhi", "\\mathit{\\Phi}");
|
426 | defineMacro("\\varPsi", "\\mathit{\\Psi}");
|
427 | defineMacro("\\varOmega", "\\mathit{\\Omega}");
|
428 |
|
429 |
|
430 |
|
431 | defineMacro("\\colon", "\\nobreak\\mskip2mu\\mathpunct{}" +
|
432 | "\\mathchoice{\\mkern-3mu}{\\mkern-3mu}{}{}{:}\\mskip6mu");
|
433 |
|
434 |
|
435 | defineMacro("\\boxed", "\\fbox{$\\displaystyle{#1}$}");
|
436 |
|
437 |
|
438 |
|
439 |
|
440 | defineMacro("\\iff", "\\DOTSB\\;\\Longleftrightarrow\\;");
|
441 | defineMacro("\\implies", "\\DOTSB\\;\\Longrightarrow\\;");
|
442 | defineMacro("\\impliedby", "\\DOTSB\\;\\Longleftarrow\\;");
|
443 |
|
444 |
|
445 | const dotsByToken = {
|
446 | ',': '\\dotsc',
|
447 | '\\not': '\\dotsb',
|
448 |
|
449 | '+': '\\dotsb',
|
450 | '=': '\\dotsb',
|
451 | '<': '\\dotsb',
|
452 | '>': '\\dotsb',
|
453 | '-': '\\dotsb',
|
454 | '*': '\\dotsb',
|
455 | ':': '\\dotsb',
|
456 |
|
457 | '\\DOTSB': '\\dotsb',
|
458 | '\\coprod': '\\dotsb',
|
459 | '\\bigvee': '\\dotsb',
|
460 | '\\bigwedge': '\\dotsb',
|
461 | '\\biguplus': '\\dotsb',
|
462 | '\\bigcap': '\\dotsb',
|
463 | '\\bigcup': '\\dotsb',
|
464 | '\\prod': '\\dotsb',
|
465 | '\\sum': '\\dotsb',
|
466 | '\\bigotimes': '\\dotsb',
|
467 | '\\bigoplus': '\\dotsb',
|
468 | '\\bigodot': '\\dotsb',
|
469 | '\\bigsqcup': '\\dotsb',
|
470 | '\\And': '\\dotsb',
|
471 | '\\longrightarrow': '\\dotsb',
|
472 | '\\Longrightarrow': '\\dotsb',
|
473 | '\\longleftarrow': '\\dotsb',
|
474 | '\\Longleftarrow': '\\dotsb',
|
475 | '\\longleftrightarrow': '\\dotsb',
|
476 | '\\Longleftrightarrow': '\\dotsb',
|
477 | '\\mapsto': '\\dotsb',
|
478 | '\\longmapsto': '\\dotsb',
|
479 | '\\hookrightarrow': '\\dotsb',
|
480 | '\\doteq': '\\dotsb',
|
481 |
|
482 | '\\mathbin': '\\dotsb',
|
483 |
|
484 | '\\mathrel': '\\dotsb',
|
485 | '\\relbar': '\\dotsb',
|
486 | '\\Relbar': '\\dotsb',
|
487 | '\\xrightarrow': '\\dotsb',
|
488 | '\\xleftarrow': '\\dotsb',
|
489 |
|
490 | '\\DOTSI': '\\dotsi',
|
491 | '\\int': '\\dotsi',
|
492 | '\\oint': '\\dotsi',
|
493 | '\\iint': '\\dotsi',
|
494 | '\\iiint': '\\dotsi',
|
495 | '\\iiiint': '\\dotsi',
|
496 | '\\idotsint': '\\dotsi',
|
497 |
|
498 | '\\DOTSX': '\\dotsx',
|
499 | };
|
500 |
|
501 | defineMacro("\\dots", function(context) {
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 | let thedots = '\\dotso';
|
508 | const next = context.expandAfterFuture().text;
|
509 | if (next in dotsByToken) {
|
510 | thedots = dotsByToken[next];
|
511 | } else if (next.substr(0, 4) === '\\not') {
|
512 | thedots = '\\dotsb';
|
513 | } else if (next in symbols.math) {
|
514 | if (utils.contains(['bin', 'rel'], symbols.math[next].group)) {
|
515 | thedots = '\\dotsb';
|
516 | }
|
517 | }
|
518 | return thedots;
|
519 | });
|
520 |
|
521 | const spaceAfterDots = {
|
522 |
|
523 | ')': true,
|
524 | ']': true,
|
525 | '\\rbrack': true,
|
526 | '\\}': true,
|
527 | '\\rbrace': true,
|
528 | '\\rangle': true,
|
529 | '\\rceil': true,
|
530 | '\\rfloor': true,
|
531 | '\\rgroup': true,
|
532 | '\\rmoustache': true,
|
533 | '\\right': true,
|
534 | '\\bigr': true,
|
535 | '\\biggr': true,
|
536 | '\\Bigr': true,
|
537 | '\\Biggr': true,
|
538 |
|
539 | '$': true,
|
540 |
|
541 | ';': true,
|
542 | '.': true,
|
543 | ',': true,
|
544 | };
|
545 |
|
546 | defineMacro("\\dotso", function(context) {
|
547 | const next = context.future().text;
|
548 | if (next in spaceAfterDots) {
|
549 | return "\\ldots\\,";
|
550 | } else {
|
551 | return "\\ldots";
|
552 | }
|
553 | });
|
554 |
|
555 | defineMacro("\\dotsc", function(context) {
|
556 | const next = context.future().text;
|
557 |
|
558 |
|
559 | if (next in spaceAfterDots && next !== ',') {
|
560 | return "\\ldots\\,";
|
561 | } else {
|
562 | return "\\ldots";
|
563 | }
|
564 | });
|
565 |
|
566 | defineMacro("\\cdots", function(context) {
|
567 | const next = context.future().text;
|
568 | if (next in spaceAfterDots) {
|
569 | return "\\@cdots\\,";
|
570 | } else {
|
571 | return "\\@cdots";
|
572 | }
|
573 | });
|
574 |
|
575 | defineMacro("\\dotsb", "\\cdots");
|
576 | defineMacro("\\dotsm", "\\cdots");
|
577 | defineMacro("\\dotsi", "\\!\\cdots");
|
578 |
|
579 |
|
580 |
|
581 | defineMacro("\\dotsx", "\\ldots\\,");
|
582 |
|
583 |
|
584 |
|
585 |
|
586 | defineMacro("\\DOTSI", "\\relax");
|
587 | defineMacro("\\DOTSB", "\\relax");
|
588 | defineMacro("\\DOTSX", "\\relax");
|
589 |
|
590 |
|
591 |
|
592 |
|
593 | defineMacro("\\tmspace", "\\TextOrMath{\\kern#1#3}{\\mskip#1#2}\\relax");
|
594 |
|
595 |
|
596 | defineMacro("\\,", "\\tmspace+{3mu}{.1667em}");
|
597 |
|
598 | defineMacro("\\thinspace", "\\,");
|
599 |
|
600 |
|
601 |
|
602 | defineMacro("\\>", "\\mskip{4mu}");
|
603 | defineMacro("\\:", "\\tmspace+{4mu}{.2222em}");
|
604 |
|
605 | defineMacro("\\medspace", "\\:");
|
606 |
|
607 |
|
608 | defineMacro("\\;", "\\tmspace+{5mu}{.2777em}");
|
609 |
|
610 | defineMacro("\\thickspace", "\\;");
|
611 |
|
612 |
|
613 | defineMacro("\\!", "\\tmspace-{3mu}{.1667em}");
|
614 |
|
615 | defineMacro("\\negthinspace", "\\!");
|
616 |
|
617 |
|
618 | defineMacro("\\negmedspace", "\\tmspace-{4mu}{.2222em}");
|
619 |
|
620 |
|
621 | defineMacro("\\negthickspace", "\\tmspace-{5mu}{.277em}");
|
622 |
|
623 | defineMacro("\\enspace", "\\kern.5em ");
|
624 |
|
625 | defineMacro("\\enskip", "\\hskip.5em\\relax");
|
626 |
|
627 | defineMacro("\\quad", "\\hskip1em\\relax");
|
628 |
|
629 | defineMacro("\\qquad", "\\hskip2em\\relax");
|
630 |
|
631 |
|
632 | defineMacro("\\tag", "\\@ifstar\\tag@literal\\tag@paren");
|
633 | defineMacro("\\tag@paren", "\\tag@literal{({#1})}");
|
634 | defineMacro("\\tag@literal", (context) => {
|
635 | if (context.macros.get("\\df@tag")) {
|
636 | throw new ParseError("Multiple \\tag");
|
637 | }
|
638 | return "\\gdef\\df@tag{\\text{#1}}";
|
639 | });
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 | defineMacro("\\bmod",
|
651 | "\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}" +
|
652 | "\\mathbin{\\rm mod}" +
|
653 | "\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}");
|
654 | defineMacro("\\pod", "\\allowbreak" +
|
655 | "\\mathchoice{\\mkern18mu}{\\mkern8mu}{\\mkern8mu}{\\mkern8mu}(#1)");
|
656 | defineMacro("\\pmod", "\\pod{{\\rm mod}\\mkern6mu#1}");
|
657 | defineMacro("\\mod", "\\allowbreak" +
|
658 | "\\mathchoice{\\mkern18mu}{\\mkern12mu}{\\mkern12mu}{\\mkern12mu}" +
|
659 | "{\\rm mod}\\,\\,#1");
|
660 |
|
661 |
|
662 |
|
663 |
|
664 | defineMacro("\\pmb", "\\html@mathml{\\@binrel{#1}{" +
|
665 | "\\mathrlap{#1}" +
|
666 | "\\mathrlap{\\mkern0.4mu\\raisebox{0.4mu}{$#1$}}" +
|
667 | "{\\mkern0.8mu#1}" +
|
668 | "}}{\\mathbf{#1}}");
|
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 | defineMacro("\\\\", "\\newline");
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 | defineMacro("\\TeX", "\\textrm{\\html@mathml{" +
|
681 | "T\\kern-.1667em\\raisebox{-.5ex}{E}\\kern-.125emX" +
|
682 | "}{TeX}}");
|
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 | const latexRaiseA = fontMetricsData['Main-Regular']["T".charCodeAt(0)][1] -
|
699 | 0.7 * fontMetricsData['Main-Regular']["A".charCodeAt(0)][1] + "em";
|
700 | defineMacro("\\LaTeX", "\\textrm{\\html@mathml{" +
|
701 | `L\\kern-.36em\\raisebox{${latexRaiseA}}{\\scriptsize A}` +
|
702 | "\\kern-.15em\\TeX}{LaTeX}}");
|
703 |
|
704 |
|
705 | defineMacro("\\KaTeX", "\\textrm{\\html@mathml{" +
|
706 | `K\\kern-.17em\\raisebox{${latexRaiseA}}{\\scriptsize A}` +
|
707 | "\\kern-.15em\\TeX}{KaTeX}}");
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 | defineMacro("\\hspace", "\\@ifstar\\@hspacer\\@hspace");
|
714 | defineMacro("\\@hspace", "\\hskip #1\\relax");
|
715 | defineMacro("\\@hspacer", "\\rule{0pt}{0pt}\\hskip #1\\relax");
|
716 |
|
717 |
|
718 |
|
719 |
|
720 |
|
721 | defineMacro("\\ordinarycolon", ":");
|
722 |
|
723 |
|
724 | defineMacro("\\vcentcolon", "\\mathrel{\\mathop\\ordinarycolon}");
|
725 |
|
726 | defineMacro("\\dblcolon", "\\html@mathml{" +
|
727 | "\\mathrel{\\vcentcolon\\mathrel{\\mkern-.9mu}\\vcentcolon}}" +
|
728 | "{\\mathop{\\char\"2237}}");
|
729 |
|
730 | defineMacro("\\coloneqq", "\\html@mathml{" +
|
731 | "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}=}}" +
|
732 | "{\\mathop{\\char\"2254}}");
|
733 |
|
734 | defineMacro("\\Coloneqq", "\\html@mathml{" +
|
735 | "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}=}}" +
|
736 | "{\\mathop{\\char\"2237\\char\"3d}}");
|
737 |
|
738 | defineMacro("\\coloneq", "\\html@mathml{" +
|
739 | "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}" +
|
740 | "{\\mathop{\\char\"3a\\char\"2212}}");
|
741 |
|
742 | defineMacro("\\Coloneq", "\\html@mathml{" +
|
743 | "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}" +
|
744 | "{\\mathop{\\char\"2237\\char\"2212}}");
|
745 |
|
746 | defineMacro("\\eqqcolon", "\\html@mathml{" +
|
747 | "\\mathrel{=\\mathrel{\\mkern-1.2mu}\\vcentcolon}}" +
|
748 | "{\\mathop{\\char\"2255}}");
|
749 |
|
750 | defineMacro("\\Eqqcolon", "\\html@mathml{" +
|
751 | "\\mathrel{=\\mathrel{\\mkern-1.2mu}\\dblcolon}}" +
|
752 | "{\\mathop{\\char\"3d\\char\"2237}}");
|
753 |
|
754 | defineMacro("\\eqcolon", "\\html@mathml{" +
|
755 | "\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\vcentcolon}}" +
|
756 | "{\\mathop{\\char\"2239}}");
|
757 |
|
758 | defineMacro("\\Eqcolon", "\\html@mathml{" +
|
759 | "\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\dblcolon}}" +
|
760 | "{\\mathop{\\char\"2212\\char\"2237}}");
|
761 |
|
762 | defineMacro("\\colonapprox", "\\html@mathml{" +
|
763 | "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\approx}}" +
|
764 | "{\\mathop{\\char\"3a\\char\"2248}}");
|
765 |
|
766 | defineMacro("\\Colonapprox", "\\html@mathml{" +
|
767 | "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\approx}}" +
|
768 | "{\\mathop{\\char\"2237\\char\"2248}}");
|
769 |
|
770 | defineMacro("\\colonsim", "\\html@mathml{" +
|
771 | "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\sim}}" +
|
772 | "{\\mathop{\\char\"3a\\char\"223c}}");
|
773 |
|
774 | defineMacro("\\Colonsim", "\\html@mathml{" +
|
775 | "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\sim}}" +
|
776 | "{\\mathop{\\char\"2237\\char\"223c}}");
|
777 |
|
778 |
|
779 | defineMacro("\u2237", "\\dblcolon");
|
780 | defineMacro("\u2239", "\\eqcolon");
|
781 | defineMacro("\u2254", "\\coloneqq");
|
782 | defineMacro("\u2255", "\\eqqcolon");
|
783 | defineMacro("\u2A74", "\\Coloneqq");
|
784 |
|
785 |
|
786 |
|
787 |
|
788 |
|
789 | defineMacro("\\ratio", "\\vcentcolon");
|
790 | defineMacro("\\coloncolon", "\\dblcolon");
|
791 | defineMacro("\\colonequals", "\\coloneqq");
|
792 | defineMacro("\\coloncolonequals", "\\Coloneqq");
|
793 | defineMacro("\\equalscolon", "\\eqqcolon");
|
794 | defineMacro("\\equalscoloncolon", "\\Eqqcolon");
|
795 | defineMacro("\\colonminus", "\\coloneq");
|
796 | defineMacro("\\coloncolonminus", "\\Coloneq");
|
797 | defineMacro("\\minuscolon", "\\eqcolon");
|
798 | defineMacro("\\minuscoloncolon", "\\Eqcolon");
|
799 |
|
800 | defineMacro("\\coloncolonapprox", "\\Colonapprox");
|
801 |
|
802 | defineMacro("\\coloncolonsim", "\\Colonsim");
|
803 |
|
804 |
|
805 | defineMacro("\\simcolon",
|
806 | "\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\vcentcolon}");
|
807 | defineMacro("\\simcoloncolon",
|
808 | "\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\dblcolon}");
|
809 | defineMacro("\\approxcolon",
|
810 | "\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\vcentcolon}");
|
811 | defineMacro("\\approxcoloncolon",
|
812 | "\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\dblcolon}");
|
813 |
|
814 |
|
815 | defineMacro("\\notni", "\\html@mathml{\\not\\ni}{\\mathrel{\\char`\u220C}}");
|
816 | defineMacro("\\limsup", "\\DOTSB\\mathop{\\operatorname{lim\\,sup}}\\limits");
|
817 | defineMacro("\\liminf", "\\DOTSB\\mathop{\\operatorname{lim\\,inf}}\\limits");
|
818 |
|
819 |
|
820 |
|
821 | defineMacro("\\gvertneqq", "\\html@mathml{\\@gvertneqq}{\u2269}");
|
822 | defineMacro("\\lvertneqq", "\\html@mathml{\\@lvertneqq}{\u2268}");
|
823 | defineMacro("\\ngeqq", "\\html@mathml{\\@ngeqq}{\u2271}");
|
824 | defineMacro("\\ngeqslant", "\\html@mathml{\\@ngeqslant}{\u2271}");
|
825 | defineMacro("\\nleqq", "\\html@mathml{\\@nleqq}{\u2270}");
|
826 | defineMacro("\\nleqslant", "\\html@mathml{\\@nleqslant}{\u2270}");
|
827 | defineMacro("\\nshortmid", "\\html@mathml{\\@nshortmid}{∤}");
|
828 | defineMacro("\\nshortparallel", "\\html@mathml{\\@nshortparallel}{∦}");
|
829 | defineMacro("\\nsubseteqq", "\\html@mathml{\\@nsubseteqq}{\u2288}");
|
830 | defineMacro("\\nsupseteqq", "\\html@mathml{\\@nsupseteqq}{\u2289}");
|
831 | defineMacro("\\varsubsetneq", "\\html@mathml{\\@varsubsetneq}{⊊}");
|
832 | defineMacro("\\varsubsetneqq", "\\html@mathml{\\@varsubsetneqq}{⫋}");
|
833 | defineMacro("\\varsupsetneq", "\\html@mathml{\\@varsupsetneq}{⊋}");
|
834 | defineMacro("\\varsupsetneqq", "\\html@mathml{\\@varsupsetneqq}{⫌}");
|
835 |
|
836 |
|
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 | defineMacro("\\llbracket", "\\html@mathml{" +
|
843 | "\\mathopen{[\\mkern-3.2mu[}}" +
|
844 | "{\\mathopen{\\char`\u27e6}}");
|
845 | defineMacro("\\rrbracket", "\\html@mathml{" +
|
846 | "\\mathclose{]\\mkern-3.2mu]}}" +
|
847 | "{\\mathclose{\\char`\u27e7}}");
|
848 |
|
849 | defineMacro("\u27e6", "\\llbracket");
|
850 | defineMacro("\u27e7", "\\rrbracket");
|
851 |
|
852 | defineMacro("\\lBrace", "\\html@mathml{" +
|
853 | "\\mathopen{\\{\\mkern-3.2mu[}}" +
|
854 | "{\\mathopen{\\char`\u2983}}");
|
855 | defineMacro("\\rBrace", "\\html@mathml{" +
|
856 | "\\mathclose{]\\mkern-3.2mu\\}}}" +
|
857 | "{\\mathclose{\\char`\u2984}}");
|
858 |
|
859 | defineMacro("\u2983", "\\lBrace");
|
860 | defineMacro("\u2984", "\\rBrace");
|
861 |
|
862 |
|
863 |
|
864 |
|
865 |
|
866 |
|
867 |
|
868 |
|
869 |
|
870 |
|
871 |
|
872 |
|
873 |
|
874 | defineMacro("\\darr", "\\downarrow");
|
875 | defineMacro("\\dArr", "\\Downarrow");
|
876 | defineMacro("\\Darr", "\\Downarrow");
|
877 | defineMacro("\\lang", "\\langle");
|
878 | defineMacro("\\rang", "\\rangle");
|
879 | defineMacro("\\uarr", "\\uparrow");
|
880 | defineMacro("\\uArr", "\\Uparrow");
|
881 | defineMacro("\\Uarr", "\\Uparrow");
|
882 | defineMacro("\\N", "\\mathbb{N}");
|
883 | defineMacro("\\R", "\\mathbb{R}");
|
884 | defineMacro("\\Z", "\\mathbb{Z}");
|
885 | defineMacro("\\alef", "\\aleph");
|
886 | defineMacro("\\alefsym", "\\aleph");
|
887 | defineMacro("\\Alpha", "\\mathrm{A}");
|
888 | defineMacro("\\Beta", "\\mathrm{B}");
|
889 | defineMacro("\\bull", "\\bullet");
|
890 | defineMacro("\\Chi", "\\mathrm{X}");
|
891 | defineMacro("\\clubs", "\\clubsuit");
|
892 | defineMacro("\\cnums", "\\mathbb{C}");
|
893 | defineMacro("\\Complex", "\\mathbb{C}");
|
894 | defineMacro("\\Dagger", "\\ddagger");
|
895 | defineMacro("\\diamonds", "\\diamondsuit");
|
896 | defineMacro("\\empty", "\\emptyset");
|
897 | defineMacro("\\Epsilon", "\\mathrm{E}");
|
898 | defineMacro("\\Eta", "\\mathrm{H}");
|
899 | defineMacro("\\exist", "\\exists");
|
900 | defineMacro("\\harr", "\\leftrightarrow");
|
901 | defineMacro("\\hArr", "\\Leftrightarrow");
|
902 | defineMacro("\\Harr", "\\Leftrightarrow");
|
903 | defineMacro("\\hearts", "\\heartsuit");
|
904 | defineMacro("\\image", "\\Im");
|
905 | defineMacro("\\infin", "\\infty");
|
906 | defineMacro("\\Iota", "\\mathrm{I}");
|
907 | defineMacro("\\isin", "\\in");
|
908 | defineMacro("\\Kappa", "\\mathrm{K}");
|
909 | defineMacro("\\larr", "\\leftarrow");
|
910 | defineMacro("\\lArr", "\\Leftarrow");
|
911 | defineMacro("\\Larr", "\\Leftarrow");
|
912 | defineMacro("\\lrarr", "\\leftrightarrow");
|
913 | defineMacro("\\lrArr", "\\Leftrightarrow");
|
914 | defineMacro("\\Lrarr", "\\Leftrightarrow");
|
915 | defineMacro("\\Mu", "\\mathrm{M}");
|
916 | defineMacro("\\natnums", "\\mathbb{N}");
|
917 | defineMacro("\\Nu", "\\mathrm{N}");
|
918 | defineMacro("\\Omicron", "\\mathrm{O}");
|
919 | defineMacro("\\plusmn", "\\pm");
|
920 | defineMacro("\\rarr", "\\rightarrow");
|
921 | defineMacro("\\rArr", "\\Rightarrow");
|
922 | defineMacro("\\Rarr", "\\Rightarrow");
|
923 | defineMacro("\\real", "\\Re");
|
924 | defineMacro("\\reals", "\\mathbb{R}");
|
925 | defineMacro("\\Reals", "\\mathbb{R}");
|
926 | defineMacro("\\Rho", "\\mathrm{P}");
|
927 | defineMacro("\\sdot", "\\cdot");
|
928 | defineMacro("\\sect", "\\S");
|
929 | defineMacro("\\spades", "\\spadesuit");
|
930 | defineMacro("\\sub", "\\subset");
|
931 | defineMacro("\\sube", "\\subseteq");
|
932 | defineMacro("\\supe", "\\supseteq");
|
933 | defineMacro("\\Tau", "\\mathrm{T}");
|
934 | defineMacro("\\thetasym", "\\vartheta");
|
935 |
|
936 | defineMacro("\\weierp", "\\wp");
|
937 | defineMacro("\\Zeta", "\\mathrm{Z}");
|
938 |
|
939 |
|
940 |
|
941 |
|
942 |
|
943 | defineMacro("\\argmin", "\\DOTSB\\mathop{\\operatorname{arg\\,min}}\\limits");
|
944 | defineMacro("\\argmax", "\\DOTSB\\mathop{\\operatorname{arg\\,max}}\\limits");
|
945 |
|
946 |
|
947 | defineMacro("\\blue", "\\textcolor{##6495ed}{#1}");
|
948 | defineMacro("\\orange", "\\textcolor{##ffa500}{#1}");
|
949 | defineMacro("\\pink", "\\textcolor{##ff00af}{#1}");
|
950 | defineMacro("\\red", "\\textcolor{##df0030}{#1}");
|
951 | defineMacro("\\green", "\\textcolor{##28ae7b}{#1}");
|
952 | defineMacro("\\gray", "\\textcolor{gray}{##1}");
|
953 | defineMacro("\\purple", "\\textcolor{##9d38bd}{#1}");
|
954 | defineMacro("\\blueA", "\\textcolor{##ccfaff}{#1}");
|
955 | defineMacro("\\blueB", "\\textcolor{##80f6ff}{#1}");
|
956 | defineMacro("\\blueC", "\\textcolor{##63d9ea}{#1}");
|
957 | defineMacro("\\blueD", "\\textcolor{##11accd}{#1}");
|
958 | defineMacro("\\blueE", "\\textcolor{##0c7f99}{#1}");
|
959 | defineMacro("\\tealA", "\\textcolor{##94fff5}{#1}");
|
960 | defineMacro("\\tealB", "\\textcolor{##26edd5}{#1}");
|
961 | defineMacro("\\tealC", "\\textcolor{##01d1c1}{#1}");
|
962 | defineMacro("\\tealD", "\\textcolor{##01a995}{#1}");
|
963 | defineMacro("\\tealE", "\\textcolor{##208170}{#1}");
|
964 | defineMacro("\\greenA", "\\textcolor{##b6ffb0}{#1}");
|
965 | defineMacro("\\greenB", "\\textcolor{##8af281}{#1}");
|
966 | defineMacro("\\greenC", "\\textcolor{##74cf70}{#1}");
|
967 | defineMacro("\\greenD", "\\textcolor{##1fab54}{#1}");
|
968 | defineMacro("\\greenE", "\\textcolor{##0d923f}{#1}");
|
969 | defineMacro("\\goldA", "\\textcolor{##ffd0a9}{#1}");
|
970 | defineMacro("\\goldB", "\\textcolor{##ffbb71}{#1}");
|
971 | defineMacro("\\goldC", "\\textcolor{##ff9c39}{#1}");
|
972 | defineMacro("\\goldD", "\\textcolor{##e07d10}{#1}");
|
973 | defineMacro("\\goldE", "\\textcolor{##a75a05}{#1}");
|
974 | defineMacro("\\redA", "\\textcolor{##fca9a9}{#1}");
|
975 | defineMacro("\\redB", "\\textcolor{##ff8482}{#1}");
|
976 | defineMacro("\\redC", "\\textcolor{##f9685d}{#1}");
|
977 | defineMacro("\\redD", "\\textcolor{##e84d39}{#1}");
|
978 | defineMacro("\\redE", "\\textcolor{##bc2612}{#1}");
|
979 | defineMacro("\\maroonA", "\\textcolor{##ffbde0}{#1}");
|
980 | defineMacro("\\maroonB", "\\textcolor{##ff92c6}{#1}");
|
981 | defineMacro("\\maroonC", "\\textcolor{##ed5fa6}{#1}");
|
982 | defineMacro("\\maroonD", "\\textcolor{##ca337c}{#1}");
|
983 | defineMacro("\\maroonE", "\\textcolor{##9e034e}{#1}");
|
984 | defineMacro("\\purpleA", "\\textcolor{##ddd7ff}{#1}");
|
985 | defineMacro("\\purpleB", "\\textcolor{##c6b9fc}{#1}");
|
986 | defineMacro("\\purpleC", "\\textcolor{##aa87ff}{#1}");
|
987 | defineMacro("\\purpleD", "\\textcolor{##7854ab}{#1}");
|
988 | defineMacro("\\purpleE", "\\textcolor{##543b78}{#1}");
|
989 | defineMacro("\\mintA", "\\textcolor{##f5f9e8}{#1}");
|
990 | defineMacro("\\mintB", "\\textcolor{##edf2df}{#1}");
|
991 | defineMacro("\\mintC", "\\textcolor{##e0e5cc}{#1}");
|
992 | defineMacro("\\grayA", "\\textcolor{##f6f7f7}{#1}");
|
993 | defineMacro("\\grayB", "\\textcolor{##f0f1f2}{#1}");
|
994 | defineMacro("\\grayC", "\\textcolor{##e3e5e6}{#1}");
|
995 | defineMacro("\\grayD", "\\textcolor{##d6d8da}{#1}");
|
996 | defineMacro("\\grayE", "\\textcolor{##babec2}{#1}");
|
997 | defineMacro("\\grayF", "\\textcolor{##888d93}{#1}");
|
998 | defineMacro("\\grayG", "\\textcolor{##626569}{#1}");
|
999 | defineMacro("\\grayH", "\\textcolor{##3b3e40}{#1}");
|
1000 | defineMacro("\\grayI", "\\textcolor{##21242c}{#1}");
|
1001 | defineMacro("\\kaBlue", "\\textcolor{##314453}{#1}");
|
1002 | defineMacro("\\kaGreen", "\\textcolor{##71B307}{#1}");
|