ifmtarg가 비어 있는 매크로를 테스트하고 있습니까?

ifmtarg가 비어 있는 매크로를 테스트하고 있습니까?

다음 코드는 예상대로 작동합니다.

\NewDocumentCommand{\checker}{m}{\@ifmtarg{#1}{empty}{not empty}}
\checker{}  % Prints "empty"
\checker{x} % Prints "not empty"

그러나 잠재적으로 비어 있는 매크로가 인수로 제공될 때 작동하게 만드는 방법은 다음과 같습니다.

\newcommand{\emptymacro}{}
\NewDocumentCommand{\checker}{m}{\@ifmtarg{#1}{empty}{not empty}}
\checker{\emptymacro}  % Prints "not empty"

empty빈 매크로를 빈 인수로 처리하여 인쇄하는 방법은 무엇입니까 ?

답변1

expl3재귀 확장을 사용하고 싶습니다 .

\ExplSyntaxOn

\NewExpandableDocumentCommand{\checker}{mmm}
 {
  \tl_if_empty:eTF { #1 } { #2 } { #3 }
 }

\ExplSyntaxOff

전체 예:

\documentclass{article}

\ExplSyntaxOn

\NewExpandableDocumentCommand{\checker}{mmm}
 {
  \tl_if_empty:eTF { #1 } { #2 } { #3 }
 }

\ExplSyntaxOff

\newcommand{\aaa}{\bbb}
\newcommand{\bbb}{\ccc}
\newcommand{\ccc}{}

\newcommand{\ddd}{\eee}
\newcommand{\eee}{e}

\begin{document}

\checker{}{empty}{not empty}

\checker{e}{empty}{not empty}

\checker{\aaa}{empty}{not empty}

\checker{\bbb}{empty}{not empty}

\checker{\ccc}{empty}{not empty}

\checker{\ddd}{empty}{not empty}

\checker{\eee}{empty}{not empty}

\end{document}

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

"비어 있는" 공백도 고려하려면 다음으로 바꾸십시오.

\NewExpandableDocumentCommand{\checker}{mmm}
 {
  \tl_if_blank:eTF { #1 } { #2 } { #3 }
 }

전체 예:

\documentclass{article}

\ExplSyntaxOn

\NewExpandableDocumentCommand{\checker}{mmm}
 {
  \tl_if_blank:eTF { #1 } { #2 } { #3 }
 }

\ExplSyntaxOff

\newcommand{\aaa}{\bbb}
\newcommand{\bbb}{\ccc}
\newcommand{\ccc}{}

\newcommand{\ddd}{\eee}
\newcommand{\eee}{e}

\newcommand{\fff}{\space\space}

\begin{document}

\checker{}{empty}{not empty}

\checker{e}{empty}{not empty}

\checker{\aaa}{empty}{not empty}

\checker{\bbb}{empty}{not empty}

\checker{\ccc}{empty}{not empty}

\checker{\ddd}{empty}{not empty}

\checker{\eee}{empty}{not empty}

\checker{\fff}{empty}{not empty}

\end{document}

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

관련 정보