< Day Day Up > |
18.2. Overview of nroff/troffThis section is condensed from the material on troff from the third edition of this book. It covers features available in all versions of nroff and troff, and focuses on those features necessary for writing manual pages. 18.2.1. Command-Line Invocationnroff and troff are invoked from the command line as follows: nroff [options] [files] troff [options] [files] Although both formatters support a plethora of options, the following two are the most important for everyday use.
18.2.1.1. ExampleFormat a manual page for printing using groff: $ groff -man /usr/share/man/man1/awk.1 | lpr 18.2.2. Conceptual OverviewThis section provides a brief overview of how to prepare input for nroff and troff. It presents the following topics:
18.2.2.1. Requests and macrosFormatting is specified by embedding brief codes (called requests) into the text source file. These codes act as directives to nroff and troff when they run. For example, to center a line of text, type the following code in a file: .ce This text should be centered. When formatted, the output appears centered: This text should be centered. There are two types of formatting codes:
Requests, also known as primitives, allow direct control of almost any feature of page layout and formatting. Macros combine requests to create a total effect. In a sense, requests are like statements, and macros are like functions. All nroff/troff requests are two-letter lowercase names. Macros are usually upper- or mixed-case names. GNU troff removes the two-character restriction on the length of names. 18.2.2.2. Specifying measurementsWith some requests, the numeric argument can be followed by a scale indicator that specifies a unit of measurement. The valid indicators and their meanings are listed in the following table. Note that all measurements are internally converted to basic units (this conversion is shown in the last column). A basic unit is the smallest possible size on the printer device. The device resolution (e.g., 600 dots per inch) determines the size of a basic unit. Also, T specifies the current point size, and R specifies the device resolution.
It is worth noting that all numbers in nroff/troff are stored internally using integers. This applies even to apparently fractional values in commands such as: .sp .5 which spaces down one-half of the current vertical spacing. An "em" is the width of the letter "m" in the current font and point size. An "en" is the width of the letter "n" in the current font and point size. Note that in nroff, an "em" and an "en" are the same the width of one character. 18.2.2.3. Requests that cause a line breakA line break occurs when nroff/troff writes the current output line, even if it is not completely filled. Most requests can be interspersed with text without causing a line break in the output. The following requests cause a break: .bp .ce .fi .in .sp .br .cf .fl .nf .ti If you need to prevent these requests from causing a break, begin them with the "no break" control character (normally ') instead of a dot (.). For example, .bp flushes the current output line and starts a new page immediately. However, 'bp starts a new page, with the current output line not being written until it is full. 18.2.2.4. Embedded formatting controlsIn addition to requests and macros, which are written on their own separate lines, you may also have formatting controls embedded within your text lines. These typically provide the following capabilities:
Comments in nroff/troff begin with \". Lines beginning with . that contain an unknown request are ignored. In general, don't put leading whitespace on your text lines. This causes a break, and nroff and troff honor the leading whitespace literally. 18.2.3. Outline of Useful RequestsThe following is a list of the requests that you may see in manual pages, or that were mentioned earlier in the chapter.
18.2.4. Useful Escape SequencesThis partial list of troff escape sequences provides those that are most useful.
18.2.5. Special CharactersTable 18-1 lists the special characters that reside in the standard fonts. troff includes a large number of other characters that we have not described here, since they are mostly for typesetting mathematics.
|
< Day Day Up > |