Lesson 2: Environments in Latex

LaTeX is actually a macro package based on Donald Knuth's typesetting program, TeX. The basic constructions in LaTeX involve various containers. For example, a paragraph is built up out of horizontal boxes (in TeX lingo, these are hboxes, and they may sometimes be overfull or underfull, which leads to warning messages, which you can ignore at first). A more basic example is the container begin{document} ... end{document}, which frames your document. We are going to look at some smaller containers that are useful for changing typefaces, etc.

If you wish to change the typeface in a short passage of text, there are two ways to do it in LaTeX. For example, to emphasize a few words, you can type {\em some text}. In this example, \em is a declaration. You could instead use the command \emph, which takes an argument, as follows: \emph{some text}. The problem with \emph for a long passage is that you may forget the closing curly brace, and then LaTeX will probably complain about a runaway argument. The declaration \em is more flexible for a longer passage. It's scope ends with either a curly brace or any \end statement. For example, the scope would be ended by \end{quote}.

These are not the best way to do change of typeface in longer passages, however, because of the likelihood of a forgotten brace every now and then.

By the way, corresponding to the pair \emph and \em, used for producing emphasized (usually, italic) text, there are pairs consisting of a command and a declaration for roman type, sans serif, typewriter type, bold type, and several others. These are listed conveniently on p. 9 of the document Essential LaTeX.

If you want to emphasize a longer passage, and you wish to have it appear as a separate paragraph, you should use one of the standard environments of LaTeX. These are used as follows:

\begin{environment-name}
      some text goes here
\end{environment-name}

For example, to set a whole paragraph in emphasized text, use:

\begin{em}
      some text goes here
\end{em}

Notice that the backslash is not used in front of the command em when the command is used as the argument in the \begin command.


Exercise on changing typeface in text: hand in during class.

To see how LaTeX handles emphasizing text, make a copy of the file you used for the first homework: if you called it einstein.tex you might make the copy einstein2.tex. You can do this by getting a UNIX shell prompt and using the UNIX command:

   cp einstein.tex einstein2.tex
In the first paragraph, choose two short passages, and emphasize one with \em and the other with \emph. Then put the second paragraph inside a \begin{em} ... \end{em} environment.
If your name does not appear at the top of your document, please put it in the file now so as to get it displayed at the top of the typeset page. Now process and print your new file. Hand it in when it looks the way you'd like.

What we just did is a simple use of LaTeX environments. These are the essential constructions for using LaTeX. In Chap. 3 of our textbook, Gratzer groups the text environments into three types:

  1. displayed: the text in the environment is display, usually set off from the text above and below by some vertical white space;
  2. those that create a large symbol (we'll use these for graphics);
  3. style and size environments.

The example of emphasized text is of the third type, of course. We now consider displayed text environments.

Here is one environment that you may need for making certain displays, such as headers:

For Centered Text

 \begin{center}
 Text on line 1 \\
 Text on line 2 \\
 .
 .
 .
 \end{center}

The center environment allows you to create a paragraph consisting of lines that are centred within the left and right margins on the current page. Each line must be terminated with the string \\, which is the short form of the command \newline, and gives a line which is not justified to the right.

Environments for Listing Text

There are three environments for listing text.

For numbered lists

 \begin{enumerate}
 \item First item
 \item Second item
 .
 .
 .
 \end{enumerate}

The enumerate environment produces a numbered list. Enumerations can be nested within one another, up to four levels deep. They can also be nested within other paragraph-making environments.

Each item of an enumerated list begins with an \item command. There must be at least one \item command within the environment.

Labelled lists

 \begin{description}
 \item [label] First item
 \item [label] Second item
 .
 .
 .
 \end{description}

The description environment is used to make labelled lists. The label is bold face and flushed right.

Bulleted lists

 \begin{itemize}
 \item First item
 \item Second item
 .
 .
 .
 \end{itemize}

The itemize environment produces a "bulleted" list. Itemizations can be nested within one another, up to four levels deep. They can also be nested within other paragraph-making environments.



Some useful URLs:

  • Help on LaTeX commands: This contains the above information plus much, much more.
  • A tutorial from Harvard.


  • Homework on Text Environments

    Create a LaTeX document (article class with the 12pt option) to demonstrate the use of the three list types just given as well as the center environment. For example, you might make a short bulleted shopping list, a numbered list of LaTeX environments, and a short captioned list of terms taken from the index of a book, with a definition given for each term. See if you can use the spell checker ispell with emacs. Process the file with latex and view it with xdvi before printing it out and emailing me a copy of the tex file (not the .dvi or .ps file).


    One annoying feature of TeX and LaTeX is that, when you run LaTeX on a file, you get error messages that are often difficult for a novice to interpret. If you use the X-window interface, as on UNIX or Linux systems, and also on our network, scivis, then you can use a program called ChkTex to help find errors in your source file. There is no man page for this, but it can be invoked on clam, crab and carp by typing "chktex" at the command prompt and giving it a file to read. The -d flag gives diagnostic messages.

    email: Martin Karel