groff_diff (7) Linux Manual Page
groff_diff – differences between GNU troff and classical troff
Description
This manual page describes the language differences between groff, the GNU roff text processing system, and the classical roff formatter of the freely available Unix~7 of the 1970s, documented in the Troff User’s Manual by Ossanna and Kernighan. This includes the roff language as well as the intermediate output format (troff output).
Section “See Also” below gives pointers to both the classical roff and the modern groff documentation.
Groff Language
In this section, all additional features of groff compared to the classical Unix~7 troff are described in detail.
Long names
The names of number registers, fonts, strings/:macros/:diversions, special characters (glyphs), and colors can be of any length. In escape sequences, additionally to the classical ‘(,xx/‘ construction for a two-character glyph name, you can use ‘[,xxx/]‘ for a name of arbitrary length.
\[xxx]- Print the special character (glyph) called xxx.
\[comp1 comp2]- Print composite glyph consisting of multiple components. Example: ‘\[A~ho]’ is capital letter A with ogonek which finally maps to glyph name ‘u0041_0328’. See Groff: The GNU Implementation of troff, the groff Texinfo manual, for details of how a glyph name for a composite glyph is constructed, and
groff_char(7) for a list of glyph name components used in composite glyph names. [xxx]- Set font xxx. Additionally,
[]is a new syntax form equal toP, i.e., to return to the previous font. \*[xxx arg1 arg2]- Interpolate string xxx, taking arg1, arg2, , as arguments.
xxx
[]- Interpolate number register xxx.
Fractional point sizes
A scaled point is equal to 1/sizescale points, where sizescale is specified in the DESC file (1 by default). There is a new scale indicator~z that has the effect of multiplying by sizescale. Requests and escape sequences in troff interpret arguments that represent a point size as being in units of scaled points, but they evaluate each such argument using a default scale indicator of~z. Arguments treated in this way are the argument to the ps request, the third argument to the cs request, the second and fourth arguments to the tkf request, the argument to the \H escape sequence, and those variants of the \s escape sequence that take a numeric expression as their argument.
For example, suppose sizescale is 1000; then a scaled point is equivalent to a millipoint; the call .ps 10.25 is equivalent to .ps 10.25z and so sets the point size to 10250 scaled points, which is equal to 10.25 points.
The number register returns the point size in points as decimal fraction. There is also a new number register
[.s] that returns the point size in scaled points.
[.ps]
It would make no sense to use the z~scale indicator in a numeric expression whose default scale indicator was neither u nor~z, and so troff disallows this. Similarly it would make no sense to use a scaling indicator other than z or~u in a numeric expression whose default scale indicator was~z, and so troff disallows this as well.
There is also new scale indicator~s which multiplies by the number of units in a scaled point. So, for example, is equal to
[.ps]s1m. Be sure not to confuse the s and z~scale indicators.
Numeric expressions
Spaces are permitted in a number expression within parentheses.
M indicates a scale of 100ths of an em. f indicates a scale of 65536 units, providing fractions for color definitions with the defcolor request. For example, 0.5f = 32768u.
- 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. If c is missing, ignore scaling indicators in the evaluation of~e.
New escape sequences
\A’anything‘- This expands to
1or~0, depending on whether anything is or is not acceptable as the name of a string, macro, diversion, number register, environment, font, or color. It returns~0if anything is empty. This is useful if you want to look up user input in some sort of associative table. \B’anything‘- This expands to
1or~0, depending on whether anything is or is not a valid numeric expression. It returns~0if anything is empty. \C’xxx‘- Typeset glyph named xxx. Normally it is more convenient to use
\[xxx]. But\Chas the advantage that it is compatible with recent versions of Unix and is available in compatibility mode. \E- This is equivalent to an escape character, but it is not interpreted in copy mode. For example, strings to start and end superscripting could be defined like this
-
- .ds { ’-.3m’\s’\En[.s]*6u/10u’ .ds } \s0’.3m’
- The use of
\Eensures that these definitions work even if\*{gets interpreted in copy mode (for example, by being used in a macro argument). -
\Ff\F(fm\F[fam]Change font family. This is the same as thefamrequest.\F[]switches back to the previous font family (note that\FPwon’t work; it selects font family ‘P’ instead).\mx\m(xx\m[xxx]Set drawing color.\m[]switches back to the previous color.\Mx\M(xx\M[xxx]Set background color for filled objects drawn with the\D’‘commands.\M[]switches back to the previous color.\N’n‘- Typeset the glyph with index~n in the current font. n~can be any integer. Most devices only have glyphs with indices between 0 and 255. If the current font does not contain a glyph with that code, special fonts are not searched. The
\Nescape sequence can be conveniently used in conjunction with thecharrequest, for example-
- .char \[phone] (ZD\N’37’
- The index of each glyph is given in the fourth column in the font description file after the
charsetcommand. It is possible to include unnamed glyphs in the font description file by using a name of—; the\Nescape sequence is the only way to use these. -
\On\O[n]Suppress troff output. The escapes\O2,\O3,\O4, and\O5are intended for internal use bygrohtml.-
\O0- Disable any ditroff glyphs from being emitted to the device driver, provided that the escape occurs at the outer level (see
\O3and\O4). \O1- Enable output of glyphs, provided that the escape occurs at the outer level.
\O0and\O1also reset the registers,
[opminx],
[opminy], and
[opmaxx]to~-1. These four registers mark the top left and bottom right hand corners of a box which encompasses all written glyphs.
[opmaxy] \O2- Provided that the escape occurs at the outer level, enable output of glyphs and also write out to stderr the page number and four registers encompassing the glyphs previously written since the last call to
\O. \O3- Begin a nesting level. At start-up,
troffis at outer level. This is really an internal mechanism forgrohtmlwhile producing images. They are generated by running the troff source throughtroffto the PostScript device andghostscriptto produce images in PNG format. The\O3escape starts a new page if the device is not html (to reduce the possibility of images crossing a page boundary). \O4- End a nesting level.
\O5[Pfilename]- This escape is
grohtmlspecific. Provided that this escape occurs at the outer nesting level, write filename to stderr. The position of the image, P, must be specified and must be one ofl,r,c, ori(left, right, centered, inline). filename is associated with the production of the next inline image.
-
\R’name ±n‘- This has the same effect as
-
.nrname ±n
-
\s(nn\s±(nn Set the point size to nn points; nn must be exactly two digits.\s[±n]\s±[n]\s’±n‘\s±’n‘Set the point size to n scaled points; n is a numeric expression with a default scale indicator of~z.\Vx\V(xx\V[xxx]Interpolate the contents of the environment variable xxx, as returned bygetenv(3).\Vis interpreted in copy mode.\Yx\Y(xx\Y[xxx]This is approximately equivalent to\X’\*[xxx]’. However the contents of the string or macro xxx are not interpreted; also it is permitted for xxx to have been defined as a macro and thus contain newlines (it is not permitted for the argument to\Xto contain newlines). The inclusion of newlines requires an extension to the Unix troff output format, and confuses drivers that do not know about this extension.\Z’anything‘- Print anything and then restore the horizontal and vertical position; anything may not contain tabs or leaders.
\$0- The name by which the current macro was invoked. The
alsrequest can make a macro have more than one name. \$*- In a macro or string, the concatenation of all the arguments separated by spaces.
\$@- In a macro or string, the concatenation of all the arguments with each surrounded by double quotes, and separated by spaces.
\$^- In a macro, the representation of all parameters as if they were an argument to the
dsrequest. \$(nn\$[nnn]In a macro or string, this gives the nn-th or nnn-th argument. Macros and strings can have an unlimited number of arguments.\?anything\?- When used in a diversion, this transparently embeds anything in the diversion. anything is read in copy mode. When the diversion is reread, anything is interpreted. anything may not contain newlines; use
\!if you want to embed newlines in a diversion. The escape sequence\?is also recognized in copy mode and turned into a single internal code; it is this code that terminates anything. Thus-
- .nr x 1 .nf .di d \?\?\\?\\\\nx\\?\?\? .di .nr x 2 .di e .d .di .nr x 3 .di f .e .di .nr x 4 .f
- prints~
4. -
\/- This increases the width of the preceding glyph so that the spacing between that glyph and the following glyph is correct if the following glyph is a roman glyph. It is a good idea to use this escape sequence whenever an italic glyph is immediately followed by a roman glyph without any intervening space.
\,- This modifies the spacing of the following glyph so that the spacing between that glyph and the preceding glyph is correct if the preceding glyph is a roman glyph. It is a good idea to use this escape sequence whenever a roman glyph is immediately followed by an italic glyph without any intervening space.
\)- Like
\&except that it behaves like a character declared with thecflagsrequest to be transparent for the purposes of end-of-sentence recognition. \~- This produces an unbreakable space that stretches like a normal inter-word space when a line is adjusted.
\:- This causes the insertion of a zero-width break point. It is equal to
\%within a word but without insertion of a soft hyphen glyph. \#- Everything up to and including the next newline is ignored. This is interpreted in copy mode. It is like
\except that\does not ignore the terminating newline.
New requests
.alnxx yy- Create an alias xx for number register object named yy. The new name and the old name are exactly equivalent. If yy is undefined, a warning of type
regis generated, and the request is ignored. .alsxx yy- Create an alias xx for request, string, macro, or diversion object named yy. The new name and the old name are exactly equivalent (it is similar to a hard rather than a soft link). If yy is undefined, a warning of type
macis generated, and the request is ignored. Thede,am,di,da,ds, andasrequests only create a new object if the name of the macro, diversion or string is currently undefined or if it is defined to be a request; normally they modify the value of an existing object. .am1xx yy- Similar to
.am, but compatibility mode is switched off during execution. To be more precise, a ‘compatibility save’ token is inserted at the beginning of the macro addition, and a ‘compatibility restore’ token at the end. As a consequence, the requestsam,am1,de, andde1can be intermixed freely since the compatibility save/:restore tokens only affect the macro parts defined by.am1and.ds1. .amixx yy- Append to macro indirectly. See the
deirequest below for more information. .ami1xx yy- Same as the
amirequest but compatibility mode is switched off during execution. .as1xx yy- Similar to
.as, but compatibility mode is switched off during expansion. To be more precise, a ‘compatibility save’ token is inserted at the beginning of the string, and a ‘compatibility restore’ token at the end. As a consequence, the requestsas,as1,ds, andds1can be intermixed freely since the compatibility save/:restore tokens only affect the (sub)strings defined byas1andds1. .asciifyxx- This request ‘unformats’ the diversion xx in such a way that ASCII and space characters (and some escape sequences) that were formatted and diverted into xx are treated like ordinary input characters when xx is reread. Useful for diversions in conjunction with the
writemrequest. It can be also used for gross hacks; for example, this-
- .tr @. .di x @nr n 1 .br .di .tr @@ .asciify x .x
- sets register~
nto~1. Note that glyph information (font, font size, etc.) is not preserved; use.unformatinstead. -
.backtrace- Print a backtrace of the input stack on stderr.
.blmxx- Set the blank line macro to xx. If there is a blank line macro, it is invoked when a blank line is encountered instead of the usual troff behaviour.
.boxxx.boxaxx These requests are similar to thedianddarequests with the exception that a partially filled line does not become part of the diversion (i.e., the diversion always starts with a new line) but is restored after ending the diversion, discarding the partially filled line which possibly comes from the diversion..break- Break out of a while loop. See also the
whileandcontinuerequests. Be sure not to confuse this with thebrrequest. .brp- This is the same as
\p. .cflagsn c1 c2- Characters c1, c2, , have properties determined by n, which is ORed from the following:
-
- 1
- The character ends sentences (initially characters
.?!have this property). - 2
- Lines can be broken before the character (initially no characters have this property); a line is not broken at a character with this property unless the characters on each side both have non-zero hyphenation codes. This can be overridden with value 64.
- 4
- Lines can be broken after the character (initially characters
-\[hy]\[em]have this property); a line is not broken at a character with this property unless the characters on each side both have non-zero hyphenation codes. This can be overridden with value 64. - 8
- The glyph associated with this character overlaps horizontally (initially characters
\[ul]\[rn]\[ru]\[radicalex]\[sqrtex]have this property). - 16
- The glyph associated with this character overlaps vertically (initially glyph
\[br]has this property). - 32
- An end-of-sentence character followed by any number of characters with this property is treated as the end of a sentence if followed by a newline or two spaces; in other words the character is transparent for the purposes of end-of-sentence recognition; this is the same as having a zero space factor in TeX (initially characters
"’)]*\[dg]\[rq]\[cq]have this property). - 64
- Ignore hyphenation code values of the surrounding characters. Use this in combination with values 2 and~4 (initially no characters have this property).
- 128
- Prohibit a line break before the character, but allow a line break after the character. This works only in combination with flags 256 and 512 and has no effect otherwise.
- 256
- Prohibit a line break after the character, but allow a line break before the character. This works only in combination with flags 128 and 512 and has no effect otherwise.
- 512
- Allow line break before or after the character. This works only in combination with flags 128 and 256 and has no effect otherwise.
- Contrary to flag values 2 and~4, the flags 128, 256, and 512 work pairwise. If, for example, the left character has value 512, and the right character 128, no line break gets inserted. If we use value~6 instead for the left character, a line break after the character can’t be suppressed since the right neighbour character doesn’t get examined.
-
.charc string- [This request can both define characters and glyphs.]
- Define entity~c to be string. To be more precise, define (or even override) a groff entity which can be accessed with name~c on the input side, and which uses string on the output side. Every time glyph~c needs to be printed, string is processed in a temporary environment and the result is wrapped up into a single object. Compatibility mode is turned off and the escape character is set to~
\while string is being processed. Any emboldening, constant spacing or track kerning is applied to this object rather than to individual glyphs in string.- A groff object defined by this request can be used just like a normal glyph provided by the output device. In particular other characters can be translated to it with the
trrequest; it can be made the leader glyph by thelcrequest; repeated patterns can be drawn with the glyph using the\land\Lescape sequences; words containing~c can be hyphenated correctly, if thehcoderequest is used to give the object a hyphenation code.- There is a special anti-recursion feature: Use of glyph within the glyph’s definition is handled like normal glyphs not defined with
char.- A glyph definition can be removed with the
rcharrequest. - Define entity~c to be string. To be more precise, define (or even override) a groff entity which can be accessed with name~c on the input side, and which uses string on the output side. Every time glyph~c needs to be printed, string is processed in a temporary environment and the result is wrapped up into a single object. Compatibility mode is turned off and the escape character is set to~
.chopxx- Chop the last element off macro, string, or diversion xx. This is useful for removing the newline from the end of diversions that are to be interpolated as strings.
.classname c1 c2- Assign name to a set of characters c1, c2, , so that they can be referred to from other requests easily (currently
.cflagsonly). Character ranges (indicated by an intermediate ‘-‘) and nested classes are possible also. This is useful to assign properties to a large set of characters. .closestream- Close the stream named stream; stream will no longer be an acceptable argument to the
writerequest. See theopenrequest. .compositeglyph1 glyph2- Map glyph name glyph1 to glyph name glyph2 if it is used in
\[]with more than one component. .continue- Finish the current iteration of a while loop. See also the
whileandbreakrequests. .colorn- If n is non-zero or missing, enable colors (this is the default), otherwise disable them.
.cpn- If n is non-zero or missing, enable compatibility mode, otherwise disable it. In compatibility mode, long names are not recognized, and the incompatibilities caused by long names do not arise.
.defcolorxxx scheme color_components- Define color xxx. scheme can be one of the following values:
rgb(three components),cmy(three components),cmyk(four components), andgrayorgrey(one component). Color components can be given either as a hexadecimal string or as positive decimal integers in the range 0-65535. A hexadecimal string contains all color components concatenated; it must start with either#or##. The former specifies hex values in the range 0-255 (which are internally multiplied by~257), the latter in the range 0-65535. Examples: #FFC0CB (pink), ##ffff0000ffff (magenta). A new scaling indicator~fhas been introduced which multiplies its value by~65536; this makes it convenient to specify color components as fractions in the range 0 to~1. Example:-
- .defcolor darkgreen rgb 0.1f 0.5f 0.2f
- Note that
fis the default scaling indicator for thedefcolorrequest, thus the above statement is equivalent to-
- .defcolor darkgreen rgb 0.1 0.5 0.2
- The color named
default(which is device-specific) can’t be redefined. It is possible that the default color for\Mand\mis not the same. -
.de1xx yy- Similar to
.de, but compatibility mode is switched off during execution. On entry, the current compatibility mode is saved and restored at exit. .deixx yy- Define macro indirectly. The following example
-
- .ds xx aa .ds yy bb .dei xx yy
- is equivalent to
-
- .de aa bb
-
.dei1xx yy- Similar to the
deirequest but compatibility mode is switched off during execution. .deviceanything- This is (almost) the same as the
\Xescape. anything is read in copy mode; a leading~"is stripped. .devicemxx- This is the same as the
\Yescape (to embed the contents of a macro into the intermediate output preceded with ‘x~X’). .doxxx- Interpret .xxx with compatibility mode disabled. For example,
-
- .do fam T
would have the same effect as
- .fam T
except that it would work even if compatibility mode had been enabled. Note that the previous compatibility mode is restored before any files sourced by xxx are interpreted.
-
.ds1xx yy- Similar to
.ds, but compatibility mode is switched off during expansion. To be more precise, a ‘compatibility save’ token is inserted at the beginning of the string, and a ‘compatibility restore’ token at the end. .ecs- Save current escape character.
.ecr- Restore escape character saved with
ecs. Without a previous call toecs, ‘\‘ will be the new escape character. .evcxx- Copy the contents of environment xx to the current environment. No pushing or popping of environments is done.
.famxx- Set the current font family to xx. The current font family is part of the current environment. If xx is missing, switch back to previous font family. The value at start-up is ‘T’. See the description of the
styrequest for more information on font families. .fcharc string- Define fallback character (or glyph)~c to be string. The syntax of this request is the same as the
charrequest; the only difference is that a glyph defined withcharhides the glyph with the same name in the current font, whereas a glyph defined withfcharis checked only if the particular glyph isn’t found in the current font. This test happens before checking special fonts. .fcolorc- Set the fill color to~c. If c is missing, switch to the previous fill color.
.fscharf c string- Define fallback character (or glyph)~c for font~f to be string. The syntax of this request is the same as the
charrequest (with an additional argument to specify the font); a glyph defined withfscharis searched after the list of fonts declared with thefspecialrequest but before the list of fonts declared with.special. .fspecialf s1 s2- When the current font is~f, fonts s1, s2, , are special, that is, they are searched for glyphs not in the current font. Any fonts specified in the
specialrequest are searched after fonts specified in thefspecialrequest. Without argument, reset the list of global special fonts to be empty. .ftrf g- Translate font~f to~g. Whenever a font named~f is referred to in an
escape sequence, in theFandSconditional operators, or in theft,ul,bd,cs,tkf,special,fspecial,fp, orstyrequests, font~g is used. If g is missing, or equal to~f then font~f is not translated. .fzoomf zoom- Set zoom factor zoom for font~f. zoom must a non-negative integer multiple of 1/1000th. If it is missing or is equal to zero, it means the same as 1000, namely no magnification. f~must be a real font name, not a style.
.gcolorc- Set the glyph color to~c. If c is missing, switch to the previous glyph color.
.hcodec1 code1 c2 code2- Set the hyphenation code of character c1 to code1 and that of c2 to code2, and so on. A hyphenation code must be a single input character (not a special character) other than a digit or a space. Initially each lower-case letter a-z has a hyphenation code, which is itself, and each upper-case letter A-Z has a hyphenation code which is the lower-case version of itself. See also the
hpfrequest. .hlalang- Set the current hyphenation language to lang. Hyphenation exceptions specified with the
hwrequest and hyphenation patterns specified with thehpfrequest are both associated with the current hyphenation language. Thehlarequest is usually invoked by thetroffrcfile to set up a default language. .hlmn- Set the maximum number of consecutive hyphenated lines to~n. If n is negative, there is no maximum. The default value is~-1. This value is associated with the current environment. Only lines output from an environment count towards the maximum associated with that environment. Hyphens resulting from
\%are counted; explicit hyphens are not. .hpffile- Read hyphenation patterns from file; this is searched for in the same way that name
.tmacis searched for when the-mname option is specified. It should have the same format as (simple) TeX patterns files. More specifically, the following scanning rules are implemented.-
- •
- A percent sign starts a comment (up to the end of the line) even if preceded by a backslash.
- •
- No support for ‘digraphs’ like
\$. - •
^^xx (x is 0-9 or a-f) and^^x (character code of~x in the range 0-127) are recognized; other use of~^causes an error.- •
- No macro expansion.
- •
hpfchecks for the expression\patterns{}(possibly with whitespace before and after the braces). Everything between the braces is taken as hyphenation patterns. Consequently,{~and~}are not allowed in patterns.- •
- Similarly,
\hyphenation{}gives a list of hyphenation exceptions. - •
ndinputis recognized also.- •
- For backwards compatibility, if
\patternsis missing, the whole file is treated as a list of hyphenation patterns (only recognizing the%~character as the start of a comment).
- Use the
hpfcoderequest to map the encoding used in hyphenation patterns files togroff‘s input encoding. By default, everything maps to itself except letters ‘A’ to ‘Z’ which map to ‘a’ to ‘z’.- The set of hyphenation patterns is associated with the current language set by the
hlarequest. Thehpfrequest is usually invoked by thetroffrcfile; a second call replaces the old patterns with the new ones. -
.hpfafile- The same as
hpfexcept that the hyphenation patterns from file are appended to the patterns already loaded in the current language. .hpfcodea b c d- After reading a hyphenation patterns file with the
hpforhpfarequest, convert all characters with character code~a in the recently read patterns to character code~b, character code~c to~d, etc. Initially, all character codes map to themselves. The arguments ofhpfcodemust be integers in the range 0 to~255. Note that it is even possible to use character codes which are invalid ingroffotherwise. .hymn- Set the hyphenation margin to~n: when the current adjustment mode is not~
b, the line is not hyphenated if the line is no more than n short. The default hyphenation margin is~0. The default scaling indicator for this request is~m. The hyphenation margin is associated with the current environment. The current hyphenation margin is available in theregister.
[.hym] .hysn- Set the hyphenation space to~n: When the current adjustment mode is~
bdon’t hyphenate the line if the line can be justified by adding no more than n extra space to each word space. The default hyphenation space is~0. The default scaling indicator for this request is~m. The hyphenation space is associated with the current environment. The current hyphenation space is available in theregister.
[.hys] .itcn macro- Variant of
.itfor which a line interrupted with
