
Я хотел бы иметь команду \NewDocumentCommands
, которая позволяет определять несколько команд одновременно, используя одно и то же определение. Например:
\NewDocumentCommands { \powerset, \Powerset, \PowerSet } {} { \mathcal{P} }
\NewDocumentCommands { \mat, \bmat } { m } { \begin{bmatrix} #1 \end{bmatrix} }
Моя наивная попытка:
\NewDocumentCommand { \NewDocumentCommands } { m m m }
{
\seq_set_split:Nnn \l_tmpa_seq { , } { #1 }
\seq_map_inline:Nn \l_tmpa_seq
{
\NewDocumentCommand { ##1 } { #2 } { #3 }
}
}
Однако это приводит к TeX capacity exceeded
ошибке.
Еще одна попытка:
\NewDocumentCommand
{ \CommandNewDocument }
{ m m m }
{ \NewDocumentCommand { #3 } { #1 } { #2 } }
\NewDocumentCommand
{ \NewDocumentCommands }
{ > { \SplitList { , } } m m m }
{ \ProcessList { #1 } { \CommandNewDocument { #2 } { #3 } } }
Это приводит к появлению всевозможных ошибок ( Command '\s__tl_stop' already defined.
, Invalid argument type
, и Command '\CommandNewDocument' already defined.
)
Я знаю, что я мог бы просто написать
\NewDocumentCommand { \powerset } {} { \mathcal{P} }
\NewDocumentCommand { \Powerset } {} { \powerset }
\NewDocumentCommand { \PowerSet } {} { \powerset }
\NewDocumentCommand { \mat } { m } { \begin{bmatrix} #1 \end{bmatrix} }
\NewDocumentCommand { \bmat } { m } { \mat { #1 } }
или, в качестве альтернативы,
\NewDocumentCommand { \powerset } {} { \mathcal{P} }
\let\Powerset\powerset
\let\PowerSet\powerset
\NewDocumentCommand { \mat } { m } { \begin{bmatrix} #1 \end{bmatrix} }
\let\bmat\mat
Однако мне кажется, что отдельная команда \NewDocumentCommands
будет удобнее, если будет определено много команд с несколькими псевдонимами.
решение1
Это проблема #
удвоения. Вы также можете избежать установки последовательности.
\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}