MCPcopy
hub / github.com/KaTeX/KaTeX / MacroExpander

Class MacroExpander

src/MacroExpander.ts:29–467  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27};
28
29export default class MacroExpander implements MacroContextInterface {
30 settings: Settings;
31 expansionCount: number;
32 lexer!: Lexer;
33 macros: Namespace<MacroDefinition>;
34 stack: Token[];
35 mode: Mode;
36
37 constructor(input: string, settings: Settings, mode: Mode) {
38 this.settings = settings;
39 this.expansionCount = 0;
40 this.feed(input);
41 // Make new global namespace
42 this.macros = new Namespace(macros, settings.macros);
43 this.mode = mode;
44 this.stack = []; // contains tokens in REVERSE order
45 }
46
47 /**
48 * Feed a new input string to the same MacroExpander
49 * (with existing macros etc.).
50 */
51 feed(input: string) {
52 this.lexer = new Lexer(input, this.settings);
53 }
54
55 /**
56 * Switches between "text" and "math" modes.
57 */
58 switchMode(newMode: Mode) {
59 this.mode = newMode;
60 }
61
62 /**
63 * Start a new group nesting within all namespaces.
64 */
65 beginGroup() {
66 this.macros.beginGroup();
67 }
68
69 /**
70 * End current group nesting within all namespaces.
71 */
72 endGroup() {
73 this.macros.endGroup();
74 }
75
76 /**
77 * Ends all currently nested groups (if any), restoring values before the
78 * groups began. Useful in case of an error in the middle of parsing.
79 */
80 endGroups() {
81 this.macros.endGroups();
82 }
83
84 /**
85 * Returns the topmost token on the stack, without expanding it.
86 * Similar in behavior to TeX's `\futurelet`.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…