\tl_case:Nn(TF) 및 \str_case:nn(TF)의 좋은 예

\tl_case:Nn(TF) 및 \str_case:nn(TF)의 좋은 예

을 배우면서 및 를 expl3사용하는 데 어려움을 겪고 있습니다 . 온라인에서 좋은 예를 찾지 못했습니다. (예를 들어,\str_case:nn(TF)\tl_case:Nn(TF)unravel\tl_case:Nn(TF)나에게는 너무 복잡합니다.) 적용 및 \str_case:nn(TF)시연 목적으로 독립적이고 간결하며 유용한 예를 제공할 수 있습니까 ? 우리가 다루자

  1. \tl_case:NnTF
  2. \str_case:nnTF
  3. \str_case_e:nnTF

첫 번째. 나는 그것들을 어디서 얻었는가?http://mirrors.ctan.org/macros/latex/contrib/l3kernel/interface3.pdf. :cnTF, :Nn 등과 같은 다른 접미사에 대한 예를 제공하고 싶다면 언제든지 알려주시기 바랍니다.

답변1

\str_case:nnTF이는 단지 , \str_case_e:nn및 를 적용하는 데모일 뿐입니다 \tl_case:nnTF.

등에 대한 사례는 :cnTF이미 질문에 대한 설명에서 설명되었습니다.

\str_case_e와 의 차이점은 \str_case논증의 확장이다. a \tl..와 차이점은 \str..문자열의 경우 문자의 catcode가 모두 동일하다는 것입니다(12). 단, 공백 문자의 경우 코드는 여전히 10입니다. 반면 토큰 목록에서는 catcode가 유지됩니다.

버전 \foo:nnTF은 입력 스트림에 조건부 분기를 입력합니다. 추가 처리 또는 설정(또는 '조판')을 위해 일치하는 괄호를 사용 {foobar}{...}하거나 이를 TF 분기로 전환하는 것이 가능합니다.

나는 개인적으로 \foo:nn유일한 것을 사용하고 지금까지 필요했던 것을 기억할 수 없지만 \foo:nnTF이것은 물론 실제 사용 사례에 따라 다릅니다.

\documentclass{article}

\usepackage{expl3}

\ExplSyntaxOn

\newcommand{\strcase}[1]{%
  \str_case:nn {#1} {
    {TeX} {\use:c{#1}\space is\space the\space predecessor\space of\space \LaTeX}
    {LaTeX} {\use:c{#1}\space is\space the\space successor\space of\space \TeX}
  }
}

\newcommand{\strcasetf}[3]{%
  \str_case:nnTF {#1} {
    {TeX} {\use:c{#1}\space is\space the\space predecessor\space of\space \LaTeX}
    {LaTeX} {\use:c{#1}\space is\space the\space successor\space of\space \TeX}
    {Word} {#1\space is\space a\space 'typesetter'}
  }{
    \space#2
  }{
    \space#3
  }
}

\newcommand{\genericstrcase}[3]{%
  \str_case:nn {#3} {
    {#1} {It was the first argument}
    {#2} {It was the second argument}
    {Other} {#1 it was 'other'}
  }
}


\newcommand{\strcasextf}[3]{%
  \str_case_e:nnTF {#1} {
    {TeX} {\use:c{#1}\space is\space the\space predecessor\space of\space \LaTeX}
    {LaTeX} {\use:c{#1}\space is\space the\space successor\space of\space \TeX}
    {Word} {#1\space is\space a\space 'typesetter'}
  }{
    \space#2
  }{
    \space#3
  }
}

\tl_new:N \l_tl_one
\tl_new:N \l_tl_two

\newcommand{\tlcase}[3]{%
  \tl_set:Nn \l_tl_one {#1}
  \tl_set:Nn \l_tl_two {#2}

\tl_set:Nn \l_tmpa_tl {#3}

\tl_case:Nn \l_tmpa_tl {
  {\l_tl_one} {Yes,\space it\space was\space #1}
  {\l_tl_two}  {Yes,\space it\space was\space #2}
}
}

\ExplSyntaxOff

\newcommand{\LaTeXStr}{LaTeX}
\newcommand{\WordPressString}{WordPress}
\newcommand{\WordString}{Word}


\begin{document}

\strcase{TeX}

\strcase{LaTeX}

\strcasetf{LaTeX}{-- the strings match}{-- the strings does not match!}

\strcasetf{Word}{-- the strings match}{-- the strings does not match!}

\strcasetf{WordPress}{-- the strings match}{-- the strings does not match!}

\textbf{Compare}

\strcasetf{\LaTeXStr}{-- the strings match}{-- the strings does not match!}

\strcasextf{\LaTeXStr}{-- the strings match}{-- the strings does not match!}

\tlcase{LaTeX}{TeX}{LaTeX}
\tlcase{LaTeX}{TeX}{\LaTeX} % Does nothing, since \LaTeX is not expanded

\textbf{Comparing command tokens}

\tlcase{\LaTeX}{TeX}{\LaTeX}% Compares again

\tlcase{LaTeX is very nice}{TeX}{LaTeX is very nice} 
\tlcase{TeX is nice}{TeX is not outdated}{TeX is very nice} % Does not match

\textbf{Comparing strings}

\genericstrcase{LaTeX}{TeX}{LaTeX}

\genericstrcase{ #LaTeX}{ #TeX}{ #TeX}

\genericstrcase{\LaTeX}{TeX}{\LaTeX}

\end{document}

관련 정보