
Eu gostaria de ter um comando \NewDocumentCommands
que permita que vários comandos sejam definidos ao mesmo tempo usando a mesma definição. Por exemplo:
\NewDocumentCommands { \powerset, \Powerset, \PowerSet } {} { \mathcal{P} }
\NewDocumentCommands { \mat, \bmat } { m } { \begin{bmatrix} #1 \end{bmatrix} }
Minha tentativa ingênua:
\NewDocumentCommand { \NewDocumentCommands } { m m m }
{
\seq_set_split:Nnn \l_tmpa_seq { , } { #1 }
\seq_map_inline:Nn \l_tmpa_seq
{
\NewDocumentCommand { ##1 } { #2 } { #3 }
}
}
Isso gera um TeX capacity exceeded
erro, no entanto.
Outra tentativa:
\NewDocumentCommand
{ \CommandNewDocument }
{ m m m }
{ \NewDocumentCommand { #3 } { #1 } { #2 } }
\NewDocumentCommand
{ \NewDocumentCommands }
{ > { \SplitList { , } } m m m }
{ \ProcessList { #1 } { \CommandNewDocument { #2 } { #3 } } }
Isso gera todos os tipos de erros ( Command '\s__tl_stop' already defined.
, Invalid argument type
, e Command '\CommandNewDocument' already defined.
)
Estou ciente de que poderia simplesmente escrever
\NewDocumentCommand { \powerset } {} { \mathcal{P} }
\NewDocumentCommand { \Powerset } {} { \powerset }
\NewDocumentCommand { \PowerSet } {} { \powerset }
\NewDocumentCommand { \mat } { m } { \begin{bmatrix} #1 \end{bmatrix} }
\NewDocumentCommand { \bmat } { m } { \mat { #1 } }
ou alternativamente,
\NewDocumentCommand { \powerset } {} { \mathcal{P} }
\let\Powerset\powerset
\let\PowerSet\powerset
\NewDocumentCommand { \mat } { m } { \begin{bmatrix} #1 \end{bmatrix} }
\let\bmat\mat
No entanto, um comando dedicado \NewDocumentCommands
parece melhor para mim se muitos comandos com vários aliases forem definidos.
Responder1
É um problema de #
duplicação. Você também pode evitar definir uma sequência.
\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}