2

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. lyx image

  • 1
    You're using the environment form of pmatrix, and then request a use of \begin{pmatrix}[...]{ ... }... can you explain and/or correct this? – Werner May 05 '20 at 03:20
  • A pmatrix environment is just an array environment in disguise. Ir's probably more straightforward to apply patches to the contents of an array environment than to a pmatrix environment. – Mico May 05 '20 at 04:19
  • @Werner, thank you. I have updated the question with a LyX screenshot to explain why I cannot directly apply the optional arguments. Basically my hands are tied on that one, since LyX doesn't have it built in, so I need to patch the command form the outside. – Zlatko-Minev May 05 '20 at 11:22

1 Answers1

7

In recent versions of nicematrix, the key transparent is deprecated (because the name was ambiguous). One should use the keys renew-dots and renew-matrix instead.


If you want the environment pmatrix of amsmath behave as the environment pNiceMatrix of nicematrix, you should load the package nicematrix with the keys renew-dots and renew-matrix:

\documentclass{article}
\usepackage[renew-dots,renew-matrix]{nicematrix}
\begin{document}
$\begin{pmatrix}[first-row,first-col]
  & a & b \\
x & 1 & 2 \\
y & 3 & 4
\end{pmatrix}$
\end{document}

Result of the above code

F. Pantigny
  • 40,250
  • Thank you. I loaded it with \usepackage[renew-matrix]{nicematrix}, which i think also redefines pmatrix. I can use transperant instead. The problem is that I am typesetting using LyX, (see updated question above), which generates LaTeX code. I cannot directly add optional arguments to pmatrix in Lyx, but I can call LaTeX code directly beforehand, as shown in picture above with \AddOptinalArgumentsHere command. Is that possible somehow? – Zlatko-Minev May 05 '20 at 11:18
  • @AimForClarity: You can use \NiceMatrixOptions which sets nicematrix options. But this command sets the options globally. We will have to put a { before \NiceMatrixOptions and a } after the matrix. However, in the current version of nicematrix, the options first-row and co are not accepted in \NiceMatrixOptions. But I can change that. If you are interested, send me an email and I will send a modified version for testing (you will find my address on the documentation of nicematrix). – F. Pantigny May 05 '20 at 13:42
  • Thank you, just e-mailed you – Zlatko-Minev May 05 '20 at 14:16