## 12.3. Conceptual Overview

This sections provides a brief overview of how to prepare input for `nroff` and `troff`. It presents the following topics:

- Requests and macros

- Common requests

- Specifying measurements

- Requests that cause a line break

- Embedded formatting controls

### 12.3.1. Requests and Macros

Formatting 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, which provide the most elementary instructions

- Macros, which are predefined combinations of requests

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 atoms, and macros are like molecules.

All `nroff`/`troff` requests are two-letter lowercase names. Macros are usually upper- or mixed-case names.

See Chapter 13, Chapter 14, Chapter 15, and Chapter 16, for more information on the standard macro packages.

### 12.3.2. Common Requests

The most commonly used requests are:

>     .ad   .ds   .ll   .nr   .sp
>     .br   .fi   .na   .po   .ta
>     .bp   .ft   .ne   .ps   .ti
>     .ce   .in   .nf   .so   .vs
>     .de   .ls

For example, a simple macro could be written as follows:

>     .	        \" Ps macro - show literal text display
>     .de Ps	        \" Define a macro named "Ps"
>     .sp .5	        \" Space down half a line
>     .in 1i	        \" Indent one inch
>     .ta 10n +10n	\" Set new tabstops
>     .ps 8	        \" Use 8-point type
>     .vs 10	        \" Use 10-point vertical spacing
>     .ft CW	        \" Use constant width font
>     .br		\" Break line (.ne begins count on next line)
>     .ne 3	        \" Keep 3 lines together
>     .nf	        \" No-fill mode (output lines as is)
>     ..	        \" End macro definition

### 12.3.3. Specifying Measurements

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

Scale Indicator | Meaning | Equivalent Unit | # of Basic Units
--- | --- | --- | ---
`c` | Centimeter | 2.54 inches | R / 2.54
`i` | Inch | 6 picas or 72 points | R
`m` | Em | T points | R × T / 72
`n` | En | 0.5 em | R × T / 144
`p` | Point | 1/72 inch | R / 72
`P` | Pica | 1/6 inch | R / 6
`u` | Basic unit |  | 1
`v` | Vertical line space |  | (Current value in basic units)
None | Default |  |

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.

You can specify a scale indicator for any of the requests in the following table, except for `.ps`, which always uses points. If no unit is given, the default unit is used. (The second column lists the scale indicators as described in the previous table.) For horizontally oriented requests, the default unit is ems. For vertically oriented requests, the default is usually vertical lines.

Request | Default Scale | Request | Default Scale
--- | --- | --- | ---
`.ch` | `v` | `.pl` | `v`
`.dt` | `v` | `.po` | `v`
`.ie` | `u` | `.ps` | `p`
`.if` | `u` | `.rt` | `v`
`.in` | `m` | `.sp` | `v`
`.ll` | `m` | `.sv` | `v`
`.lt` | `m` | `.ta` | `m`
`.mc` | `m` | `.ti` | `m`
`.ne` | `v` | `.vs` | `p`
`.nr` | `u` | `.wh` | `v`

### 12.3.4. Requests That Cause a Line Break

A 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, `.sp` takes effect right away, but `'sp` waits until the output line is completely filled. Only then does it add a line space.

### 12.3.5. Embedded Formatting Controls

In 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:

General formatting
  Considerable formatting control is available, such as switching fonts (`\f`), changing point sizes (`\s`), computing widths (`\w`), and many other things. For example:

  >     This text is in \fIitalic\fR, but this is in roman.
  >     This text is \s-2VERY SMALL\s0 but this text is not.

Special characters
  Predefined special typesetting characters, such as the bullet symbol `\(bu` (), the left hand `\(lh` (), and the right hand `\(rh` ().
Strings
  User-defined sequences of characters, like macros, but usable inline. For example:

  >     .\" define a shorthand for UNIX
  >     .ds UX  the \s-1UNIX\s0 Operating System
  >     ...
  >     Welcome to \*(UX.
  >     While \*(UX may appear daunting at first,
  >     it is immensely powerful. ...

Number registers
  Like variables in programming languages, number registers store numeric values that can be printed in a range of formats (decimal, roman, etc.). They can be set to auto-increment or auto-decrement, and are particularly useful when writing macro packages, for managing automatic numbering of headings, footnotes, figures, and so on. For example:

  >     .nr Cl 0 1  \" Chapter Level
  >     .de CH
  >     .bp
  >     \\n+(Cl. \\$1 \\$2 \\$3
  >     ..

  This creates a macro that uses register `Cl` as the “chapter level.” The first three arguments to the macro become the chapter title. The extra backslashes are needed inside the macro definition.

Later sections in this chapter describe the predefined special characters, strings and number registers, and all of the escape sequences that are available.

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