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.

8.4. User-defined environments 197<br />

which produces the desired result.<br />

This example does not appear <strong>to</strong> be very practical since the same<br />

effect can be achieved with less typing by adding \small\itshape at<br />

the beginning of the quote environment. However, it is more consistent<br />

with the concept of logical markup introduced in Section 1.2.2. This<br />

special quotation environment may be used throughout the document<br />

without worrying about its typographical details, which are specified in<br />

its definition located in the document preamble. Doing it this way not<br />

only ensures consistency, it also simplifies any substitution that may be<br />

dem<strong>and</strong>ed later by a typographical expert.<br />

Let us exp<strong>and</strong> the previous example somewhat as follows:<br />

\newcounter{com}<br />

\newenvironment{comment}<br />

{\noindent\slshape Comment:\begin{quote}\small\itshape}<br />

{\stepcounter{com}\hfill(\arabic{com})\end{quote}}<br />

where now beg def contains the text <strong>and</strong> comm<strong>and</strong>s<br />

\noindent\slshape Comment:\begin{quote}\small\itshape<br />

<strong>and</strong> end def is<br />

\stepcounter{com}\hfill(\arabic{com})\end{quote}<br />

where com is a user counter created by the \newcounter comm<strong>and</strong>. Now<br />

since the comm<strong>and</strong> \begin{comment} inserts the text beg def at the start<br />

of the environment <strong>and</strong> \end{comment} the text end def at the finish, it<br />

should be clear that<br />

\begin{comment} This is a comment.<br />

Comments should ...<br />

... in round parentheses.<br />

\end{comment}<br />

will generate the following type of structure:<br />

Comment:<br />

This is a comment. Comments should be preceded by the word Comment:<br />

the text being in a small, italic typeface, indented on both sides<br />

from the main margins. Each comment receives a running comment<br />

number at the lower right in round parentheses. (1)<br />

The user should examine the sequence of comm<strong>and</strong>s with the replacement<br />

text of this example <strong>to</strong> see precisely what the effect of this<br />

environment is. Two weaknesses should become apparent: what would<br />

happen if \begin{comment} were called in the middle of a line of text<br />

without a blank line before, <strong>and</strong> what would happen if the last line of the<br />

comment text were so long that there was no more room for the running<br />

comment number on the same line?<br />

The following revision removes these two problems:

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

Saved successfully!

Ooh no, something went wrong!