
同じ定義を使用して複数のコマンドを一度に定義できるコマンドが必要です\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}