# groff_tmac - macro files in the GNU roff typesetting system - man(5) - [phpMan]

[_groff_tmac_(5)](https://www.chedong.com/phpMan.php/man/grofftmac/5/markdown)                            File Formats Manual                           [_groff_tmac_(5)](https://www.chedong.com/phpMan.php/man/grofftmac/5/markdown)

## Name
       groff_tmac - macro files in the GNU _roff_ typesetting system

## Description
       Definitions  of macros, strings, and registers for use in a [_roff_(7)](https://www.chedong.com/phpMan.php/man/roff/7/markdown) document can be collected
       into _macro_ _files_, _roff_ input files designed to produce no output themselves but instead  ease
       the  preparation of other _roff_ documents.  There is no syntactical difference between a macro
       file and any other _roff_ document; only its purpose distinguishes it.  When a  macro  file  is
       installed  at  a standard location, named according to a certain convention, and suitable for
       use by a general audience, it is termed a _macro_ _package_.  Macro packages  can  be  loaded  by
       supplying the **-m **option to [_troff_(1)](https://www.chedong.com/phpMan.php/man/troff/1/markdown) or a _groff_ front end.

       Each  macro  package  stores  its macro, string, and register definitions in one or more _tmac_
       files.  This name originated in early Unix culture as an abbreviation of “_troff_ macros”.

       A macro file must have a name in the form name_.tmac_ (or _tmac._name) and be placed in  a  “_tmac_
       directory”  to  be  loadable with the **-m_**name_ option.  Section “Environment” of [_troff_(1)](https://www.chedong.com/phpMan.php/man/troff/1/markdown) lists
       these directories.  Alternatively, a _groff_ document requiring a macro file can load  it  with
       the **mso **(“macro source”) request.

       Like  any  other _roff_ document, a macro file can use the “**so**” request (“source”) to load fur‐
       ther files relative to its own location.

       Macro files are named for their most noteworthy application, but a macro file need not define
       any macros.  It can restrict itself to defining registers and strings or invoking other _groff_
       requests.  It can even be empty.

## Macro packages
       Macro packages come in two varieties; those which assume responsibility for page  layout  and
       other  critical  functions (“major” or “full-service”) and those which do not (“supplemental”
       or “auxiliary”).  GNU _roff_ provides most major macro packages found in AT&T and BSD Unix sys‐
       tems, an additional full-service package, and many supplemental packages.  Multiple full-ser‐
       vice macro packages cannot be used by the same document.  Auxiliary packages can generally be
       freely combined, though attention to their use of the _groff_ language name spaces for  identi‐
       fiers  (particularly  registers, macros, strings, and diversions) should be paid.  Name space
       management was a significant challenge in AT&T _troff_; _groff_'s support  for  arbitrarily  long
       identifiers  affords  few  excuses  for name collisions, apart from attempts at compatibility
       with the demands of historical documents.

### Man pages
       _an_
       _man_    _an_ is used to compose man pages in the format originating in Version  7  Unix  (1979).
              It has a small macro interface and is widely used; see [_groff_man_(7)](https://www.chedong.com/phpMan.php/man/groffman/7/markdown).

       _doc_
       _mdoc_   _doc_  is used to compose man pages in the format originating in 4.3BSD-Reno (1990).  It
              provides many more features than _an_, but is also larger,  more  complex,  and  not  as
              widely adopted; see [_groff_mdoc_(7)](https://www.chedong.com/phpMan.php/man/groffmdoc/7/markdown).

       Because  readers  of man pages often do not know in advance which macros are used to format a
       given document, a wrapper is available.

       _andoc_
       _mandoc_ This macro file, specific to _groff_, recognizes whether a document  uses  _man_  or  _mdoc_
              format  and loads the corresponding macro package.  Multiple man pages, in either for‐
              mat, can be handled; _andoc_ reloads each macro package as necessary.

### Full-service packages
       The packages in this section provide a complete set of macros for writing  documents  of  any
       kind,  up  to  whole books.  They are similar in functionality; it is a matter of taste which
       one to use.

       _me_     The classical _me_ macro package; see [_groff_me_(7)](https://www.chedong.com/phpMan.php/man/groffme/7/markdown).

       _mm_     The semi-classical _mm_ macro package; see [_groff_mm_(7)](https://www.chedong.com/phpMan.php/man/groffmm/7/markdown).

       _mom_    The _mom_ macro package, only available in groff.  As this was not based on other  pack‐
              ages, it was freely designed as quite a nice, modern macro package.  See [_groff_mom_(7)](https://www.chedong.com/phpMan.php/man/groffmom/7/markdown).

       _ms_     The classical _ms_ macro package; see [_groff_ms_(7)](https://www.chedong.com/phpMan.php/man/groffms/7/markdown).

### Localization packages
       For  Western languages, the localization file sets the hyphenation mode and loads hyphenation
       patterns and exceptions.  Localization files can also adjust  the  date  format  and  provide
       translations  of strings used by some of the full-service macro packages; alter the input en‐
       coding (see the next section); and change the amount of additional inter-sentence space.  For
       Eastern languages, the localization file defines character classes and sets  flags  on  them.
       By default, _troffrc_ loads the localization file for English.

       _trans_  loads  localized  strings  used  by various macro packages after their localized forms
              have been prepared by a localization macro file.

       _groff_ provides the following localization files.

       _cs_     Czech; localizes _man_, _me_, _mm_, _mom_, and _ms_.  Sets the  input  encoding  to  Latin-2  by
              loading _latin2.tmac_.

       _de_
       _den_    German;  localizes  _man_,  _me_,  _mm_, _mom_, and _ms_.  Sets the input encoding to Latin-1 by
              loading _latin1.tmac_.

              _de.tmac_ selects hyphenation patterns for traditional orthography,  and  _den.tmac_  does
              the same for the new orthography (“Rechtschreibreform”).

       _en_     English.

       _fr_     French;  localizes  _man_,  _me_,  _mm_, _mom_, and _ms_.  Sets the input encoding to Latin-9 by
              loading _latin9.tmac_.

       _it_     Italian; localizes _man_, _me_, _mm_, _mom_, and _ms_.

       _ja_     Japanese.

       _sv_     Swedish; localizes _man_, _me_, _mm_, _mom_, and _ms_.  Sets the input encoding  to  Latin-1  by
              loading  _latin1.tmac_.   Some  of  the  localization of the _mm_ package is handled sepa‐
              rately; see [_groff_mmse_(7)](https://www.chedong.com/phpMan.php/man/groffmmse/7/markdown) (only in Swedish locales).

       _zh_     Chinese.

### Input encodings
       _latin1_
       _latin2_
       _latin5_
       _latin9_ are various ISO 8859 input encodings supported by _groff_.  On systems using ISO charac‐
              ter encodings, _groff_ loads _latin1.tmac_ automatically at startup.  A document that uses
              Latin-2, Latin-5, or Latin-9 can specify one of these alternative encodings.

       _cp1047_ provides  support  for  EBCDIC-based  systems.   On  those  platforms,   _groff_   loads
              _cp1047.tmac_ automatically at startup.

       Because  different  input  character codes constitute valid GNU _troff_ input on ISO and EBCDIC
       systems, the _latin_ macro files cannot be used on EBCDIC systems, and _cp1047_ cannot be used on
       ISO systems.

### Auxiliary packages
       The macro packages in this section are not intended for stand-alone use, but  can  add  func‐
       tionality to any other macro package or to plain (“raw”) _groff_ documents.

       _62bit_  provides  macros for addition, multiplication, and division of 62-bit integers (allow‐
              ing safe multiplication of signed 31-bit integers, for example).

       _hdtbl_  allows the generation of tables using a syntax similar to the HTML table model.   This
              Heidelberger  table  macro  package  is not a preprocessor, which can be useful if the
              contents of table entries are determined by  macro  calls  or  string  interpolations.
              Compare  to  [_tbl_(1)](https://www.chedong.com/phpMan.php/man/tbl/1/markdown).   It  works  only  with  the  **ps  **and  **pdf  **output  devices.  See
              [_groff_hdtbl_(7)](https://www.chedong.com/phpMan.php/man/groffhdtbl/7/markdown).

       _papersize_
              enables the paper format to be set on the command line by giving a  “**-d  paper=_**format_”
              option  to  _troff_.   Possible  values  for _format_ are the ISO and DIN formats “**A0**–**A6**”,
              “**B0**–**B6**”,  “**C0**–**C6**”,  and  “**D0**–**D6**”;  the  U.S.  formats  “**letter**”,  “**legal**”,  “**tabloid**”,
              “**ledger**”,  “**statement**”,  and “**executive**”; and the envelope formats “**com10**”, “**monarch**”,
              and “**DL**”.  All formats, even those for envelopes, are  in  portrait  orientation:  the
              length measurement is vertical.  Appending “l” (ell) to any of these denotes landscape
              orientation  instead.   This  macro file assumes one-inch horizontal margins, and sets
              registers recognized by the _groff_ _man_, _mdoc_, _mm_, _mom_, and  _ms_  packages  to  configure
              them accordingly.  If you want different margins, you will need to use those packages'
              facilities, or _troff_ **ll **and/or **po **requests to adjust them.  An output device typically
              requires  command-line options **-p **and **-l **to override the paper dimensions and orienta‐
              tion, respectively, defined in  its  _DESC_  file;  see  subsection  “Paper  format”  of
              [_groff_(1)](https://www.chedong.com/phpMan.php/man/groff/1/markdown).  This macro file is normally loaded at startup by the _troffrc_ file when for‐
              matting for a typesetting device (but not a terminal).

       _pdfpic_ provides a single macro, **PDFPIC**, to include a PDF graphic in a document using features
              of the **pdf **output driver.  For other output devices, **PDFPIC **calls **PSPIC**, with which it
              shares an interface (see below).  This macro file is normally loaded at startup by the
              _troffrc_ file.

       _pic_    supplies  definitions  of the macros **PS**, **PE**, and **PF**, usable with the [_pic_(1)](https://www.chedong.com/phpMan.php/man/pic/1/markdown) preproces‐
              sor.  They center each picture.  Use it if your document does not use  a  full-service
              macro  package, or that package does not supply working _pic_ macro definitions.  Except
              for _man_ and _mdoc_, those provided with _groff_ already do so (exception: _mm_  employs  the
              name **PF **for a different purpose).

       _pspic_  provides  a  macro,  **PSPIC**, that includes a PostScript graphic in a document.  The **ps**,
              **dvi**, **html**, and **xhtml **output devices support such inclusions; for  all  other  drivers,
              the  image  is  replaced  with  a  rectangular border of the same size.  _pspic.tmac_ is
              loaded at startup by the _troffrc_ file.

              Its syntax is as follows.

                     **.PSPIC **[**-L**|**-R**|**-C**|**-I _**n_] _file_ [_width_ [_height_]]

              _file_ is the name of the PostScript file; _width_ and _height_ give the desired  width  and
              height  of  the image.  If neither a _width_ nor a _height_ argument is specified, the im‐
              age's natural width (as given in the file's bounding box) or the current  line  length
              is  used  as  the width, whatever is smaller.  The _width_ and _height_ arguments may have
              scaling units attached; the default scaling unit is **i**.  **PSPIC **scales the graphic  uni‐
              formly in the horizontal and vertical directions so that it is no more than _width_ wide
              and _height_ high.  Option **-C **centers the graphic horizontally; this is the default.  **-L**
              and  **-R  **left- and right-align the graphic, respectively.  **-I **indents the graphic by _n_
              (with a default scaling unit of **m**).

              To use **PSPIC **within a diversion, we recommend extending it with  the  following  code,
              assuring that the diversion's width completely covers the image's width.

                     .am PSPIC
                     .  vpt 0
                     \h'(\\n[ps-offset]u + \\n[ps-deswid]u)'
                     .  sp -1
                     .  vpt 1
                     ..

              Failure  to load **PSPIC**'s image argument is not an error.  (The **psbb **request does issue
              an error diagnostic.)  To make such a failure fatal, append  to  the  **pspic*error-hook**
              macro.

                     .am pspic*error-hook
                     .  ab
                     ..

       _ptx_    provides  a  macro, **xx**, to format permuted index entries as produced by the GNU [_ptx_(1)](https://www.chedong.com/phpMan.php/man/ptx/1/markdown)
              program.  If your formatting needs differ, copy the macro into your document and adapt
              it to your needs.

       _rfc1345_
              defines special character escape sequences named for the glyph mnemonics specified  in
              RFC 1345 and the digraph table of the Vim text editor.  See [_groff_rfc1345_(7)](https://www.chedong.com/phpMan.php/man/groffrfc1345/7/markdown).

       _sboxes_ offers  an  interface  to  the  “**pdf:  background**” device control command supported by
              [_gropdf_(1)](https://www.chedong.com/phpMan.php/man/gropdf/1/markdown).  Using this package, _groff_ _ms_ documents can draw colored rectangles beneath
              any output.

              **.BOXSTART SHADED _**color_ **OUTLINED _**color_ **INDENT _**size_ **WEIGHT _**size_
                     begins a box, where the argument after **SHADED **gives the fill color and that af‐
                     ter **OUTLINED **the border color.  Omit the former to get a borderless filled  box
                     and  the latter for a border with no fill.  The specified **WEIGHT **is used if the
                     box is **OUTLINED**.

                     **INDENT **precedes a value which leaves a gap between the border and the  contents
                     inside the box.

                     Each  _color_ must be a defined _groff_ color name, and each _size_ a valid _groff_ nu‐
                     meric expression.  The keyword/value pairs can be specified in any order.

              Boxes can be stacked, so you can start a box within another  box;  usually  the  later
              boxes  would be smaller than the containing box, but this is not enforced.  When using
              **BOXSTART**, the left position is the current indent minus the **INDENT **in the command, and
              the right position is the left position  (calculated  above)  plus  the  current  line
              length and twice the indent.

              **.BOXSTOP**
                     takes  no  parameters.   It closes the most recently started box at the current
                     vertical position after adding its **INDENT **spacing.

              Your _groff_ documents can conditionally exercise the _sboxes_ macros.  The register **GSBOX**
              is defined if the package is loaded, and interpolates a true value if the  **pdf  **output
              device is in use.

              _sboxes_  furthermore  hooks  into the [_groff_ms_(7)](https://www.chedong.com/phpMan.php/man/groffms/7/markdown) package to receive notifications when
              footnotes are growing, so that it can close boxes  on  a  page  before  footnotes  are
              printed.   When  that condition obtains, _sboxes_ will close open boxes two points above
              the footnote separator and re-open them on the next page.  (This amount probably  will
              not match the box's **INDENT**.)

              See “Using PDF boxes with _groff_ and the _ms_ macros” for a demonstration.

       _trace_  aids the debugging of _groff_ documents by tracing macro calls.  See [_groff_trace_(7)](https://www.chedong.com/phpMan.php/man/grofftrace/7/markdown).

       _www_    defines macros corresponding to HTML elements.  See [_groff_www_(7)](https://www.chedong.com/phpMan.php/man/groffwww/7/markdown).

## Naming
       AT&T  _nroff_  and _troff_ were implemented before the conventions of the modern C [_getopt_(3)](https://www.chedong.com/phpMan.php/man/getopt/3/markdown) call
       evolved, and used a naming scheme for macro packages that looks odd to  modern  eyes.   Macro
       packages  were  typically loaded using the **-m **option to the formatter; when directly followed
       by its argument without an intervening space, this looked like a long option  preceded  by  a
       single  minus—a  sensation  in  the  computer stone age.  Macro packages therefore came to be
       known by names that started with the letter “m”, which was omitted from the name of the macro
       file as stored on disk.  For example, the manuscript macro package was stored as  _tmac.s_  and
       loaded with the option **-ms**.

       _groff_  commands  permit  space  between  an option and its argument.  The syntax “**groff -m s**”
       makes the macro file name more clear but may surprise users familiar with the  original  con‐
       vention, unaware that the package's “real” name was “s” all along.  For such packages of long
       pedigree,  _groff_  accommodates different users' expectations by supplying wrapper macro files
       that load the desired file with **mso **requests.  Thus, all of “**groff  -m  s**”,  “**groff  -m  ms**”,
       “**groff -ms**”, and “**groff -mms**” serve to load the manuscript macros.

       Wrappers are not provided for packages of more recent vintage, like _www.tmac_.

       As  noted in passing above, AT&T _troff_ named macro files in the form _tmac._name.  It has since
       become conventional in operating systems to use a suffixed file name extension to  suggest  a
       file type or format.

## Inclusion
       The  traditional  method  of employing a macro package is to specify the **-m _**package_ option to
       the formatter, which then reads _package_'s macro file prior to any input files.  Historically,
       _package_ was sought in a file named _tmac._package (that is, with a “**tmac.**” prefix).  GNU  _troff_
       searches for package_.tmac_ in the macro path; if not found, it looks for _tmac._package instead,
       and vice versa.

       Alternatively,  one  could  include  a macro file by using the request “**.so _**file-name_” in the
       document; _file-name_ is resolved relative to the location of the input  document.   GNU  _troff_
       offers an improved feature in the similar request “**mso _**package-file-name_”, which searches the
       macro path for _package-file-name_.  Because its argument is a file name, its “**.tmac**” component
       must  be  included  for the file to be found; however, as a convenience, if opening it fails,
       **mso **strips any such suffix and tries again with a “**tmac.**” prefix, and vice versa.

       If a sourced file requires preprocessing, for example if it includes _tbl_ tables or _eqn_  equa‐
       tions,  the preprocessor [_soelim_(1)](https://www.chedong.com/phpMan.php/man/soelim/1/markdown) must be used.  This can be achieved with a pipeline or, in
       _groff_, by specifying the **-s **option to the formatter (or front end).   [_man_(1)](https://www.chedong.com/phpMan.php/man/man/1/markdown)  librarian  pro‐
       grams  generally  call _soelim_ automatically.  (Macro packages themselves generally do not re‐
       quire preprocessing.)

## Writing macros
       A [_roff_(7)](https://www.chedong.com/phpMan.php/man/roff/7/markdown) document is a text file that is enriched by predefined formatting constructs,  such
       as  requests,  escape sequences, strings, numeric registers, and macros from a macro package.
       These elements are described in [_roff_(7)](https://www.chedong.com/phpMan.php/man/roff/7/markdown).

       To give a document a personal style, it is most useful to extend  the  existing  elements  by
       defining  some  macros  for repeating tasks; the best place for this is near the beginning of
       the document or in a separate file.

       Macros without arguments are just like strings.  But the full power of macros occurs when ar‐
       guments are passed with a macro call.  Within the macro definition, the arguments are  avail‐
       able  as  the escape sequences **\$1**, ..., **\$9**, **\$[**...**]**, **\$***, and **\$@**, the name under which the
       macro was called is in **\$0**, and the number of arguments is in register **\n[.$]**; see [_groff_(7)](https://www.chedong.com/phpMan.php/man/groff/7/markdown).

### Draft mode
       Writing groff macros is easy when the escaping mechanism is temporarily disabled.  In  groff,
       this  is  done  by  enclosing  the macro definition(s) within a pair of **.eo **and **.ec **requests.
       Then the body in the macro definition is just like a normal part of the document —  text  en‐
       hanced  by  calls  of requests, macros, strings, registers, etc.  For example, the code above
       can be written in a simpler way by

              .eo
              .ds midpart was called with the following
              .de print_args
              \f[I]\$0\f[] \*[midpart] \n[.$] arguments:
              \$*
              ..
              .ec

       Unfortunately, draft mode cannot be used universally.  Although it is good enough for  defin‐
       ing  normal  macros,  draft mode fails with advanced applications, such as indirectly defined
       strings, registers, etc.  An optimal way is to define and test all macros in draft  mode  and
       then do the backslash doubling as a final step; do not forget to remove the _.eo_ request.

### Tips for macro definitions
       •      Start  every  line  with  a dot, for example, by using the groff request **.nop **for text
              lines, or write your own macro that handles also text lines with a leading dot.

                     .de Text
                     .  if (\\n[.$] == 0) \
                     .    return
                     .  nop \)\\$*\)
                     ..

       •      Write a comment macro that works both for copy and draft modes; since the escape char‐
              acter is off in draft mode, trouble might occur  when  comment  escape  sequences  are
              used.   For example, the following macro just ignores its arguments, so it acts like a
              comment line:

                     .de c
                     ..
                     .c This is like a comment line.

       •      In long macro definitions, make ample use of comment lines or almost-empty lines (this
              is, lines which have a leading dot and nothing else) for a better structuring.

       •      To increase readability, use groff's indentation facility for requests and macro calls
              (arbitrary whitespace after the leading dot).

### Diversions
       Diversions can be used to implement quite advanced programming constructs.  They are compara‐
       ble to pointers to large data structures in the C programming language, but  their  usage  is
       quite different.

       In  their  simplest  form,  diversions are multi-line strings, but diversions get their power
       when used dynamically within macros.  The (formatted) information stored in a  diversion  can
       be retrieved by calling the diversion just like a macro.

       Most  of  the problems arising with diversions can be avoided if you remember that diversions
       always store complete lines.  Using diversions when the line buffer has not been flushed pro‐
       duces strange results; not knowing this, many people get desperate about diversions.  To  en‐
       sure that a diversion works, add line breaks at the right places.  To be safe, enclose every‐
       thing that has to do with diversions within a pair of line breaks; for example, by explicitly
       using  **.br  **requests.   This  rule should be applied to diversion definition, both inside and
       outside, and to all calls of diversions.  This is a bit of overkill, but it works nicely.

       (If you really need diversions which should ignore the current partial line, use environments
       to save the current partial line and/or use the **.box **request.)

       The most powerful feature using diversions is to start a diversion within a macro  definition
       and  end  it  within  another macro.  Then everything between each call of this macro pair is
       stored within the diversion and can be manipulated from within the macros.

## Authors
       This document was written by [Bernd Warken](mailto:<groff-bernd.warken-72@web.de>), [Werner Lemberg](mailto:<wl@gnu.org>), and [G. Branden Robinson](mailto:<g.branden.robinson@gmail.com>).

**See also**
       _Groff:_ _The_ _GNU_ _Implementation_ _of_ _troff_, by Trent A. Fisher and Werner Lemberg, is the primary
       _groff_ manual.  You can browse it interactively with “info groff”.

       The [Filesystem Hierarchy Standard](<https://wiki.linuxfoundation.org/lsb/fhs>) is maintained by the Linux Foundation.

       [_groff_(1)](https://www.chedong.com/phpMan.php/man/groff/1/markdown)
              is an overview of the _groff_ system.

       [_groff_man_(7)](https://www.chedong.com/phpMan.php/man/groffman/7/markdown),
       [_groff_mdoc_(7)](https://www.chedong.com/phpMan.php/man/groffmdoc/7/markdown),
       [_groff_me_(7)](https://www.chedong.com/phpMan.php/man/groffme/7/markdown),
       [_groff_mm_(7)](https://www.chedong.com/phpMan.php/man/groffmm/7/markdown),
       [_groff_mom_(7)](https://www.chedong.com/phpMan.php/man/groffmom/7/markdown),
       [_groff_ms_(7)](https://www.chedong.com/phpMan.php/man/groffms/7/markdown),
       [_groff_rfc1345_(7)](https://www.chedong.com/phpMan.php/man/groffrfc1345/7/markdown),
       [_groff_trace_(7)](https://www.chedong.com/phpMan.php/man/grofftrace/7/markdown),
               and
       [_groff_www_(7)](https://www.chedong.com/phpMan.php/man/groffwww/7/markdown)
              are _groff_ macro packages.

       [_groff_(7)](https://www.chedong.com/phpMan.php/man/groff/7/markdown)
              summarizes the language recognized by GNU _troff_.

       [_troff_(1)](https://www.chedong.com/phpMan.php/man/troff/1/markdown)
              documents the default macro file search path.

groff 1.23.0                                31 March 2024                              [_groff_tmac_(5)](https://www.chedong.com/phpMan.php/man/grofftmac/5/markdown)
