[texhax] controlling expansion

Neal H. Walfield neal at walfield.org
Thu Feb 28 12:41:07 CET 2013


Hi, Lars,

Thanks for the quick response.

At Thu, 28 Feb 2013 11:34:29 +0000,
Lars Madsen wrote:
> 
> any reason why you don't just use the etoolbox package instead? It has very powerfull macros to test this sort of thing
> 

I wasn't aware of etoolbox, thanks for pointing it out!  Nevertheless,
I'd still like to better understand the issue.

Thanks,

Neal

> ________________________________________
> From: texhax [texhax-bounces at tug.org] on behalf of Neal H. Walfield [neal at walfield.org]
> Sent: 28 February 2013 12:22
> To: texhax at tug.org
> Subject: [texhax] controlling expansion
> 
> Hi,
> 
> I'm writing a macro that compares the value of a parameter.  I'm
> currently using \ifx to do this as follows:
> 
>   \documentclass{article}
> 
>   \def\dosomething#1{
>     \def\empty{}
>     \def\arg{#1}
>     \ifx\empty\arg
>       empty
>     \else
>       not empty
>     \fi}
> 
>   \begin{document}
> 
>   1: \dosomething{}
> 
>   2: \dosomething{1}
> 
>   \edef\foo{\dosomething{}}
>   3: \foo
> 
>   \end{document}
> 
> This breaks if the caller uses \edef: \empty is expanded.  However, if
> I protect \empty and \arg with a \noexpand, then bare uses (such as 1
> and 2 in my above example) don't work:
> 
>   ! Use of \noexpand doesn't match its definition.
>   \dosomething #1-> \def \noexpand \empty
>                                         {} \def \noexpand \arg {#1}
>                                         \ifx \em...
>   l.18 \edef\foo{\dosomething{}
> 
> What is the "right way" to compare argument values such that the macro
> can (but need not) be used in an \edef context?
> 
> Thanks,
> 
> Neal
> _______________________________________________
> TeX FAQ: http://www.tex.ac.uk/faq
> Mailing list archives: http://tug.org/pipermail/texhax/
> More links: http://tug.org/begin.html
> 
> Automated subscription management: http://tug.org/mailman/listinfo/texhax
> Human mailing list managers: postmaster at tug.org
> 
> _______________________________________________
> TeX FAQ: http://www.tex.ac.uk/faq
> Mailing list archives: http://tug.org/pipermail/texhax/
> More links: http://tug.org/begin.html
> 
> Automated subscription management: http://tug.org/mailman/listinfo/texhax
> Human mailing list managers: postmaster at tug.org
> 


More information about the texhax mailing list