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.

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

\newenvironment{env name}[narg][opt]{beg def }{end def }<br />

\renewenvironment{env name}[narg][opt]{beg def }{end def }<br />

where the arguments have the following meanings:<br />

env name: the name of the environment; for \newenvironment, it may<br />

not be the same as any existing environment or comm<strong>and</strong> name,<br />

whether L AT E X or user-defined. For \renewenvironment, on the other<br />

h<strong>and</strong>, there must already be an environment bearing this name. Any<br />

changes <strong>to</strong> L AT E X environments should only be undertaken if the user<br />

knows what he or she is doing.<br />

narg: a number between 1 <strong>and</strong> 9 that states how many arguments the<br />

environment is <strong>to</strong> have; if the optional argument narg is omitted,<br />

the environment is <strong>to</strong> have no arguments.<br />

opt: the default text for the first argument (#1) if it is <strong>to</strong> be optional; this<br />

behaves the same as for \(re)newcomm<strong>and</strong> (page 185).<br />

beg def: the initial text <strong>to</strong> be inserted when \begin{env name} is called;<br />

if this text contains entries of the form #n, with n = 1, . . .,narg, then<br />

when the environment is started with the call<br />

\begin{env name}{arg 1}...{arg n}...<br />

each occurrence of #n within beg def is replaced by the text of the<br />

argument arg n.<br />

end def: the final text that is inserted when \end{env name} is called;<br />

here the dummy arguments #n are not allowed since they are only<br />

<strong>to</strong> appear in the beg def text.<br />

8.4.1 Environments without arguments<br />

Just as for user-defined comm<strong>and</strong>s, environments without the optional<br />

argument narg will be illustrated first. A user-defined environment named<br />

sitquote is created with<br />

\newenvironment{sitquote}{\begin{quote}\small<br />

\itshape}{\end{quote}}<br />

which sets the text appearing between \begin{sitquote} text \end<br />

{sitquote} in the typeface \small\itshape, <strong>and</strong> indented on both<br />

sides from the main margins, as demonstrated here.<br />

In this case, beg def consists of the comm<strong>and</strong> sequence \begin{quote}<br />

\small\itshape while end def is simply \end{quote}. Now the call<br />

\begin{sitquote} text \end{sitquote} is the same as<br />

\begin{quote}\small\itshape text \end{quote}

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

Saved successfully!

Ooh no, something went wrong!