kirkaas@ewa.cs.ucla.edu (paul kirkaas) (10/18/90)
I wonder if there is an equivalent to C's "#ifdef" for TeX --- that is, if there is something like: \ifdef{adef1} I want to see the first line of text included. \fi \ifdef{adef2} I want to see the second line of text included. \fi The point is that rather than defining adef1 to some value and testing for it, I can still run the source through TeX EVEN IF adef1 is NOWHERE DEFINED. I want that because I want to \include files from various source documents, which may or may not know all the possible \def's. Thanks for any help. Paul -- -- Paul Kirkaas kirkaas@cs.ucla.edu
spqr@ecs.soton.ac.uk (Sebastian Rahtz) (10/20/90)
In article <40303@shemp.CS.UCLA.EDU> kirkaas@ewa.cs.ucla.edu (paul kirkaas) writes: \ifdef{adef1} I want to see the first line of text included. \fi \ifdef{adef2} I want to see the second line of text included. \fi The point is that rather than defining adef1 to some value and testing for it, I can still run the source through TeX EVEN IF adef1 is NOWHERE DEFINED. I want that because I want to \include its not quite the same, but here, for instance, is code which takes various actions dependent on the value of \driver@setup, and starts by checking to see if it defined at all. \@ifundefined is LaTeX-ese, and needs to be in a style file or enclosed by \makeatletter .... \makeatother. \@ifundefined{driver@setup}% { \typeout{WARNING *** driver setup codes are unknown in this setup ***} } { \typeout{Driver type \the\driver@setup} \ifcase\driver@setup % case 0 \typeout{case 0} \or % case 1 \typeout{case 1} \or % case 2 \else \typeout{WARNING *** This driver setup is unknown -} \fi } -- Sebastian Rahtz S.Rahtz@uk.ac.soton.ecs (JANET) Computer Science S.Rahtz@ecs.soton.ac.uk (Bitnet) Southampton S09 5NH, UK S.Rahtz@sot-ecs.uucp (uucp)
marcel@cs.caltech.edu (Marcel van der Goot) (10/22/90)
In <40303@shemp.CS.UCLA.EDU> Paul Kirkaas (kirkaas@ewa.cs.ucla.edu) wonders > I wonder if there is an equivalent to C's "#ifdef" for TeX --- > that is, if there is something like: > ... Testing whether a control sequence \cs is defined is quite easy: \ifx\cs\undefined % \cs is not defined \else % \cs is defined \fi where you should make sure that \undefined is never defined. This works because both \cs and \undefined are macros (at least, according to TeX they cannot be anything else), and, if \cs is not defined, they both have the same top-level "expansion" (namely, none), so that \ifx tests true. The only thing you need to worry about is that if you insert commands in the place of the comments above, they must have properly nested \if ... \fi pairs. This method (trick?) comes straight from the TeX-book, the last paragraph of section 4: selective loading of macros, in appendix D (p. 384). Marcel van der Goot marcel@vlsi.cs.caltech.edu
em@dce.ie (Eamonn McManus) (10/22/90)
In article <40303@shemp.CS.UCLA.EDU> kirkaas@ewa.cs.ucla.edu (paul kirkaas) writes: > >I wonder if there is an equivalent to C's "#ifdef" for TeX --- >that is, if there is something like: > >\ifdef{adef1} > I want to see the first line of text included. >\fi The standard TeX way of doing this relies on the fact that if \thing is undefined then referring to \csname thing\endcsname causes \thing to be implicitly defined as \relax. This is the method used by LaTeX's \if@undefined. As an easier alternative when the name of the control sequence is fixed, you can simply say \ifx\undefined\thing, where \undefined is any control sequence that you know is undefined. I prefer this in general because I don't like things appearing from nowhere. -- Eamonn McManus <em@dce.ie> Are they the pearls of song Dropped by countless angel throng From paradise above? No.