# groff_tmac

## Name



           groff_tmac - macro files in the GNU _roff_ typesetting system
    


## Description



           Definitions of macros, strings, and registers for use in a _roff_(7)
           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_.  The “tmac” name originated in early Unix culture as an
           abbreviation of “ _troff_ macros”.
    
           Macro packages can be loaded by supplying the **-m** option to
           _troff_(1) or a _groff_ front end.  A macro file's name must have 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) lists these directories.  Alternatively, a _groff_
           document requiring a macro file can load it with the **mso**(“macro
           source”) request.
    
           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.
    
           Encode macro files in ISO 646:1991 IRV (US-ASCII) or ISO Latin-1
           (8859-1).  To prepare for a future _groff_ release supporting UTF-8
           input, restrict files to ISO 646 codes.  _soelim_(1) by design does
           not interpret **mso** requests, and the encodings used by documents
           employing a macro file can vary.
    


## Macro packages



           Some macro packages assume responsibility for page layout and
           other critical functions (“major” or “full-service”); others do
           not (“supplemental” or “auxiliary”).  GNU _roff_ provides most major
           macro packages found in AT&T and BSD Unix systems, an additional
           full-service package, and many supplemental packages.  Multiple
           full-service macro packages cannot be used by the same document.
           Auxiliary packages can, in general, be freely combined, though
           attention to their use of the _groff_ language name spaces for
           identifiers (particularly registers, macros, strings, and
           diversions) should be paid.  Name space management challenged AT&T
           _troff_ users; GNU _troff_ '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**
           Two full-service macro packages are specialized for formatting
           Unix reference manuals; they do not support features like
           footnotes or multiple columnation.
    
           _an_     constructs man pages in a format introduced by Seventh
                  Edition Unix (1979).  Its macro interface is small, and the
                  package widely used; see _groff_man_(7).
    
           _doc_    constructs man pages in a format introduced by 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).
    
           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_  recognizes a document's use of _an_ or _doc_ and loads the
                  corresponding macro package.  Multiple man pages, in either
                  format, can be handled; _andoc_ reloads each macro package as
                  necessary.
    
       **General full-service packages**
           The following packages each support composition of documents of
           any kind, from single-page memos to lengthy monographs.  They are
           similar in functionality; select one that suits your taste.
    
           _me_     originates in 2BSD (1978); see _groff_me_(7).
    
           _mm_     originates in Programmer's Workbench (PWB) Unix 1.0 (1977);
                  see _groff_mm_(7).
    
           _mom_    was contributed to _groff_ in 2002, and freely exercises its
                  many extended features.  See _groff_mom_(7).
    
           _ms_     originates in Sixth Edition Unix (1975); see _groff_ms_(7).
    
       **Localization packages**
           For Western languages, an auxiliary package for localization 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 encoding (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.  Sets the input encoding to Latin-1 by loading
                  _latin1.tmac_.
    
           _es_     Spanish; localizes _man_ , _me_ , _mm_ , _mom_ , and _ms_.  Sets the
                  input encoding to Latin-9 by loading _latin9.tmac_.
    
           _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_.  Sets the
                  input encoding to Latin-1 by loading _latin1.tmac_.
    
           _ja_     Japanese.
    
           _ru_     Russian; localizes _man_ , _me_ , _mm_ , _mom_ , and _ms_.  Sets the
                  input encoding to KOI8-R by loading _koi8-r.tmac_.
    
           _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 separately;
                  see _groff_mmse_(7).
    
           _zh_     Chinese.
    
       **Input encodings**
           Localization influences automatic hyphenation in two distinct but
           related respects.  A macro file specific to a character coding
           identifies which character codes correspond to letters expected in
           the language's hyphenation pattern files and sets up case
           equivalences for those letters.  A language's macro file
           determines which of these letters are equivalent to other letters
           for hyphenation purposes.
    
           For example, in English, the letter “ñ” occurs in loan words.  The
           _latin1.tmac_ and _latin9.tmac_ macro files define a hyphenation code
           for “ñ” and make “Ñ” equivalent to it.  The English localization
           file _en.tmac_ furthermore makes “ñ” equivalent to “n”.  In Spanish
           (_es.tmac_), however, “ñ” and “n” are _not_ equivalent.  The language
           localization file loads an appropriate encoding localization file;
           a document need not do so directly.
    
           _latin1_
           _latin2_
           _latin5_
           _latin9_ support the ISO Latin-1, Latin-2, Latin-5, and Latin-9
                  encodings (8859-1, 8859-2, 8859-9, and 8859-15,
                  respectively).
    
           _koi8-r_ supports the KOI8-R encoding.  KOI8-R code points in the
                  range 0x80–0x9F are not valid input to GNU _troff_ ; see
                  section “Identifiers” in _groff_(7).  This should be no
                  impediment to practical documents, as these KOI8-R code
                  points do not encode letters, but box-drawing symbols and
                  characters that are better obtained via special character
                  escape sequences; see _groff_char_(7).
    
       **General auxiliary packages**
           The macro packages in this section are not intended for stand-
           alone use, but can add functionality to any other macro package or
           to plain (“raw”) _groff_ documents.
    
           _62bit_  provides macros for addition, multiplication, and division
                  of 62-bit integers (allowing 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).  It works only
                  with the **ps** and **pdf** output devices.  See _groff_hdtbl_(7).
    
           _papersize_
                  enables the paper format to be set on the command line with
                  the “**-d paper=**_fmt_ ” option to _troff_.  Valid _fmt_ s 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 longer
                  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 orientation,
                  respectively, defined in its _DESC_ file; see subsection
                  “Paper format” of _groff_(1).  This macro file is normally
                  loaded at startup by the _troffrc_ file when formatting for a
                  typesetter (but not a terminal).
    
           _pdfpic_ provides a single macro, **PDFPIC** , that operates in two
                  modes.  If it is not used with _gropdf_ , the given _file_ must
                  be a PDF; **PDFPIC** then relies on the external program
                  _pdftops_(1) to convert the PDF to an encapsulated PostScript
                  (EPS) file and calls the **PSPIC** macro with which it shares
                  an interface.  If output is to a PDF, **PDFPIC** uses the “**pdf:**
                  **pdfpic** ” device extension command (see _gropdf_(1)); the given
                  _file_ can then be a PDF or any graphic file format supported
                  by _gropdf_.
    
                  Since **PDFPIC** needs to discover the width and height of the
                  image (to check if sufficient room exists to place it on
                  the page), it has dependencies on external programs as
                  shown below.
    
                        ┌───────┬────────────┬─────────┬─────────────┐
                        │       │ _pdfinfo_(1) │ _file_(1) │ _identify_(1) │
                        ├───────┼────────────┼─────────┼─────────────┤
                        │ _.pdf_  │     ✓      │    ✓    │      ✓      │
                        ├───────┼────────────┼─────────┼─────────────┤
                        │ _.jpg_  │     ✗      │    ✓    │      ✓      │
                        ├───────┼────────────┼─────────┼─────────────┤
                        │ _.jp2_  │     ✗      │    ✗    │      ✓      │
                        ├───────┼────────────┼─────────┼─────────────┤
                        │ other │     ✗      │    ✗    │      ✓      │
                        └───────┴────────────┴─────────┴─────────────┘
    
                  To include image formats such as PNG, PAM, and GIF, _gropdf_
                  relies upon PerlMagick modules to embed the graphic.  They
                  are not needed for the types listed in the table above.
    
                  If the required programs are not available, _file_ is treated
                  as a PDF; failure is likely if it is not one.
    
           _pic_    supplies definitions of the macros **PS** , **PE** , **PF** , and **PY** , used
                  with the _pic_(1) preprocessor.  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 image'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 uniformly 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) program.  If your formatting
                  needs differ, copy the macro into your document and adapt
                  it.
    
           _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).
    
           _sboxes_ offers an interface to the “**pdf: background** ” device
                  extension command supported by _gropdf_(1).  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 after **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 that 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_ numeric 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) 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”
                  ⟨file:///usr/local/share/doc/groff-1.23.0/msboxes.pdf⟩ for
                  a demonstration.
    
           _trace_  aids the debugging of _groff_ documents by tracing macro
                  calls.  See _groff_trace_(7).
    
           _www_    defines macros corresponding to HTML elements.  See
                  _groff_www_(7).
    


## Naming



           AT&T _nroff_ and _troff_ were implemented before the conventions of
           the modern C _getopt_(3) call evolved, and used a naming scheme for
           macro packages that looks oddly terse to modern eyes.  The
           formatter's **-m** option was the main means of loading a macro
           package, and its argument had to follow immediately without
           intervening space.  This looked like a long option name 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**.  It has since
           become conventional in operating systems to use a suffixed file
           name extension to suggest a file type or format, thus we see _roff_
           documents with names ending in _.man_ , _.me_ , and so on.
    
           _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 convention, 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.
    


## 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.  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 with the request “**so**
           _file-name_ ”; the argument is resolved as _fopen_(3) would, from the
           current working directory of the formatter.  This approach was
           inadequate to locate macro packages, since systems stored them in
           varying locations.  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.
    
           If a sourced file requires preprocessing, for example if it
           includes _tbl_ tables or _eqn_ equations, the preprocessor _soelim_(1)
           must be used.  This can be achieved with a pipeline or by
           specifying the **-s** option to _groff_(1).  _man_(1) librarian programs
           typically run _soelim_ automatically.  (As a rule, macro packages
           themselves do not require preprocessing.)
    


## Writing macros



           A _roff_(7) 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.
           _roff_(7) describes these elements.
    
           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 arguments are passed with a macro
           call.  Within the macro definition, the arguments are available 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).
    
       **Drafting macros**
           One approach temporarily disables escape sequences by bracketing a
           macro definition with **eo** and **ec** requests.
    
                  .eo
                  .ds midpart was called with the following
                  .de print_args
                  \f[I]\$0\f[] \*[midpart] \n[.$] arguments: \$*
                  ..
                  .ec
    
           The above procedure has limitations; it is unsuitable for a macro
           that requires certain interpolations at the time it is defined, or
           for indirect definitions of identifiers.  See section “Copy mode”
           of _groff_(7).  In such cases, you might define and test the macro
           with the escape character doubled before escape sequences that are
           interpreted even in copy mode, then bracket it with **eo** and **ec**
           requests, un-double the escape characters, then test again.
    
       **Tips for macro definitions**
           •  Use only control lines in macro definitions; that is, start
              every input line with a control character.  _groff_ 's **nop** request
              makes use of text lines unnecessary.
    
                     .de Text
                     .  if (\\n[.$] == 0) \
                     .    return
                     .  nop \&\\$*\&
                     ..
    
           •  Write a comment macro that works in both draft and non-draft
              modes; since the escape character is disabled in draft mode,
              trouble might occur when comment escape sequences are used.
    
                     .de c
                     ..
                     .c This is my comment.
    
           •  Comment lengthy macro definitions.
    
           •  Use empty requests, and indentation after control characters,
              to clarify a macro's structure.
    


## Authors



           This document was written by Werner Lemberg ⟨wl@gnu.org⟩ and G.
           Branden Robinson ⟨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”.
    
           _groff_(1)
                  is an overview of the _groff_ system.
    
           _groff_man_(7),
           _groff_mdoc_(7),
           _groff_me_(7),
           _groff_mm_(7),
           _groff_mom_(7),
           _groff_ms_(7),
           _groff_rfc1345_(7),
           _groff_trace_(7),
           and
           _groff_www_(7)
                  are _groff_ macro packages.
    
           _groff_(7)
                  summarizes the language recognized by GNU _troff_.
    
           _troff_(1)
                  documents the default macro file search path.
    


* * *