I was using a cool macro to write some nice matrices inside a particular math environment, from this question:
But then I wanted to use the same macro to fix some other matrices which have nothing to do with the ones in the previous question (in another chapter of the same document). I just noticed that the macro gives the same column spacings for all matrices, even when they aren't in the same environment. The macro appears to have a global effect, which I certainly don't want.
How can I make that macro to work locally only, in a given environment, without having any affect on other environments?
Here's a MWE which shows the problem:
\documentclass[11pt,letterpaper,twoside]{book}
\usepackage{lmodern}
\usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
\usepackage{microtype}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{eqparbox}
\newcommand{\squash}[2][M]{\eqmakebox[#1]{$#2$}}
\begin{document}
These matrices are affected by the last matrices, which is bad:
\begin{align}
A &=
\begin{bmatrix}
0 & \squash{\sigma_2} \[1em]
\squash{\sigma_2}& 0
\end{bmatrix},
\
B &=
\begin{bmatrix}
\squash{-i \sigma_3} & 0 \[1em]
0 & \squash{-i \sigma_3}
\end{bmatrix},
\end{align}
These matrices are affecting the first matrices which is bad:
\begin{align}
C &=
\begin{bmatrix}
0 & \squash{1} \[1em]
\squash{r \sin \vartheta \cos \varphi} & 0
\end{bmatrix},
\
D &=
\begin{bmatrix}
\squash{-, r^2} & 0 \[1em]
0 & \squash{-, r^2}
\end{bmatrix},
\end{align}
\end{document}
Preview with the problem shown in red:



}was missing – egreg Jun 26 '20 at 16:49