¿Ifmtarg prueba una macro que está vacía?

¿Ifmtarg prueba una macro que está vacía?

El siguiente código funciona como se esperaba:

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

Sin embargo, cómo hacer que funcione cuando se proporciona como argumento una macro potencialmente vacía:

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

¿Cómo hacer que se imprima emptymanejando una macro vacía como argumento vacío?

Respuesta1

Quieres utilizar expl3una expansión recursiva.

\ExplSyntaxOn

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

\ExplSyntaxOff

Ejemplo completo:

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

ingrese la descripción de la imagen aquí

Si desea considerar "vacío" también la secuencia de espacios, reemplácela con

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

Ejemplo completo:

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

ingrese la descripción de la imagen aquí

información relacionada