// Copyright 2017-2022 The MathJax Consortium // SPDX-License-Identifier: Apache-2.0 // Sources: BaseItems.NonscriptItem and BaseConfiguration.filterNonscript.
package tex import ( ) // NonscriptItem remembers only the immediately following MML item when it // contains a space. Other stack items consume it; commands which push no item // leave it pending. The inherited scriptlevel is not available until the // post-filter, so no parser-time style approximation belongs here. func ( *parser) ( *mml.Node) *mml.Node { if == nil { return } := if .Kind == "mstyle" && .Flags.NotParent { if len(.Children) == 0 || len(.Children[0].Children) == 0 { return } = .Children[0].Children[0] } if .Kind != "mspace" { return } if != { // Fixed-size spacing macros explicitly set their mstyle's level to // zero. This temporary outer row records the surrounding level. = node("mrow", ) } .state.nonscriptSpaces = append(.state.nonscriptSpaces, ) return } // The source filter runs after inheritance, before moveLimits/cleanStretchy. // Retained styled spaces shed only the temporary row; script spaces are // removed with their wrapper. Genuine authored groups never enter this list. func filterNonscript( []*mml.Node) error { for , := range { := .Parent if == nil { continue } , := .Attributes.Get("scriptlevel") // The source's > 0 comparison uses the same ECMAScript scalar // number conversion as the existing maction selection helper. if mml.MactionSelectionNumber(, ) > 0 { // The original filter splices required children too, which can // make its output wrapper throw. Report that conversion failure // instead of handing an incomplete fixed-arity node to layout. if := .Flags.Arity; > 0 && != mmlUnboundedArity && len(.Children)-1 < { return fmt.Errorf("nonscript removal leaves %s without a required child", .Kind) } _ = .RemoveChild() } else if .Kind == "mrow" && len(.Children) != 0 { _ = .ReplaceChild(.Children[0], ) } } return nil }