
Me gustaría tener un comando \NewDocumentCommands
que permita definir varios comandos a la vez usando la misma definición. Por ejemplo:
\NewDocumentCommands { \powerset, \Powerset, \PowerSet } {} { \mathcal{P} }
\NewDocumentCommands { \mat, \bmat } { m } { \begin{bmatrix} #1 \end{bmatrix} }
Mi ingenuo intento:
\NewDocumentCommand { \NewDocumentCommands } { m m m }
{
\seq_set_split:Nnn \l_tmpa_seq { , } { #1 }
\seq_map_inline:Nn \l_tmpa_seq
{
\NewDocumentCommand { ##1 } { #2 } { #3 }
}
}
Sin embargo, esto arroja un TeX capacity exceeded
error.
Otro intento:
\NewDocumentCommand
{ \CommandNewDocument }
{ m m m }
{ \NewDocumentCommand { #3 } { #1 } { #2 } }
\NewDocumentCommand
{ \NewDocumentCommands }
{ > { \SplitList { , } } m m m }
{ \ProcessList { #1 } { \CommandNewDocument { #2 } { #3 } } }
Esto arroja todo tipo de errores ( Command '\s__tl_stop' already defined.
, Invalid argument type
y Command '\CommandNewDocument' already defined.
)
Soy consciente de que podría simplemente escribir
\NewDocumentCommand { \powerset } {} { \mathcal{P} }
\NewDocumentCommand { \Powerset } {} { \powerset }
\NewDocumentCommand { \PowerSet } {} { \powerset }
\NewDocumentCommand { \mat } { m } { \begin{bmatrix} #1 \end{bmatrix} }
\NewDocumentCommand { \bmat } { m } { \mat { #1 } }
o alternativamente,
\NewDocumentCommand { \powerset } {} { \mathcal{P} }
\let\Powerset\powerset
\let\PowerSet\powerset
\NewDocumentCommand { \mat } { m } { \begin{bmatrix} #1 \end{bmatrix} }
\let\bmat\mat
Sin embargo, un comando dedicado \NewDocumentCommands
me parece mejor si se definen muchos comandos con múltiples alias.
Respuesta1
Es un problema de #
duplicación. También puedes evitar establecer una secuencia.
\documentclass{article}
\usepackage{amsmath}
\ExplSyntaxOn
\NewDocumentCommand { \NewDocumentCommands } { m m m }
{
\tl_set:Nn \l_tmpa_tl { #3 }
\clist_map_inline:nn { #1 }
{
\exp_args:NnnV \NewDocumentCommand { ##1 } { #2 } \l_tmpa_tl
}
}
\ExplSyntaxOff
\NewDocumentCommands { \powerset, \Powerset, \PowerSet } {} { \mathcal{P} }
\NewDocumentCommands { \mat, \bmat } { m } { \begin{bmatrix} #1 \end{bmatrix} }
\begin{document}
$\powerset\Powerset\PowerSet$
$\mat{a\\b}+\bmat{a\\b}$
\end{document}