groff - a short reference for the GNU roff language
Description
Conditions
Requests
Registers
Compatibility
Bugs
Authors
The name groff stands for GNU roff and is the free implementation of the roff type-setting system. See roff(7) for a survey and the background of the groff system.This document gives only short descriptions of the predefined roff language elements as used in groff. Both the classical features and the groff extensions are provided.
Historically, the roff language was called troff. groff is compatible with the classical system and provides proper extensions. So in GNU, the terms roff, troff, and groff language could be used as synonyms. However troff slightly tends to refer more to the classical aspects, whereas groff emphasizes the GNU extensions, and roff is the general term for the language.
This file is only a short version of the complete documentation that is found in the groff info(1) file, which contains more detailed, actual, and concise information.
The general syntax for writing groff documents is relatively easy, but writing extensions to the roff language can be a bit harder.
The roff language is line-oriented. There are only two kinds of lines, control lines and text lines. The control lines start with a control character, by default a period or a single quote all other lines are text lines.
Control lines represent commands, optionally with arguments. They have the following syntax. The leading control character can be followed by a command name; arguments, if any, are separated by blanks from the command name and among themselves, for example,
For indentation, any number of space or tab characters can be inserted between the leading control character and the command name, but the control character must be on the first position of the line.
Text lines represent the parts that will be printed. They can be modified by escape sequences, which are recognized by a leading backslash These are in-line or even in-word formatting elements or functions. Some of these take arguments separated by single quotes others are regulated by a length encoding introduced by an open parenthesis or enclosed in brackets and
The roff language provides flexible instruments for writing language extension, such as macros. When interpreting macro definitions, the roff system enters a special operating mode, called the copy mode.
The copy mode behavior can be quite tricky, but there are some rules that ensure a safe usage.
This does not produce the most efficient code, but it should work as a first measure. For better strategies, see the groff info file and groff_tmac(5).
1. Printable backslashes must be denoted as [rs]e. To be more precise, [rs]e represents the current escape character. To get a backslash glyph, use [rs](rs or [rs][rs]. 2. Double all backslashes. 3. Begin all text lines with the special non-spacing character [rs]&. Reading roff source files is easier, just reduce all double backslashes to a single one in all macro definitions.
The roff language elements add formatting information to a text file. The fundamental elements are predefined commands and variables that make roff a full-blown programming language.There are two kinds of roff commands, possibly with arguments. Requests are written on a line of their own starting with a dot or a whereas Escape sequences are in-line functions and in-word formatting elements starting with a backslash
The user can define her own formatting commands using the * request. These commands are called macros, but they are used exactly like requests. Macro packages are pre-defined sets of macros written in the groff language. A users possibilities to create escape sequences herself is very limited, only special characters can be mapped.
The groff language provides several kinds of variables with different interfaces. There are pre-defined variables, but the user can define her own variables as well.
String variables store character sequences. They are set with the * request and retrieved by the [rs]* escape sequences. Strings can have variables.
Register variables can store numerical values, numbers with a scale unit, and occasionally string-like objects. They are set with the * request and retrieved by the [rs]n escape sequences.
Environments allow the user to temporarily store global formatting parameters like line length, font size, etc. for later reuse. This is done by the * request.
Fonts are identified either by a name or by an internal number. The current font is chosen by the * request or by the [rs]f escape sequences. Each device has special fonts, but the following fonts are available for all devices. R is the standard font Roman. B is its bold counterpart. The italic font is called I and is available everywhere, but on text devices it is displayed as an underlined Roman font. For the graphical output devices, there exist constant-width pendants of these fonts, CR, CI, and CB. On text devices, all characters have a constant width anyway.
Moreover, there are some advanced roff elements. A diversion stores information into a macro for later usage. A trap is a positional condition like a certain number of lines from page top or in a diversion or in the input. Some action can be prescribed to be run automatically when the condition is met.
More detailed information and examples can be found in the groff info file.
There is a small set of characters that have a special controlling task in certain conditions.
A dot is only special at the beginning of a line or after the condition in the requests * * * and * There it is the control character that introduces a request (or macro). The special behavior can be delayed by using the [rs]. escape. By using the * request, the control character can be set to a different character, making the dot a non-special character. In all other positions, it just means a dot character. In text paragraphs, it is advantageous to start each sentence at a line of its own. The single quote has two controlling tasks. At the beginning of a line and in the conditional requests it is the non-breaking control character. That means that it introduces a request like the dot, but with the additional property that this request doesnt cause a linebreak. By using the * request, the non-break control character can be set to a different character. As a second task, it is the most commonly used argument separator in some functional escape sequences (but any pair of characters not part of the argument will work). In all other positions, it denotes the single quote or apostrophe character. Groff provides a printable representation with the [rs](cq escape sequence. The double quote is used to enclose arguments in requests, macros, and strings. In the * and * requests, a leading double quote in the argument will be stripped off, making everything else afterwards the string to be defined (enabling leading whitespace). The escaped double quote [rs][dq] introduces a comment. Otherwise, it is not special. Groff provides a printable representation with the [rs](dq escape sequence. The backslash usually introduces an escape sequence (this can be changed with the * request). A printed version of the escape character is the [rs]e escape; a backslash glyph can be obtained by [rs](rs. The open parenthesis is only special in escape sequences when introducing an escape name or argument consisting of exactly two characters. In groff, this behavior can be replaced by the CB][]] construct. The opening bracket is only special in groff escape sequences; there it is used to introduce a long escape name or long escape argument. Otherwise, it is non-special, e.g. in macro calls. The closing bracket is only special in groff escape sequences; there it terminates a long escape name or long escape argument. Otherwise, it is non-special. CI]space] Space characters are only functional characters. They separate the arguments in requests, macros, and strings, and the words in text lines. They are subject to groffs horizontal spacing calculations. To get a defined space width, escape sequences like (this is the escape character followed by a space), [rs]|, [rs]^, or [rs]h should be used. CI]newline] In text paragraphs, newlines mostly behave like space characters. Continuation lines can be specified by an escaped newline, i.e., by specifying a backslash as the last character of a line. CI]tab] If a tab character occurs during text the interpreter makes a horizontal jump to the next pre-defined tab position. There is a sophisticated interface for handling tab positions.
A numerical value is a signed or unsigned integer or float with or without an appended scaling indicator. A scaling indicator is a one-character abbreviation for a unit of measurement. A number followed by a scaling indicator signifies a size value. By default, numerical values do not have a scaling indicator, i.e., they are normal numbers.The roff language defines the following scaling indicators.
c Centimeter i Inch P Pica [eq] 1/6 inch p Point [eq] 1/72 inch m Em [eq] R]the font size in points (width of letter CR]mR]) M 100th R]of an CR]Em n En [eq] Em/2 u Basic unit for actual output device v Vertical line space in basic units scaled point [eq] 1/CI]sizescaleR] of a point (defined in font I]DESC] file) f Scale by 65536. Numerical expressions are combinations of the numerical values defined above with the following arithmetical operators already defined in classical troff.
+ Addition - Subtraction * Multiplication / Division % Modulo = Equals == Equals < Less than > Greater than <= Less or equal >= Greater or equal & Logical and : Logical or ! Logical not ( Grouping of expressions ) Close current grouping Moreover, groff added the following operators for numerical expressions:
The maximum of e1 and e2. The minimum of e1 and e2. Evaluate e using c as the default scaling indicator. For details see the groff info file.
Conditions occur in tests raised by the * * and the * requests. The following table characterizes the different types of conditions.
N A numerical expression N yields true if its value is greater than~0. !N True if the value of I is~0. s1s2 True if string~ s1 is identical to string~ s2. !s1s2 True if string~ s1 is not identical to string~ s2. cch True if there is a character~ ch available. dname True if there is a string, macro, diversion, or request called name. e Current page number is even. o Current page number is odd. mname True if there is a color called name. n Formatter is nroff. rreg True if there is a register named reg. t Formatter is troff.
This section provides a short reference for the predefined requests. In groff, request and macro names can be arbitrarily long. No bracketing or marking of long names is needed.Most requests take one or more arguments. The arguments are separated by space characters (no tabs!); there is no inherent limit for their length or number. An argument can be enclosed by a pair of double quotes. This is very handy if an argument contains space characters, e.g., [dq]arg with space[dq] denotes a single argument.
Some requests have optional arguments with a different behaviour. Not all of these details are outlined here. Refer to the groff info file and groff_diff(7) for all details.
In the following request specifications, most argument names were chosen to be descriptive. Only the following denotations need clarification.
c denotes a single character. font a font either specified as a font name or a font number. anything all characters up to the end of the line or within [rs]{ and [rs]}. n is a numerical expression that evaluates to an integer value. N is an arbitrary numerical expression, signed or unsigned. [+-]N has three meanings depending on its sign, described below. If an expression defined as [+-]N starts with a sign the resulting value of the expression will be added to an already existing value inherent to the related request, e.g. adding to a number register. If the expression starts with a the value of the expression will be subtracted from the request value.
Without a sign, N replaces the existing value directly. To assign a negative number either prepend~0 or enclose the negative number in parentheses.
Empty line, ignored. Useful for structuring documents. Complete line is a comment. Print string on standard error, exit program. Begin line adjustment for output lines in current adjust mode. Start line adjustment in mode c (CI]c]CR][eq]l,r,b,n]). Assign format c to register (CI]c]CR][eq]l,i,I,a,A]). Create alias name for register. Create alias name for request, string, macro, or diversion object. Append to macro until .. is encountered. Append to macro until * is called. Append to a macro whose name is contained in the string register macro until .. is encountered. Append to a macro indirectly. macro and end are string registers whose contents are interpolated for the macro name and the end macro, respectively. Same as * but with compatibility mode switched off during macro expansion. Same as * but with compatibility mode switched off during macro expansion. Append anything to stringvar. Unformat ASCII characters, spaces, and some escape sequences in diversion. Same as * but with compatibility mode switched off during string expansion. Print a backtrace of the input on stderr. Embolden font by N-1 units. Embolden Special Font S when current font is font. Unset the blank line macro. Set the blank line macro to macro. End current diversion. Divert to macro, omitting a partially filled line. End current diversion. Divert and append to macro, omitting a partially filled line. Eject current page and begin new page. Eject current page; next page number [+-]N. Line break. Break and spread output line. Same as [rs]p. Break out of a while loop. Reset no-break control character to Set no-break control character to c. Reset control character to Set control character to c. Center the next input line. Center following N input lines. Copy contents of file filename unprocessed to stdout or to the diversion. Treat characters c1, c2, ... according to mode number. Change trap location to N . Define character c as string anything. Chop the last character off macro, string, or diversion object. Close the stream. Enable colors. If N is zero disable colors, otherwise enable them. Finish the current iteration of a while loop. Enable compatibility mode. If N is zero disable compatibility mode, otherwise enable it. Set constant character width mode for font to N/36 ems with em M. Continuous underline in nroff, like * in troff. End current diversion. Divert and append to macro. Define or redefine macro until .. is encountered. Define or redefine macro until * is called. Same as * but with compatibility mode switched off during macro expansion. Same as * but with compatibility mode switched off during macro expansion. Define or redefine a color with name color. scheme can be rgb, cym, cymk, gray, or grey. component can be single components specified as fractions in the range 0 to 1 (default scaling indicator~ as a string of two-digit hexadecimal color components with a leading #, or as a string of four-digit hexadecimal components with two leading #. The color default cant be redefined.