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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

\noexp<strong>and</strong> \exp<strong>and</strong>after<br />

D.3. Sample packages 451<br />

control the expansion of comm<strong>and</strong>s in definitions <strong>and</strong> execution. Any comm<strong>and</strong>s<br />

in the definition part of \edef are exp<strong>and</strong>ed (their meanings inserted) unless<br />

they have \noexp<strong>and</strong> before them. The opposite is achieved with \exp<strong>and</strong>after,<br />

which jumps over the following comm<strong>and</strong>, exp<strong>and</strong>s the next one, <strong>and</strong> then<br />

executes the one skipped. This is very deep T E Xnology, <strong>and</strong> is best illustrated by<br />

an example with the \Exp comm<strong>and</strong> defined above.<br />

\newcomm<strong>and</strong>*{\mynums}{1.1(4)} \exp<strong>and</strong>after\Exp\mynums<br />

is identical <strong>to</strong> \Exp1.1(4), whereas \Exp\mynums is not; \mynums is exp<strong>and</strong>ed<br />

<strong>to</strong> 1.1(4) before \Exp is executed.<br />

\let\cmd a = \cmd b or \let\cmd a\cmd b<br />

makes \cmd a take on the current meaning of \cmd b. This is often employed<br />

<strong>to</strong> save the current meaning of a comm<strong>and</strong> before redefining it, possibly using<br />

the older meaning <strong>to</strong>o.<br />

\relax<br />

does absolutely nothing, but it is often inserted in places where something should<br />

be but nothing is wanted.<br />

\ifcond true code \else false code \fi<br />

is the form of a T E X conditional. There are <strong>to</strong>o many variations on the condition<br />

cond <strong>to</strong> explain here, but one common application is the equivalent of the L AT E X<br />

boolean switch comm<strong>and</strong>s:<br />

\newif\ifflag = \newboolean{flag}<br />

\flagtrue = \setboolean{flag}{true}<br />

\flagfalse = \setboolean{flag}{false}<br />

\ifflag ..\else..\fi = \ifthenelse{\boolean{flag}}{..}{..}<br />

For those who are used <strong>to</strong> it, the T E X form is more compact, but does not conform<br />

<strong>to</strong> the general L AT E X style of doing things.<br />

\ifcase num text 0 \or text 1 \or . . . \fi<br />

executes one of the text num according <strong>to</strong> the value of num.<br />

\endinput<br />

terminates the current file being input. This is not really necessary, but it is<br />

considered good programming <strong>to</strong> end all files this way. The main document file<br />

does not need it since \end{document} has the same effect.<br />

D.3 Sample packages<br />

We present here some demonstration packages <strong>to</strong> illustrate the programming<br />

comm<strong>and</strong>s of the previous section. These packages are not trivial<br />

<strong>and</strong> are all useful in their own right, even though their functionality is<br />

covered by others described in this book.

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

Saved successfully!

Ooh no, something went wrong!