import Parser from "./Parser";
import ParseError from "./ParseError";
import {Token} from "./Token";
import type Settings from "./Settings";
import type {AnyParseNode} from "./parseNode";
const parseTree = function(toParse: string, settings: Settings): AnyParseNode[] {
if (!(typeof toParse === 'string' || toParse instanceof String)) {
throw new TypeError('KaTeX can only parse string typed expression');
}
const parser = new Parser(toParse, settings);
delete parser.gullet.macros.current["\\df@tag"];
let tree = parser.parse();
delete parser.gullet.macros.current["\\current@color"];
delete parser.gullet.macros.current["\\color"];
if (parser.gullet.macros.get("\\df@tag")) {
if (!settings.displayMode) {
throw new ParseError("\\tag works only in display equations");
}
tree = [{
type: "tag",
mode: "text",
body: tree,
tag: parser.subparse([new Token("\\df@tag")]),
}];
}
return tree;
};
export default parseTree;