[texhax] Finding blank argument to macro

Uwe Lueck uwe.lueck at web.de
Fri Jun 11 16:43:31 CEST 2010


Jim Diamond <Jim.Diamond at acadiau.ca> wrote at 27.05.2010 13:43:48:
>On Thu, May 27, 2010 at 07:17 (-0400), Michael Barr wrote:
>
>> Here is a fragment of a macro I use to find if an argument is empty:
>
>>     \setbox0\hbox{$#9$}%
>>    \ifdim \wd0=0pt%
>>    %%%%%%%% omitted what you do if arg empty
>>    \else
>>    %%%%%%%% omitted what you do if not
>>    \if
>
>Hmmm... what if #9 is
>	\hbox to 0 pt{blah \hss}
>?
>
>Arguably a pathological example, but arguably not.

    ctan.org/pkg/ifmtarg

is Donald Arseneau's solution. \@ifmtarg{arg1}{if}{otherwise} expands to "if" if "arg1" is nothing or a sequence of spaces, otherwise to "otherwise".

I know how to fool it, I guess you can fool any test that is expandable. Michael Barr's macro is not expandable. A non-expandable macro that is absolutely reliable is \IfEmpty with

    \def\IfEmpty#1{\def\Arg{#1}\ifx\Arg\Empty\FirstOfTwo\else\SecondOfTwo\fi}

with

    \def\Empty{} \def\FirstOfTwo#1#2{#1} \def\SecondOfTwo#1#2{#2}

With LaTeX, you may replace \Empty by \@empty, \FirstOfTwo by \@firstoftwo, \SecondOfTwo by \@secondoftwo without defining them.

Sorry for looking late at this.

Cheers, 

    Uwe.


More information about the texhax mailing list