If I have a macro \Name
that expands to a macro name, I can use that with \csname
or the various tools from etoolbox. Can I do the opposite, i.e., get the name of a macro?
My use case is the following: I want to write a command \Mtx
that produces a smallmatrix
(from mathtools). An optional argument should take a delimiter size, and if it is not provided, the size is determined automatically (this deviates slightly from the syntax mathtools' \DeclarePairedDelimiterX
imposes for the commands it defines).
I tried
\DeclareDocumentCommand{\Mtx}{om}{
\IfNoValueTF{#1}{
\left(\begin{smallmatrix}#2\end{smallmatrix}\right)
}{
#1(\begin{smallmatrix}#2\end{smallmatrix}#1)
}
}
However, I thought it might be advisable to have a provided \big
for #1
replaced by \bigl
and \bigr
, respectively. Is it advisable?
So, I thought, if there is a command \GetName
such that \GetName{\command}
expands to command
, then I could do:
\DeclareDocumentCommand{\Mtx}{om}{
\IfNoValueTF{#1}{
\left(\begin{smallmatrix}#2\end{smallmatrix}\right)
}{
\csuse{\GetName{#1}l}(\begin{smallmatrix}#2\end{smallmatrix}\csuse{\GetName{#1}r})
}
}
Is that possible? I guess someone will point at lacking error handling. But now I'm curious!