// Copyright (c) 2009-2022 The MathJax Consortium // SPDX-License-Identifier: Apache-2.0 // Source: ts/input/tex/physics/PhysicsMethods.ts, createVectorToken/VectorBold.
package tex import ( ) const vectorFactoryToken = "go-vector-factory-token" const vectorFactoryDone = "go-vector-factory-done" // Token factory selection happens before an enclosing font scope is lowered. // Each token is visited once in its creating parser's environment; subparser // results must not be recolored when their parent later appends them. func ( *parser) ( *mml.Node) { if !.vectorFactory || == nil { return } .Walk(func( *mml.Node) bool { , := .Property(vectorFactoryToken) , := .Property(vectorFactoryDone) if != true || == true { return true } .SetProperty(vectorFactoryDone, true) := textContent() , := utf8.DecodeRuneInString() // The source uses text.length === 1 (UTF-16), excluding supplementary runes. if .activeFont != "" || .vectorFont == "" || == 0 || != len() || > 0xFFFF { return true } , := .Attributes.Get("accent") := >= 'A' && <= 'Z' || >= 'a' && <= 'z' || >= 0x391 && <= 0x3A9 || >= '0' && <= '9' || .vectorStar && >= 0x3B1 && <= 0x3C9 || == true if { .Attributes.Set("mathvariant", .vectorFont) } return true }) } func ( *parser) ( string, bool) (*mml.Node, error) { // VectorBold always creates a genuine child TexParser, including when // reached through a registered macro in a StarMacro continuation. := .state.macroCount .state.macroCount = 0 defer func() { .state.macroCount = }() := "bold" if { = "bold-italic" } := &parser{source: , state: .state, display: .display, inRoot: .inRoot, activeColor: .activeColor, multiLetterFont: .multiLetterFont, vectorFactory: true, vectorFont: , vectorStar: , identifierPattern: .identifierPattern, operatorLetters: .operatorLetters, noAutoOP: .noAutoOP, // VectorBold deletes font; an absent font still permits identifier grouping. fontExplicitEmpty: false, genfracPalette: .genfracPalette, starMacroChildren: .starMacroChildren, derivativeChildren: .derivativeChildren} , , := .parseRow(0, false) if != nil { return nil, } := row(, true) // Deleting the outer font applies to unselected and authored tokens too. // Protect their resulting default/explicit choice from deferred outer scopes. .Walk(func( *mml.Node) bool { if .Flags.Token { .SetProperty(resolvedFontScope, true) } return true }) // The pinned handler deletes, rather than restores, the current vector env. // A nested VectorBold thus clears that env for later tokens in the same row. .vectorFont = "" .vectorStar = false .fontExplicitEmpty = false return , nil }