~% This is part of the book TeX for the Impatient.
~% Copyright (C) 2003 Paul W. Abrahams, Kathryn A. Hargreaves, Karl Berry.
~% See file fdl.tex for copying conditions.
% TeX ignores anything on a line after a %
% The next two lines define fonts for the title
\font\xmplbx = cmbx10 scaled \magstephalf
\font\xmplbxti = cmbxti10 scaled \magstephalf
% Now here's the title.
\leftline{\xmplbx Example !xmpnum:\quad\xmplbxti Entering simple text}
\vglue .5\baselineskip % skip an extra half line
~\count255 = \pageno
~\xdef\examplepage{\number\count255}
~\markinfo{Example 1: Entering simple text}
~\ifrewritetocfile
~\write\tocfile{\string\tocsectionentry{Entering simple text}{}{\examplepage}}%
~\fi
~^^{footnotes} ^^{comments} ^^{punctuation} ^^{quotation marks}
~^^{space characters} ^^{dashes} ^^{paragraphs//ending}
~\edef\examplepageno{\number\count255}%
It's easy to prepare ordinary text for \TeX\ since
\TeX\ usually doesn't care about how you break up your input into
lines. It treats the end of a line of text like a space.%
\footnote \dag{\TeX\ treats a tab like a space too, as we point
out in this {\it footnote}.}   If you don't want a space there,
put a per%
cent sign (the comment character) at the end of the line.
   \TeX\ ignores spaces at the start of a line, and treats more
than        one      space as equivalent to a single space,
even after a period.      You indicate a new paragraph by
skipping a line (or more than one line).


When \TeX\ sees a period followed by a space (or the end of the
line, which is equivalent), it ordinarily assumes you've ended a
sentence and inserts a little extra space after the period.  It
treats question marks and exclamation points the same way.   

  But \TeX's rules for handling periods sometimes need fine 
tuning. \TeX\ assumes that a capital letter before a period
doesn't end the sentence, so you have to do something a little 
different if, say, you're writing about DNA\null.  
% The \null prevents TeX from perceiving the capital `A'
% as being next to the period.
It's a good idea to tie words together in references such as 
``see Fig.~8'' and in names such as V.~I\null. Lenin and in
$\ldots$ so that \TeX\ will never split them in an awkward place
between two lines.  (The three dots indicate an ellipsis.)

You should put quotations in pairs of left and right
single ``quotes'' so that you get the correct left and right
double quotation marks.  ``For adjacent single and double
quotation marks, insert a `thinspace'\thinspace''. You can
get en-dashes--like so, and em-dashes---like so.

\bye % end the document
:::
\xmpheader !xmpnum/{Indentation}% !xmpheaddef
~^^{indentation} ^^{margins} ^^{paragraphs//narrow}
\noindent Now let's see how to control indentation.  If an 
ordinary word processor can do it, so surely can \TeX. Note 
that this paragraph isn't indented.

Usually you'll either want to indent paragraphs or to leave
extra space between them.  Since we haven't changed anything
yet, this paragraph is indented.

{\parindent = 0pt \parskip = 6pt
% The left brace starts a group containing the unindented text.
Let's do these two paragraphs a different way,
with no indentation and six printer's points of extra space
between paragraphs. 

So here's another paragraph that we're typesetting without
indentation.  If we didn't put space between these paragraphs,
you would have a hard time knowing where one ends
and the next begins.
\par % The paragraph *must* be ended within the group.
}% The right brace ends the group containing unindented text.

It's also possible to indent both sides of entire paragraphs.  
The next three paragraphs illustrate this:
\smallskip % Provide a little extra space here.
% Skips like this and \vskip below end a paragraph.
{\narrower
``We've indented this paragraph on both sides by the paragraph
indentation.  This is often a good way to set long quotations.

``You can do multiple paragraphs this way if you choose.  This
is the second paragraph that's singly indented.''\par}

{\narrower \narrower You can even make paragraphs doubly narrow
if that's what you need.  This is an example of a doubly 
narrowed paragraph.\par}
\vskip 1pc % Skip down one pica for visual separation.
In this paragraph we're back to the normal margins, as you can
see for yourself.  We'll let it run on a little longer so that
the margins are clearly visible.

{\leftskip .5in Now we'll indent the left margin by half
an inch and leave the right margin at its usual position.\par}
{\rightskip .5in Finally, we'll indent the right margin by half
an inch and leave the left margin at its usual position.\par}
\bye % end the document
:::
\xmpheader !xmpnum/{Fonts and special characters}% !xmpheaddef
\chardef \\ = `\\ % Let \\ denote a backslash.
~^^{fonts} ^^{characters//special} ^^{accents}
~^^{music symbols} ^^{card suits}
~^^|$| ^^|&| ^^|#| ^^|_| ^^|%| ^^|^| ^^|~| ^^|{| ^^|}| \indexchar \
{\it Here are a few words in an italic font}, {\bf a 
few words in a boldface font}, {\it and a\/ {\bf mixture} 
of the two, with two\/ {\rm roman words} inserted}.
Where an italic font is followed by a nonitalic font, we've
inserted an ``italic correction'' ({\tt \\/}) to make the
spacing look right. 
Here's a {\sevenrm smaller} word---but the standard \TeX\
fonts won't give you anything smaller than {\fiverm this}.

If you need any of the ten characters:
\medskip
\centerline{\$ \quad \& \quad \# \quad \_ \quad \% \quad
   \char `\^ \quad \char `\~ \quad $\{$ \quad
   $\}$ \quad $\backslash$}
% The \quad inserts an em space between characters.
\medskip
\noindent  you'll need to write them a special way.  Look at
the facing page to see how to do it.

\TeX\ has the accents and letters that you'll need
for French words such as {\it r\^ ole\/} and  {\it \'
el\` eve\/}, for German words such as {\it Schu\ss\/},
and for words in several other languages as well.
You'll find a complete list of \TeX's accents and letters
of European languages on !xrefdelim[accents] and !xrefdelim[fornlets].  

You can also get Greek letters such as ``$\alpha$'' and
``$\Omega$'' for use in math, card suits such as
``$\spadesuit$'' and ``$\diamondsuit$'', music symbols
such as ``$\sharp$'' and ``$\flat$'', and many other special
symbols that you'll find listed on !xrefdelim[specsyms].
\TeX\ will only accept these sorts of special symbols in its
``math mode'', so you'll need to enclose them
within `{\tt \$}' characters.
\bye % end the document
:::
\xmpheader !xmpnum/{Interline spacing}% !xmpheaddef
~^^{spacing//interline} ^^{baselines}
\baselineskip = 2\baselineskip % double spacing
\parskip = \baselineskip % Skip a line between paragraphs.
\parindent = 3em % Increase indentation of paragraphs.

% The following macro definition gives us nice inline
% fractions.  You'll find it in our eplain macros.
\def\frac#1/#2{\leavevmode
   \kern.1em \raise .5ex \hbox{\the\scriptfont0 #1}%
   \kern-.1em $/$%
   \kern-.15em \lower .25ex \hbox{\the\scriptfont0 #2}%
}%

Once in a while you may want to print a document with extra
space between the lines.  For instance, bills before Congress
are printed this way so that the legislators can mark them up.
For the same reason, book publishers usually insist that
manuscripts be double-spaced. Double spacing is rarely
appropriate for finished documents, however.

A baseline is an imaginary line that acts like the lines
on a pad of ruled paper.   You can control the interline
spacing---what printers call ``leading''---%
by setting the amount of space between baselines. Take a
look at the input to see how to do it. You could use
the same method for $1\;1/2$ spacing as well, using {\tt 1.5}
instead of {\tt 2}. (You can also write $1\frac 1/2$
a nicer way.)
% Here we've used the macro definition given above.

For this example we've also increased the paragraph indentation
and skipped an extra line between paragraphs.

\bye % end the document
:::
\xmpheader !xmpnum/{Spacing, rules, and boxes}% !xmpheaddef
~^^{description lists} ^^{boxes//drawing} ^^{revision bars}
Here's an example of a ``description list''.  In practice you'd 
be better off using a macro to avoid the repetitive constructs
and to make sure that the subhead widths are wide enough:
\bigskip
% Call the indentation for descriptions \descindent
% and set it to 8 picas.
\newdimen\descindent \descindent = 8pc
% Indent paragraphs by \descindent.
% Skip an additional half line between paragraphs.
{\noindent \leftskip = \descindent  \parskip = .5\baselineskip
% Move the description to the left of the paragraph.
\llap{\hbox to \descindent{\bf Queen of Hearts\hfil}}%
An ill-tempered woman, prone to saying ``Off with his
head!!''\ at the slightest provocation.\par
\noindent\llap{\hbox to \descindent{\bf Cheshire Cat\hfil}}%
A cat with an enormous smile that Alice found
in a tree.\par
\noindent\llap{\hbox to \descindent{\bf Mock Turtle\hfil}}%
A lachrymose creature, quite a  storyteller, who was a
companion to the Gryphon.  Reputedly the principal ingredient
of Mock Turtle Soup.
\par}
\bigskip\hrule\bigskip % A line with vertical space around it.
Here's an example of some words in a ruled box, just as
Lewis Carroll wrote them:
\bigskip
% Put 8pt of space between the text and the surrounding rules.
\hbox{\vrule\vbox{\hrule
   \hbox spread 8pt{\hfil\vbox spread 8pt{\vfil
      \hbox{Who would not give all else for twop}%
      \hbox{ennyworth only of Beautiful Soup?}%
   \vfil}\hfil}
\hrule}\vrule}%

\bigskip\line{\hfil\hbox to 3in{\leaders\hbox{ * }\hfil}\hfil}
\bigskip

\line{\hskip -4pt\vrule\hfil\vbox{
Here we've gotten the effect of a revision bar on the material
in this paragraph.  The revision bar might indicate a change.}}
\bye % end the document
:::
\xmpheader !xmpnum/{Odds and ends}% !xmpheaddef
~^^{hyphenation} ^^{theorems} ^^{lemmas} ^^{itemized lists}
~^^{flush left} ^^{flush right} ^^{centering}
\chardef \\ = `\\ % Let \\ denote a backslash.
\footline{\hfil{\tenit - \folio -}\hfil}
~\global\footline{\hfil{\tenit - \folio\ -}\hfil}
% \footline provides a footer line.
% Here it's a centered, italicized page number.
\TeX\ knows how to hyphenate words, but  it isn't infallible.
If you are discussing the chemical
${\it 5}$-[p-(Flouro\-sul\-fonyl)ben\-zoyl]-l,%
$N^6$-ethe\-no\-adeno\-sine
and \TeX\ complains to you about an ``overfull hbox'', try
inserting some ``discretionary hyphens''. The notation
`{\tt \\-}' tells \TeX\ about a  dis\-cre\-tion\-ary hyphen,
that is, one that it might not have inserted otherwise.
\medskip
{\raggedright   You can typeset text unjustified, i.e., with
an uneven right margin. In the old days, before word
processors were common, typewritten documents were
unjustified because there was no convenient alternative.
Some people  prefer text to be  unjustified so that the
spacing between words can be uniform.  Most books are set
with justified margins, but not all. \par}

\proclaim Assertion 27. There is an easy way to typeset
the headings of assertions, lemmas, theorems, etc.

Here's an example of how to typeset an itemized list two
levels deep.  If you need more levels, you'll have to
program it yourself, alas.
\smallskip
\item {1.} This is the first item.
\item {2.} This is the second item.  It consists of two
paragraphs.  We've indented the second paragraph so that
you can easily see where it starts.

\item{} \indent The second paragraph has three subitems
underneath it.
\itemitem {(a)} This is the first subitem.
\itemitem {(b)} This is the second subitem.
\itemitem {(c)} This is the third subitem.
\item {$\bullet$} This is a strange-looking item because it's
completely different from the others.
\smallskip
\leftline{Here's a left-justified line.$\Leftarrow$}
\rightline{$\Rightarrow$Here's a right-justified line.}
\centerline{$\Rightarrow$Here's a centered line.$\Leftarrow$}
% Don't try to use these commands within a paragraph.
\bye % end the document
:::
\xmpheader !xmpnum/{Using fonts from other sources}% !xmpheaddef
~\xrdef{palatino}
~\idxref{Palatino fonts}
~\idxref{Zapf, Hermann}
~\idxref{Computer Modern fonts} ^^{\Metafont}
\font\tenrm = pplr % Palatino
% Define a macro for invoking Palatino.
\def\pal{\let\rm = \tenrm \baselineskip=12.5pt \rm}
\pal % Use Palatino from now on.

You aren't restricted to using the Computer Modern fonts that
come with \TeX.  Other fonts are available from many sources,
and you may prefer them.  For instance, we've set this page
in 10-point Palatino Roman. Palatino was designed by
Hermann Zapf, considered to be one of the greatest type
designers of the twentieth century.  This page will
give you some idea of what it looks like.

Fonts can be provided either as outlines or as bitmaps.  An
outline font describes the shapes of the characters, while a
bitmap font specifies each pixel (dot) that makes up each
character.  A font outline can be used to generate many
different sizes of the same font.  The Metafont program
that's associated with \TeX\  provides a particularly
powerful way of generating bitmap fonts, but it's not the
only way.

The fact that a single outline can generate a great range of
point sizes for a font tempts many vendors of digital
typefaces to provide just one set of outlines for a typeface
such as Palatino Roman.  This may be a sensible economic
decision, but it is an aesthetic sacrifice.  Fonts cannot be
scaled up and down linearly without loss of quality. 
Larger sizes of letters should not, in general, have the
same proportions as smaller sizes; they just don't look
right.  For example, a font that's linearly scaled down will
tend to have too little space between strokes, and its
x-height will be too~small. % tie added to avoid widow word

A type designer can compensate for these changes by
providing different outlines for different point sizes, but
it's necessary to go to the expense of designing these
different outlines.  One of the great advantages of Metafont
is that it's possible to parameterize the descriptions of
characters in a font.  Metafont can then maintain the
typographical quality of characters over a range of point
sizes by adjusting the character shapes accordingly.
\bye % end the document
:::
~\idxref{mushrooms}
\xmpheader !xmpnum/{A ruled table}% !xmpheaddef
\bigskip
\offinterlineskip % So the vertical rules are connected.
% \tablerule constructs a thin rule across the table.
\def\tablerule{\noalign{\hrule}}
% \tableskip creates 9pt of space between entries.
\def\tableskip{\omit&height 9pt&&&\omit\cr}
% & separates templates for each column. TeX substitutes
% the text of the entries for #. We must have a strut
% present in every row of the table; otherwise, the boxes
% won't butt together properly, and the rules won't join.
\halign{\tabskip = .7em plus 1em  % glue between columns
% Use \vtop for short multiline entries in the first column.
% Typeset the lines ragged right, without hyphenation.
   \vtop{\hsize=6pc\pretolerance = 10000\hbadness = 10000
      \normalbaselines\noindent\it#\strut}%
  &\vrule #&#\hfil &\vrule #% the rules and middle column
% Use \vtop to get whole paragraphs in the last column.
  &\vtop{\hsize=11pc \parindent=0pt \normalbaselineskip=12pt
    \normalbaselines \rightskip=3pt plus2em #}\cr
% The table rows begin here.
\noalign{\hrule height2pt depth2pt \vskip3pt}
  % The header row spans all the columns.
  \multispan5\bf Some Choice Edible Mushrooms\hfil\strut\cr
\noalign{\vskip3pt} \tablerule
  \omit&height 3pt&\omit&&\omit\cr
  \bf Botanical&&\bf Common&&\omit \bf Identifying \hfil\cr
\noalign{\vskip -2pt}% close up lines of heading
  \bf Name&&\bf Name &&\omit \bf Characteristics \hfil\cr
\tableskip Pleurotus ostreatus&&Oyster mushroom&&
  Grows in shelf\kern 1pt like clusters on stumps or logs,
  % without the kern, the `f' and `l' would be too close
  pink-gray oyster-shaped caps, stem short or absent.\cr
\tableskip Lactarius hygrophoroides&&Milky hygroph&&
  Butterscotch-brown cap and stem, copious white latex,
  often on ground in woods near streams.\cr
\tableskip Morchella esculenta&&White morel&&Conical cap
  with black pits and white ridges; no gills. Often found
  near old apple trees and dying elms in the spring.\cr
\tableskip Boletus edulus&&King bolete&&Reddish-brown to
  tan cap with yellow pores (white when young),
  bulbous stem, often near conifers, birch, or~aspen.\cr
\tableskip \tablerule \noalign{\vskip 2pt} \tablerule
}\bye
:::
\xmpheader !xmpnum/{Typesetting mathematics}% !xmpheaddef
~^^{math}
For a spherical triangle with sides $a$, $b$, and $c$, and
opposite angles $\alpha$, $\beta$, and $\gamma$, we have:
$$\cos \alpha = -\cos \beta \cos \gamma +
  \sin \beta \sin \gamma \cos \alpha \quad
  \hbox{(Law of Cosines)}$$
and:
$$\tan {\alpha \over 2} = \sqrt{
  {- \cos \sigma \cdot \cos(\sigma - \alpha)} \over
  {\cos (\sigma - \beta) \cdot \cos (\sigma - \gamma)}},\quad
  \hbox{where $\sigma = {1 \over 2}(a+b+c)$}$$
We also have:$$\sin x = {{e^{ix}-e^{-ix}}\over 2i}$$
and:
$$\int _0 ^\infty {{\sin ax \sin bx}\over{x^2}}\,dx
% The \, above produces a thin space
  = {\pi a\over 2}, \quad \hbox{if $a < b$}$$

\noindent The number of combinations ${}_nC_r$ of $n$
things taken $r$ at a time is:
$$C(n,r) = {}_nC_r = {n \choose r} =
  {{n(n-1) \cdots (n-r+1)} \over {r(r-1) \cdots (1)}} =
  {{n!!}\over {r!!(n-r)!!}}$$

\noindent
The value of the determinant $D$ of order $n$:
$$D = \left|\matrix{a_{11}&a_{12}&\ldots&a_{1n}\cr
  a_{21}&a_{22}&\ldots&a_{2n}\cr
  \vdots&\vdots&\ddots&\vdots\cr
  a_{n1}&a_{n2}&\ldots&a_{nn}\cr}\right| $$
is defined as the sum of $n!!$ terms:
$$\sum\>(\pm)\>a_{1i}a_{2j} \ldots a_{nk}$$
% The \> above produces a medium space.
where $i$, $j$, \dots,~$k$\/ take on all possible values
between $1$ and $n$, and the sign of the product is 
$+$ if the sequence $i$, $j$, \dots,~$k$\/ is an
even permutation and $-$ otherwise.  Moreover:
$$Q(\xi) = \lambda_1 y_1^2 \sum_{i=2}^n \sum_{j=2}^n y_i
b_{ij} y_j,\qquad B = \Vert b_{ij} \Vert = B'$$
\bye
:::
\xmpheader !xmpnum/{More mathematics}% !xmpheaddef
~^^{math}
The absolute value of $X$, $|x|$, is defined by:
$$|x| = \cases{x, &if $x\ge 0$;\cr
-x,&otherwise.\cr}$$
Now for some numbered equations.
It is the case that for $k \ge 0$:
$$x^{k^2}=\overbrace{x\>x\>\cdots\> x}^{2k\ \rm times}
   \eqno (1)$$

Here's an example that shows some spacing controls, with 
a number on the left:
$$[u]!negthin[v][w]\,[x]\>[y]\;[z]\leqno(2a)$$
The amount of space between the items in brackets
gradually increases from left to right.  (We've made
the space between the first two items be {\it less\/}
than the natural space.)
It is sometimes the case that $$\leqalignno{
u'_1 + tu''_2 &= u'_2 + tu''_1&(2b)\cr
\hat\imath &\ne \hat \jmath&(2c)\cr
\vec {\vphantom{b}a}&\approx \vec b\cr}$$
% The \vphantom is an invisible rule as tall as a `b'.
The result is of order $O(n \log\log n)$.  Thus
$$\sum_{i=1}^n x_i = x_1+x_2+\cdots+x_n
= {\rm Sum}(x_1,x_2,\ldots,x_n). \eqno(3)$$
and
$$dx\,dy = r\,dr\,d\theta!negthin.\eqno(4)$$
The set of all $q$ such that $q\le0$ is written as:
$$\{\,q\mid q\le0\, \}$$
Thus
$$\forall x\exists y\;P(x,y)\Rightarrow
\exists x\exists y\;P(x,y)$$
where
$$P(x,y) \buildrel \rm def \over \equiv 
\hbox{\rm any predicate in $x$ and $y$} . $$
\bye
:::
