MCPcopy Create free account
hub / github.com/KaTeX/KaTeX / parse

Method parse

src/Parser.ts:120–152  ·  view source on GitHub ↗

* Main parsing function, which parses an entire input.

()

Source from the content-addressed store, hash-verified

118 * Main parsing function, which parses an entire input.
119 */
120 parse(): AnyParseNode[] {
121 if (!this.settings.globalGroup) {
122 // Create a group namespace for the math expression.
123 // (LaTeX creates a new group for every $...$, $$...$$, \[...\].)
124 this.gullet.beginGroup();
125 }
126
127 // Use old \color behavior (same as LaTeX's \textcolor) if requested.
128 // We do this within the group for the math expression, so it doesn't
129 // pollute settings.macros.
130 if (this.settings.colorIsTextColor) {
131 this.gullet.macros.set("\\color", "\\textcolor");
132 }
133
134 try {
135 // Try to parse the input
136 const parse = this.parseExpression(false);
137
138 // If we succeeded, make sure there's an EOF at the end
139 this.expect("EOF");
140
141 // End the group namespace for the expression
142 if (!this.settings.globalGroup) {
143 this.gullet.endGroup();
144 }
145
146 return parse;
147
148 // Close any leftover groups in case of a parse error.
149 } finally {
150 this.gullet.endGroups();
151 }
152 }
153
154 /**
155 * Fully parse a separate sequence of tokens as a separate job.

Callers 8

parseTreeFunction · 0.95
cli.jsFile · 0.80
initFunction · 0.80
symgroups.tsFile · 0.80
verify-build.jsFile · 0.80
screenshotter.jsFile · 0.80
index.jsFile · 0.80
getOptionsFunction · 0.80

Calls 6

parseExpressionMethod · 0.95
expectMethod · 0.95
setMethod · 0.80
beginGroupMethod · 0.45
endGroupMethod · 0.45
endGroupsMethod · 0.45

Tested by

no test coverage detected