\sectiontitle{Introduction to Plain \TeX}
\label{pl-intro}
\subsectiontitle{What is Plain \TeX?}
\TeX\ is a computer program for typesetting documents. It
takes a computer file, prepared according to the rules of
\TeX, and converts it to a form that may be printed on a
high-quality printer, such as a laser writer, to produce
a printed document of a quality comparable with good
quality books and journals. Simple documents, which do
not contain mathematical formulae or tables may be produced
very easily: effectively all one has to do is to type the
text straight in (though observing certain rules relating to
quotation marks and punctuation dashes). Typesetting
mathematics is somewhat more complicated, but even here
\TeX\ is comparatively straightforward to use when one
considers the complexity of some of the formulae that it
has to produce and the large number of mathematical symbols
which it has to produce.
There are various `dialects' of \TeX, including \LaTeX.
Plain \TeX\ (created by D.~E.~Knuth) is the basic version
of \TeX\ on which these other `dialects' are based. The
reference manual for Plain \TeX\ is ``The \TeX book'', by
D.~E.~Knuth.
\subsectiontitle{A Typical Plain \TeX\ Input File}
In order to produce a document using \TeX, we must first
create a suitable {\it input file\/} on the computer. We
apply the \TeX\ program to the input file and then use the
printer to print out the so-called `DVI' file produced by
the \TeX\ program (after first using another program to
translate the `DVI' file into a form that the printer
can understand). Here is an example of a typical
Plain \TeX\ input file:
\begin{quote}
\begin{verbatim}
The foundations of the rigorous study of {\it analysis}
were laid in the nineteenth century, notably by the
mathematicians Cauchy and Weierstrass. Central to the
study of this subject are the formal definitions of
{\it limits} and {\it continuity}.
Let $D$ be a subset of $\bf R$ and let
$f \colon D \to {\bf R}$ be a real-valued function on
$D$. The function $f$ is said to be {\it continuous} on
$D$ if, for all $\epsilon > 0$ and for all $x \in D$,
there exists some $\delta > 0$ (which may depend on $x$)
such that if $y \in D$ satisfies
$$|y - x| < \delta$$
then
$$|f(y) - f(x)| < \epsilon.$$
One may readily verify that if $f$ and $g$ are continuous
functions on $D$ then the functions $f+g$, $f-g$ and
$f.g$ are continuous. If in addition $g$ is everywhere
non-zero then $f/g$ is continuous.
\bye
\end{verbatim}
\end{quote}
When we apply \TeX\ to these paragraphs we produce the text
\begin{quotation}
\small
The foundations of the rigorous study of {\it analysis}
were laid in the nineteenth century, notably by the
mathematicians Cauchy and Weierstrass. Central to the
study of this subject are the formal definitions of
{\it limits} and {\it continuity}.
Let $D$ be a subset of $\bf R$ and let
$f \colon D \to {\bf R}$ be a real-valued function on
$D$. The function $f$ is said to be {\it continuous} on
$D$ if, for all $\epsilon > 0$ and for all $x \in D$,
there exists some $\delta > 0$ (which may depend on $x$)
such that if $y \in D$ satisfies
$$|y - x| < \delta$$
then
$$|f(y) - f(x)| < \epsilon.$$
One may readily verify that if $f$ and $g$ are continuous
functions on $D$ then the functions $f+g$, $f-g$ and
$f.g$ are continuous. If in addition $g$ is everywhere
non-zero then $f/g$ is continuous.
\end{quotation}
This example illustrates various features of \TeX. Note
that the line
\begin{quote}
\begin{verbatim}
\bye
\end{verbatim}
\end{quote}
is placed at the end of the input file. This is to tell \TeX
when the end of the document has been reached.
Note also that, although most characters occurring in this file
have their usual meaning, yet there are special characters such
as \verb?\?, \verb?$?, \verb?{? and \verb?}? which have special
meanings within \TeX. Note in particular that there are
sequences of characters which begin with a `backslash'
\verb?\? which are used to produce mathematical symbols and
Greek letters and to accomplish tasks such as changing fonts.
These sequences of characters are known as
{\it control sequences}.
\subsectiontitle{Characters and Control Sequences}
We now describe in more detail some of the features of
\TeX\ illustrated in the above example.
Most characters on the keyboard, such as letters and
numbers, have their usual meaning. However the characters
\begin{quote}
\begin{verbatim}
\ { } $ ^ _ % ~ # &
\end{verbatim}
\end{quote}
are used for special purposes within \TeX. Thus typing one of
these characters will not produce the corresponding character
in the final document. Of course these characters are very
rarely used in ordinary text, and there are methods of
producing them when they are required in the final document.
In order to typeset a mathematical document it is
necessary to produce a considerable number of special
mathematical symbols. One also needs to be able to
change fonts. Also mathematical documents often contain
arrays of numbers or symbols (matrices) and other complicated
expressions. These are produced in \TeX\ using {\it control
sequences}. Most control sequences consist of a backslash
\verb?\? followed by a string of (upper or lower case) letters.
For example, \verb?\alpha?, \verb?\it?, \verb?\sum? and
\verb?\TeX? are control sequences.
In the example above we used the control sequences
\verb?\it? and \verb?\bf? to change the font to {\it italic}
and {\bf boldface} respectively. Also we used the control
sequences \verb?\to?, \verb?\in?, \verb?\delta? and
\verb?\epsilon? to produce the mathematical symbols $\to$
and $\in$ and the Greek letters $\delta$ and $\epsilon$.
\begin{quotation}
\footnotesize
There is another variety of control sequence which consists
of a backslash followed by a {\it single} character that
is not a letter. Examples of control sequences of this sort
are \verb?\{?, \verb?\"? and \verb?\$?.
\end{quotation}
The special characters \verb?{? and \verb?}? are used for
{\it grouping} purposes. Everything enclosed within
matching pair of such brackets is treated as a single unit.
We have applied these brackets in the example above whenever
we changed fonts. We shall see other instances where one needs
to use \verb?{? and \verb?}? in \TeX\ to group words and symbols
together (e.g., when we need to produce superscripts and
subscripts which contain more than one symbol).
The special character \verb?$? is used when one is
changing from ordinary text to a mathematical expression
and when one is changing back to ordinary text. Thus we
used
\begin{quote}
\begin{verbatim}
for all $\epsilon > 0$ and for all $x \in D$,
\end{verbatim}
\end{quote}
to produce the phrase
\begin{quote}
\small
for all $\epsilon > 0$ and for all $x \in D$,
\end{quote}
in the example given above. Note also that we used
\verb?$$? and \verb?$$? in the example above to mark the beginning
and end respectively of a mathematical formula that is displayed
on a separate line.
The remaining special characters
\begin{quote}
\begin{verbatim}
^ _ % ~ # &
\end{verbatim}
\end{quote}
have special purposes within \TeX\ that we shall discuss
later.