명령을 정의하는 동안 명령에 대한 별칭 추가

명령을 정의하는 동안 명령에 대한 별칭 추가

\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 typeCommand '\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}

여기에 이미지 설명을 입력하세요

관련 정보