The command \matrix
is defined in the LaTeX kernel
% latex.ltx, line 4509:
\def\matrix#1{\null\,\vcenter{\normalbaselines\m@th
\ialign{\hfil$##$\hfil&&\quad\hfil$##$\hfil\crcr
\mathstrut\crcr\noalign{\kern-\baselineskip}
#1\crcr\mathstrut\crcr\noalign{\kern-\baselineskip}}}\,}
\def\pmatrix#1{\left(\matrix{#1}\right)}
(the version of LaTeX used is LaTeX2e <2018-12-01>
).
Comparing it with plain.tex
% plain.tex, line 1093:
\def\matrix#1{\null\,\vcenter{\normalbaselines\m@th
\ialign{\hfil$##$\hfil&&\quad\hfil$##$\hfil\crcr
\mathstrut\crcr\noalign{\kern-\baselineskip}
#1\crcr\mathstrut\crcr\noalign{\kern-\baselineskip}}}\,}
\def\pmatrix#1{\left(\matrix{#1}\right)}
we see no difference at all.
The reason is historical: when LaTeX was first issued, it incorporated much of plain.tex
, in order to ease switch from one to the other. Moreover, the original LaTeX kernel had very basic support for math: in addition to plain TeX structures it only provided displaymath
, equation
, eqnarray
and eqnarray*
. The eqnarray
environment and its starred companion were designed as replacement for eqalignno
and eqalign
(but not the best replacement).
When amsmath
came to light (at first named amslatex
), a problem arose: the original amstex.tex
plug in for plain.tex used \matrix ... \endmatrix
which ought to get the LaTeX syntax \begin{matrix}...\end{matrix}
. There's of course a conflict: a document using \matrix{...}
as supported by the LaTeX kernel would be at stake if amsmath
is loaded. Similarly for \pmatrix{...}
and \begin{pmatrix}...\end{pmatrix}
.
Indeed amsmath
has
\renewenvironment{matrix}{%
\matrix@check\matrix\env@matrix
}{%
\endarray \hskip -\arraycolsep
}
\def\env@matrix{\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{*\c@MaxMatrixCols c}}
\newcount\c@MaxMatrixCols \c@MaxMatrixCols=10
\def\matrix@check#1{%
\@xp\ifx\csname\@currenvir\endcsname#1%
\else\matrix@error#1%
\@xp\@gobble
\fi
}
\def\matrix@error#1{%
\@amsmath@err{%
Old form `\string#1' should be \string\begin{\@xp\@gobble\string#1}%
}{%
`\string#1{...}' is old Plain-TeX syntax whose use is
ill-advised in LaTeX.%
}%
}
\renewenvironment{pmatrix}{%
\left(%
\matrix@check\pmatrix\env@matrix
}{
\endmatrix\right)%
}
What does this mean? We know that \begin{foo}
first does some bookkeeping, including defining \@currenvir
to mean foo
and then executes \foo
, so replacing it with the tokens given in the “begin part” at definition time. In the case of \matrix
and \pmatrix
, \matrix@check
is performed; this command checks whether the current environment name matches either matrix
or pmatrix
; this will be true if the document has used \begin{matrix}
or \begin{pmatrix}
, but false if the plain TeX syntax \matrix{...}
or \pmatrix{...}
is used. In the latter case, an error is raised and the argument to \matrix
or \pmatrix
is gobbled for allowing to complete the LaTeX run.
This conflict is not really so serious: every document with substantial use of math should load amsmath
and therefore employ the \begin{matrix}
or \begin{pmatrix}
syntax.
By the way, this has a consequence; if one wants to build over matrix
using “macho programming style”, an environment should not be defined like
\newenvironment{foomatrix}
{<something at the beginning>\matrix}
{\endmatrix<something at the end>}
because this would trigger \matrix@error
. Instead
\makeatletter
\newenvironment{foomatrix}
{<something at the beginning>\env@matrix}
{\endmatrix<something at the end>}
\makeatother
should be used; for instance, amsmath
has
\newenvironment{bmatrix}{\left[\env@matrix}{\endmatrix\right]}
With MathJax, both
\matrix{ 1 & 0 \cr 0 & 1 }
and
\begin{matrix} 1 & 0 \\ 0 & 1 \end{matrix}
are allowed. The implementation doesn't really “expand” \begin
like it's done in LaTeX, so it is free to do other tricks.
\usepackage{amsmath}
doom
avatar. But I've reached the limit cap. Wait, is that doom or wolfenstein?doom
and I upped for you :)