home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: 15.2 Predefined Strings Chapter 16 Next: 16.2 Eqn

16. Preprocessors


This section is divided into the following three subsections, each covering a different preprocessor of the nroff/troff formatting system:

  • The tbl preprocessor

  • The eqn preprocessor

  • The pic graphics language

Each of these preprocessors translates code into nroff/troff requests and escape sequences, which run independently of the formatter. Usually, one or more of these preprocessors are invoked as part of a command pipeline to format a file:




 | tbl | eqn | troff | 


On multi-user systems, it is typical to have a general-purpose shell script for formatting. You would then select various command-line options to specify which (if any) preprocessors to include in your particular format command. But you can also invoke the preprocessors individually. This is useful for confirming that syntax is correct or for determining where it fails. For example, the command:




takes input between each .TS/.TE macro pair and converts it into tbl code. All other input is passed to output unchanged.

16.1 Tbl

Tbl is a preprocessor for formatting tables in nroff/troff. When used in a command pipeline, tbl should precede eqn. This makes output processing more efficient. Tbl has the following command-line syntax:

/usr/ucb/tbl [ options ] [ files ]



Prepend the me macros to the front of files .


Prepend the mm macros to the front of files .


Prepend the ms macros to the front of files .


Produce output using only full vertical line motions. This is useful when formatting with nroff or when printing to a device that does not support fractional line motion.

16.1.1 General Coding Scheme

In a text file, coding for tbl might look like this:







Column Titles


Item1	Item2	Item3

Item1	Item2	Item3 ...


Successful processing of a table by tbl depends largely on the header lines, which consist of one line listing the options and one or more format lines. Each field of the table input must be separated by a tab or designated tab symbol, with each row typed entirely on a single line unless a field is enclosed by the text block symbols T{ and T} .

16.1.2 Tbl Macros

.TS Start table.
.TE End table.

Used when the table will continue onto more than one page. Used with .TH to define a header that will print on every page.

.TH With .TS H , ends the header portion of the table.
.T& Continue table after changing format line.

16.1.3 Options

Options affect the entire table. Options can be separated by commas or spaces, but the line must end with a semicolon.

center Center with current margins.
expand Flush with current right and left margins.
blank Flush with current left margin (the default).
box Enclose table in a box.
doublebox Enclose table in two boxes.
allbox Enclose each table entry in a box.
tab ( x ) Define the tab symbol to be x instead of a tab.
linesize n Set type size of lines or rules (e.g., from box) to n points.
delim xy Recognize x and y as the eqn delimiters.

16.1.4 Format

The format line affects the layout of individual columns and rows of the table. Each line contains a key letter for each column of the table. The column entries should be separated by spaces, and the format section must end with a period. Each line of format corresponds to one line of the table, except for the last, which corresponds to all following lines up to the next .T& , if any. Key Letters

c Center.
l Flush left.
r Flush right.
n Align numerical entries.
a Align alphabetic subcolumns.
s Horizontally span previous column entry across this column.
^ Vertically span (center) entry from previous row down through this row. Key Modifiers

These must follow a key letter.

b Boldface.
i Italics.
f x Font x .
p n Point size.
v n Vertical line spacing, in points. Applies only to text blocks.

Begin any corresponding vertically-spanned table entry (i.e., from ^ ) at the top line of its range.

e Equal width columns.
w( n )

Minimum column width. Also used with text blocks. n can be given in any acceptable troff units.

n Amount of separation (in ens) between columns (default is 3).
| Separate columns with a single vertical line. Typed between key letters.
|| Separate columns with a double vertical line. Typed between key letters.
_ Separate rows with a single horizontal line. Used in place of a key letter.
= Separate rows with a double horizontal line. Used in place of a key letter.

16.1.5 Data

The data portion includes both the heading and text of the table. Each table entry must be separated by a tab symbol.

. xx Troff requests may be used (such as .sp n , .na , etc.).

As last character in a line, combine following line with current line (hide newline).


Span table entry that is above this row, bringing it down to be vertically centered.

\&_ or =

As the only character in a line, extend a single or double horizontal line the full width of the table.

\$_ or \$=

Extend a single or double horizontal line the full width of the column.

\_ Extend a single horizontal line the width of the column's contents.
\R x

Print x 's as wide as the column's contents.

...[ tab ] T{

Start text block as a table entry. Must end a line. Necessary when a line of text is input over more than one line, or will span more than one line of output.

... T} [ tab ] End text block. Must begin a line.

16.1.6 A Tbl Example


center box linesize(6) tab(@);
cb s s.
Horizontal Local Motions
ci | ci s
ci | ci s
ci | ci | ci
c | l s.
Function@Effect in
\eh'n'@Move distance N
\e(space)@Unpaddable space-size space
\e0@Digit-size space
c | l | l.
\e|@1/6 em space@ignored
\e^@1/12 em space@ignored


Horizontal Local Motions
Function Effect in
troff nroff
\h'n' Move distance N
\(space) Unpaddable space-size space
\0 Digit-size space
\| 1/6 em space ignored
\^ 1/12 em space ignored

Previous: 15.2 Predefined Strings UNIX in a Nutshell: System V Edition Next: 16.2 Eqn
15.2 Predefined Strings Book Index 16.2 Eqn

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System