// Copyright (c) 2009-2022 The MathJax Consortium // SPDX-License-Identifier: Apache-2.0 // Source: ts/input/tex/ParseUtil.ts fixInitialMO; base/BaseItems.ts // EqnArrayItem.EndEntry and ams/AmsItems.ts MultlineItem.EndEntry.
package tex import // fixInitialMO preserves operator spacing at an alignment boundary. Source // skips mspace and empty TeXAtoms, then inspects the first remaining node. // Every embellished operator qualifies, as does a relation TeXAtom. func fixInitialMO( []*mml.Node) []*mml.Node { for , := range { if == nil || .Kind == "mspace" { continue } if .Kind == "TeXAtom" && (len(.Children) == 0 || len(.Children[0].Children) == 0) { continue } if .Flags.Embellished || (.Kind == "TeXAtom" && .TeXClass == mml.TeXClassRel) { return append([]*mml.Node{node("mi")}, ...) } break } return } // EqnArray applies the repair to every entry after the first in each row. // Multline applies it to each entry after the first row. Call before adding // label cells or layout padding that was not present at EndEntry. func fixInitialArrayOperators( *mml.Node, , int) { if len(.Children) <= { return } for , := range .Children[:] { if len(.Children) <= { continue } for , := range .Children[:] { if len(.Children) == 0 { continue } := .Children[0] .SetChildren(fixInitialMO(.Children)) } } }