Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!julius.cs.uiuc.edu!ux1.cso.uiuc.edu!csrd.uiuc.edu!s41.csrd.uiuc.edu!eijkhout From: eijkhout@s41.csrd.uiuc.edu (Victor Eijkhout) Newsgroups: comp.text.tex Subject: Re: simple tex/latex question/puzzler/quiz Message-ID: <1990Dec10.155526.647@csrd.uiuc.edu> Date: 10 Dec 90 15:55:26 GMT References: <4221@exodus.Eng.Sun.COM> Sender: news@csrd.uiuc.edu (news) Organization: UIUC Center for Supercomputing Research and Development Lines: 73 rom@xor.Eng.Sun.COM (Circuit Group) writes: >I'm stuck; any help is welcome. >------------------------------------------- >\documentstyle{article} >\begin{document} >\def\macro1{apple} This defines a macro \macro, which has to be followed by '1'. >\def\macro2{\macro1} This redefines \macro, now to be followed by '2', and if you don't you get an error message. >\ifx \macro1\macro2 truetext \else falsetext \fi Here \macro is matched to '1', which is a mismatch. The test \ifx never expands macros, it only checks if the top-level expansion is the same. Example: \def\a{\b} \def\c{\d} \def\b{x} \def\d{x} makes \b and \d equal for \ifx, but not \a and \b or \a and \d. >macro1\macro1 end This I don't believe. When I do this I get: ! Use of \macro doesn't match its definition. <*> macro1\macro1 end so the information you gave wasn't quit correct. >macro2\macro2 end This one is nice. You call \macro followed by '2' the way it should be, but it expands to \macro followed by '1' which is an error. See for yourself: ! Use of \macro doesn't match its definition. \macro 2->\macro 1 <*> macro2\macro2 end Now the whole point is that macro nams can contain only letters. Not digits or punctuation, unless you change the category codes of these. >It appears that \ifx is not expanding the macro \macro1, does this >make sense? How can I get an if statement that expands macros until >its just text? Am I doing this the wrong way? Try this: \def\ifREALLYequal#1#2{\edef\testa{#1}\edef\testb{#2}\ifx\testa\testb} Here the \edef's expand your arguments down to the bottom, and then you can simply test them. >BTW are there any books other than the ones by Knuth and Lamport that >explain this stuff; I have both books and find the one by Knuth to be >cryptic, wereas the one by Lamport does not give enough information. There are some books. Probably 'TeX for the impatient' would be a nice book for you; it explains a number of concepts of TeX quit well. Can't remember if the treatment of conditionals is especially good. (authors: Abrahams, Hargreaves and Berry). Maybe 'Introduction to TeX' by Schwarz. (both Addison-Wesley) The book by Stephan von Bechtolsheim (you out there Stephan?) has been announced for a while, but I haven't seen it yet. Victor.