// Copyright 2017-2022 The MathJax Consortium
// SPDX-License-Identifier: Apache-2.0
// Sources: ts/input/tex/{NodeFactory,ParseOptions,ParseUtil}.ts.

package tex

import 

// Registration belongs to this parse, including its argument subparsers. It
// records actual construction events before handlers can reorder or detach
// nodes. Pure constructors and the shared MML factory have no mutable hook.
func ( *parser) ( *mml.Node) *mml.Node {
	if  != nil && .Kind == "mo" && .state != nil {
		.state.operators = append(.state.operators, )
	}
	return 
}

func ( *parser) (,  string) *mml.Node {
	return .noteMO(token(, ))
}

func ( *parser) ( string,  mml.TeXClass,  map[string]any) *mml.Node {
	return .noteMO(operator(, , ))
}

// ParseUtil.copyNode registers the copied tree in preorder immediately after
// copying, including nodes later detached by pruning. It does not register
// nodes that have merely been reparented. Derivative instead reparses source
// through a child parser sharing this same parse state.
func ( *parser) ( *mml.Node) *mml.Node {
	 := .Clone()
	if  != nil {
		.Walk(func( *mml.Node) bool {
			.noteMO()
			.notePoppedScript()
			return true
		})
	}
	return 
}

func ( *parser) ( string) *mml.Node {
	return .noteMO(namedOperator())
}

func ( *parser) ( string) (*mml.Node, bool) {
	,  := lookupExtensionSymbol()
	return .noteMO(), 
}

func ( *parser) ( string) *mml.Node {
	return .noteMO(cdHorizontalArrow())
}

func ( *parser) ( string) *mml.Node {
	return .noteMO(cdVerticalArrow())
}

func ( *parser) ( string,  mml.TeXClass) *mml.Node {
	return amsFixedFencePaletteWithToken(, , .token)
}

func ( *parser) ( string,  *mml.Node,  string,  bool) *mml.Node {
	return fencedWithOperator(, , , , .operator)
}

func ( *parser) ( string,  *mml.Node,  string,  bool) *mml.Node {
	 := .fenced(, , , )
	.SetProperty("open", )
	.SetProperty("close", )
	.SetProperty("texClass", mml.TeXClassInner)
	.TeXClass = mml.TeXClassInner
	return 
}

func ( *parser) () *mml.Node {
	return physicsNablaWithOperator(.operator)
}

func ( *parser) ( *mml.Node) *mml.Node {
	return empheqCopiedTopRowTable(.copyNode())
}

// Source symbols create one token with no intervening parse. Register only that
// new node, retaining the source map's actual token kind and attributes.
func ( *parser) ( string) (*mml.Node, bool) {
	,  := lookupMJSourceSymbol()
	if  && .fontExplicitEmpty && .activeFont == "" {
		// mathchar7 applies the environment's font only when it is truthy.
		// An explicit empty MathFont keeps the mapped default (e.g. upright
		// Gamma), and an enclosing font must not later overwrite that choice.
		if ,  := .Property(ambientFontSource);  == true {
			.SetProperty(resolvedFontScope, true)
		}
	}
	return .noteMO(), 
}

func ( *parser) ( string,  *mml.Node,  string,  bool) *mml.Node {
	 := .fenced(, , , )
	.TeXClass = mml.TeXClassInner
	return 
}

// AutoOpen fences use the node factory; changing to p.token would alter the
// accepted construction. Content has already supplied its own creation events.
func ( *parser) ( string,  mml.TeXClass) *mml.Node {
	return .noteMO(autoOpenFence(, ))
}

func ( *parser) ( *mml.Node) *mml.Node {
	return normalizeDecorationBaseWithMO(, func() *mml.Node { return .noteMO(node("mo")) })
}