I would like to define a new command with two optional arguments, one at the end. This works:
\newcommand{\matr}[3]{{}_{#1}\textbf{#2}_{#3}}
\matr{b}{M}{e}
But I would like to call it like this:
\matr[b]{M}[e]
leaving out the optional brackets, if I don't need them. Is it possible?
Best Answer
You want to use
\NewDocumentCommand
. Theo
argument specifier means an optional argument with no default value, which can be tested with\IfValueTF
(in this case only the “true“ branch is necessary).Note that
\textbf
is wrong in this context and you want\mathbf
.