I have lots of matrices so I want to define a mat environment. I sometimes need the matrix to have right-aligned columns so I am using mathtools and I want to have an optional argument that is usually c but that I can make r when I want.
A small working example is below. The definition works great in lots of cases, including inside the equation* but inside of align* it fails.
Specifically, I get ! Extra }, or forgotten $. <recently read> } l.22 \end{align*}.
If I add [c] or [r] as optional arguments to the mat inside the align* then compilation will succeed. Adding a \ (slash, space) to the first line of the mat, before the &\vdots, also works.
To me this looks like a problem with LaTeX trying to read the optional argument when I don't want it to. I've tried putting %'s in various places in the \begin{pmatrix*}[#1] line but to no avail. Any suggestions?
\documentclass{article}
\RequirePackage{mathtools}
\newenvironment{mat}[1][c]{\begin{pmatrix*}[#1]
}{\end{pmatrix*}}
\begin{document}
\begin{equation*}
\begin{mat}
&\vdots \\
\cdots &ra_{j,i}+sb_{j,i} &\cdots \\
&\vdots
\end{mat}
\end{equation*}
\begin{align*}
\begin{mat}
&\vdots \\
\cdots &ra_{j,i}+sb_{j,i} &\cdots \\
&\vdots
\end{mat}
&= 0
\end{align*}
\end{document}