Usando \notblank en la declaración \ifboolexpr de etoolbox

Usando \notblank en la declaración \ifboolexpr de etoolbox

Como dice el título, actualmente estoy intentando utilizar \ifboolexprla declaración de etoolbox sobre \notblanklas condiciones, pero tengo problemas con ella. El código en cuestión se ve así:

\ifboolexpr{%
  test {\notblank{\Temp@Temp@Text@a}} or %
  test {\notblank{\Temp@Temp@Text@b}} or %
  test {\notblank{\Temp@Temp@Text@c}}    %
}%
{}{}%

Sin embargo, genera un montón de errores. Incluso intentar algo como esto no parece funcionar mejor:

\ifboolexpr{%
  test {\notblank{}} or %
  test {\notblank{}} or %
  test {\notblank{}}    %
}%
{}{}%

Lo máximo que puedo usar sin problemas es (dado como MWE. Para reproducir mis problemas, simplemente sustituya la \ifbookexprdeclaración):

\documentclass[10pt,a4paper,titlepage,twoside,onecolumn]{report}
\RequirePackage{etoolbox}

\makeatletter
\def\Temp@Temp@Text@a{testa}
\def\Temp@Temp@Text@b{testb}
\def\Temp@Temp@Text@c{testc}

\makeatother

\begin{document}

\makeatletter

\ifboolexpr{%
  test {} or %
  test {} or %
  test {}    %
}%
{true}{false}%

\makeatother

\end{document}

Entonces mi pregunta es:

  • Qué estoy haciendo mal ?
  • Cómo resolverlo ?

Respuesta1

La documentación de etoolboxestablece que el argumento hacia \ifblanky hacia \notblankesnoexpandido. Por lo tanto, \notblank{\xyz}devolverá "verdadero" sin importar cuál sea la definición de \xyz.

Si desea una expansión completa, debe solicitarla explícitamente, por ejemplo

\documentclass[10pt,a4paper,titlepage,twoside,onecolumn]{report}
\usepackage{etoolbox}

\begin{document}

\makeatletter

\def\Temp@Temp@Text@a{testa}
\def\Temp@Temp@Text@b{testb}
\def\Temp@Temp@Text@c{testc}

\begingroup\edef\x{\endgroup
  \noexpand\ifboolexpr{%
    test {\noexpand\notblank{\Temp@Temp@Text@a}} or 
    test {\noexpand\notblank{\Temp@Temp@Text@b}} or 
    test {\noexpand\notblank{\Temp@Temp@Text@c}}    
  }}\x{\typeout{true}}{\typeout{false}}%

\def\Temp@Temp@Text@a{}
\def\Temp@Temp@Text@b{}
\def\Temp@Temp@Text@c{}

\begingroup\edef\x{\endgroup
  \noexpand\ifboolexpr{%
    test {\noexpand\notblank{\Temp@Temp@Text@a}} or 
    test {\noexpand\notblank{\Temp@Temp@Text@b}} or 
    test {\noexpand\notblank{\Temp@Temp@Text@c}}    
  }}\x{\typeout{true}}{\typeout{false}}%

\makeatother

\end{document}

La primera instancia regresa true, mientras que la segunda regresa false.

Respuesta2

El catoptionspaquete tiene exactamente lo que necesitas sin más código. \xifblankFTmediocompletamente expandido, no en blanco. También existe \oifblankFTsu significadoexpandido en un paso, no en blanco.

\documentclass{report}
\usepackage{catoptions}
\def\vgap{\par\bigskip}

\begin{document}
\def\tempa{testa}
\def\tempb{testb}
\def\tempc{testc}

First test (true):
\ifexprTF{%
  test {\xifblankFT{\tempa}} or
  test {\xifblankFT{\tempb}} or
  test {\xifblankFT{\tempc}}
}{
  true
}{
  false
}

\vgap
\def\tempa{}
\def\tempb{}
\def\tempc{}

Second test (false):
\ifexprTF{%
  test {\xifblankFT{\tempa}} or
  test {\xifblankFT{\tempb}} or
  test {\xifblankFT{\tempc}}
}{
  true
}{
  false
}

\def\tempd{x}

\vgap
Third test (false):
\ifexprTF{%
  ( test {\xifblankTF{\tempa}} or test {\xifblankTF{\tempb}} )
  and
  ( test {\xifblankFT{\tempc}} and test {\xifblankFT{\tempd}} )
}{
  true
}{
  false
}

\vgap
\def\tempe{00}
\newif\iftestbool

Fourth test (true):
\ifexprTF{%
  ( switch {tempe} or bool {testbool} )
  and
  (  ( test {\xifblankTF{\tempc}} and not test {\xifblankTF{\tempd}} )
     or
     ( test {\xifstrcmpTF\tempa\tempb} or not test {\ifxTF\tempc\tempd} )
  )
}{
  true
}{
  false
}
\end{document}

Este tipo de cálculo booleano es caro. Sólo necesita mirar el registro de seguimiento para confirmar esta afirmación. El 99 por ciento de las veces puedes hacerlo con una prueba mucho más simple. Por ejemplo, como \xifstrcmpFTes ampliable, tenemos una prueba económica:

\def\do#1{\ifx\do#1\relax\else+\xifstrcmpFT{#1}{}01\expandafter\do\fi}
\ifnum0=\numexpr0\do\tempa\tempb\tempc\tempd\do
  true
\else
  false
\fi

información relacionada