Re: how to compare two macros in TeX?
On 19 Nov 2002 16:47:03 +0100
martin f krafft <madduck@debian.org> wrote:
>
> let's say i have this in a TeX document:
>
> \def\variable{somevalue}
>
> how can i use a switch or if statement, testing for this value?
>
This compares the complete expansions of whatever you throw at it:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\same#1#2{00\fi%
\edef\tmpone{#1}%
\edef\tmptwo{#2}%
\ifx\tmpone\tmptwo}
\def\variable{somevalue}
\if\same{\variable}{somevalue}
same\else diff\fi
\if\same{\variable}{typo}
same\else diff\fi
\if\same{typo}{typo}
same\else diff\fi
\bye
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Rupert
Reply to: