// Copyright (c) 2020-2022 MathJax Consortium
// SPDX-License-Identifier: Apache-2.0
// This file is a Go translation and modification of MathJax 3.2.2.
//
// Source: ts/input/tex/mathtools/MathtoolsMethods.ts,
// MathtoolsUtil.ts, MathtoolsItems.ts, and MathtoolsMappings.ts.

package tex

import 

// mathtoolsCommand is the single command-dispatch hook for the central parser.
// commandNodes resolves macro-map priorities before calling this hook: an
// existing dynamic delimiter registration has priority -5 over user macros.
// This hook precedes the generic source-symbol and legacy delimiter paths.
func ( *parser) ( string) ( []*mml.Node,  bool,  error) {
	if ,  := .state.pairedDelimiters[];  {
		,  = .mathtoolsPairedDelimiter(, )
		return , true, 
	}

	switch  {
	case "mathllap", "mathrlap", "mathclap", "crampedllap", "crampedrlap", "crampedclap", "clap", "textllap", "textrlap", "textclap":
		,  = .lap()
	case "cramped":
		,  = .cramped()
	case "mathmbox":
		,  = .mathMBox()
	case "mathmakebox":
		,  = .mathMakeBox()
	case "overbracket", "underbracket":
		,  = .mathtoolsUnderOverBracket()
	case "DeclarePairedDelimiter", "DeclarePairedDelimiters", "DeclarePairedDelimiterX", "DeclarePairedDelimitersX", "DeclarePairedDelimiterXPP", "DeclarePairedDelimitersXPP":
		 = .mathtoolsDeclarePairedDelimiter()
	case "centercolon":
		 = []*mml.Node{.mathtoolsCenterColon(true, true, false)}
	case "ordinarycolon":
		 = []*mml.Node{.mathtoolsCenterColon(false, false, false)}
	case "MTThinColon":
		 = []*mml.Node{.mathtoolsCenterColon(true, true, true)}
	case "coloneqq", "Coloneqq", "coloneq", "Coloneq", "eqqcolon", "Eqqcolon", "eqcolon", "Eqcolon", "colonapprox", "Colonapprox", "colonsim", "Colonsim", "dblcolon":
		,  = .mathtoolsRelation()
	case "nuparrow", "ndownarrow":
		 = []*mml.Node{mathtoolsNArrow()}
	case "splitfrac", "splitdfrac":
		,  = .mathtoolsSplitFrac(,  == "splitdfrac")
	case "xmathstrut":
		,  = .mathtoolsXMathStrut()
	case "prescript":
		,  = .prescript()
	case "adjustlimits":
		,  = .mathtoolsAdjustLimits()
	case "mathtoolsset":
		 = .mathtoolsSetOptions()
	case "newtagform", "renewtagform":
		 = .mathtoolsNewTagForm(,  == "renewtagform")
	case "usetagform":
		 = .mathtoolsUseTagForm()
	case "Aboxed", "ArrowBetweenLines", "MTFlushSpaceAbove", "MTFlushSpaceBelow", "vdotswithin", "shortvdotswithin":
		 = texError("NotInAlignment", "\\%s can only be used in aligment environments", )
	case "shoveleft", "shoveright":
		 = texError("CommandOnlyAllowedInEnv", "\\%s only allowed in %s environment", , "multline")
	default:
		return nil, false, nil
	}
	return , true, 
}

// mathtoolsEnvironment is the single begin-environment hook.  p.pos must be
// immediately after the parsed environment-name argument; the handler owns
// any following options/arguments and capture of its matching \end.
func ( *parser) ( string) ( []*mml.Node,  bool,  error) {
	switch  {
	case "smallmatrix", "smallmatrix*",
		"psmallmatrix", "psmallmatrix*", "bsmallmatrix", "bsmallmatrix*",
		"Bsmallmatrix", "Bsmallmatrix*", "vsmallmatrix", "vsmallmatrix*",
		"Vsmallmatrix", "Vsmallmatrix*":
		,  = .mathtoolsSmallMatrix()
	case "multlined":
		,  = .mathtoolsMultlined()
	case "spreadlines":
		,  = .mathtoolsSpreadLines()
	case "cases*", "dcases*", "rcases*", "drcases*":
		,  = .mathtoolsCases()
	case "multline", "multline*":
		,  = .mathtoolsMultline()
	default:
		return nil, false, nil
	}
	return , true, 
}