* Main parsing function, which parses an entire input.
()
| 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. |
no test coverage detected