// Copyright 2017-2022 The MathJax Consortium // SPDX-License-Identifier: Apache-2.0 // Based on PhysicsMethods.Derivative/Differential/Commutator, AmsMethods, and TexParser.
package tex import ( ) // Derivative, Differential, Commutator, OperatorApplication, VectorOperator, // SideSet, OperatorName and BuildRel create child TexParsers. // Configuration remains shared, but the lexical environment is copied and // the parser's macro count starts at zero. Only source-proven child-parser // boundaries inherit this local policy; sliced same-parser rows do not reset. func ( *parser) ( string) (*mml.Node, error) { := .state.macroCount .state.macroCount = 0 defer func() { .state.macroCount = }() := &parser{source: , state: .state, display: .display, inRoot: .inRoot, activeColor: .activeColor, multiLetterFont: .multiLetterFont, activeFont: .activeFont, identifierPattern: .identifierPattern, operatorLetters: .operatorLetters, noAutoOP: .noAutoOP, fontExplicitEmpty: .fontExplicitEmpty, vectorFactory: .vectorFactory, vectorFont: .vectorFont, vectorStar: .vectorStar, vectorAlias: .vectorAlias, genfracPalette: .genfracPalette, starMacroChildren: .starMacroChildren, derivativeChildren: true} , , := .parseRow(0, false) if != nil { return nil, } := row(, true) if .activeFont != "" { applyScopedMathVariant(, .activeFont) } return , nil } // Differential reparses the operator, optional power and raw operand together. // In particular, registered operators are honored and leading operand scripts // attach to the differential rather than to an independently parsed empty base. func ( *parser) ( string, **derivativeAutoOpen) ([]*mml.Node, error) { , , := .readBrackets(nil) if != nil { var *Error if errors.As(, &) && .ID == "MissingCloseBracket" { return nil, texError(.ID, "Could not find closing ']' for argument to %s", "\\"+) } return nil, } := "\\diffd" if == "variation" || == "var" { = "\\delta" } if { += "^{" + + "}" } else { += " " } .skipNextSpaces() := .pos < len(.source) && .source[.pos] == '(' := .pos < len(.source) && .source[.pos] == '{' if ! { , , := .readArgument(, !) if != nil { return nil, } += } , := .parseChild() if != nil { return nil, } if { return []*mml.Node{texAtom(, mml.TeXClassOp)}, nil } if { * = &derivativeAutoOpen{} } return unwrapInferred(), nil }