# Empty pmatrix looks weird

I just noticed that an empty pmatrix looks somewhat unexpected. Namely,

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\begin{pmatrix} \end{pmatrix}$
\end{document}


looks like )( rather than (). First of all, is this a bug or feature? Second, is it possible to tell LaTeX to render an empty pmatrix like ()?

P.S.: The same thing happens if I manually add braces using \left(\begin{matrix}\end{bmatrix}\right) instead of pmatrix.

• \begin{pmatrix} \null \end{pmatrix} will also render the parentheses in the expected order.
– Mico
Jun 10 '18 at 13:10
• Is there any difference between \null and \relax? Jun 10 '18 at 13:15
• \null is defined in the LaTeX kernel as \hbox{}, i.e., it is an instruction that creates an empty (horizontal) box -- in the present context, a truly empty cell inside the array created by the pmatrix environment. In contrast, \relax (which is a TeX "primitive" command) means, somewhat colloquially speaking, "stop whatever it is you're doing right now (and start over afresh with the next command)". In the case of \begin{pmatrix}\relax\end{pmatrix}, the end effect of \relax is to start an array cell, as noted in @egreg's answer.
– Mico
Jun 10 '18 at 13:55
• @Mico \relax (or \leavevmode etc would be safer to insert in a modified environment as if a cell has real content a \relax at the end will not change anything, but adding a \null could change the spacing of binary oprators etc) Jun 10 '18 at 14:01
• @Mico mostly I was musing to myself since if it's going to be changed in amsmath it would be in my lap, I suspect changes required would be too intrusive unfortunately Jun 10 '18 at 15:20

That's essentially expected, because the code executed for pmatrix is something like

\left(
\hspace{-\arraycolsep}
\begin{array}{*{\value{MaxMatrixCols}{c}}
<body of the matrix>
\end{array}
\hspace{-\arraycolsep}
\right)


so if the array is empty only the two \hspace{-\arraycolsep} act.

Use \begin{pmatrix}\relax\end{pmatrix}, the unexpandable token \relax will start an array cell, if you don't want to use the easier ().

Example:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

X$\begin{pmatrix}\end{pmatrix}$X

X$(\hspace{-2\arraycolsep})$X

X$\begin{pmatrix}\relax\end{pmatrix}$X

\end{document}


• It may be "expected" for TeX hackers, but certainly not for end users! Jun 10 '18 at 13:14

One possible fix in the package would be

\documentclass{article}
\usepackage{amsmath}
\renewenvironment{matrix}{%
\matrix@check\matrix\env@matrix
}{%
\leavevmode\endarray \hskip -\arraycolsep
}
\begin{document}
$\begin{pmatrix} \end{pmatrix}$
\end{document}


But It's not safe in general, need to think if there is a suitable guard, you need to avoid forcing an extra row in

   $\begin{pmatrix} x\\ \end{pmatrix}$


which should act like

    $\begin{pmatrix} x \end{pmatrix}$