Why the alignat environment in amsmath needs a mandatory argument

alignatamsmath

Why must the alignat environment in amsmath need a mandatory argument? Is it an unnecesssary design (as we can see, the align doesn't need any mandatory or optional arguments) or there is something that makes the argument indispensable?

Best Answer

This is inherited from the original amstex code. It certainly isn't required by the implementation which just uses it to raise an error if the number of & doesn't match the number of column-pairs specified by the argument. It is an undocumented secret but the value of -1 is used as a flag by align to allow an arbitrary number of columns, and would also work here.

Clearly it could have been defined to always work without the number of columns check then the number of columns argument wouldn't be needed. Presumably the original author thought that the syntax was confusing and getting the document author to be explicit would help catch errors.

enter image description here

\documentclass{article}

\usepackage{amsmath}

\begin{document}

2/2 no error
\begin{alignat}{2}
 a&=1   \quad & b&=2\\
 aa&=11 \quad & bb&=22
\end{alignat}

-1/2 no error
\begin{alignat}{-1}
 a&=1   \quad & b&=2\\
 aa&=11 \quad & bb&=22
\end{alignat}


-1/3 no error
\begin{alignat}{-1}
 a&=1   \quad & b&=2   &\quad c&=3\\
 aa&=11 \quad & bb&=22
\end{alignat}

2/3 error
\iffalse
\begin{alignat}{2}
 a&=1   \quad & b&=2   &\quad c&=3\\
 aa&=11 \quad & bb&=22
\end{alignat}
\fi
\end{document}
Related Question