목록의 각 요소에 대한 새 명령 노출

목록의 각 요소에 대한 새 명령 노출

패키지 에서 lVars사용하여 정의된 매크로가 있습니다 (일부).foreachpgfforPGF) 처럼:

\newcommand{\lVars}[1]{\foreach \x [count=\ii] in {#1}{
  \ifnum\ii=1{} \else {,} \fi \lVar[\x]}
}

\exists \lVars{a, b, c, d}의도된 사용은 결과를 생성하는 것과 같은 용어입니다 \exists \lVar[a], \lVar[b], \lVar[c], \lVar[d]. 이 명령은 \lVar[a]형식의 또 다른 사용자 정의 명령이지만 \newcommand{\lVar}[1][x]{\textsc{#1}}곧 더 복잡해질 수 있습니다. 그런 다음 \lVar더 큰 포럼 내에서 새로 정량화된 요소를 사용합니다 .

그러나 나는 매우 게으르다. 나는 이 매크로가 각 목록 요소를 양식 등의 새로운 명령으로 노출시키고, 그 자체가 실제 기본 , ...로 확장되기를 원합니다. \lA이러한 \lB새로운 \lVar[A]명령 \lVar[B]은 내 수식 표기법을 훨씬 덜 장황하게 만들 것입니다. 이러한 새 명령은 다음에 a, b,...가 매크로의 목록 매개변수에 사용될 때까지 지속되어야 합니다 lVars. 따라서 전반적인 사용법은 다음과 같은 상황이 됩니다.

\begin{displaymath}
  \begin{array}{l}
    \exists \lVars{a, b, c}.~ \lA = \lB \implies \lA = \lC \\
    \lC = 0 \implies \lA = 0
    \exists \lVars{a, b}.~ \lA \neq \lB
  \end{array}
\end{displaymath}

And, as we see in the term $\lA = \lB$, the implication...

나는 행운 없이 의 본문 안팎 \newcommand에서 다양한 순열을 실험했습니다 . 조언이나 팁이 있나요?\defforeach

답변1

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\ExplSyntaxOn

\NewDocumentCommand{\lVars}{m}
 {
  % cycle through the argument
  \clist_map_inline:nn { #1 }
   {
    % print the variable
    \lVar[##1]
    % if the variable is a, define \lA
    \tl_to_uppercase:n
     {
      \cs_gset_protected:cpn { \c_wright_prefix_tl ##1 }
     }
     { \lVar[##1] }
   }
 }
% We need to store the `l' prefix in a control sequence to hide it from \uppercase
\tl_const:Nn \c_wright_prefix_tl { l }
\ExplSyntaxOff

\newcommand{\lVar}[1][x]{\textsc{#1}}

\begin{document}
\begin{displaymath}
  \begin{array}{l}
    \exists \lVars{a, b, c}.~ \lA = \lB \implies \lA = \lC \\
    \lC = 0 \implies \lA = 0
    \exists \lVars{a, b}.~ \lA \neq \lB
  \end{array}
\end{displaymath}

And, as we see in the term $\lA = \lB$, the implication...
\end{document}

그러나 '의 정의'는 \lC영원히 유지됩니다. 이를 다른 셀에서 사용할 계획이라면 array전역 정의가 필요합니다.

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


\lFoo다중 문자 변수를 허용하고 다음에서 정의하는 버전 \lVars{foo}:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\lVars}{m}
 {
  % cycle through the argument
  \clist_map_inline:nn { #1 }
   {
    % print the variable
    \lVar[##1]
    % build the name with the first letter uppercase
    \wright_make_var_name:n { ##1 }
    \cs_gset_protected:cpn { \l__wright_var_name_tl } { \lVar[##1] }
   }
 }
\tl_const:Nn \c_wright_prefix_tl { l }
\cs_new:Npn \wright_make_var_name:n #1
 {
  % get the first letter and uppercase it
  \tl_to_uppercase:n
   {
    \tl_set:Nx \l__wright_var_name_tl { \tl_head:n {#1} }
   }
  % add the rest
  \tl_put_right:Nx \l__wright_var_name_tl { \tl_tail:n {#1} }
  % add the prefix
  \tl_put_left:Nx \l__wright_var_name_tl { \c_wright_prefix_tl }
 }
\ExplSyntaxOff
\newcommand{\lVar}[1][x]{\textsc{#1}}

\begin{document}
\begin{displaymath}
  \begin{array}{l}
    \exists \lVars{a, b, c}.~ \lA = \lB \implies \lA = \lC \\
    \lC = 0 \implies \lA = 0
    \exists \lVars{a, b}.~ \lA \neq \lB
  \end{array}
\end{displaymath}

And, as we see in the term $\lA = \lB$, the implication...

Now $\forall\lVars{foo}\;\lFoo=0$
\end{document}

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

관련 정보