28.03.2013 Views

Guide to LaTeX (4th Edition) (Tools and Techniques

Guide to LaTeX (4th Edition) (Tools and Techniques

Guide to LaTeX (4th Edition) (Tools and Techniques

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

194 Chapter 8. User Cus<strong>to</strong>mizations<br />

Testing text<br />

To test if two comm<strong>and</strong>s evaluate <strong>to</strong> the same piece of text, or if a<br />

comm<strong>and</strong> is defined as a certain string of text, use<br />

\equal{string1}{string2}<br />

where string1 <strong>and</strong> string2 are texts or comm<strong>and</strong>s that reduce <strong>to</strong> text. For<br />

example, with<br />

\ifthenelse {\equal{\name}{Fred}} {Frederick} {??}<br />

the text Frederick is inserted if \name has been defined <strong>to</strong> be Fred (with<br />

\newcomm<strong>and</strong>), otherwise two question marks are printed.<br />

Testing lengths<br />

Another logical statement compares two lengths.<br />

\lengthtest{relation}<br />

where relation consists of two lengths or length comm<strong>and</strong>s separated by<br />

a relational opera<strong>to</strong>r . For example,<br />

\newlength{\horiz} \newlength{\vert}<br />

\newlength{\min}<br />

. . . . . . .<br />

\ifthenelse {\lengthtest{\horiz > \vert}}<br />

{\setlength{\min}{\vert}} {\setlength{\min}{\horiz}<br />

sets \min <strong>to</strong> be the smaller of \horiz <strong>and</strong> \vert.<br />

Testing switches<br />

A boolean switch is a parameter that is either 〈true〉 or 〈false〉, also called<br />

a flag. Three comm<strong>and</strong>s exist <strong>to</strong> h<strong>and</strong>le them:<br />

\newboolean{string} creates a new switch<br />

\setboolean{string}{value} assigns a value true or false<br />

\boolean{string} tests its value<br />

The last of these is used as test in \ifthenelse <strong>and</strong> \whiledo.<br />

There are a number of internal L AT E X switches that may also be tested<br />

(but never reset!). The most useful of these are @twoside <strong>and</strong> @twocolumn<br />

for checking if two-side or two-column modes are active. Since they<br />

contain the character @, they may only be used inside a class or package<br />

file (Appendix D).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!