I need to patch the math command pmatrix with optional arguments. For example, I'd like to patch the following code, while treating it as immutable.
\[
\begin{pmatrix}
& a & b\\
c & 1 & 2\\
d & 3 & 4
\end{pmatrix}
\]
The goal is supply some optional arguments to pmatrix, such as in \begin{pmatrix}[first-row, first-col]{ ..., which are required from
nicematrix. So the arguments would be supplied like this:
{
\AddOptionalArgumentsHere[first-row,first-col]
\[
\begin{pmatrix}
& a & b\\
c & 1 & 2\\
d & 3 & 4
\end{pmatrix}
\]
}
Seems etoolbox or xpatch should be able to easily do this, but I'm struggling to figure it out. I guess it should be something like
\patchcmd{pmatrix}{}{}{}{}
The reason I can't just type the optional arguments into latex is because the code is generated by lyx.


pmatrix, and then request a use of\begin{pmatrix}[...]{ ... }... can you explain and/or correct this? – Werner May 05 '20 at 03:20pmatrixenvironment is just anarrayenvironment in disguise. Ir's probably more straightforward to apply patches to the contents of anarrayenvironment than to apmatrixenvironment. – Mico May 05 '20 at 04:19