// Copyright (c) 2009-2022 The MathJax Consortium
// SPDX-License-Identifier: Apache-2.0
//
// This file is a Go translation and modification of MathJax 3.2.2.
// Sources: ts/input/tex/ams/AmsMethods.ts (AlignAt, AmsEqnArray),
// base/BaseMethods.ts (EqnArray), and ParseUtil.ts (setArrayAlign).

package tex

import (
	
	

	
)

func ( *parser) () (string, error) {
	, ,  := .readBrackets(nil)
	var  *Error
	if errors.As(, &) && .ID == "MissingCloseBracket" {
		return "", texError("MissingCloseBracket", "Could not find closing ']' for argument to \\begin")
	}
	return , 
}

func finishAlignedatTable( *mml.Node, ,  string,  int) {
	// AlignAt's positive counts supply repeated rl/zero-gap patterns, not a
	// maximum number of authored columns. EqnArray extends those patterns to
	// the actual row width. Empty and all-zero counts instead retain the
	// empty alignment and BaseMethods.EqnArray's fallback spacing.
	,  := "right left", "0em 0em"
	if strings.TrimLeft(, "0") == "" {
		,  = "", "1em"
	}
	.Attributes.Set("columnalign", repeatAMSEqnArrayDefinition(, ))
	.Attributes.Set("columnspacing", repeatAMSEqnArrayDefinition(, -1))

	setArrayAlign(, )
}

func setArrayAlign( *mml.Node,  string) {
	// ParseUtil.trimSpaces uses JavaScript whitespace and preserves the last
	// control-space before setArrayAlign interprets t/b/c.
	 := strings.TrimFunc(, internalTextSpace)
	if strings.HasSuffix(, `\`) && strings.HasSuffix(, " ") {
		 += " "
	}
	switch  {
	case "t":
		 = "baseline 1"
	case "b":
		 = "baseline -1"
	case "c":
		 = "axis"
	}
	if  != "" {
		.Attributes.Set("align", )
	}
}