# What is the mandatory argument of alignedat for?

alignedat has a mandatory argument. But Herbert (in his mathmode.pdf) wrote as follows,

I have made a trial and error, I noticed that the largest number that can be passed is 1073741823 and no failure occurs.

\documentclass[twocolumn]{article}
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{amsmath}
\begin{document}
\begin{enumerate}
\item The degree of (C) is 3.
\item The degree of (A) is 1.
\item%
\! \begin{alignedat}[t]{1073741823} -3x(x+1)&-2x(x-1)\\ &+4(x^2-3x-1) &&=\rlap{-3x^2-3x-2x^2+2x+v$} \\ & &&\hphantom{{}={}}{+}4x^2&&-12x-4\\ & &&=-3x^2 &&-3x-2x^2+2x+v \\ & && &&+4x^2-12x-4 \\ & &&=\rlap{$-x^2-13x-4} \end{alignedat}
\end{enumerate}
\end{document}


My question: What is this argument for? Why is it mandatory if it is not necessary? It should be an optional argument, I think.

-
The mbox file format strikes again! –  Mariano Suárez-Alvarez Jan 31 '13 at 4:35
It stores the value in \maxfields@ and is used avoid using more than the specified number of alignment points. So, of course, using a large number would have no impact. –  Werner Jan 31 '13 at 4:41
... (continuing from Werner's comment) - indeed, you'll get errors if you use a value that is too small... –  cmhughes Jan 31 '13 at 4:56
...it also relates to a shared "base function" \start@aligned. It is shared between aligned and alignedat; the mandatory argument distinguishes a specific use of the base function. –  Werner Jan 31 '13 at 5:21
It's mandatory because you want to use it for alignments you build the intercolumn spaces of and you want to be in control of what you're doing. If Herbert Voß has different opinions about this, they're just opinions: mine is that users should specify precisely what they want or use align. In any case, keep in mind that amsmath descends from AMS-TeX, where the argument to \alignedat was necessary. –  egreg Jan 31 '13 at 8:04

The definitions of the "align" environments are

\newenvironment{alignat}
{\start@align\z@\st@rredfalse}
{\endalign}
\newenvironment{xalignat}
{\start@align\@ne\st@rredfalse}
{\endalign}
\newenvironment{xxalignat}
{\start@align\tw@\st@rredtrue}
{\endalign}
\newenvironment{align}
{\start@align\@ne\st@rredfalse\m@ne}
{...}
\newenvironment{flalign}
{\start@align\tw@\st@rredfalse\m@ne}
{\endalign}


The first argument to \start@align (which has three of them) is a number telling what type of alignment is desired, with respect to the intercolumn spaces; the second declares what \ifst@rred should mean (the *-variants, of course, have \st@rredtrue) and the third is the number of column groups, which is -1 for align and flalign that haven't a predefined number of them. In the case of alignat, the third argument is the (apparent) argument to \begin{alignat} (and the same for xalignat and xxalignat).

The number of columns (if set) is important for the later measurements for accommodating the equation numbers.

One could argue that the argument to \begin{alignat} is not really necessary, but since one uses the environment for stating explicitly what the spacing between (groups of two) columns is, the number is useful for making users certain about where they are and if no \\ has been forgotten. Maybe the argument could have been made optional, but amsmath is a direct descendant of AMS-TeX, where optional arguments weren't used; so the syntax has been preserved and I see good uses of it.

Since alignedat is the "inner" version of alignat it must have the same syntax. And the same considerations about its usefulness apply as well.

-

Well I came across a reason to not use a large number for the mandatory parameter, and instead to specify exactly the precise number: so that an error message is issued if one accidentally forgets a trailing \\ at the end of a line. Using a large number will not result in an error message:

## Notes:

• Now that I reread the comments, I think that this what Werner and cmhughes were getting at in their comments, but didn't understand that until I actually encountered this problem just now.

• The example below uses alignat*, but alignedat exhibits similar issues.

## Code:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\noindent
This will flag an error \verb|Package amsmath Error: Extra & on this line| if the double backslash is missing:
\begin{alignat*}{3}
v_5 &= v_4 - v_3 +1 &&= 1 - 3 +1 &&= 1, \\
v_6 &= v_5 - v_4 +1 &&= 1 - 1 +1 &&= 0,
\end{alignat*}
But if a large number is used \LaTeX will happily typeset it without warning:
\begin{alignat*}{999}
v_5 &= v_4 - v_3 +1 &&= 1 - 3 +1 &&= 1,
v_6 &= v_5 - v_4 +1 &&= 1 - 1 +1 &&= 0,
\end{alignat*}
\end{document}

-