[t152@vmars.tuwien.ac.at: Re: [texhax] Macro Problem]
Michael Doob
mdoob at cc.UManitoba.CA
Mon May 5 11:54:26 CEST 2003
> That's exactly the point; I have extended your example:
>
> INPUT:
>
> \def\truefalseX#1{%
> \ifx#1\empty\typeout{X:true}\else\typeout{X:false}\fi}
>
> \def\truefalseY#1{%
> \ifx#1\empty\else\typeout{Y:false}\fi}
>
> \truefalseX{}
> \truefalseX{\empty}
> \truefalseX{hello}
>
> \truefalseY{}
> \truefalseY{\empty}
> \truefalseY{hello}
>
> OUTPUT:
>
> X:false
> X:true
> X:false
> % empty string
> % empty string
> Y:false
>
>
> -> it works properly if I remove the true-expression.
>
Take a look at the TeXBook, page 209 and 210 where it discusses the expansion
of tokens when using \if and \ifx. For the latter the comparison must be between
macros or between characters. Sometimes measuring with width of expanded value
of the macro parametercan be a quick, easily understandable, but
rather inelegant solution.
Cheers,
Michael
------------------------------------------------------------------
Michael Doob Telephone: (204) 474-9796
Department of Mathematics Fax: (204) 474-7606
University of Manitoba email: Michael_Doob at umanitoba.ca
Winnipeg, MB, Canada R3T 2N2
------------------------------------------------------------------
More information about the texhax
mailing list