Book HomeBook TitleSearch this book

Chapter 17. troff Preprocessors

Contents:

tbl
eqn
pic
refer

This chapter is divided into the following four sections, each covering a different preprocessor of the nroff/troff formatting system:

Each of these preprocessors translates code into nroff/troff requests and escape sequences. They process information only between delimiting macros: other input text is left alone. Usually, one or more of these preprocessors are invoked as part of a command pipeline to format a file:

$ pic file | tbl | eqn | troff options | spooler

On multiuser 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. However, 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:

$ tbl file

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

In SVR4, these commands are part of the BSD compatibility package and are found in /usr/ucb. On Solaris, with the exception of pic, they are a standard part of the system and are found in /usr/bin. The GNU version of troff (groff, see http://www.gnu.org) comes with versions of tbl, eqn, pic, and refer.

17.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:

tbl [options] [files]

The canonical reference for tbl is Tbl--A Program to Format Tables, by L.L. Cherry and M.E. Lesk, in UNIX Programmer's Manual, Tenth Edition, Volume 2, AT&T Bell Laboratories, M.D. McIlroy and A.G. Hume editors, Holt Rinehart & Winston, 1990. This paper may be downloaded from http://cm.bell-labs.com/cm/cs/doc/76/tbl.ps.gz.

17.1.1. Options

-me
Prepend the me macros to the front of files.

-mm
Prepend the mm macros to the front of files.

-ms
Prepend the ms macros to the front of files.

-TX
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. (This option is not on Solaris tbl.)

17.1.2. General Coding Scheme

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

.TS H
options;
format1
format2.
Column Titles
.TH
Item1	Item2	Item3
Item1	Item2	Item3 ...
.TE

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 the 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}.

17.1.3. tbl Macros

.TSStart table.
.TEEnd table.
.TS H

Used when the table continues onto more than one page. Used with .TH to define a header that prints on every page.

.THWith .TS H, end the header portion of the table.
.T&Continue table with new format line(s).

17.1.4. Options

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

centerCenter with current margins.
expandFlush with current right and left margins.
(leave blank)Flush with current left margin (the default).
boxEnclose table in a box.
doubleboxEnclose table in two boxes.
allboxEnclose 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.

17.1.5. 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.

17.1.5.1. Key letters

cCenter.
lFlush left.
rFlush right.
nAlign numerical entries.
aAlign alphabetic subcolumns.
s

Horizontally span previous column entry across this column.

^

Vertically span (center) entry from previous row down through this row.

17.1.5.2. Key modifiers

These must follow a key letter.

bBoldface.
iItalics.
fxFont x.
pnPoint size n.
vn

Vertical line spacing, in points. Applies only to text blocks.

t

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

eEqual-width columns.
w(n)

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

nAmount 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.

17.1.6. Data

The data portion includes both the heading and text of the table. Each table entry must be separated by a tab character. In the description below, tab represents the tab character.

.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.

\Rx

Print xs as wide as the column's contents.

...tabT{

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 it will span more than one line of output.

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

17.1.7. A tbl Example

Input:

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

Result:

Figure 17.1.7


Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.