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.

8.5. Some comments on user-defined structures 203<br />

Local definitions are really not <strong>to</strong> be recommended. It is far better <strong>to</strong><br />

place all user definitions at the beginning, in the preamble, where they<br />

are most easily visible. A local redefinition of a st<strong>and</strong>ard comm<strong>and</strong> can<br />

lead <strong>to</strong> puzzling effects that are hard for others, or even for the author,<br />

<strong>to</strong> trace down. Of course, some special effects might just be wanted.<br />

8.5.5 Order of definitions<br />

User-defined structures may be nested within one another. If one user<br />

definition contains another user-defined structure, it is often the case that<br />

the inner one has already been defined. However, this is not necessary.<br />

User definitions may contain other user structures that are defined afterwards.<br />

What is important is that the other structure is defined before the<br />

first comm<strong>and</strong> is invoked.<br />

For example, a normal sequence of definitions would be<br />

\newcomm<strong>and</strong>{\A}{defa}<br />

\newcomm<strong>and</strong>{\B}{defb}<br />

\newcomm<strong>and</strong>{\C}{\A \B}<br />

where \C is defined in terms of \A <strong>and</strong> \B. However, it is also permissible<br />

<strong>to</strong> write<br />

\newcomm<strong>and</strong>{\C}{\A \B}<br />

normal text, but without calling \C<br />

\newcomm<strong>and</strong>{\B}{defb}<br />

\newcomm<strong>and</strong>{\A}{defa}<br />

further text with any number of calls <strong>to</strong> \A, \B <strong>and</strong> \C<br />

8.5.6 Nested definitions<br />

User definitions may be nested inside one another. A structure such as<br />

! \newcomm<strong>and</strong>{\outer}{{\newcomm<strong>and</strong>{\inner}...}}<br />

is permissible. The comm<strong>and</strong> that is defined with the name {\inner} is valid<br />

<strong>and</strong> known only within the comm<strong>and</strong> {\outer}, according <strong>to</strong> the remarks on the<br />

scope of definitions on the facing page. Although the T E X macros make copious<br />

use of nested comm<strong>and</strong> definitions <strong>to</strong> limit the lifetime of temporary comm<strong>and</strong>s,<br />

it is not recommended <strong>to</strong> nest L AT E X definitions excessively since it is <strong>to</strong>o easy<br />

<strong>to</strong> lose track of the bracketing. A forgotten bracket pair will produce an error<br />

message on the second call <strong>to</strong> the outer comm<strong>and</strong>, since the inner definition still<br />

exists as a lef<strong>to</strong>ver from the first call. Nevertheless, here is an example:<br />

\newcomm<strong>and</strong>{\twentylove}<br />

{{\newcomm<strong>and</strong>{\fivelove}<br />

{{{\newcomm<strong>and</strong>{\onelove}<br />

{I love \<strong>LaTeX</strong>!}%<br />

\onelove\ \onelove\ \onelove\ \onelove\ \onelove}}}<br />

\fivelove\\ \fivelove\\ \fivelove\\ \fivelove}}

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

Saved successfully!

Ooh no, something went wrong!