From: gmaltby@unpcs1.cs.unp.ac.za (Gavin Maltby)
Newsgroups: comp.text.tex
Subject: latex notes: 1 of 4
Summary: part 1 of 4
Keywords: latex notes
Date: 27 Jan 93 06:51:57 GMT
Organization: University of Natal, Pietermaritzburg, South Africa
NNTP-Posting-Host: pc038.cc.unp.ac.za

% introduction to \TeX
% written for course at unp, november 1992
% written in \LaTeX
% with the NFSS, but should work with normal \LaTeX

\documentstyle[12pt]{report}

\begin{document}
\pagenumbering{roman}

\newcommand{\contact}{Gavin Maltby (Maths Department, UNP)}

\newcommand{\AmSLaTeX}{{\protect\the\textfont2 A}\kern-.1667em\lower.5ex\hbox
{\protect\the\textfont2 M}\kern-.125em{\protect\the\textfont2 S}-\LaTeX}


\newcommand{\AmSTeX}{{\protect\the\textfont2 A}\kern-.1667em\lower.5ex\hbox
{\protect\the\textfont2 M}\kern-.125em{\protect\the\textfont2 S}-\TeX}

\newcommand{\usertype}[1]{\vspace{3pt plus 3pt}\centerline{%
#1}\vspace{3pt plus 3pt}}

\newcommand{\BibTeX}{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
    T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}

\newcommand\bs{\char '134 }   % A backslash character for \tt font
\newcommand{\lb}{\char '173 } % A left brace character for \tt font
\newcommand{\rb}{\char '175 } % A right brace character for \tt font

\newenvironment{syntax}[1]{\smallskip\hspace{1.3cm}\tt\bs#1}{\smallskip}
\newcommand{\opt}[1]{[{\em #1\/}]}
\newcommand{\man}[1]{\{{\em #1\/}\}}

\long\def\result#1{{\smallskip\moveright0.1\textwidth\vbox{\hsize 0.8\textwidth\footnotesize#1}}\smallskip}

%\newcommand{\nsubsubsection}[1]{\subsubsection{#1}\addcontentsline{toc}
%{subsection}{\quad\quad#1}}
\newcommand{\nsubsubsection}[1]{\subsection{#1}}

\newenvironment{mathegs}%
{\medskip\footnotesize\begin{center}%
\renewcommand{\arraystretch}{1.3}
\begin{tabular}{ll}%
\it \makebox[190pt][l]{Type} & \it To produce\\}
{\end{tabular}\end{center}\medskip}

\title{An introduction to \TeX\ and friends}
\author{Gavin Maltby}
\date{November 1992}

\maketitle
\tableofcontents
\listoftables
\newpage
\pagenumbering{arabic}

\chapter{Getting acquainted with \TeX}
\TeX\ is well known to be {\em the\/} typesetting package,
and a vast cult of \TeX\ lovers has evolved.  But to the beginning
\TeX\ user, or to someone wondering if they should bother changing
to \TeX, it is often not clear what all the fuss is about.  After all,
are not both WordPerfect and Ventura Publisher capable of
high quality output?  Newcomers have often already seen what \TeX\
is capable of (many books, journals, letters are now prepared with \TeX)
and so expect to find a tremendously powerful and friendly package.
In fact they {\em do}, but that fact is well hidden in one's initial
\TeX\ experiences.  In this chapter we describe a little of what
makes \TeX\ great, and why other packages cannot even begin
to compete.  Be warned that a little patience is required---\TeX's
virtues are rather subtle to begin with.  But when the penny drops,
you will wonder how you ever put up with anything different.

\section{The spirit of \TeX}
In order to really appreciate \TeX\ one needs to get a feel
for what I call the ``spirit'' of \TeX.  When \TeX\
appears to be making me work overtime to achieve something
that I think ought to be perfectly straightforward, consultation
with the \TeX\ spirit shows me the error of my ways.

\subsection{\TeX\ is a typesetter, not a word-processor}
% we chat about the pros and cons of this;
% talk about compilation, previewing, printing
% start to convince of the essential power of this
% a few examples
% macro packages & style files
\TeX\ was designed with no limiting application in mind.
It was intended to be able to prepare practically any document---from
a single page all-text letter to a full blown book with huge numbers
of formulae, tables, figures etc.  The size and the complexity of a
{\TeX}able document is limited only by hardware considerations.
Furthermore, \TeX\ seeks to achieve all this whilst setting
typesetting standards of the highest order for itself.  The expertise
of generations of professional printers has been captured in
\TeX, and it has been taught all the tricks of the trade.

Historically, printers prepared a document by placing metal
characters in a large tray and arranging and binding them
to form a page.  This was very precisely done, but the ultimate
precision was limited because of the mechanical nature of
things and by time considerations.  \TeX\ prepares a page
in an analogous manner (putting your characters and
formulae into ``boxes'' which are then ``glued'' together
to form the page), but has the advantage of enormous
precision because placement calculations are performed
by computer.  Indeed, \TeX's internal unit (the ``scaled
point'') is about one-hundredth of the wavelength of
natural light!

``But conventional word processors run on computers , too'',
you object.  Yes, but their fundamental limitation is that
they try to ``keep up'' with you and ``typeset'' your document
as you type.  This means that it can only make decisions at
a local level (eg, it decides where to break a line just as you
type the end of the line).  \TeX's secret is that it waits until
you have typed the {\em whole\/} document before it typesets
a single thing!  This means that \TeX\ can make decisions of
a global nature in order to optimise the aesthetic appeal of
your document.  It has been taught what looks good and what
looks bad (having been given a measure of the ``badness'' of
various possibilities) and makes choices for your document that
are designed to make it ``minimally bad''.

But \TeX's virtues run much deeper than that, which is just as well
because it is possible to get satisfactory, though imperfect, results from
some word processors.  One of \TeX's strongest points is its ability
to typeset complicated formulae with ease.  Not only does \TeX\
make hundreds of special symbols easily accessible, it will lay them
out for you in your formulae.  It has been taught all the spacing,
size, font, \ldots conventions that printers have decided look
best in typeset formulae.  Although, of course, it doesn't understand
any mathematics it knows the grammar of mathematics---it
recognises binary relations, binary operators, unary operators, etc.\
and has been taught how these parts should be set.  It is consequently
rather difficult to get an equation to look bad in \TeX.

Another advantage of compiling a document after it is typed is that
cross-referencing can be done.  You can label and refer back to
chapters, sections, tables etc.\ by {\em name\/} rather than absolute
number, and \TeX\ will number and cross-reference these for you.
Similarly, it will compile a table of contents, glossary, index and bibliography
for you.

Essential to the spirit of \TeX\ is that {\em it formats the document whilst
you just take care of the content}, making for increased productivity.
The cross-referencing just mentioned is just part of this.  Many more
labour-saving mechanisms are provided for through {\em style files}.
These are generic descriptions of classes of documents, teaching \TeX\
just how each class likes to be formatted.  This is taught in terms
of font preferences, default page sizes, placement of title, author, date,
etc.  For instance, a {\tt paper} style file could teach \TeX\ that
when typesetting a theorem it should embolden the part that states
the theorem number and typeset the text of the theorem statement
in slanted Roman typeface (as in many journals).  The typist simply
provides and indication that a theorem is being stated, and then
types the text of the theorem {\em without\/} bothering to choose
any fonts or do any formatting---all that is done by the style
file.  Style files exist for all manner of document---letters,
articles, papers, books, proceedings, review articles, and so on.

In addition to style files, there are {\em macro packages}.  A
{\em macro\/} is just a definition of a new \TeX\ command
in terms of existing ones.  Don't think small when you think of
macros!  When typing a document that has a lot of repetition
in it, say the same expression is used again and again in different
different equations, you can define a macro in  your document
to abbreviate that expression.  But macros can teach \TeX\
how to typeset all sorts of complicated structures, not just
parts of an equation.  Many macro packages (files that are
just collections of definitions) have been written to teach \TeX\
all sorts of applications.  There are specialist maths packages
(\AmSTeX, \AmSLaTeX), general purpose packages (\LaTeX),
packages for setting tree diagrams, Feynmann diagrams,
languages like Chinese, Arabic and Ancient Greek,
orchestral scores, and many, many more.  All these are
freely available, a spin-off of the giant \TeX\ cult.

Another facet of the design of \TeX\ allows it to use
practically {\em any\/} output device.  In fact, \TeX\
doesn't talk to any printers, screens, phototypesetters
at all!  Instead, when a document is compiled a
{\em device independent\/} ({\tt .dvi}) is produced---%
\TeX\ does not compile with any particular output
device in mind.  Printer drivers are then invoked on
this {\tt .dvi} file and, in consultation with the font
data for that printer, produce output suitable for the
particular device.  You can choose an HP Laserjet
driver, or an Apple LaserWriter driver, or a dot matrix
driver etc.  All use the same {\tt .dvi} file as input (and
remember the material in there is set to enormous
accuracy) and attempt to image that file on the particular
device as faithfully as possible.  If you are using a top of the
line laser printer or phototypesetter, then \TeX's
massive internal precision will not be wasted.  Alternatively,
a dot matrix printer
will give a coarse approximation of the ideal image that is
suitable only for proof-reading.  In addition to portability,
these {\tt .dvi} files help ensure that there are very few printing
surprises when you move from one device to another:  how many times
has your favourite word-processor made you reformat a document when
you wish to change printers?

There are many other motivations one could cite for the
superiority of \TeX.    But it is time that we started to get
our hands dirty.  One last comment:  \TeX\ was not designed
to supplant secretaries and professional printers---it was designed
to aid them in their work and, in the words of the \TeX\ designer
Donald Knuth, allow them to ``go forward and create masterpieces
of the publishing art''.% or was that typesetting art?
It also allows those who generate the material
to be typeset---mathematicians, physicists, computer scientists, etc---to
prepare their own documents in a language that is intimately linked
to the language we use for writing such material.

The novice reader will still have no idea of what a \TeX\ source file
looks like.  Indeed, why do we keep referring to it as a {\em source
file}?  The fact of the matter is that \TeX\ is essentially a
{\em programming language}.  Just as in any compiled language
(e.g.,\ Pascal, C) one prepares a source file and submits it to the
compiler which attempts to produce an object file ({\tt .dvi} file
in the \TeX\ case).  To learn \TeX\ is to learn the command syntax
of the commands that can be used in the source file.

\subsection{Typical \TeX\ interfaces}
% multicompter setting
% device independence
% command line level and script files
% \TeX\ shells
\TeX\ was designed to run on a multitude of computers.  It is therefore
the case that the documentation for \TeX\ and its ``friends''
\LaTeX, \AmSTeX, etc.\ is not computer specific.  Only
command syntax is described---i.e., the content of your source file---but
few details of how to get from there to a printout are given.  Those details
are left to site-specific documents.

The average user loses little in using \TeX\ on, say, a PC rather than
on a bigger machine.  Indeed, compilation times on the
new PCs begin to rival those on a Sun Sparc
Station 2 (no slouch).  Running on top of DOS can cause memory problems
when very large documents are being prepared.  That aside, the quality
of the document is not affected because of the careful design of \TeX---%
whether you work on a a machine with massive floating point precision or
a modest XT the {\tt .dvi} files produced on compilation will be 
identical; and when those files are submitted to printer equivalent
printer drivers (say for an HP LaserJet III attached to a Sun in one case
and a PC in the other) the output will be identical because the font
information they draw on is identical.

By the nature of \TeX\ most time is spent editing the source document
(before submitting it for compilation).  No special interface is necessary
here, you just use your favourite text editor (perhaps customising it
to enhance {\TeX}nical typing.  Thus \TeX\ user interfaces are usually
small and simple, often even missing.  One frequently uses \TeX\ at
command line level, just running the editor, compiler etc.\ as you need them.
Sometimes a {\TeX}shell program is present, which runs these for you
when you choose various menu options.

Whatever the interface, there are just a few basic steps to preparing
a document:
\begin{enumerate}
\item Choose a document style to base your document on (e.g., letter, article).
\item Glance through the material you have to type, and decide what
            definitions might be made to save you a lot of time.  Also, decide on
            the overall structure of the prospective document (e.g., will the largest
            sectional unit be a chapter or a part?).  If you are going to compose as
            you type, then pause a moment to think ahead and plan the structure
            of your document.  The importance of this step cannot be overstressed,
            for it makes clear in {\em your\/} mind what you want from \TeX.
\item Prepare your input file, specifying only the content and the logical
            structure (parts, sections, theorems,...) thereof and forgetting about formatting details.
\item Submit your input, or source, file to the \TeX\ compiler for compilation
             of a {\tt .dvi} file.
\item If the compiler finds anything in your source file strongly objectionable,
            say incorrect command syntax, then return to editing.
\item Run a {\em previewer\/} to preview your compiled document on the
            screen.  Resolution is only limited by your screen, and can be very
             good indeed on some modern monitors.
\item Go back to editing your document until glaring errors have been taken
             care of.
\item Make a printout of your compiled document, and check for those errors that
             you failed to notice on the screen.
\end{enumerate}
Performing these steps may be effected through typing at the system prompt
(barebones technique) or through choosing menu options in a {\TeX}shell program.
The latter will probably provide some conveniences to make your life easier.

If you think this sounds like a lot of work, it is time that you consult with the
\TeX\ spirit!  Sure your first couple of tries may be hesitant, but before long
you'll find that you can take {\em less\/} time to prepare a document on \TeX\
than on any other package.


\chapter{Getting started with \LaTeX}
\section{Why start with \LaTeX?}
To answer this question we must say a little more about
some of  the macro packages we mentioned earlier.

The \TeX\ typesetting system was designed by the eminent Stanford
computer scientist Donald Knuth, on commission from the American
Mathematical Society.  It was designed with enormous care, to be
ultimately powerful and maximally flexible.  The enormous success
of Knuth's design is apparent from the vast number of diverse applications
\TeX\ has found.  In reading the following you must keep one thing clearly
in mind:  {\em there is only \TeX\ language, and all the other packages whose
names end in the suffix \mbox{-\TeX} simply harness it's power via a whole
lot of complicated macro definitions}.

\TeX\ proper is a collection of around 300 so called {\em primitive\/}
typesetting commands.  These work at the very lowest level, affording
enormous power.  But to make this raw power manageable, some macros
must be defined to tame raw \TeX\ somewhat.  The standard set
of macros is called Plain \TeX, and consists of about 600 macro definitions.
It is clear that these definitions must be made in terms of \TeX\ primitives,
or in terms of previously made definitions.  Plain \TeX, however, is still
no place for the timid.  A strong working knowledge of \TeX\ is still required
to understand the ins and outs of Plain \TeX.

In the few years after the initial \TeX\ release (1982), the macro packages
\AmSTeX\ and \LaTeX\ were born.  \AmSTeX\ was written by Michael
Spivak, also on commission from the AMS.  This package was designed to
facilitate the preparation of the numerous books, journals, and review
indices that fall under the auspices of the AMS and its affiliates.
Married to the macro package was a style file---the AMS preprint style.
This was distributed along with the macro package, so that authors
submitting to journals could use it in the preparation of their articles.
The given style was based on the style used by the {\em Journal of the
American Mathematical Society}, i.e., it conformed to their page sizes
and typographical conventions.  This meant that people around the world
produced papers that were all based on the same style.  The clever part
is this:  when a source file is submitted to a journal {\em other\/} than
the {\em  Journal of the AMS}, the journal staff simply substitute their
style file for the AMS preprint style and the paper will appear completely
different {\em with no other changes to the source code\/}!  To create
their style file, a journal just needed to tweak the standard AMS prepint
style:  for instance, the original preprint style places author addresses
at the very end of a paper;  If a journal wishes this to appear on the first
page then they just modify their in-house version of the style file, and
the change will be effected without having to change the file submitted
by the author.

\LaTeX\ was written for more general usage.  It lacks some of the
mathematical finesse inherited by \AmSTeX\ from the vast experience of the AMS
technical staff, but more than makes up for this in its ability to enhance
the typesetting of letters, books, poetry, etc.  \LaTeX\ also scores high
points for its enhanced command syntax.

With \AmSTeX\ and \LaTeX\ being released at around the same time (1984--1985),
there were born many \AmSTeX\ literate but \LaTeX\ illiterate users,
and conversely.  \LaTeX\ was easier to learn because of its more friendly
syntax, and also provided powerful cross-referencing commands that
\AmSTeX\ did not.  So the AMS commissioned another project to
furnish \LaTeX\ users with the additional power of \AmSTeX\
while not compromising the \LaTeX\ command syntax or
cross-referencing commands.  This resulted in the \AmSLaTeX\
macro package and associated style file for submission to journals.

{\em That\/} is why we will kick off our \TeX\ careers with \LaTeX!
It is easier to learn and provides many conveniences, and the user
who requires additional mathematical typesetting prowess can
easily move on to \AmSLaTeX.  Much of what we say will be true
for \TeX\ itself, but we shall regard \LaTeX\ as the lowest
common-denominator.  By far the majority of \LaTeX\ and
\AmSLaTeX\ users will never have to learn ``raw'' \TeX, for they will
be shielded from direct exposure by the numerous powerful macro packages.
In the rare case that something way out of the ordinary is required,
the local \TeX\ guru can be consulted.

\section{\LaTeX\ formats, and we compose}
% free form nature of input file
The {\em free form nature\/} of the input file is essential to the
spirit of \TeX.  As we type, we do not concern ourselves with linebreaks
and pagebreaks so much as the content of what we are typing.  In fact,
we'll see that \TeX\ will choose nice line breaks even for bizarre looking
input.  This is just part of the concept of only having to describe the
{\em logical\/} structure of the document to \LaTeX, and not worry
about nuisance-value formatting details.  We inform \LaTeX\
of the logical structure of our document by telling it when to begin
a new paragraph, subsection, section, chapter, theorem, definition,
remark, poem, list etc.  When typing a particular element of the logical
structure, we need pay little attention to how we lay our source file out.

A consequence of this is that we have to go to a bit of effort to mess things
up.  Starting a new line, for instance, entails more than just pressing
Return because \LaTeX\ will just regard the next word you type
as exactly that---the next word in the paragraph.  You have to specifically
ask for a line to be terminated.  Things like this may seem to be a bit of a
nuisance, but it is a small price to pay for the automatic formatting that
necessitated it.  Further, such small inconveniences have been localised
to rare events.  I have, for instance, not once forced a new line up until
this point in the present document.

\section{Document styles}
We have explained the concept of a document style during our discussion
of the virtues of \TeX\ and the discussion of \AmSTeX.  It remains to
name a few, and indicate where they would be used.  One {\em always\/}
has to choose a document style when preparing a document with \LaTeX.

The basic document styles in \LaTeX\ are {\tt letter}, {\tt article}, {\tt report},
and {\tt book}.  Many more are available, but these few cover the majority
of straightforward applications.  This is because styles are not rigid---you
can impose your own parameter choices if you want.  So one chooses the
style that most closely approximates the document you have in mind, and
performs some minor tweaks here and there.  The {\tt article} style is
used for documents that are to have the appearance of a journal or
magazine article. The {\tt report} style is usually used
for larger documents than the {\tt article} style.  These styles really only
differ in their choice of default page size, font, placement of title and author,
sectional units, etc.\ and on how they format certain \LaTeX\ constructs.
You use the same \LaTeX\ commands in each.  Since the
examples here will be small, we will choose to use the {\tt article} document
style.

There are a number of possible options with each document style.  The syntax
for choosing a document style follows.  Don't worry if this leaves you with no idea
of how to choose a document style, for we will soon be seeing some examples.  Also,
remember that an argument in square brackets is optional, and can omitted
altogether (including the brackets).
\begin{syntax}{documentstyle}
\opt{options}\man{style}
\end{syntax}
where {\em style\/} is the main document style (eg {\tt report})
and the optional argument {\em options\/} is a list of document style options chosen
from the following list:
\begin{itemize}
\item[\tt 11pt] chooses 11-point as the default font size for the document, instead
                       of the default 10-point.
\item[\tt 12pt] chooses 12-point as the default font size.
\item[\tt twoside] formats output as left and right pages, as in a book.
\item[\tt twocolumn] produces two-column magazine like output.
\item[\tt titlepage] applies to the {\tt article} style only, causing the
           title and abstract to appear on a page each.
\end{itemize}

In fact there are many, many more document style options but we
won't mention any more here.

\section{Preparing a non-mathematical document}
We assume that you have read the local guides to \TeX\ at your site and have
decided which system environment you want to work in.  There you have been
shown how to perform the steps required to produce a printed document from a
\LaTeX\ source file.

\subsection{Sentences and paragraphs}
Let's create our very first \LaTeX\ document, which will consist
of just a few paragraphs.

As mentioned above, paragraph input is free-form.  You type the words
and separate them by spaces so that \LaTeX\ can distinguish between
words.  For these purposes, pressing Return is equivalent to inserting
a space---it does not indicate the end of a line, but the end of a word.
You tell \LaTeX\ that a sentence has ended by typing a period followed
by a space.  \LaTeX\ ignores extra spaces; typing three or three thousand will
get you no more space between the words that these spaces separate than
typing just one space.  Finally, you tell \LaTeX\ that a paragraph has
ended by leaving one or more blank lines.
In summary: \LaTeX\ concerns itself only with the
logical concepts end-of-word, end-of-sentence, and end-of-paragraph.
Sounds complicated?  An example should clear things up:

\moveright0.1\textwidth\vbox{%
\footnotesize\begin{verbatim}
\documentstyle{article}
\begin{document}
Words within a sentence are ended by spaces.  One space
between words  is     equivalent      to any number. We are only
interested in separating      one    word      from        the
next, not in formatting       the space between them.
For these purposes, pressing Return
at the end of a line
and starting a new word on the next line
just serves to separate
words, not to cut a line short.
The end of a sentence is indicated by a period
followed by one or more spaces.

The end of a paragraph is indicated by leaving a blank line.
All this
means that we can type without too much regard for layout, and
the typesetter will sort things out for us.
\end{document}
\end{verbatim}
}
\noindent produces the result

\result{%
Words within a sentence are ended by spaces.  One space
between words  is     equivalent      to any number. We are only
interested in separating      one    word      from        the
next, not in formatting       the space between them.
For these purposes, pressing Return
at the end of a line
and starting a new word on the next line
just serves to separate
words, not to cut a line short.
The end of a sentence is indicated by a period
followed by one or more spaces.

The end of a paragraph is indicated by leaving a blank line.  All this
means that we can type without too much regard for layout, and
the typesetter will sort things out for us.
}

Perhaps you would like to try running \LaTeX\ on the above input.
Consult your local guide for details.

Note that we have learned more than just how \LaTeX\ recognises words,
sentences and paragraphs.  We've also seen how to specify our choice
of document style and how to tell \LaTeX\ where our document begins
and ends.  Any material that is to be printed must lie somewhere between
the declaration of \verb@\begin{document}@ and that of \verb@\end{document}@.
Definitions that are to apply to the entire document can be made before
the declaration of the document beginning.  The specification of
document style must precede all other material.

In future examples we won't explicitly display the commands that
select document style and delimit the start and end of the document.
But if you wish to try any of the examples, don't forget to include those
commands.  The {\tt article} document style will do for most of our examples.
Of course, the preceding example looks not at all like an article because
it is so short and because we specified no title or author information.

Most of what you need to know to type regular text is contained in the
example above.  When you consider that by far the majority of any document
consists of straight text, it is obvious that \LaTeX\ makes this fabulously straightforward.
\LaTeX\ will do all the routine work of formatting, and we simply get on with the
business of composing.

\LaTeX\ does more than simply choose pleasing line breaks and
provide natural spacing when setting a paragraph.  Remember we
said that \TeX\ has inherited the knowledge of generations of
professional printers---well part of that knowledge includes
being on the look-out for {\em ligatures}.  These are combinations
of letters within words which should be typeset as a single special
symbol because they will ``clash'' with each if this is not done.
Have a look at these words
\begin{center}
flight, flagstaff, chaff, fixation
\end{center}
and compare them with these
\begin{center}
f{l}ight, f{l}agstaf{f}, chaf{f}, f{i}xation
\end{center}
See the difference?  In the first set I let \LaTeX\ run as it usually does.
In the second I overruled it somewhat, and stopped it from creating
ligatures.  Notice how the `fl', `ff', and `fi' combinations are different
in the two sets---in the former they form a single symbol (a ligature)
and in the latter they are comprised of two disjoint symbols.  There
are other combinations that yields ligatures, but we don't have to bother
remembering any of them because \LaTeX\ will take care of these, too.

Notice, too, that \LaTeX\ has been taught how to hyphenate the
majority of words.  It will hyphenate a word if it feels that the overall
quality of the paragraph will be improved.  For long words it has been
taught several potential hyphenation positions.

\LaTeX\ also goes to a lot of trouble to try to choose pleasing page
breaks.  It avoids ``widows'', which are single lines of a paragraph
occurring by themselves at either the bottom of a page (where
it would have to be the first line of a paragraph) or at the top
of a page (where it would have to be the last).  It also
``vertically justifies'' your page so that all pages have exactly
the same height, no matter what appears on them.  As testimony
to the success of the pagebreaking algorithm, I have (to
this point) not once chosen a page break in this document.

\subsection{Punctuation}
Typists have a convention whereby a single space is left after a
mid-sentence comma, and two spaces are left after a sentence-ending
period.  How do we enforce this if \LaTeX\ treats a string of spaces just like
a single one?  The answer, unsurprisingly, is that we {\em don't}.

\moveright0.1\textwidth\vbox{%
\footnotesize\begin{verbatim}
To have a comma followed by the appropriate space,  we simply
type a comma follows by at least one space. To end a sentence
we type a period with at least one following space.     No space will
be inserted if we type a comma or period followed straight away
by something other than a space, because there are times when
we won't require any space, i.e., we do what comes narurally.
\end{verbatim}
}
\noindent will produce

\result{%
To have a comma followed by the appropriate space,  we simply
type a comma follows by at least one space. To end a sentence
we type a period with at least one following space.     No space will
be inserted if we type a comma or period followed straight away
by something other than a space, because there are times when
we won't require any space, i.e., we do what comes naturally.
}

\LaTeX\ will produce suitable space after commas, periods,
semi-colons and colons, exclamation marks, question marks etc.\
if they are followed by a space.
In stretching a line to justify to the
right margin, it also knows that space after a punctuation
character should be more ``stretchable'' than normal inter-word
space and that space after a sentence-ending period should be stretched
more than space after a mid-sentence comma.  \TeX\ knows the nature of
punctuation if you stick to the simple rules outlined here.  As we've already
said, those rules tell \LaTeX\ how to distinguish consecutive words,
sentences, phrases, etc.

Actually, there is more to ending sentences than mentioned above.
Since \LaTeX\ cannot speak English, it works on the assumption
that {\em a period followed by a space ends a sentence unless the period
follows a capital
letter}.  This works most of the time, but can fail.  To get a normal
inter-word space after a period that doesn't end a sentence,
follow the period by a {\em control space}---a \verb*@\ @
(a {\tt \bs} character followed by a space or return).  Very
rarely, you will have to force a sentence to end after a
period that follows a capital letter (remember that \LaTeX\
assumes this doesn't end a sentence).  This is done by preceding
the period with a \verb!\@! command (you can guess from the odd
syntax that this is rarely needed).

It's time we saw some examples of this.  After all, this is our first
experience of {\em control symbols} (don't worry, there are many
more to come).

\moveright0.1\textwidth\vbox{%
\footnotesize\begin{verbatim}
We must be careful not to confuse intra-sentence periods
with periods that end a sentence, i.e.\ we must remember
that our task is to describe the sentence structure.  Periods
that the typesetter requires a little help with typically result
from abbreviations, as in etc.\ and  others.  We have to work
somewhat harder to break a sentence after a capital letter,
but that shouldn't bother us to much if we keep up our intake
of vitamin E\@.  All this goes for other sentence-ending
punctuation characters, so I could have said vitamin E\@!
Fortunately, these are rare occurrences.
\end{verbatim}
}
\noindent results in

\result{%
We must be careful not to confuse intra-sentence periods
with periods that end a sentence, i.e.\ we must remember
that our task is to describe the sentence structure.  Periods
that the typesetter requires a little help with typically result
from abbreviations, as in etc.\ and  others.  We have to work
somewhat harder to break a sentence after a capital letter,
but that shouldn't bother us to much if we keep up our intake
of vitamin E\@.  All this goes for other sentence-ending
punctuation characters, so I could have said vitamin E\@!
Fortunately, these are rare occurrences.
}

Quotation marks is another area where \LaTeX\ will do some
work for us.  Keyboards have the characters \verb@`@, \verb@`@, and \verb@"@ but we
want to to have access to each of `, ', ``, and ''.  So we proceed like this:

\moveright0.1\textwidth\vbox{%
\footnotesize\begin{verbatim}
`\LaTeX' is no conventional word-processor, and
to to get quotes, like ``this'', we type repeated
` and ' characters.  Note that modern
convention is that ``punctuation comes after
the closing quote character''.
\end{verbatim}
}
\noindent which gives just what we want

\result{%
`\LaTeX' is no conventional word-processor, and
to to get quotes, like ``this'', we type repeated
{\tt `} and {\tt '} characters.  Note that modern
convention is that ``punctuation comes after
the closing quote character''.
}

Very rarely, you have three quote characters together.
Merely typing those three quote characters one-after-the-other
is ambiguous---how should they be grouped?  You tell
\LaTeX\ how you want them grouped by inserting a
very small space called \verb@\,@.

\moveright0.1\textwidth\vbox{%
\footnotesize\begin{verbatim}
``\,`Green ham' or `Eggs?'\,'' is the question.
\end{verbatim}
}
\noindent gives the desired result

\result{%
``\,`Green ham' or `Eggs?'\,'' is the question.
}

Since we have a typesetter at our disposal, we might as
well use the correct dashes where we need them.  There
are three types of dash: the hyphen, the endash, and
the emdash.  A minus sign is not a dash.

Hyphens are typed as you'd hope, just by typing a \verb@-@
at the point in the word that you want a hyphen.  Don't
forget that \LaTeX\ takes care of hyphenation that is
required to produce pretty linebreaks.  You only type
a hyphen when you explicitly want one to appear,
as in a combination like ``inter-college''.

An endash is the correct dash to use in indicating
number ranges, as in ``questions~1--3''.  To
specify an endash you type two consecutive
dashes on the keyboard, as in \verb@1--3@.

An emdash is a punctuation dash, used at the end
of a sentence---I tend to use them too much.
To specify an emdash you type three consecutive
dashes on the keyboard, as in ``\ldots\verb@a sentence---I tend to@\ldots''.

\moveright0.1\textwidth\vbox{%
\footnotesize\begin{verbatim}
Theorems 1--3 concern the semi-completeness
of our new construct---in the case that it
satisfies the first axiom.
\end{verbatim}
}
\noindent yields

\result{%
Theorems 1--3 concern the semi-completeness
of our new construct---in the case that it
satisfies the first axiom.
}

\subsection{Ties}
When you always remember to use {\em ties\/}, you know
that you are becoming {\TeX}nically inclined.  Ties are
used to prevent \LaTeX\ from breaking lines at
certain places.  \LaTeX\ will always choose line breaks
that result in the most aesthetically pleasing paragraph
as judged by its stringent rules.  But because \LaTeX\
does not actually understand the material it is setting
so beautifully, it can make some poor choices.

A {\em tie\/} is the character \verb@~@.  It behaves as a
normal interword space in all respects {\em except\/}
that the line-breaking algorithm will never break a
line at that point.  Thus

\moveright0.1\textwidth\vbox{%
\footnotesize\begin{verbatim}
Dr. Seuss should be typed as Dr.~Seuss
\end{verbatim}
}
\unskip\noindent for this makes sure that \LaTeX\ will never
leave the `Dr' at the end of one line and put the `Seuss'
at the beginning of the next.

One should try to get in to the habit of typing ties first-time,
not after waiting to see if \LaTeX\ will make a poor choice  This will allow
you to make all sorts of changes to your text without ever
having to go back and insert a tie at a point that has migrated
to the end of a line from the middle of a line as a result
of those changes.  Remember, of course, that the line-breaks 

Here are some more examples of places where you should remember to
place ties.

\moveright0.1\textwidth\vbox{%
\footnotesize\tt\begin{tabbing}
Lemmas 3 and\verb!~!4\quad      \= \kill
Chapter\verb!~!10       \> Donald\verb!~!E. Knuth\\
Appendix\verb!~!C     \> width\verb!~!2\\
Figure\verb!~!1   \>    function\verb!~!f\\
Theorem\verb!~!2    \>   1,\verb!~!2, or\verb!~!3\\
Lemmas 3 and\verb!~!4   \>  equals\verb!~!5\\
\end{tabbing}
}

\subsection{Specially reserved symbols}\label{sec:reserved}
In the sequel we will see that the the ten characters

\moveright0.1\textwidth\hbox{\verb!# $ % & ~ _ ^ \ { }!}

\noindent are reserved for special use.  Indeed, we have seen already
that {\tt\bs} and \verb@~@ are non-printing characters
that perform special services (and we'll have a lot more to
say about the use of {\tt\bs}).

But what if we need one of these special symbols to appear
in our document?  The answer for seven of the symbols
is to precede them by a {\tt\bs} character, so forming
another {\em control symbol\/} (remember that
{\tt\bs} followed by a space was also a control symbol).

\moveright0.1\textwidth\vbox{%
\footnotesize\begin{verbatim}
It is not 100\% straightforward to typeset the
characters \$ \& \% \_ \{ \}, but given the
enormous convenience of the use they are normally
reserved for this is a small price to pay.
\end{verbatim}
}
\noindent produces

\result{%
It is not 100\% straightforward to typeset the
characters \$ \& \% \_ \{ \}, but given the
enormous convenience of the use they are normally
reserved for this is a small price to pay.
}

\subsection{So what are control symbols and words?}
In typing a document, we can think of ourselves as
being in one of two distinct modes.  We are either
typing {\em literal text\/} (which will just be set into neat
paragraphs for us) or we are typing text that will
be {\em interpreted\/} by \LaTeX\ as an instruction
to insert a special symbol or to perform some action.
Thus we are either typing material that will go
straight into the document (with some beautification),
or we are giving commands to \LaTeX.

Some commands are implicit, in that we don't have to
do anything much extra.  For instance, we command
\LaTeX\ to end the present sentence by typing a
period (that doesn't follow a capital letter).  These are
no so much commands as part of having to describe
the logical structure of a document.

A {\em control word\/} is something of the form
\verb@\commandname@, where the command name
is a word made up only of the letters  a to~z and A to~Z.  A
{\em control symbol\/} consists of a {\tt\bs}
followed by single symbol that is not a letter.

Here are some examples:
\begin{itemize}
\item we have met the control space symbol \verb*@\ @ before,
\item the commands to set symbols like \% and \$ are control symbols
\item \verb!\@! was a control symbol that told told \LaTeX\ that
             the very next period did really end the sentence,
\item \verb@\LaTeX@ is a control word that tell \LaTeX\ to insert
            its own name at the current point,
\item \verb@\clubsuit@ instructs that a $\clubsuit$ be inserted,
\item \verb@\pounds@ inserts a \pounds\ symbol,
\item \verb@\S@ inserts a \P\ symbol,
\item \verb@\em@ makes the ensuing text {\em be emphasised},
\end{itemize}

These examples show that control sequences can be used to
access symbols not available from the keyboard,
do some typesetting tricks like setting the word
\LaTeX\ the way it does, and change the appearance of
whole chunks of text as with \verb@\em@.  We'll be meeting
many more of these type of control sequences.

Another enormously powerful class of control sequences is
those that accept {\em arguments}.  They tell \LaTeX\
to take the parts of text you supply and do something
with them---like make a fraction by setting the first
argument over the second and drawing a line of the
appropriate length between them.  These are part of
what makes \LaTeX\ so powerful, and here are some
examples.

\begin{itemize}
\item \verb@\chapter{The beginning}@ causes \LaTeX\ to
           start a new chapter with name ``The Beginning'', number
           it in sequence, typeset the chapter heading in a suitable
           font, and make an entry in the table of contents,
\item \verb@\overline{words}@ causes $\overline{\mbox{words}}$ to
           be overlined,
\item \verb@\frac{a+b}{c+d}@ sets the given two argument as
            a fraction, doing most of the dirty work for us: $\frac{a+b}{c+d}$,
\item \verb@\sqrt[5]{a+b}@ typesets the fifth-root of $a+b$,
            like this: $\sqrt[5]{a+b}$. The {\tt 5} is in square brackets
            instead of braces because it is an optional argument and
             could be ommited all together (giving the default of square root),
\end{itemize}

Mandatory arguments are given enclosed by braces, and
optional arguments enclosed by square brackets.  Each
command knows how many arguments to expect, so
you don't have to provide any indication of that.

We have actually jumped the gun a little.  The above examples
include examples of {\em mathematical\/} typesetting, and we
haven't yet seen how to tell \LaTeX\ that it is typesetting
maths as opposed to some other random string of symbols
that it doesn't understand either.  We'll come to mathematical
typesetting in good time.

We need to dwell on a {\TeX}nicality for a moment.  How does
\LaTeX\ know where the name of a control sequence ends?
Will it accept both \verb@\pounds3@ and \verb@\pounds 3@
in order to set \pounds3, and will \verb@\emWalrus@
and \verb@\em Walrus@ both be acceptable in order to
get {\em Walrus\/}?  The answer is easy when you remember
that a control word consists only of alphabetic characters,
and a control symbol consists of exactly one nonalphabetic
character.

So to determine which control sequence you typed,
\LaTeX\ does the following:
\begin{enumerate}
\item when a {\tt\bs} character is encountered, \LaTeX\ knows
            that either a control symbol or a control word will follow.
 \item If the {\tt\bs} is followed by a nonalphabetic character,
             then \LaTeX\ knows that it is a control {\em symbol\/}
             that you have typed.  It then recognises which one it was,
             typesets it, and goes on to read the character which follows
             the symbol you typed.
\item If the {\tt\bs} is followed by an alphabetic character, then
            \LaTeX\ knows that it is a control word that you have typed.
             But it has to work out where the name of the control word ends
              and where the ensuing text takes over again.  Since only alphabetic
              characters are allowed, \LaTeX\ reads everything up to 
              just before that first
              nonalphabetic character as the control sequence name.  Since
              it is common to delimit the end of a control word by a space,
              \LaTeX\ will {\em ignore\/} any space that follows a control
              word, since you want that space treated as end-of-control-word
              space rather than interword space.
\end{enumerate}

This has one important consequence:  The character in the input
file immediately after a control symbol will be ``seen'' by \LaTeX,
but {\em any space following a control word  will be
discarded and never processed.}  This does not affect one much if you adopt
the convention of always typing a space after a control sequence name.

There is a rare circumstance where this necessitates a little extra work
and thought, which we illustrate by example:

\moveright0.1\textwidth\vbox{%
\footnotesize\begin{verbatim}
If we type a control word like \LaTeX in the running text
then we must be cautious, because the string of spaces that
come after it will be discarded by the \LaTeX\ system.
\end{verbatim}
}
\noindent which produces the output

\result{%
If we type a control word like \LaTeX in the running text
then we must be cautious, because the string of spaces that
come after it will be discarded by the \LaTeX\ system.
}

\subsection{Commands to change appearance}\label{sec:groups}
We've seen a little of how to access  various symbols using
control sequences and we mentioned the \verb@\em@
command to emphasise text, but we didn't see how to use
them.  We look here at commands that change the appearance
of the text.

Each of the control words here is a directive rather
than a control sequence that accepts an argument.
This is because potential arguments consisting
of text that wants to be emboldened or emphasised
are very large, and it would be a nuisance to have
to enclose such an argument in argument-enclosing
braces.

To delimit the area of text over which one of these commands
has effect (its {\em scope}) we make that text into what
is called a {\em group}.  Groups are used extensively in
\LaTeX\ to keep effects local to an area, rather than
affecting the whole document.  Apart from enhancing
usability, this also in a sense protects distinct parts
of a document from each other.

The \LaTeX\ commands for changing type style are given
in table~\ref{tab:typestyles}, and those for changing type
size are given in table~\ref{tab:sizes}.  Commands for
selecting fonts other than these are not discussed here.

\begin{table}[ht]
\centering
\begin{tabular}{llllllll}
\verb@\rm@ & Roman                    & & \verb@\it@ & \it italic          & & \verb@\sc@ & \sc Capitals\\
\verb@\em@ & \em Emphasised &  & \verb@\sl@ & \sl slanted     & & \verb@\tt@  & \tt typewriter\\
\verb@\bf@   & \bf boldface           &  & \verb@\sf@ & \sf sans serif & &\\
\end{tabular}
\caption{Commands for selecting type styles}
\label{tab:typestyles}
\end{table}

Each of the type style selection commands selects the specified style but does
not change the size of font being used.  The default type style is roman (you
are reading a roman style font now).  To change type size you issue one of
the type size changing commands in table~\ref{tab:sizes}, which will select
the indicated size in the currently active style.  The release of \LaTeX\
3.0 (the present version is 2.09) will see the New Font Selection Scheme
in place as a standard feature. This makes font matters much easier to deal
with.

--
Gavin Maltby, University of Natal, Pietermaritzburg, South Africa
gmaltby@unpcs1.cs.unp.ac.za, maltby@unpsun1.cc.unp.ac.za
Any opinion expressed is mine and mine alone.
------------------------------------------------------------------