diff --git a/src/Parser.js b/src/Parser.js index 7649128d..045c2bfe 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -464,7 +464,6 @@ export default class Parser { * \textrm, where instead of keeping a style we just pretend that there is an * implicit grouping after it until the end of the group. E.g. * small text {\Large large text} small text again - * It is also used for \left and \right to get the correct grouping. */ parseImplicitGroup(breakOnTokenText?: "]" | "}" | "$"): ?ParseNode { const start = this.parseSymbol(); @@ -497,25 +496,6 @@ export default class Parser { style: "text", value: body, }, "math"); - } else if (func === "\\left") { - // If we see a left: - // Parse the entire left function (including the delimiter) - const left = this.parseGivenFunction(start); - // Parse out the implicit body - ++this.leftrightDepth; - const body = this.parseExpression(false); - --this.leftrightDepth; - // Check the next token - this.expect("\\right", false); - const right = this.parseFunction(); - if (!right) { - throw new ParseError('failed to parse function after \\right'); - } - return new ParseNode("leftright", { - body: body, - left: left.value.value, - right: right.value.value, - }, this.mode); } else if (func === "\\begin") { // begin...end is similar to left...right const begin = this.parseGivenFunction(start); diff --git a/src/functions/delimsizing.js b/src/functions/delimsizing.js index 9e5a8b30..a7782984 100644 --- a/src/functions/delimsizing.js +++ b/src/functions/delimsizing.js @@ -128,12 +128,34 @@ defineFunction({ handler: (context, args) => { const delim = checkDelimiter(args[0], context); - // \left and \right are caught somewhere in Parser.js, which is - // why this data doesn't match what is in buildHTML. - return { - type: "leftright", - value: delim.value, - }; + if (context.funcName === "\\left") { + const parser = context.parser; + // Parse out the implicit body + ++parser.leftrightDepth; + // parseExpression stops before '\\right' + const body = parser.parseExpression(false); + --parser.leftrightDepth; + // Check the next token + parser.expect("\\right", false); + const right = parser.parseFunction(); + if (!right) { + throw new ParseError('failed to parse function after \\right'); + } + return { + type: "leftright", + body: body, + left: delim.value, + right: right.value.value, + }; + } else { + // This is a little weird. We return this object which gets turned + // into a ParseNode which gets returned by + // `const right = parser.parseFunction();` up above. + return { + type: "leftright", + value: delim.value, + }; + } }, htmlBuilder: (group, options) => { // Build the inner expression