home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / text / tex / 15464 < prev    next >
Encoding:
Text File  |  1993-01-27  |  1.5 KB  |  35 lines

  1. Newsgroups: comp.text.tex
  2. Path: sparky!uunet!ukma!gatech!udel!sbcs.sunysb.edu!hanche
  3. From: hanche@ams.sunysb.edu (Harald Hanche-Olsen)
  4. Subject: Re: Problems with false conditionals
  5. In-Reply-To: Donald Arseneau's message of Tue, 26 Jan 1993 02: 20 PDT
  6. Message-ID: <HANCHE.93Jan27163157@ptolemy.ams.sunysb.edu>
  7. Sender: usenet@sbcs.sunysb.edu (Usenet poster)
  8. Nntp-Posting-Host: ptolemy.ams.sunysb.edu
  9. Organization: University at Stony Brook, NY
  10. References: <10348853@MVB.SAIC.COM>
  11. Date: Wed, 27 Jan 1993 21:31:57 GMT
  12. Lines: 21
  13.  
  14. The question of how to write if tests so they nest properly is one
  15. which leads people with short memories (like me) into trouble every
  16. time.  So I thought about it for a while, and came up with the
  17. following test building macro (for people who favour the \if\test style):
  18.  
  19. \def\maketest#1#{\m@ketest{#1}}
  20. \def\m@ketest#1#2{\def#1{..\fi#2}}
  21.  
  22. For example, here is how you can use it to define a macro to test
  23. whether a control sequence has a given expansion:
  24.  
  25. \maketest\expands #1->#2{{\def\temp{#2}\expandafter}\ifx#1\temp}
  26.  
  27. Example:  The following prints "Good." on the console.
  28. \def\foo{bar} \if\expands \foo->{bar}\message{Good.}\fi
  29.  
  30. You can even put \global or \long in front of \maketest, and it will
  31. do what is expected.  But if a \maketest invocation ever occurs in
  32. text that might be skipped, you'll still have to, you'll still have to
  33. put a \ifx\fi\relax\fi after it, because a \maketest usage by its
  34. nature must always contain an unbalanced \ifsomething.
  35.