I often want to define a command (using xparse) like the following
\NewDocumentCommand{\Comon}{oo}{
\IfNoValueTF{#1}{
\mathsf{Mod}
}{
\IfNoValueTF{#2}{
\mathsf{Mod}_{#1}
}{
\mathsf{Mod}_{#1}(#2)
}
}
}
so that the same command name \Mod
with different numbers of optional arguments displays differently.
Ideally, I'd be able to write my own command \NewCommandAlts
which would be called like
\NewCommandAlts{\Mod}{2}
{\mathsf{Mod}}
{\mathsf{Mod}_{#1}}
{\mathsf{Mod}_{#1}(#2)}
and would define a command \Mod
that is equivalent to the one defined above.
The best that I have is
\newcommand{\NewCommandAltsTwo}[4]{
\NewDocumentCommand{#1}{oo}{
\IfNoValueTF{##1}{#2}{\IfNoValueTF{##2}{#3}{#4}}
}
}
\NewCommandAltsTwo{\Mod}
{\mathsf{Mod}}
{\mathsf{Mod}_{#1}}
{\mathsf{Mod}_{#1}(#2)}
which works. Any ideas for how to write the case that handles any number of arguments?
\Mod[a][b][c][d]
is impossible to read and you can't not supply a if you want to supply d, at that stage it's better to use a different syntax such as\mod[field=2, value=42, whatever=something,...]
\Mod[a]{}[b]{}[c]{}[d]
. ;-))\NewDocumentCommand\splat{d<> o}
...\splat<one>[two]
.