.MH "Applications Notes"
This section will illustrate the capabilities of 'fmt' with
some actual applications.
Most of the examples are macros
that assist in common formatting operations, but
attention has also been given to
table construction.  All of the macros
presented here are available for general use in the file
"//extra/fmacro/report", which may be named on the command line
invoking 'fmt' or may be included with a 'source' command as
follows:
.be
 [bf .so] =fmac=/report
.ee
.#
.SH "Paragraphs"
One standard way of beginning a new paragraph is to skip
a line and indent by a few spaces, as was done
throughout this guide.  This can be done by giving
an [bf sp] command followed by a [bf ti]
command.  A better way is to define a macro.  This allows
procrastination on deciding the format of paragraphs
and facilitates change
at some later date without a major
editing effort.
.pp
Here is the paragraph macro used in this document:
.be 8
 [bf  .#] pp --- begin paragraph
 [bf .de] pp
 [bf .sp]
 [bf .ne] 2
 [bf .ti] @@@[in]
 [bf .ti] +5
 [bf .ns]
 [bf .en] pp
.ee
First a line is skipped via the 'space' command.  Then, after
checking that there is room on the current page for the first
two lines of the new paragraph, a temporary indentation is
set up that is five columns to the right of the
running indentation with the two [bf ti]
commands.  Finally, no-space mode is turned on to suppress
unwanted blank lines.
.#
.SH "Sub-headings"
Sub-headings such as the ones used here may be easily produced
with the following macro:
.be 9
 [bf  .#] sh --- sub-heading
 [bf .de] sh
 [bf .sp] 2
 [bf .ne] 4
 [bf .ti] @@@[in]
 [bf .bf]
 [1]
 [bf .pp]
 [bf .en] sh
.ee
First, two blank lines are put out.
Then it is determined if there are
four contiguous lines on the current page: one for the
heading itself, one for the blank line after the heading,
and two for the first two lines of the next paragraph.
The temporary indentation value is then set to coincide with
the current indentation value. Next, the first parameter
passed to the macro (the text of the sub-heading) is boldfaced
and a new paragraph is begun. The "pp" macro will insert
the blank line after the heading.
.#
.SH "Major Headings"
Each section of this guide is introduced by a major heading
that is boldfaced, underlined and centered on the page.  The
macro used to produce these headings is the following:
.be 11
 [bf  .#] mh --- major heading
 [bf .de] mh
 [bf .sp] 3
 [bf .ne] 5
 [bf .ce]
 [bf .ul]
 [bf .bf]
 [1]
 [bf .sp]
 [bf .pp]
 [bf .en] mh
.ee
This is similar to the sub-heading macro: three blank lines
are put out; a check for enough room is made; the parameter
is centered, underlined and boldfaced; another blank line
is put out; and a new paragraph is begun.
.#
.SH "Tables of Contents"
.#
.#
Table of contents can be automatically generated by
writing the contents to a temporary file, then at the
end reading that file to produce the table of contents.
In the examples above we could divert subheadings and
headings to a temporary file; e.g., add the following to
the 'sh' and 'mh' macros.  (These examples are similar
to what is used to produce the table of
contents of this guide; for pedagogical reasons
we have simplified it a little).
.be
 [bf .#] generate a table of contents entry for a heading
 [bf .dv] 5
 [bf .cc] #
 [bf #sp]
 [bf #ne] 8
 @[bf [1]][bl]@@@[tc]@@@[tcpn]
 [bf #cc] .
 [bf .dv]

 [bf .#] table of contents entry for sub-heading
 [bf .dv] 5
 [bf .cc] #
 [bf #ne] 4
 [bl 3][1][bl]@@@[tc]@@@[tcpn]
 [bf #br]
 [bf #cc] .
 [bf .dv]
.ee
Each time a heading is printed a line is written to
temporary file "5" containing the heading, boldfaced, followed by
a blank, a tab and finally the current page number right justified
in four columns.
Each time a subheading is printed a line is written
containing three blanks, the subheading, a blank, a tab and finally
the current page number.
Note that we precede diverted commands by a different control
character because 'dv' will execute commands instead of diverting them.
.pp
The very last command of the document would be a
generate table of contents macro, e.g.,
.be
 [bf .#] TC --- generate table of contents
 [bf .de] TC
 [bf .cc] #
 [bf #bp]
 [bf #fo] ..- @@@[rn @@@[pn]] -..
 [bf #ce] "TABLE OF CONTENTS"
 [bf #rm] -6
 [bf #ta] @@@[rm]
 [bf #rm] +6
 [bf #rc] .
 [bf #ns]
 [bf #so] 5
 [bf #cc] .
 [bf .en] TC
.ee
This macro will set the control character to correspond
to the control characters written to output stream "5,"
advance to the top of the next page, center
the heading "TABLE OF CONTENTS", set the footer to print
the page number in small roman numerals (the page number must
be set prior to calling 'TC'), set the tab column to 6 columns
to the left of the right margin (this generates 2 blanks
followed by the page number which is right justified in four
columns),
sets the replacement tab character to "." and reads
the contents of temporary file "5".
.SH "Quotations"
Lengthy quotations are often set apart from other text by
altering the left and right margins to narrow
the width of the quoted text.  Here is a pair of
macros that may be used to delimit the beginning and end
of a direct quotation:
.be 7
 [bf  .#] bq --- begin direct quote
 [bf .de] bq
 [bf .sp]
 [bf .ne] 2
 [bf .in] +5
 [bf .rm] -5
 [bf .lt] +5
 [bf .en] bq
.ee
.#
.be 6
 [bf  .#] eq --- end direct quote
 [bf .de] eq
 [bf .sp]
 [bf .in] -5
 [bf .rm] +5
 [bf .en] eq
.ee
Notice the [bf lt]
command in the first macro.  To avoid affecting page headings
and footings, the left margin is not adjusted; rather, an
additional indentation is applied.  But to increase the
right margin width, there is no other alternative but to use
the [bf rm]
command.  The 'title-length' command is thus necessary to
allow headings and footings to remain unaffected by the
interim right margin.
.#
.SH "Italics"
Since most printers can't easily produce italics,
they are frequently simulated by underlining.  The following
macro 'italicizes' its parameter by underlining it.
.ne 6
.be 5
 [bf  .#] it --- italicize (by underlining)
 [bf .de] it
 [bf .ul]
 [1]
 [bf .en] it
.ee
.#
.SH "Boldfacing"
While 'fmt' has built-in facilities for boldfacing, their use
may be somewhat cumbersome if there are many short phrases
or single words that need boldfacing; each phrase or word
requires two input lines: one for the [bf bf]
command and one for the actual text.  The following macro
cuts the overhead in half by allowing the command and
the text to appear on the same line.
.be 5
 [bf  .#] bo --- boldface parameter
 [bf .de] bo
 [bf .bf]
 [1]
 [bf .en] bo
.ee
.#
.SH "Examples"
This guide is peppered with examples, each one set apart
from other text by surrounding blank lines and additional
indentation.  The next two macros, used like the "bq" and
"eq" macros, facilitate the production of examples.
.be 7
 [bf  .#] bx --- begin example text
 [bf .de] bx
 [bf .sp]
 [bf .ne] 2
 [bf .nf]
 [bf .in] +10
 [bf .en] bx
.ee
.#
.be 6
 [bf  .#] ex --- end example text
 [bf .de] ex
 [bf .sp]
 [bf .fi]
 [bf .in] -10
 [bf .en] ex
.ee
Note that the definition of the "ex" macro causes the [bf ex]
command to become inaccessible.
.#
.SH "Table Construction"
One example of table construction (for a table of contents)
has already been mentioned
in the section dealing with tabs.
Another type of table
that occurs frequently is that used in the command summaries
in this guide.  Each entry of such a table consists of
a number of 'fields', followed on the right by a body of
explanatory text that needs to be filled and adjusted.
.pp
The easiest way to construct a table like this involves
using a combination of tabs and indentation, as the following
series of commands illustrates:
.be
 [bf .in] +40
 [bf .ta] 14 24 34 41
 [bf .tc] \
.ee
The idea is to set a tab stop in each column that begins a field,
and one last one in the column that is to be the left margin for
the explanatory text.  The extra indentation moves the effective
left margin to this column.
To begin a new entry,
temporarily undo the extra indentation with a [bf ti]
command, and then type the text of the entry, separating
the fields from one another with a tab character:
.be
 [bf .ti] -40
 field 1\field 2\field 3\field 4\Explanatory text
.ee
The first line of the entry will start at the old left margin. Then
all subsequent lines will be filled and adjusted between column
forty-one and the right margin (inclusive).
