Lecture 10 Notes

These are the notes for lecture 10

Mark


Title: Math 481/581 Lecture 10: LaTeX Part I

Math 481/581 Lecture 10: LaTeX Part I

This is the first of a series of lectures on the LaTeX document formatting system.

Introduction

LaTeX is the primary typesetting system for UNIX systems (though it is available for most other operating systems commonly in use). LaTeX is especially suited for typesetting mathematics.

Several lectures ago, we met the MSWord word processor. MSWord is called a WYSIWYG (What You See Is What You Get) word processor: what you see on the screen is what your hardcopy will look like.

LaTeX takes a different approach. A LaTeX document is a plain ASCII text file that you can edit with any text editor. Like HTML, font changes, tables, lists, etc. are created by using special formatting commands that you embed in the source code. To see the final document, you need to process the LaTeX source code with a special program; only then can you see the final result.

There are advantages and disadvantages to both approaches. On the one hand, MSWord is very easy to use because it is GUI (Graphical User Interface) based. Since it is WYSIWYG, you immediately see the effect of every keystroke. With LaTeX, you don't really know what you've got until after the postprocessing phase. You also need to know the formatting commands to embed in the source code.

WYSIWYG editors can also be characterized as "What You See Is All You've Got" (attributed to Brian Reid and/or Brian Kernighan). Leslie Lamport, the creator of LaTeX, discusses a nice example of the advantages of LaTeX's logical design over WYSIWYG's visual design. Suppose your are writing a document that contains a lot of inner products -- and you decide to display the inner product between the vectors A and B as

(A,B)

With a WYSIWYG word processor you'd simply type (A,B) to obtain the desired output. A savvy LaTeX user, on the other hand, would probably define a LaTeX macro called \ip to do the job. In your LaTeX source, you could then generate the inner product with \ip{A}{B}.

The nice thing about doing it this way is that you change the way that all inner products are formatted simply by changing the definition of \ip. For example, it is trivial to reformat all inner products like this:

<A | B>

With most WYSIWYG editors, you would have to go through the entire document a replace every occurrence by hand. Ouch.

He goes on to state that he believes that logical design lets you focus on your writing without worrying about formatting decisions. Formatting decisions (like font size, pagination, number of columns of text, etc.) can be made at any time. For example, to format your text in two columns, you simply change the line:

   \documentclass{article}

to
   \documentclass[twocolumn]{article}

at the top of your LaTeX source code.

Leslie Lamport summarizes his position as follows:

The purpose of writing is to present your ideas to the reader. This should always be your primary concern. It is easy to become so engrossed with form that you neglect content. Formatting is no substitute for writing. Good ideas couched in good prose will be read and understood, regardless of how badly the document is formatted. LaTeX was designed to free you from formatting concerns, allowing you to concentrate on writing. If you spend a lot of time worrying about form, you are misusing LaTeX.

If you need to typeset mathematical formulae, I highly recommend LaTeX simply because the final result looks more professional. I have yet to see any other program that produces output that is anywhere near as beautiful as that produced by LaTeX. The reason for this is twofold. First, TeX (on which LaTeX is based) is designed to typeset mathematical text. Second, there are a lot of differences between mathematical text and "normal" text --- mainstream word processors aren't too well equipped to handle these special needs.

LaTeX is great for dealing with large documents; however, it is a bit painful to use for things like memos and letters. You'll probably need to keep a "skeleton" file hanging around in your account for these occasions.

A nice thing about LaTeX is that the source code is plain ASCII text. It is easy to email someone a piece of LaTeX code or extract a piece of code for inclusion in another document. This is a Big Win when you include chunks of your publications into your thesis or dissertation, for example.

Many scientists (especially mathematicians) use LaTeX almost exclusively -- if you are going to interoperate with such people, you should, at a minimum, know enough LaTeX to get by. Also, many journals now allow you to submit articles written in LaTeX via email. This speeds up the review process considerably (by weeks or months, usually -- when you submit an article in hardcopy, someone at the journal usually typesets it in LaTeX. Then you have to endure a series of iterations to correct typos that the journal people introduced before your paper can get published). I don't know of any scientific journals that let you submit articles in MSWord.

A word of warning: there are dozens of add-on packages available for LaTeX. To make matters worse, the world is currently in the transition from LaTeX 2.09 to LaTeX 2e -- and there are incompatibilities between the two. When exchanging LaTeX code with someone else, you should indicate your LaTeX version and distribution near the top of the code, as well as any extra packages required to process the file.

In this course, we will focus on the teTeX distribution of LaTeX 2e.

A Simple LaTeX Document

% LaTeX 2e file -- works with teTeX-0.4
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is a comment.
%
% LaTeX ignores everything from a "%" to EOL
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Every document should begin with this line.
% Other common classes include report'' and
% book''. Among other things, the document
% class controls section numbering, title page
% generation, etc.
%
%
% You can also specify options in square brackets.
% Some commonly used option include 12pt'' and
% twocolumn''.
%
\documentclass[12pt]{article}

% documentclass'' is an example of a LaTeX command. All
% LaTeX commands consist of a backslash followed by the
% name of the command. Some commands require arguments;
% for example, the documentclass command expects an
% argument specifying the sort of document that follows.
% In the present case, we are telling LaTeX to use the
% article'' style. Some commands also have optional
% arguments -- these follow the command name and are
% enclosed in square brackets instead of curly brackets.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The document environment'' encloses the body of the
% doument, much like the <html> ... </html> tags in HTML.
%
% LaTeX uses environments to modify interpretation of
% your text -- we'll meet more environments as we go.
%
% An environment called thingie'' lives between
% \begin{thingie} and \end{thingie} markers.
%
% The body of your text lives inside a document''
% environment. The \end{document} is at the end of
% this file.
%
\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% There are 4 commands that control the specifics of
% the title page:
%
%%% Document title
\title{A Sample \LaTeX\ File}
%
%%% Author
\author{Mark Hays}
%
%%% The date
\date{\today}
%
%%% Command that actually creates the title page (exact
%%% formatting depends on the document class). The title
%%% page'' is not on a separate page for the article''
%%% class...
\maketitle
%
% On the hardcopy, you'll notice that LaTeX automatically
% picked a large font for the title and smaller fonts
% for the author and date.
%
% If there are multiple authors, you should use \and''
% inside \author like this:
%
%	\author{M. Hays \and A.C. Scott}
%
% Reason: \and in interpreted differently based on the
% chosen document class.
%
% The \LaTeX command produces the funny logo you see.
% The \ '' following \LaTeX causes a space to be
% inserted -- see below.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The abstract (if required) appears in an abstract''
% environment. You can't have an abstract in the book
% class.
%
\begin{abstract}
This is a simple \LaTeX\   document. The source code for
the hardcopy you are reading illustrates some of the
fundamental concepts of \LaTeX. This document will only make
at the same time.
\end{abstract}

% The abstract environment automagically formatted the text
% inside it in a manner appropriate for an abstract.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Sectioning commands:
%
%   \part{text}			report and book only
%   \chapter{text}		report and book only
%   \section{text}		all styles:
%   \subsection{text}
%   \subsubsection{text}
%
% These commands control how sections are numbered. In
% conjunction with the document class, this determines
% how headings are displayed, how equations are numbered,
% and what cross references look like.
%
\section{Regular Text}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Regular text:
%

In \LaTeX, you can format regular old text by simply
typing it in.
Whitespace    in        the input file           is
ignored --- one
space is the same as 100 spaces.
One or more blank lines in the input file denote a paragraph break.
%
% \LaTeX does not include a trailing space -- so that you can
% follow it with punctuation. To force a space to be inserted,
% use the \ '' (baskslash space) command.
%
% Blank line breaks the paragraph:

This is the second paragraph. It is very short. It is also
uninteresting. Fortunately, it terminates here.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% New section.
%
\section{Special Characters}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following characters are interpreted in special ways
% by LaTeX:
%
%		# $% & ~ _ ^ { } | < > \ " % % To generate them literally in regular text, you'll need % to do something like this: % You must use special commands to generate the following special characters: % \begin{center} \# \$ \% \~ \_ \^ \{ \} \verb+|+ \verb+<+ \verb+>+ \verb+\+ \verb+"+
\end{center}
%
% This also demonstrates the center'' environment -- it does
% what you expect.

Alternative ways to generate some of the special symbols look like
this in the output:
\begin{center}
$$|$$ $$<$$ $$>$$ $$\backslash$$
\end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Simple Equations}

%
% If you want an equation inline with your text, enclose it
% between $$and$$ -- you can also use the math'' environment.
%
It is true that $$x+y = y+x$$. For example,
\begin{math}
1+4=4+1
\end{math}.
%
Notice how the font and character spacing changed. You can also
cause equations to be displayed'':
$2+2 < 5$
%
% The $...$ is the same as the displaymath'' environment:
%
This is due to the fact that
\begin{displaymath}
2+2=4
\end{displaymath}
%
Finally, the equation'' environment is used to generate
numbered equations:
$$a+b+c+\ldots+z = 724$$
%
We will see how to reference equations by number in the main
text later on. It's pretty easy.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{How To Do Footnotes}

% Generating footnotes is easy, too:
This sentence will make use of footnoted text\footnote{This is
the text of the footnote.}.
Note that you don't want spaces or a newline between the word
to receive the number and the footnote'' command\footnote{
Otherwise, you end up with undesired space in the output.}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Lists}

% There are three list environments in LaTeX:
%   itemize		bulleted list
%   enumerate		numbered list
%   description		list labelled with text

Here are two of \LaTeX's lists:

\begin{itemize}
\item Under itemize,'' list entries are marked with bullets.
\item You can include math, too $$x+y=z$$.
\item Lists can also be nested:
\begin{enumerate}
\item Under enumerate,'' list entries are numbered.
\item Blank lines in your source code are ignored within
list-like environments.
\item Displaying an equation in a list gives: $1+2=3$
\item This is the last item.
\end{enumerate}
\item All done.
\end{itemize}

% How to force a page break:
\newpage

% How to start a paragraph without indenting it:
\noindent
The description'' environment looks like this:

\begin{description}
\item[Fly] I hate flies. They bother me. Especially when they
vomit on my food or in my beer.
\item[Mosquito] These are even worse than flies. I really
got chowed by them this summer\footnote{
I heard a rumor that some chucklehead at the UA accidentally
released a bunch of Egyptian desert mosquitos a while back.
Apparently, Tucson is a paradise for them.
}.
\item[Cricket] Crickets are O.K., but they make too much
racket at night.
\item[Spider] I hate spiders, but I tolerate them because
they eat flies and mosquitos. Crickets are
generally too much for spiders to handle.
\item[Lizard] I like lizards because they \emph{hunt}
flies, mosquitos, and crickets. There are
a couple of lizards living in my house. They
stop by and say hi'' now and again.
\item[Cat] A cat lives at my house, but he is not my cat ---
he simply came with the house. He's a pretty cool
cat, but he eats lizards. This is bad because he
won't eat flies or mosquitos.  I'm not sure if he
eats crickets. He is partial to Palo Verde
beetles.
\item[Palo Verde Beetle] I rarely see these things alive because
the cat likes to eat them. Instead, I usually see
Palo Verde beetle \emph{halves}. Usually
when I am barefooted. Yuck. I \emph{think}
that he is leaving me the good half'' as a
gift.''
\item[Ant] I dislike ants. I usually kill most of them with
Diazinon. But I have to leave a few colonies alone;
otherwise, my yard fills up with pieces of Palo Verde
beetles.
\item[Bird] The birds like to eat (and fight over) the cat food.
The cat will eat cat food, but he seems to prefer
lizards and beetles on most days. He also likes to
eat birds. This morning there are feathers all over
my yard --- guess he got one of 'em.
\item[Pigeon] I hate pigeons. They are nasty, flying rats. I
always try to hit them with my bike, but I have
not yet succeeded in this quest.
\item[Ol' Doc Hays] An environmentalist --- can't you tell?
\end{description}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Miscellany}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Quoting
%
You hardly ever use the \verb+"+ character in your \LaTeX\ code.
Double quoted material can be done like this: He said Yes.''
Single quoted material works the same way: Haha'.
%
% The \, command causes LaTeX to insert a little extra space.
% This helps disambiguate the following:
Here's a pathological example:
%
\begin{center}
\,Fi' or Fum'\,'' he asked.
\end{center}

% Ellipsis:
Generating ellipsis is as easy\ldots as this.
Typing three periods doesn't produce the correct spacing,
though...

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Emphasis and the nonbreakable space
%

You can \emph{emphasize words} using the emph'' command.
%
% You can also nest emphasis:
This sentence
\emph{demonstrates
\emph{nested
\emph{emphasis}
but}
it gets}
ridiculous pretty fast.
%
% LaTeX treats everything inside curly braces as a
% single unit.
%
% You can use indentation to make code more readable.
%

% Normally LaTeX will choose where to break lines in the
% output. Usually it does a good job, but sometimes it
% doesn't. You can use the tilde to get around this:
The tilde character prevents undesired line breaks:
Dr.~Restrepo, I presume?

\end{document}

`