groff (7) Linux Manual Page
groff – a short reference for the GNU roff language
Description
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 provides only short descriptions of roff language elements. Groff: The GNU Implementation of troff, by Trent A. Fisher and Werner Lemberg, is the primary groff manual, and is written in Texinfo. You can browse it interactively with “info groff”. 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. 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 spaces (but not tab characters) 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 linesrepresent the parts that is 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 thecopy mode. The copy mode behaviour can be quite tricky, but there are some rules that ensure a safe usage.- 1.
- Printable backslashes must be denoted as
. To be more precise,represents the current escape character. To get a backslash glyph, use\(rsor\[rs]. - 2.
- Double all backslashes.
- 3.
- Begin all text lines with the special non-spacing character
\&.
This does not produce the most efficient code, but it should work as a first measure. For better strategies, see the groff Texinfo manual and
groff_tmac(5). Reading roff source files is easier, just reduce all double backslashes to a single one in all macro definitions.Groff Elements
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.
Requestsare written on a line of their own starting with a dot or a whereasEscape sequencesare in-line functions and in-word formatting elements starting with a backslashThe user can define her own formatting commands using the
derequest. These commands are calledmacros, but they are used exactly like requests. Macro packages are pre-defined sets of macros written in the groff language. A user’s 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.
Stringvariables store character sequences. They are set with thedsrequest and retrieved by the\*escape sequences. Strings can have variables.Registervariables can store numerical values, numbers with a scale unit, and occasionally string-like objects. They are set with thenrrequest and retrieved by theescape sequences.
Environmentsallow the user to temporarily store global formatting parameters like line length, font size, etc. for later reuse. This is done by theevrequest.Fontsare identified either by a name or by an internal number. The current font is chosen by theftrequest or by theescape sequences. Each device has special fonts, but the following fonts are available for all devices.Ris the standard font Roman.Bis itsboldcounterpart. The italic font is calledIand 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, andCB. On text devices, all glyphs have a constant width anyway.Glyphsare visual representation forms ofcharacters. In groff, the distinction between those two elements is not always obvious (and a full discussion is beyond the scope of this man page). A first approximation is that glyphs have a specific size and colour and are taken from a specific font; they can’t be modified any more – characters are the input, and glyphs are the output. As soon as an output line has been generated, it no longer contains characters but glyphs. In this man page, we use either ‘glyph’ or ‘character’, whatever is more appropriate.Moreover, there are some advanced roff elements. A
diversionstores (formatted) information into a macro for later usage. Seegroff_tmac(5) for more details. Atrapis 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 Texinfo manual.
Control Characters
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
if,ie,el, andwhile. There it is the control character that introduces a request (or macro). By using theccrequest, 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 doesn’t cause a linebreak. By using the
c2request, 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 do work). In all other positions, it denotes the single quote or apostrophe character. Groff provides a printable representation with the
\(cqescape sequence. - 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 do work). In all other positions, it denotes the single quote or apostrophe character. Groff provides a printable representation with the
- "
- The double quote is used to enclose arguments in macros (but not in requests and strings). In the
dsandasrequests, a leading double quote in the argument is stripped off, making everything else afterwards the string to be defined (enabling leading whitespace). The escaped double quote\"introduces a comment. Otherwise, it is not special. Groff provides a printable representation with the\(dqescape sequence. - \
- The backslash usually introduces an escape sequence (this can be changed with the
ecrequest). A printed version of the escape character is theescape; a backslash glyph can be obtained by\(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 behaviour can be replaced by the [] 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.
- 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 groff’s horizontal spacing calculations. To get a defined space width, escape sequences like (this is the escape character followed by a space),
\|,\^, or\hshould be used. - 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.
- 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.
Numerical Expressions
A
numerical valueis a signed or unsigned integer or float with or without an appended scaling indicator. Ascaling indicatoris 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 = 1/6 inch
-
p - point = 1/72 inch
-
m - em = the font size in points (approx. width of letter ‘m’)
-
M - 100th of an em
-
n - en = em/2
-
u - Basic unit for actual output device
-
v - Vertical line space in basic units
-
s - scaled point = 1/sizescale of a point (defined in font DESC file)
-
f - Scale by 65536.
-
Numerical expressionsare 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:
-
- e1/>?,e2
- The maximum of e1 and e2.
- e1/<?,e2
- The minimum of e1 and e2.
- (,c/;,e/)
- Evaluate e using c as the default scaling indicator.
For details see the groff Texinfo manual.
Conditions
Conditionsoccur in tests raised by theif,ie, and thewhilerequests. 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 N is~0 (see below).
-
‘s1‘s2‘ - True if string~s1 is identical to string~s2.
-
!’s1‘s2‘ - True if string~s1 is not identical to string~s2 (see below).
-
cch - True if there is a glyph~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. -
Ffont - True if there exists a font named font.
-
Sstyle - True if a style named style has been registered.
Note that the
!operator may only appear at the beginning of an expression, and negates the entire expression. This maintains bug-compatibility with AT&T troff.Requests
This section provides a short reference for the predefined requests. In groff, request, macro, and string 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.
Some requests have optional arguments with a different behaviour. Not all of these details are outlined here. Refer to the groff Texinfo manual 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
\{and\}. - 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 is 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 is 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.
Request Short Reference
- 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 (c/=l,r,c,b,n).
- Assign format c to register (c/=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
.end is called.- Same as
.ambut with compatibility mode switched off during macro expansion.- Same as
.ambut with compatibility mode switched off during macro expansion.- 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
.amibut with compatibility mode switched off during macro expansion.- Same as
.amibut with compatibility mode switched off during macro expansion.- Append anything to stringvar.
- Same as
.asbut with compatibility mode switched off during string expansion.- Unformat ASCII characters, spaces, and some escape sequences in diversion.
- 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 output line; adjust if applicable.
- 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 entity c as string anything.
- Chop the last character off macro, string, or diversion object.
- Assign a set of characters, character ranges, or classes c1, c2, … to name.
- Close the stream.
- Enable colors.
- If N is zero disable colors, otherwise enable them.
- Map glyph name from to glyph name to while constructing a composite glyph name.
- 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
.ulin troff.- End current diversion.
- Divert and append to macro.
- Define or redefine macro until
..is encountered.- Define or redefine macro until
.end is called.- Same as
.debut with compatibility mode switched off during macro expansion.- Same as
.debut with compatibility mode switched off during macro expansion.- Define or redefine a color with name color. scheme can be
rgb,cym,cymk,gray, orgrey. 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 colordefaultcan’t be redefined.- Define or redefine a macro whose name is contained in the string register macro until
..is encountered.- Define or redefine a macro indirectly. macro and end are string registers whose contents are interpolated for the macro name and the end macro, respectively.
- Same as
.deibut with compatibility mode switched off during macro expansion.- Same as
.deibut with compatibility mode switched off during macro expansion.- Write anything to the intermediate output as a device control function.
- Write contents of macro or string name uninterpreted to the intermediate output as a device control function.
- End current diversion.
- Divert to macro. See
groff_tmac(5) for more details.- Interpret
.name with compatibility mode disabled.- Set stringvar to anything.
- Same as
.dsbut with compatibility mode switched off during string expansion.- Set diversion trap to position N (default scaling indicator~
- Reset escape character to
- Set escape character to c.
- Restore escape character saved with
.ecs.- Save current escape character.
- Else part for if-else (
.ie) request.- The macro is run after the end of input.
- Turn off escape character mechanism.
- Switch to previous environment and pop it off the stack.
- Push down environment number or name env to the stack and switch to it.
- Copy the contents of environment env to the current environment. No pushing or popping.
- Exit from roff processing.
- Return to previous font family.
- Set the current font family to name.
- Disable field mechanism.
- Set field delimiter to~a and pad glyph to space.
- Set field delimiter to~a and pad glyph to~b.
- Define fallback character (or glyph) c as string anything.
- Set fill color to previous fill color.
- Set fill color to c.
- Fill output lines.
- Flush output buffer.
- Mount font on position n.
- Mount font with long external name to short internal name on position n.
- Define fallback character (or glyph) c for font f as string anything.
- Reset list of special fonts for font to be empty.
- When the current font is font, then the fonts s1, s2, … are special.
- Return to previous font. Same as
\or\.- Change to font name or number font; same as escape sequence.
- Translate font1 to font2.
- Don’t magnify font.
- Set zoom factor for font (in multiples of 1/1000th).
- Set glyph color to previous glyph color.
- Set glyph color to c.
- Remove additional hyphenation indicator character.
- Set up additional hyphenation indicator character~c.
- Set the hyphenation code of character c1 to code1, that of c2 to code2, etc.
- Set the current hyphenation language to lang.
- Set the maximum number of consecutive hyphenated lines to n.
- Read hyphenation patterns from file.
- Append hyphenation patterns from file.
- Set input mapping for
.hpf.- List of words with exceptional hyphenation.
- Switch to hyphenation mode N.
- Set the hyphenation margin to n (default scaling indicator~
- Set the hyphenation space to n.
- If cond then anything else goto
.el.- If cond then anything; otherwise do nothing.
- Ignore text until
..is encountered.- Ignore text until
.end is called.- Change to previous indentation value.
- Change indentation according to ±N (default scaling indicator~
- Set an input-line count trap for the next N lines.
- Same as
.itbut don’t count lines interrupted with - Complete line is a comment.
