Path: utzoo!attcan!uunet!wuarchive!rex!uflorida!gatech!bloom-beacon!eru!hagbard!sunic!nuug!sigyn.idt.unit.no!ugle.unit.no!hanche From: hanche@imf.unit.no (Harald Hanche-Olsen) Newsgroups: comp.text.tex Subject: Re: simple tex/latex question/puzzler/quiz Message-ID: Date: 10 Dec 90 18:07:55 GMT References: <4221@exodus.Eng.Sun.COM> Sender: news@ugle.unit.no Organization: The Norwegian Institute of Technology, Trondheim, Norway. Lines: 62 In-Reply-To: rom@xor.Eng.Sun.COM's message of 10 Dec 90 06:37:54 GMT In article <4221@exodus.Eng.Sun.COM> rom@xor.Eng.Sun.COM (Circuit Group) writes: I'm stuck; any help is welcome. ------------------------------------------- \documentstyle{article} \begin{document} \def\macro1{apple} \def\macro2{\macro1} \ifx \macro1\macro2 truetext \else falsetext \fi macro1\macro1 end macro2\macro2 end some text here. \end{document} -------------------------------------------- produces: falsetext macro1appleend macro2appleend some text here. ------------------------------------------- When I run this through LaTeX, I get ! Use of \macro doesn't match its definition. l.6 macro1\macro1 end ? because Macro names are made up of letters only, no digits allowed. So you first defined \macro in such a manner that it must always be immediately followed by `1' when used, and then so it must be immediately follwed by `2'. Your \ifx line compared the meaning of \macro with that of 1, and found them different. Your usage of \macro1 on line 6 is an error. Now that that is out of the way, lets assume you had named your macros \macroa and \macrob. Now your example essentially does what you described. It appears that \ifx is not expanding the macro \macro1, does this make sense? Yes, \ifx only compares the immediate meaning of tokens, and for macros that means comparing the immediate replacement text (and the garbage, if any, conatining a description of parameters and text to be matched). How can I get an if statement that expands macros until its just text? Am I doing this the wrong way? \edef\1{\macroa} \edef\2{\macrob} \ifx \1\2 truetext \else falsetext \fi will work. Exercise 1: Look up \edef in the TeXbook and figure out why this works. Exercise 2: Why is it ok to have macros named \1 and \2 when I just expalined above that macro names consist of letters only? The answer is in the TeXbook. - Harald Hanche-Olsen Division of Mathematical Sciences The Norwegian Institute of Technology N-7034 Trondheim, NORWAY