Empty pmatrix looks weird

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}\]

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}

enter image description here

Tags:

Matrices