1groff_tmac(5)                 File Formats Manual                groff_tmac(5)
2
3
4

Name

6       groff_tmac - macro files in the GNU roff typesetting system
7

Description

9       Definitions of macros, strings, and registers for use in a roff(7) doc‐
10       ument can be collected into macro files, roff input files  designed  to
11       produce  no output themselves but instead ease the preparation of other
12       roff documents.  There is no syntactical  difference  between  a  macro
13       file  and  any  other roff document; only its purpose distinguishes it.
14       When a macro file is installed at a standard location, named  according
15       to a certain convention, and suitable for use by a general audience, it
16       is termed a macro package.  Macro packages can be loaded  by  supplying
17       the -m option to troff(1) or a groff front end.
18
19       Each  macro  package stores its macro, string, and register definitions
20       in one or more tmac files.  This name originated in early Unix  culture
21       as an abbreviation of “troff macros”.
22
23       A  macro file must have a name in the form name.tmac (or tmac.name) and
24       be placed in a “tmac directory” to be loadable with the -mname  option.
25       Section  “Environment”  of  troff(1) lists these directories.  Alterna‐
26       tively, a groff document requiring a macro file can load  it  with  the
27       mso (“macro source”) request.
28
29       Like  any  other  roff  document, a macro file can use the “so” request
30       (“source”) to load further files relative to its own location.
31
32       Macro files are named for their  most  noteworthy  application,  but  a
33       macro  file  need  not  define  any  macros.  It can restrict itself to
34       defining registers and strings or invoking other  groff  requests.   It
35       can even be empty.
36

Macro packages

38       Macro packages come in two varieties; those which assume responsibility
39       for page layout and other critical  functions  (“major”  or  “full-ser‐
40       vice”)  and  those  which  do not (“supplemental” or “auxiliary”).  GNU
41       roff provides most major macro packages found in AT&T and BSD Unix sys‐
42       tems,  an  additional full-service package, and many supplemental pack‐
43       ages.  Multiple full-service macro packages cannot be used by the  same
44       document.   Auxiliary packages can generally be freely combined, though
45       attention to their use of the groff language name  spaces  for  identi‐
46       fiers  (particularly registers, macros, strings, and diversions) should
47       be paid.  Name space management was a  significant  challenge  in  AT&T
48       troff; groff's support for arbitrarily long identifiers affords few ex‐
49       cuses for name collisions, apart from attempts  at  compatibility  with
50       the demands of historical documents.
51
52   Man pages
53       an
54       man    an  is  used  to  compose man pages in the format originating in
55              Version 7 Unix (1979).  It has a small macro  interface  and  is
56              widely used; see groff_man(7).
57
58       doc
59       mdoc   doc  is  used  to compose man pages in the format originating in
60              4.3BSD-Reno (1990).  It provides many more features than an, but
61              is  also  larger,  more  complex, and not as widely adopted; see
62              groff_mdoc(7).
63
64       Because readers of man pages often do not know in advance which  macros
65       are used to format a given document, a wrapper is available.
66
67       andoc
68       mandoc This  macro  file, specific to groff, recognizes whether a docu‐
69              ment uses man or mdoc format and loads the  corresponding  macro
70              package.   Multiple man pages, in either format, can be handled;
71              andoc reloads each macro package as necessary.
72
73   Full-service packages
74       The packages in this section provide a complete set of macros for writ‐
75       ing  documents  of  any  kind,  up to whole books.  They are similar in
76       functionality; it is a matter of taste which one to use.
77
78       me     The classical me macro package; see groff_me(7).
79
80       mm     The semi-classical mm macro package; see groff_mm(7).
81
82       mom    The mom macro package, only available in groff.  As this was not
83              based on other packages, it was freely designed as quite a nice,
84              modern macro package.  See groff_mom(7).
85
86       ms     The classical ms macro package; see groff_ms(7).
87
88   Localization packages
89       For Western languages, the localization file sets the hyphenation  mode
90       and  loads hyphenation patterns and exceptions.  Localization files can
91       also adjust the date format and provide translations of strings used by
92       some  of the full-service macro packages; alter the input encoding (see
93       the next section); and change the amount of  additional  inter-sentence
94       space.   For Eastern languages, the localization file defines character
95       classes and sets flags on them.  By default, troffrc loads  the  local‐
96       ization file for English.
97
98       trans  loads  localized  strings  used  by various macro packages after
99              their localized forms have been prepared by a localization macro
100              file.
101
102       groff provides the following localization files.
103
104       cs     Czech;  localizes  man, me, mm, mom, and ms.  Sets the input en‐
105              coding to Latin-2 by loading latin2.tmac.
106
107       de
108       den    German; localizes man, me, mm, mom, and ms.  Sets the input  en‐
109              coding to Latin-1 by loading latin1.tmac.
110
111              de.tmac  selects  hyphenation patterns for traditional orthogra‐
112              phy, and den.tmac does the same for the new orthography (“Recht‐
113              schreibreform”).
114
115       en     English.
116
117       fr     French;  localizes man, me, mm, mom, and ms.  Sets the input en‐
118              coding to Latin-9 by loading latin9.tmac.
119
120       it     Italian; localizes man, me, mm, mom, and ms.
121
122       ja     Japanese.
123
124       sv     Swedish; localizes man, me, mm, mom, and ms.  Sets the input en‐
125              coding to Latin-1 by loading latin1.tmac.  Some of the localiza‐
126              tion of the mm package is handled separately; see groff_mmse(7).
127
128       zh     Chinese.
129
130   Input encodings
131       latin1
132       latin2
133       latin5
134       latin9 are various ISO 8859 input encodings  supported  by  groff.   On
135              systems  using  ISO character encodings, groff loads latin1.tmac
136              automatically  at  startup.   A  document  that  uses   Latin-2,
137              Latin-5,  or Latin-9 can specify one of these alternative encod‐
138              ings.
139
140       cp1047 provides support for EBCDIC-based systems.  On those  platforms,
141              groff loads cp1047.tmac automatically at startup.
142
143       Because  different input character codes constitute valid GNU troff in‐
144       put on ISO and EBCDIC systems, the latin macro files cannot be used  on
145       EBCDIC systems, and cp1047 cannot be used on ISO systems.
146
147   Auxiliary packages
148       The  macro  packages  in  this section are not intended for stand-alone
149       use, but can add functionality to any other macro package or  to  plain
150       (“raw”) groff documents.
151
152       62bit  provides  macros  for  addition, multiplication, and division of
153              62-bit integers (allowing safe multiplication of  signed  31-bit
154              integers, for example).
155
156       hdtbl  allows  the  generation  of tables using a syntax similar to the
157              HTML table model.  This Heidelberger table macro package is  not
158              a preprocessor, which can be useful if the contents of table en‐
159              tries are determined by macro calls  or  string  interpolations.
160              Compare to tbl(1).  It works only with the ps and pdf output de‐
161              vices.  See groff_hdtbl(7).
162
163       papersize
164              enables the paper format to be set on the command line by giving
165              a “-d paper=format” option to troff.  Possible values for format
166              are the ISO and  DIN  formats  “A0A6”,  “B0B6”,  “C0C6”,  and
167D0D6”;   the   U.S.   formats  “letter”,  “legal”,  “tabloid”,
168ledger”, “statement”, and “executive”; and the envelope formats
169com10”,  “monarch”,  and “DL”.  All formats, even those for en‐
170              velopes, are in portrait orientation: the length measurement  is
171              vertical.  Appending “l” (ell) to any of these denotes landscape
172              orientation instead.  This macro file assumes one-inch  horizon‐
173              tal  margins,  and  sets  registers recognized by the groff man,
174              mdoc, mm, mom, and ms packages to  configure  them  accordingly.
175              If  you want different margins, you will need to use those pack‐
176              ages' facilities, or troff ll and/or po requests to adjust them.
177              An  output device typically requires command-line options -p and
178              -l to override the paper  dimensions  and  orientation,  respec‐
179              tively,  defined in its DESC file; see subsection “Paper format”
180              of groff(1).  This macro file is normally loaded at  startup  by
181              the  troffrc  file when formatting for a typesetting device (but
182              not a terminal).
183
184       pdfpic provides a single macro, PDFPIC, to include a PDF graphic  in  a
185              document  using  features  of  the pdf output driver.  For other
186              output devices, PDFPIC calls PSPIC, with which it shares an  in‐
187              terface  (see  below).   This  macro  file is normally loaded at
188              startup by the troffrc file.
189
190       pic    supplies definitions of the macros PS, PE, and PF,  usable  with
191              the  pic(1)  preprocessor.  They center each picture.  Use it if
192              your document does not use a full-service macro package, or that
193              package  does  not supply working pic macro definitions.  Except
194              for man and mdoc, those provided with groff already do  so  (ex‐
195              ception: mm employs the name PF for a different purpose).
196
197       pspic  provides a macro, PSPIC, that includes a PostScript graphic in a
198              document.  The ps, dvi, html, and xhtml output  devices  support
199              such  inclusions;  for  all other drivers, the image is replaced
200              with a rectangular border  of  the  same  size.   pspic.tmac  is
201              loaded at startup by the troffrc file.
202
203              Its syntax is as follows.
204
205                     .PSPIC [-L|-R|-C|-I n] file [width [height]]
206
207              file  is  the name of the PostScript file; width and height give
208              the desired width and height of the image.  If neither  a  width
209              nor  a  height  argument is specified, the image's natural width
210              (as given in the file's bounding box) or the current line length
211              is used as the width, whatever is smaller.  The width and height
212              arguments may have scaling units attached; the  default  scaling
213              unit is i.  PSPIC scales the graphic uniformly in the horizontal
214              and vertical directions so that it is no more  than  width  wide
215              and  height  high.   Option -C centers the graphic horizontally;
216              this is the default.   -L  and  -R  left-  and  right-align  the
217              graphic,  respectively.  -I indents the graphic by n (with a de‐
218              fault scaling unit of m).
219
220              To use PSPIC within a diversion, we recommend extending it  with
221              the  following  code,  assuring  that the diversion's width com‐
222              pletely covers the image's width.
223
224                     .am PSPIC
225                     .  vpt 0
226                     \h'(\\n[ps-offset]u + \\n[ps-deswid]u)'
227                     .  sp -1
228                     .  vpt 1
229                     ..
230
231              Failure to load PSPIC's image argument is not  an  error.   (The
232              psbb  request  does  issue an error diagnostic.)  To make such a
233              failure fatal, append to the pspic*error-hook macro.
234
235                     .am pspic*error-hook
236                     .  ab
237                     ..
238
239       ptx    provides a macro, xx, to format permuted index entries  as  pro‐
240              duced  by the GNU ptx(1) program.  If your formatting needs dif‐
241              fer, copy the macro into your document  and  adapt  it  to  your
242              needs.
243
244       rfc1345
245              defines  special  character escape sequences named for the glyph
246              mnemonics specified in RFC 1345 and the digraph table of the Vim
247              text editor.  See groff_rfc1345(7).
248
249       sboxes offers an interface to the “pdf: background” device control com‐
250              mand supported by gropdf(1).  Using this package, groff ms docu‐
251              ments can draw colored rectangles beneath any output.
252
253              .BOXSTART SHADED color OUTLINED color INDENT size WEIGHT size
254                     begins  a  box, where the argument after SHADED gives the
255                     fill color and that  after  OUTLINED  the  border  color.
256                     Omit  the  former  to get a borderless filled box and the
257                     latter for a border with no fill.  The  specified  WEIGHT
258                     is used if the box is OUTLINED.
259
260                     INDENT  precedes  a  value which leaves a gap between the
261                     border and the contents inside the box.
262
263                     Each color must be a defined groff color name,  and  each
264                     size a valid groff numeric expression.  The keyword/value
265                     pairs can be specified in any order.
266
267              Boxes can be stacked, so you can start a box within another box;
268              usually  the  later  boxes  would be smaller than the containing
269              box, but this is not enforced.  When using  BOXSTART,  the  left
270              position  is the current indent minus the INDENT in the command,
271              and the right position is the left position  (calculated  above)
272              plus the current line length and twice the indent.
273
274              .BOXSTOP
275                     takes no parameters.  It closes the most recently started
276                     box at the current vertical  position  after  adding  its
277                     INDENT spacing.
278
279              Your  groff  documents  can  conditionally  exercise  the sboxes
280              macros.  The register GSBOX is defined if the package is loaded,
281              and  interpolates  a  true  value if the pdf output device is in
282              use.
283
284              sboxes furthermore hooks into the groff_ms(7) package to receive
285              notifications  when  footnotes are growing, so that it can close
286              boxes on a page before footnotes are printed.  When that  condi‐
287              tion  obtains, sboxes will close open boxes two points above the
288              footnote separator and re-open them on  the  next  page.   (This
289              amount probably will not match the box's INDENT.)
290
291              See “Using PDF boxes with groff and the ms macros” ⟨file:///usr/
292              share/doc/groff/msboxes.pdf⟩ for a demonstration.
293
294       trace  aids the debugging of groff documents by  tracing  macro  calls.
295              See groff_trace(7).
296
297       www    defines    macros   corresponding   to   HTML   elements.    See
298              groff_www(7).
299

Naming

301       AT&T nroff and troff were implemented before  the  conventions  of  the
302       modern  C  getopt(3)  call  evolved, and used a naming scheme for macro
303       packages that looks odd to modern eyes.  Macro packages were  typically
304       loaded  using the -m option to the formatter; when directly followed by
305       its argument without an intervening space, this looked like a long  op‐
306       tion  preceded by a single minus—a sensation in the computer stone age.
307       Macro packages therefore came to be known by names  that  started  with
308       the  letter  “m”,  which was omitted from the name of the macro file as
309       stored on disk.  For example, the manuscript macro package  was  stored
310       as tmac.s and loaded with the option -ms.
311
312       groff  commands  permit  space between an option and its argument.  The
313       syntax “groff -m s” makes the macro file name more clear but  may  sur‐
314       prise  users  familiar  with  the original convention, unaware that the
315       package's “real” name was “s” all along.  For  such  packages  of  long
316       pedigree, groff accommodates different users' expectations by supplying
317       wrapper macro files that load  the  desired  file  with  mso  requests.
318       Thus, all of “groff -m s”, “groff -m ms”, “groff -ms”, and “groff -mms
319       serve to load the manuscript macros.
320
321       Wrappers are not provided for packages of  more  recent  vintage,  like
322       www.tmac.
323
324       As  noted  in  passing  above, AT&T troff named macro files in the form
325       tmac.name.  It has since become conventional in  operating  systems  to
326       use a suffixed file name extension to suggest a file type or format.
327

Inclusion

329       The  traditional  method of employing a macro package is to specify the
330       -m package option to the formatter, which then  reads  package's  macro
331       file  prior  to any input files.  Historically, package was sought in a
332       file named tmac.package (that is, with a “tmac.”  prefix).   GNU  troff
333       searches for package.tmac in the macro path; if not found, it looks for
334       tmac.package instead, and vice versa.
335
336       Alternatively, one could include a macro file by using the request “.so
337       file-name” in the document; file-name is resolved relative to the loca‐
338       tion of the input document.  GNU troff offers an  improved  feature  in
339       the  similar  request “mso package-file-name”, which searches the macro
340       path for package-file-name.  Because its argument is a file  name,  its
341.tmac”  component  must be included for the file to be found; however,
342       as a convenience, if opening it fails, mso strips any such  suffix  and
343       tries again with a “tmac.” prefix, and vice versa.
344
345       If  a  sourced  file requires preprocessing, for example if it includes
346       tbl tables or eqn equations, the preprocessor soelim(1) must  be  used.
347       This can be achieved with a pipeline or, in groff, by specifying the -s
348       option to the formatter (or front end).  man(1) librarian programs gen‐
349       erally call soelim automatically.  (Macro packages themselves generally
350       do not require preprocessing.)
351

Writing macros

353       A roff(7) document is a text file that is enriched by  predefined  for‐
354       matting  constructs,  such  as requests, escape sequences, strings, nu‐
355       meric registers, and macros from a macro package.  These  elements  are
356       described in roff(7).
357
358       To  give  a  document a personal style, it is most useful to extend the
359       existing elements by defining some macros for repeating tasks; the best
360       place  for  this is near the beginning of the document or in a separate
361       file.
362
363       Macros without arguments are just like strings.  But the full power  of
364       macros  occurs when arguments are passed with a macro call.  Within the
365       macro definition, the arguments are available as the  escape  sequences
366       \$1,  ...,  \$9,  \$[...], \$*, and \$@, the name under which the macro
367       was called is in \$0, and  the  number  of  arguments  is  in  register
368       \n[.$]; see groff(7).
369
370   Draft mode
371       Writing groff macros is easy when the escaping mechanism is temporarily
372       disabled.  In groff, this is done by enclosing the macro  definition(s)
373       within a pair of .eo and .ec requests.  Then the body in the macro def‐
374       inition is just like a normal part of the document — text  enhanced  by
375       calls  of  requests, macros, strings, registers, etc.  For example, the
376       code above can be written in a simpler way by
377
378              .eo
379              .ds midpart was called with the following
380              .de print_args
381              \f[I]\$0\f[] \*[midpart] \n[.$] arguments:
382              \$*
383              ..
384              .ec
385
386       Unfortunately, draft mode cannot be used universally.  Although  it  is
387       good  enough for defining normal macros, draft mode fails with advanced
388       applications, such as indirectly defined strings, registers,  etc.   An
389       optimal  way is to define and test all macros in draft mode and then do
390       the backslash doubling as a final step; do not forget to remove the .eo
391       request.
392
393   Tips for macro definitions
394       •      Start every line with a dot, for example, by using the groff re‐
395              quest .nop for text lines, or write your own macro that  handles
396              also text lines with a leading dot.
397
398                     .de Text
399                     .  if (\\n[.$] == 0) \
400                     .    return
401                     .  nop \)\\$*\)
402                     ..
403
404       •      Write  a comment macro that works both for copy and draft modes;
405              since the escape character is off in draft mode,  trouble  might
406              occur  when comment escape sequences are used.  For example, the
407              following macro just ignores its arguments, so it  acts  like  a
408              comment line:
409
410                     .de c
411                     ..
412                     .c This is like a comment line.
413
414       •      In  long  macro  definitions, make ample use of comment lines or
415              almost-empty lines (this is, lines which have a leading dot  and
416              nothing else) for a better structuring.
417
418       •      To  increase  readability,  use groff's indentation facility for
419              requests and macro calls (arbitrary whitespace after the leading
420              dot).
421
422   Diversions
423       Diversions  can  be  used  to implement quite advanced programming con‐
424       structs.  They are comparable to pointers to large data  structures  in
425       the C programming language, but their usage is quite different.
426
427       In  their  simplest form, diversions are multi-line strings, but diver‐
428       sions get their power when used dynamically within macros.   The  (for‐
429       matted)  information  stored in a diversion can be retrieved by calling
430       the diversion just like a macro.
431
432       Most of the problems arising with diversions can be avoided if you  re‐
433       member  that  diversions always store complete lines.  Using diversions
434       when the line buffer has not been flushed produces strange results; not
435       knowing  this,  many  people get desperate about diversions.  To ensure
436       that a diversion works, add line breaks at the  right  places.   To  be
437       safe,  enclose  everything that has to do with diversions within a pair
438       of line breaks; for example, by explicitly using  .br  requests.   This
439       rule  should  be  applied to diversion definition, both inside and out‐
440       side, and to all calls of diversions.  This is a bit of  overkill,  but
441       it works nicely.
442
443       (If  you really need diversions which should ignore the current partial
444       line, use environments to save the current partial line and/or use  the
445       .box request.)
446
447       The  most  powerful  feature  using  diversions is to start a diversion
448       within a macro definition and end it within another macro.  Then every‐
449       thing  between each call of this macro pair is stored within the diver‐
450       sion and can be manipulated from within the macros.
451

Authors

453       This document was written by  Bernd  Warken  ⟨groff-bernd.warken-72@web
454       .de⟩,  Werner  Lemberg ⟨wl@gnu.org⟩, and G. Branden Robinson ⟨g.branden
455       .robinson@gmail.com⟩.
456

See also

458       Groff: The GNU Implementation of troff, by Trent A. Fisher  and  Werner
459       Lemberg,  is the primary groff manual.  You can browse it interactively
460       with “info groff”.
461
462       The Filesystem  Hierarchy  Standard  ⟨https://wiki.linuxfoundation.org/
463       lsb/fhs⟩ is maintained by the Linux Foundation.
464
465       groff(1)
466              is an overview of the groff system.
467
468       groff_man(7),
469       groff_mdoc(7),
470       groff_me(7),
471       groff_mm(7),
472       groff_mom(7),
473       groff_ms(7),
474       groff_rfc1345(7),
475       groff_trace(7),
476               and
477       groff_www(7)
478              are groff macro packages.
479
480       groff(7)
481              summarizes the language recognized by GNU troff.
482
483       troff(1)
484              documents the default macro file search path.
485
486
487
488groff 1.23.0                    2 November 2023                  groff_tmac(5)
Impressum