Ch 8 -- Basic Formatting with troff/nroff
UNIX Unleashed, Internet Edition
- 8 -
Basic Formatting with troff/nroff
by James C. Armstrong and David B. Horvath, CCP
UNIX was originally developed by Ken Thompson on a little-used PDP-7. The justification
for the purchase of a PDP-11/20 for the second version was to provide a text editing
and formatting system. The purpose of that system was to develop, maintain, and track
documents and memos within the telephone company (AT&T/Bell Telephone).
Many products are available for text editing and formatting for the PC, including
Microsoft Word and WordPerfect. Versions of these products and others are available
for UNIX systems, but the most common are the nroff and troff text
processors. nroff stands for "next run-off," and troff
stands for "typesetter run-off," both of which are based on roff
("run-off"). The original version of RUNOFF was developed by J. E. Saltzer
for the CTSS operating system effort at MIT during the 1960s. Most text processors
can trace their beginnings to the original RUNOFF; they include SCRIPT (for IBM mainframes),
Scribe (by Brian Reid), DSR (Digital Standard Runoff), Donald Knuth's Tex, and, of
course, UNIX roff.
In the early 1970s, Joe Ossanna rewrote roff to produce nroff.
He added flexibility and an internal programming language to aid in document formatting.
nroff was enhanced (and renamed troff) to support the Graphics
Systems CAT typesetter with multiple fonts, font sizes, and additional characters
that regular printers did not support.
In 1979, Brian Kernighan rewrote troff to support more typesetting machines.
Although alternatives were investigated, the Bell Labs portion of the telephone company
had already invested a great deal of effort in troff, including macro packages
and preprocessors that made document preparation easier for users. One of these macro
packages is used to format the UNIX manual pages.
troff and nroff are closely related. They both use the same
set of commands to format text. The biggest exception is that nroff does
not support commands for changing character fonts and sizes; it supports a limited
number of character set changes. nroff also provides ASCII output, so you
can see the results of an nroff command onscreen. Although third-party products
can show the results of a troff command onscreen if they have graphics capabilities,
on a standard UNIX system, the only way to see the exact troff output is
to send it to a printer. (troff can produce only an approximation of its
output to normal terminals.)
This chapter will show you:
- How to format documents using nroff and troff
- How to display and print the formatted documents
- The various embedded commands (primitives) used with nroff and troff
- How to format program output through nroff/troff
- How to post-process troff output to send it to various devices
Formatting with nroff/troff: An Overview
Many word processors, such as Microsoft Word and WordPerfect, are WYSIWYG (What
You See Is What You Get) processors. With these word processors, as you type and
format your text, you see exactly how they are going to print. Text processors such
as nroff and troff are called descriptive markup languages,
which means that you embed the formatting codes into your document like any other
text, and you don't see the effects of the instructions until you print the file.
Some other text formatting or markup languages are Standard Generalized Markup
Language (SGML), HyperText Markup Language (HTML), Encapsulated PostScript (EPS),
and others. Although their syntax, or command format, may be different from nroff/troff,
they share the same heritage. See Chapter 15, "HTML--A Brief Introduction,"
for more information about HTML.
Several building blocks are available for formatting files using nroff
and troff, including the following:
Primitive requests: The standard command in troff, called a primitive
request, has the form of a period followed by two lowercase letters. The period
must appear in the first column, and any text after the request is an argument. You
use primitives to do all kinds of formatting, such as indenting paragraphs, adding
space between paragraphs, changing fonts, and centering text. This chapter provides
examples of using the more common primitives and a quick reference that briefly describes
all primitives. If you're new to nroff/troff, you might want to
try using a macro package before you dive into primitives.
Macros: Most UNIX systems provide standard macro packages, which enable
you to format documents more easily than with primitives. Macros perform operations
more or less automatically, such as formatting bulleted lists, headings, and indented
paragraphs. Four macro packages--mm, ms, me, and man--are
described in detail in Chapter 9, "Formatting with Macro Packages." Chapter
10, "Writing Your Own Macros," shows you the ins and outs of creating macros.
You can create a file using only macro package commands, or you can mix macros and
primitives in the same file.
Preprocessors: Most UNIX systems provide standard preprocessors. Each preprocessor
is a set of commands devoted to a special task. You can format tables with the tbl
preprocessor, equations with eqn or neqn, line drawings with pic,
and graphs with grap (described in Chapter 11, "Tools for Writers").
You can create a file containing only preprocessor commands, and you can embed preprocessor
commands in regular documents formatted with primitives, a macro package, or both.
Strings: You can define strings, just as you can define macros. For example,
if you're writing about a new product whose name hasn't been decided yet, you can
define a string for the temporary name "Hot New Product." When the name
is finally chosen, you don't have to do a global search and replace for "Hot
New Product." You can just redefine the string to produce "XYZZY Thingo."
Specific instructions for defining strings are in the section titled "Strings
and Macros" later in this chapter, and in Chapter 10, "Writing Your Own
Macros."
Number registers: You use number registers to keep track of values such
as your current font and point size, your current indentation, and the current list
item. These registers are really nothing more than storage locations. Some are read-only;
others can be manipulated. You can define your own number registers and use them
in macros. Specific examples are given in the section titled "Number Registers"
later in this chapter, and in Chapter 10, "Writing Your Own Macros."
NOTE: troff insists on calling
these registers "number registers," but in fact they don't need to contain
numbers; they can--and often do--contain alphabetic characters.
Escape sequences: You can use escape sequences (backslash-character or
backslash-open-parenthesis-character-character) to change fonts and point sizes and
for many other tasks. Some escape sequences enable you to enter troff primitives
inline with the text they affect rather than on lines by themselves. You can find
specific examples in the section "Inline Escape Sequences" later in this
chapter and in other chapters where they apply.
Special characters: Although special characters are system-dependent, several
of them are usually available on all systems, such as a long dash, a degree symbol,
and a copyright symbol. You can find specific examples in the section "Special
Characters" later in this chapter and in other chapters where they apply.
Chapters 8 through 11 give you an introduction to the nroff/troff
family of text processing tools, but many more features are available than room allows
me to describe. You can find online man pages for each of the commands described.
You also can find books and papers dedicated to this topic; for example, The NROFF/TROFF
User's Manual by J. F. Ossanna and A TROFF Tutorial by B. W. Kernighan
are the original documents from the UNIX Programmer's Manual, Volume 2.
Basic Printing with nroff and troff
UNIX offers a variety of commands and utilities for printing. In addition, your
system may have a number of local commands. Check with your colleagues or the system
administrator. If they tell you that they use a shell script called prinnumup
to send their files to the printer, you should use prinnumup too.
Because you can print in so many ways (as with many tasks in UNIX), asking the
system administrator is often the best way to get information. Most of administrators
do not mind being asked these questions. Just be sure to write down the answer so
that you don't ask the same question again.
The truth is that versions of UNIX differ, printers differ, and ways of getting
the data from your file to a printer differ (because of different networks and connections).
New models and entirely new printers are being introduced all the time.
Displaying nroff Files
nroff enables you to format your file on the screen instead of (or before)
formatting it for a printer. troff does the same if you have a graphics
terminal, and it also produces an approximation of the printed results for a regular
screen.
To use nroff on a file containing only nroff/troff
primitives to the standard output device (screen), use one of the following commands:
nroff filename | pg
nroff filename | more
The choice between piping to pg or to more depends on your system
and your personal preference. Sometimes more produces just a single line
of additional text rather than a new screenful. You need to use one or the other
to prevent the text from scrolling off your screen. Remember, these tools are designed
to produce full pages for a printer; most pages have more lines than your screen
can show.
Differences Between nroff Output and troff
Output
Printed files look different, depending on whether they are formatted with nroff
or troff. In general, files printed using nroff exhibit the following
characteristics: All values are treated as a number of character positions (spaces)
or line spaces. Vertical space is in multiples of a full linespace. Tabs are set
every eight characters by default. Certain troff requests are not available
(for example, .fp, .lg, .ss). Text in italic font is underlined;
text in bold font is emboldened by overstriking. Point size and vertical space requests
(.ps and .vs) are ignored. Right-margin justification is turned
off for the mm macros. In addition, the default left margin is flush with
the left edge of the physical page.
When printing to the screen, some of the formatting may not be obvious because
the terminal cannot handle it.
The output from troff looks a lot more like a typeset document (like
this book for instance)--as the name, typesetting roff, implies. You can have fonts
of different sizes, overprinting of characters, proportional fonts, and even italics.
Printing troff Files
The original versions of troff produced output in the format required
by the phototypesetter. The new version is more device independent and requires its
output to be post-processed before it can be accepted by most printers. Although
some implementations on UNIX refer to this as the ditroff command ("Device
Independent troff"), most just replaced the original troff
with the new version.
Using the troff command to print your file on a Hewlett-Packard LaserJet
series printer (which is common in office environments), for example, you enter the
following:
troff filename | hplj | lpr -Phpprinter
troff -Thplj filename | hplj | lpr -Phpprinter
The hplj command post-processes the troff output into a form
that the laser printer can handle. The lpr -Phpprinter command sends your
output to the physical printer assigned to hpprinter; note that some installations
may use the lp -dhpprinter command instead. If you use the -Thplj
option on the troff command, the page is properly formatted and available
fonts are adjusted. (The nroff/troff options and other post-processors
are discussed later in this chapter.)
You can also print the source file (showing the nroff/troff
embedded commands) by using the lp or lpr commands as follows:
lpr -Phpprinter filename
lp -dhpprinter filename
You need to check with your system administrator to determine the local command
and printer names.
Printing nroff Files
Printing nroff output is similar to printing troff output except
that post-processing is not required.
Using nroff to print your document and send it to the same printer as
used in the preceding troff example, you enter the following:
nroff filename | lpr -Phpprinter
nroff -Thplj filename | lpr -Phpprinter
If you use the -Thplj option on the nroff command, the page
is properly formatted and available fonts are adjusted.
Text Filling and Adjusting
You get the cleanest look to any document when the text looks symmetric, with
one or two smooth margins, and spread across the page--like this paragraph. The default
settings for nroff and troff are to "fill" each line
with text, and to "adjust" the position of the text so that all lines begin
at the left margin and the right margin is justified. In the simplest case, the input
file does not need any troff requests to format a basic document. Listing
8.1 illustrates a basic input file, and Figure 8.1 illustrates the output produced
by nroff.
Listing 8.1. Basic nroff/troff source
with no requests.
We, the people of the United States, in order
to form a more perfect Union, establish justice, insure
domestic tranquility, provide for the common defense, promote
the general welfare,
and secure the blessing of liberty to ourselves and our posterity do
ordain and establish this Constitution for the United States of
America.
Figure 8.1.
nroff output with no requests.
The raw text file has a ragged right margin, with some lines very short and one
line longer than desired. If you put the text through nroff, the lines are
set to an even length, and the margins are smooth. Two words are broken across lines.
If you look closely at the output in Figure 8.1, you'll see that nroff justifies
the right margin by inserting extra spaces between words, at alternating ends of
each line. The first line needs no extra spaces, but to even the margin on the second
line, an extra space is included between perfect and Union, and the
third line needs four extra spaces.
troff output of the same text, shown in Figure 8.2, shows that the lines
are expanded to justify the margins by changing the spacing of letters across the
entire line.
Figure 8.2.
troff output of Figure 8.1.
You can set the ability to fill the text by using two requests. The first, .fi,
tells troff that you want the text to be filled with input. This setting
is the default. The request .nf tells troff that you don't want
text filled but that you want the right margin to be ragged. This request is useful
for cases in which a block of text is inappropriate, such as a return address or
poetry. Listing 8.2 shows a sample input file for a letter, with no fill in places
and some fill in places. Figure 8.3 shows the output.
Listing 8.2. troff source illustrating
the fill requests.
.nf
101 Main Street
Morristown, NJ 07960
15 March, 1997
Dear Sir,
.fi
I just wanted to drop you a note to thank you for spending the
time to give me a tour of your facilities. I found the experience
both educational and enjoyable. I hope that we can work together
to produce a product we can sell.
Figure 8.3.
troff output showing filled and non-filled text.
Note that a blank line separates blocks of text. On a longer document, you can
use these blank lines to separate paragraphs. Another way to separate blocks is to
use .br, which interrupts the filling of the current line and starts a new
block of text. You can do the same by starting a line of text with a space. Figure
8.4 shows the output of Listing 8.1, but output includes a break after the words
the general welfare.
Figure 8.4.
troff output showing the effect of a break in midsentence.
Although smooth margins are the default, you also have control of the margins.
The .ad command controls adjustment. It can take the following as arguments:
l means to adjust the left margin only; r is to adjust the right
margin only; c is to center each line; and b or n means
to adjust both margins. Figure 8.5 shows the effects of using .ad l, .ad
r, and .ad c on the first text example. .ad b is the default
starting value and is effectively demonstrated in the first example.
Figure 8.5.
troff output showing the effects of different line adjustments.
Obviously, adjustment makes no sense if the text is not filled. You also can turn
off right margin adjustment by using .na. The adjustment mode is not changed.
The last type of text adjustment is centering. It is somewhat different from .ad
c, which continues to fill lines before centering the text but only if .fi
is specified. The centering request is .ce, which can be followed by a number.
This request centers the next line or lines, without filling text. If the text is
filled, each input line is treated as if it were followed by a break. Non-filled
lines are treated the same as .ce. Chapter titles are an example of text
centering. Listing 8.3 shows the source for a centering command, and the output is
illustrated in Figure 8.6.
Listing 8.3. troff source for the centering
command.
.ce 3
Scientific Methods of Computing
A Simulation
by John Smith
Figure 8.6.
The effects of the centering request.
Vertical Spacing
troff includes three types of vertical space controls. Baseline spacing
controls the basic spacing between consecutive lines of text. The next type is extra
line spacing; with this type, you can double-space text, or more, both on a regular
basis and on a per case basis. The last is a block of vertical space.
Space measurements have different scales. When a request needs a distance, you
can use the default type or modify the number with an indicator. The measurement
types are inches, centimeters, picas, ems, ens, points, units, and vertical line
spaces. A pica is one-sixth of an inch. An em is the width of the letter m
and is dependent on the font used in troff. An en is half an em. The modifiers
are listed in Table 8.1.
Table 8.1. troff space measurement modifiers.
Measurement Option |
Description |
i |
inch |
c |
centimeter |
p |
pica |
m |
em |
n |
en |
p |
point |
u |
unit |
v |
vertical space |
The default vertical spacing between lines of text is dependent on the text processor
used. For nroff, it is one-sixth of an inch. For troff, it is 12
points. You can change this setting by using .vs. For nroff, the
command argument is rounded to picas, so if you need extra space regularly, .ls
is clearer. With troff, the default space measurement is points, although
any measurement type can be used. Figure 8.7 shows examples of different spacings
using the initial text example.
Figure 8.7.
Different vertical spacing using troff.
The .ls request, mentioned previously, is used to indicate the number
of blank lines between each line of text. The default value is 1, for single
spacing. You can double-space text by using .ls 2. Figure 8.8 shows the
first text example with .ls 2.
Figure 8.8.
Different line spacing using troff.
You can achieve block spacing by using the .sp request. With no arguments,
this request gives a single blank line. It can take arguments of any size, with the
default unit being the vertical spacing. Negative numbers space back up the page;
positive numbers head down the page. Spacing changes requested here do not leave
the page; if the requested space is beyond the bottom of the page, the text starts
at the top of the next page. Using the sample letter started earlier in this chapter,
you can leave an inch of space between the date and the salutation. The source is
changed in Listing 8.4, with the output in Figure 8.9.
Listing 8.4. troff source for block spacing.
.nf
101 Main Street
Morristown, NJ 07960
15 March, 1997
.sp 1i
Dear Sir,
.fi
I just wanted to drop you a note to thank you for spending the
time to give me a tour of your facilities. I found the experience
both educational and enjoyable. I hope that we can work together
to produce a product we can sell.
Figure 8.9.
troff output with a block of space.
Another method to grab a block of vertical space is to use the .sv request.
It takes the same arguments as .sp but has some different behaviors. You
cannot request space at the top of a page using .sp, for example. Also,
if a space request exceeds the size of the page, the space is truncated at the bottom
of the page with .sp. With .sv, the space is not generated unless
room is available on the page for the space. In this case, the space requested is
remembered and can be released on a new page with .os. Normally, .os
appears only in complicated macro definitions, which are discussed later.
For the sample letter, save a half inch of space at the top of the page. The modified
source is shown in Listing 8.5, and the output is shown in Figure 8.10.
Listing 8.5. troff source using .sv.
.sv 0.5i
.nf
101 Main Street
Morristown, NJ 07960
15 March, 1997
.sp 1i
Dear Sir,
.fi
I just wanted to drop you a note to thank you for spending the
time to give me a tour of your facilities. I found the experience
both educational and enjoyable. I hope that we can work together
to produce a product we can sell.
Figure 8.10.
troff output with requested space using .sv.
Two other spacing controls are also available. The request .ns turns
off spacing mode, effectively disabling the .sp command. To restore spacing,
you can use .rs. These commands are more likely to be found in macros.
Line Controls
In addition to requests for filling and adjusting lines of text and for changing
position on a page are requests to change lines themselves.
By default, the length of a line of text is 6.5 inches in nroff and 7.54
inches in troff. You can change this length by using the .ll request.
The default space measurement is in ems, but most people prefer using inches or centimeters.
Listing 8.6 shows the modified source for the same letter, with the line length
changed to 4 inches; its effect on the output is shown in Figure 8.11.
You also can indent lines of text, both for a single line and for all text. The
.in request indents all lines of text a common distance. Listing 8.6 shows
how you can indent the return address. You can request a temporary indent, such as
might lead a paragraph, by using .ti. This request is also illustrated in
Listing 8.6 and shown in the output in Figure 8.11.
Listing 8.6. troff source illustrating line
indents and lengths.
.nf
.ll 4.0i
.in 2.0i
101 Main Street
Morristown, NJ 07960
15 March, 1997
.sp 1i
.in 0
Dear Sir,
.fi
.ti 0.25i
I just wanted to drop you a note to thank you for spending the
time to give me a tour of your facilities. I found the experience
both educational and enjoyable. I hope that we can work together
to produce a product we can sell.
Figure 8.11.
troff output with line indents and lengths.
Using text indents can help you organize a document.
Page Control
For most documents, not only must you format the text, but you also must control
the page. Both nroff and troff default to an 11-inch page. troff
has a one-inch left margin, and nroff has no left margin. Pages start at
page one and are sequentially numbered. You can change each of these details if you
want.
The .pl request sets the length of a page; the default space measurement
is in vertical spaces. Again, inches can be better used here. For the sample letter,
assume a page length of 8 inches. (Some other normal page lengths are 12 inches for
A4 paper and 14 inches for legal-sized paper. troff can support pages up
to 75 inches long, and nroff can support up to 136 inches.)
You can force new pages by using the .bp request. An argument can affect
the number of pages output. The .ns request, which I mentioned earlier,
disables the .bp request, unless you specify a specific number of pages.
The .pn request assigns a page number to the next page printed. This
request does not affect the present page, only subsequent pages. These three requests
are illustrated in the source in Listing 8.7 and the output in Figure 8.12, showing
an extended form of the letter.
Listing 8.7. troff source illustrating page
controls.
.nf
.ll 5.0i
.pl 8.0i
.in 2.5i
101 Main Street
Morristown, NJ 07960
15 March, 1997
.in 0
.sp 1i
Dear Sir,
.fi
.ti 0.5i
I just wanted to drop you a note to thank you for spending the
time to give me a tour of your facilities. I found the experience
both educational and enjoyable. I hope that we can work together
to produce a product we can sell.
.pn 4
I am sending a copy of our proposal on the next page. I look forward
to hearing from you.
.sp 2
.in 2.5i
Yours,
.sp 0.5i
Joe Smith, President Any Corp.
.bp
.in 0
We propose to build our widget tools with your widget makers.
Figure 8.12.
troff output with page controls.
Note that the page number is not printed in Figure 8.12. Page numbers are printed
only if you explicitly request them. These techniques are discussed later in this
chapter in the section "Flotsam and Jetsam," which discusses page titling.
You can offset the text on the page by using the .po request. It is different
from the .in request. .po sets the 0 value for indents
and temporary indents. Figure 8.13 shows a page offset of two inches to the preamble
of the Constitution.
Figure 8.13.
troff output with a two-inch page offset.
Two very powerful page controls are the .mk and the .rt requests.
The .mk request saves the current vertical location in an internal register
(which can be specified in the argument). This request sets a flag at the current
location. The .rt request returns to that previous location. One good use
for these requests is to establish multiple column output. You can set the mark at
the top of the page and at the bottom of the page return to the mark. This use is
illustrated in the source in Listing 8.8 and output in Figure 8.14. Note that the
simple multiple column approach also requires the use of the .ll and .po
requests.
Listing 8.8. troff source using .mk
and .rt requests.
.ll 3i
.mk a
.ce
Preamble
.sp
We, the people of the United States, in order
to form a more perfect Union, establish justice, insure
domestic tranquility, provide for the common defense, promote
the general welfare,
and secure the blessing of liberty to ourselves and our posterity do
ordain and establish this Constitution for the United States of
America.
.sp
.ce
Article I
.sp
Section 1 Legislative powers; in whom vested:
.sp
All legislative powers herein granted shall be vested in a
Congress of the United States, which shall consist of a Senate
and a House of Representatives.
.sp
Section 2 House of Representatives, how and by whom chosen,
Qualifications of a Representative. Representatives and direct
taxes, how apportioned. Enumeration. Vacancies to be filled.
Power of choosing officers and of impeachment.
.sp
1. The House of Representatives shall be composed of members
chosen every second year by the people of the several states,
and the electors in each State shall have the qualifications
requisite for electors of the most numerous branch of the
State Legislature.
.sp
2. No person shall be a Representative who shall not have
attained to the age of twenty-five years, and been seven years
a citizen of the United States, and who shall not, when elected,
be an inhabitant of that State in which he shall be chosen.
.sp
.rt
.po 4.5i
3. Representatives and direct taxes shall be apportioned among
the several States which maybe included within this Union,
according to their respective numbers, which shall be determined
by adding to the whole number of free persons, including those
bound for service for a term of years, and excluding Indians not
taxed, three-fifths of all other persons. The actual enumeration
shall be made within three years after the first meeting of the
Congress of the United States, and within every subsequent term
of ten years, in such manner as they shall by law direct. The
number of Representatives shall not exceed one for every thirty
thousand, but each State shall have at least one Representative;
and until such enumeration shall be made, the State of New
Hampshire shall be entitled to choose three, Massachusetts eight,
Rhode Island and Providence Plantations one, Connecticut five,
New York six, New Jersey four, Pennsylvania eight, Delaware one,
Maryland six, Virginia ten, North Carolina five, South Carolina
five, and Georgia three.
.sp
4. When vacancies happen in the representation from any State,
the Executive Authority thereof shall issue writs of election
to fill such vacancies.
.sp
5. The House of Representatives shall choose their Speaker and
other officers; and shall have the sole power of impeachment.
Figure 8.14.
troff output showing the work of .mk and .rt.
The last page control is .ne. It is used to indicate that a certain amount
of space is needed before the end of a page. Using this request, you can avoid starting
paragraphs at the bottom of a page. Normally, .ne would be included in a
macro. If the space requested is available, nothing happens. If the space is not
available, the end of page processing is triggered.
Fonts and Style Controls
In the preceding sections, you learned about the positioning of text on the page
but did not learn about the actual modification of the text itself. In this section,
you learn about different fonts and point sizes.
The standard font is a Times Roman font. Italic, bold, and special fonts are also
available on all systems. Some sites may also include Helvetica, Bold-Helvetica,
Italic-Helvetica, and Constant-Width fonts. Check your local system for which fonts
are available.
On most systems the fonts are stored in /usr/lib/font/devNAME,
where NAME is the device specified with the -T option. Some
systems store the fonts in /usr/ucblib/doctools/font/devNAME.
The request .ft sets the appropriate font. The process of mounting and
unmounting fonts is performed automatically with this request. You must specify the
requested font in the argument; if no argument is present, the previous font is restored.
The arguments are shown in Table 8.2.
Table 8.2. Standard troff and nroff
fonts.
Identifier |
Font |
B |
Bold |
I |
Italic |
R |
Roman |
P |
Previous |
H |
Helvetica |
CW |
Constant Width |
HB |
Helvetica Bold |
HI |
Helvetica Italic |
Fonts have limited meaning in nroff. The font used is a constant-width
font. If you specify bold, characters are overstruck in printing. Italic is interpreted
as an underline. Other fonts have no meaning.
By setting fonts, you can italicize the preamble to the Constitution and print
each section header in bold. The modified source is shown in Listing 8.9, and the
output is shown in Figure 8.15.
Listing 8.9. Font selection in troff.
.ce
.ft B
Preamble
.sp
.ft I
We, the people of the United States, in order
to form a more perfect Union, establish justice, insure
domestic tranquility, provide for the common defense, promote
the general welfare,
and secure the blessing of liberty to ourselves and our
posterity do ordain and establish this Constitution for the
United States of America.
.sp
.ce
.ft B
Article I
.sp
.ft R
Section 1 Legislative powers; in whom vested:
.sp
All legislative powers herein granted shall be vested in a
Congress of the United States, which shall consist of a Senate
and a House of Representatives.
Figure 8.15.
troff output using multiple fonts.
The .bd request sets an artificial bold capability by offsetting a second
printing of the character by a number of points. You can use this request to make
the italic font appear to be bold by using .bd I 3. There is no effect in
nroff.
You can create different sizes of text by using the .ps request. You
can specify either a relative change or an absolute point size. Closely related is
the .ss request, which sets the width of the space character. Similarly,
when you change the point size, you also can change the vertical spacing; otherwise,
parts of consecutive lines may overlap. Using these requests, you can increase the
size of the section headers in the Constitution and increase the size of the words
We the people. See the source in Listing 8.10 and the output in Figure 8.16.
Figure 8.16.
Multiple point sizes in troff output.
Listing 8.10. troff source showing multiple
point sizes.
.ce
.ft B
.ps 24
.ss 28
.vs 28
Preamble
.sp
.ft I
We, the people
.ps 12
.ss 14
.vs 14
of the United States, in order
to form a more perfect Union, establish justice, insure
domestic tranquility, provide for the common defense, promote
the general welfare,
and secure the blessing of liberty to ourselves and our
posterity do ordain and establish this Constitution for the
United States of America.
.sp
.ce
.ft B
Article I
.sp
.ft R
Section 1 Legislative powers; in whom vested:
.sp
All legislative powers herein granted shall be vested in a
Congress of the United States, which shall consist of a Senate
and a House of Representatives.
The last text request is .cs, which sets a constant character width for
a given font in troff. This request takes three arguments. The first is
a font, the second is the width of the space, and the last is the character point
size. If the third argument is absent, the default is the current character width.
If the second argument is also absent, the constant width is turned off.
Listing 8.11 shows this request for the default Times Roman font in the preamble
and turns it off for the remainder of the Constitution. Figure 8.17 shows the output.
Listing 8.11. troff source illustrating the
.cs request.
.ce
.ft B
.ps 24
.ss 28
.vs 28
Preamble
.sp
.ft I
We, the people
.ps 12
.ss 14
.vs 14
.ft R
.cs R 15
of the United States, in order
to form a more perfect Union, establish justice, insure
domestic tranquility, provide for the common defense, promote
the general welfare,
and secure the blessing of liberty to ourselves and our
posterity do ordain and establish this Constitution for the
United States of America.
.sp
.cs R
.ce
.ft B
Article I
.sp
.ft R
Section 1 Legislative powers; in whom vested:
.sp
All legislative powers herein granted shall be vested in a
Congress of the United States, which shall consist of a Senate
and a House of Representatives.
Figure 8.17.
troff output using .cs.
You can also specify fonts by position: font 1, font 2, font 3, and so on. In
the early versions of troff, before device-independent troff (ditroff),
only four font positions were available. Quite naturally, 1 was the body
type (Times Roman), 2 was the italic version of 1, and 3
was the bold version of 1. You got one elective--position 4--but
it was usually used for the Special font (the one with Greek letters and mathematical
symbols). As a consequence, specifying fonts by position is not done frequently.
TIP: You are better off specifying fonts by using
the .ft request. You can guarantee the way your document will print even
if the positional fonts differ.
Inline Escape Sequences
In addition to requests in the form .xx, you also can use inline requests
that can make document preparation easier. These requests can generate special characters,
change fonts, change point sizes, and produce local motions.
You can use escape sequences (backslash-character or backslash-open-parenthesis-character-character)
to change fonts and point sizes and for many other tasks. Table 8.3 lists troff
escape sequences.
Table 8.3. troff escape sequences.
Sequence |
Description |
|
Prevents the next character from being processed by troff |
e |
Prints the escape character; default is the backslash () |
' |
Prints acute accent |
' |
Prints grave accent |
- |
Prints a minus sign in the current font |
[space] |
Creates an unpaddable 1-en space |
| |