GROFF_TMAC(5)          (9 September 2021)           GROFF_TMAC(5)

          groff_tmac - macro files in the roff typesetting system

          The roff(7) type-setting system provides a set of macro
          packages suitable for special kinds of documents.  Each
          macro package stores its macros and definitions in a file
          called the package's tmac file.  The name is deduced from

          The tmac files are normal roff source documents, except that
          they usually contain only definitions and setup commands,
          but no text.  All tmac files are kept in a single or a small
          number of directories, the tmac directories.

          groff provides all classical macro packages, some more full
          packages, and some secondary packages for special purposes.
          Note that it is not possible to use multiple primary macro
          packages at the same time; saying e.g.

               sh# groff -m man -m ms foo


               sh# groff -m man foo -m ms bar

          fails.  Exception to this is the use of man pages written
          with either the mdoc or the man macro package.  See below
          the description of the andoc.tmac file.

          man  This is the classical macro package for Unix manual
               pages (man~pages); it is quite handy and easy to use;
               see groff_man(7).

          doc  mdoc An alternative macro package for man~pages mainly
               used in BSD systems; it provides many new features, but
               it is not the standard for man~pages; see

               mandoc Use this file in case you don't know whether the
               man macros or the mdoc package should be used.  Multi-
               ple man pages (in either format) can be handled.

        Full Packages
          The packages in this section provide a complete set of mac-
          ros for writing documents of any kind, up to whole books.
          They are similar in functionality; it is a matter of taste

     Page 1                    groff 1.22.4          (printed 5/24/22)

     GROFF_TMAC(5)          (9 September 2021)           GROFF_TMAC(5)

          which one to use.

          me   The classical me macro package; see groff_me(7).

          mm   The semi-classical mm macro package; see groff_mm(7).

          mom  The new mom macro package, only available in groff.  As
               this is not based on other packages, it can be freely
               designed.  So it is expected to become quite a nice,
               modern macro package.  See groff_mom(7).

          ms   The classical ms macro package; see groff_ms(7).

        Language-specific Packages
          cs   This file adds support for Czech localization, includ-
               ing the main macro packages (me, mom, mm, and ms).

               Note that cs.tmac sets the input encoding to latin-2.

          de   den German localization support, including the main
               macro packages (me, mom, mm, and ms).

               de.tmac selects hyphenation patterns for traditional
               orthography, and den.tmac does the same for the new
               orthography ([oq]Rechtschreibreform[cq]).  It should be
               used as the last macro package on the command line.

          fr   This file adds support for French localization, includ-
               ing the main macro packages (me, mom, mm, and ms).

                    sh# groff -ms -mfr >

               Note that fr.tmac sets the input encoding to latin-9 to
               get proper support of the [oq]oe[cq] ligature.

          sv   Swedish localization support, including the me, mom,
               and ms macro packages.  Note that Swedish for the mm
               macros is handled separately; see groff_mmse(7) (only
               in Swedish locales).  It should be used as the last
               macro package on the command line.

        Input Encodings
               latin2 latin5 latin9 Various input encodings supported
               directly by groff.  Normally, this macro is loaded at
               the very beginning of a document or specified as the
               first macro argument on the command line.  roff loads
               latin1 by default at start-up.  Note that these macro
               packages don't work on EBCDIC hosts.


     Page 2                    groff 1.22.4          (printed 5/24/22)

     GROFF_TMAC(5)          (9 September 2021)           GROFF_TMAC(5)

               Encoding support for EBCDIC.  On those platforms it is
               loaded automatically at start-up.  Due to different
               character ranges used in roff it doesn't work on archi-
               tectures which are based on ASCII.

          Note that it can happen that some input encoding characters
          are not available for a particular output device.  For exam-
          ple, saying

          groff -Tlatin1 -mlatin9 ...

          fails if you use the Euro character in the input.  Usually,
          this limitation is present only for devices which have a
          limited set of output glyphs (-Tascii, -Tlatin1); for other
          devices it is usually sufficient to install proper fonts
          which contain the necessary glyphs.

        Special Packages
          The macro packages in this section are not intended for
          stand-alone usage, but can be used to add special function-
          ality to any other macro package or to plain groff.

               Provides macros for addition, multiplication, and divi-
               sion of 62-bit integers (allowing safe multiplication
               of 31-bit integers, for example).

          ec   Switch to the EC and TC font families.  To be used with
               grodvi(1) [en] this man page also gives more details of
               how to use it.

               The Heidelberger table macros, contributed by Joachim
               Walsdorff, allow the generation of tables through a
               syntax similar to the HTML table model.  Note that
               hdtbl is a macro package, not a preprocessor like
               tbl(1).  hdtbl works only with the -Tps and -Tpdf out-
               put devices.  See groff_hdtbl(7).

               This macro file is already loaded at start-up by troff
               so it isn't necessary to call it explicitly.  It pro-
               vides an interface to set the paper size on the command
               line with the option B]-dpaper=],I]size].  Possible
               values for size are the same as the predefined
               papersize values in the DESC file (only lowercase; see
               groff_font(5) for more) except a7[en]d7.  An appended l
               (ell) character denotes landscape orientation.  Exam-
               ples: a4, c3l, letterl.

               Most output drivers need additional command-line
               switches -p and -l to override the default paper length

     Page 3                    groff 1.22.4          (printed 5/24/22)

     GROFF_TMAC(5)          (9 September 2021)           GROFF_TMAC(5)

               and orientation as set in the driver-specific DESC
               file.  For example, use the following for PS output on
               A4 paper in landscape orientation:

               sh# groff -Tps -dpaper=a4l -P-pa4 -P-l -ms >

               A single macro is provided in this file, PSPIC, to
               include a PDF graphic in a document, i.e., under the
               output device -Tpdf.  For all other devices, pspic is
               used.  So pdfpic is an extension of pspic. By that you
               can now even replace all PSPIC by PDFPIC, nothing gets
               lost by that.  The options of PDFPIC are identical to
               the PSDIF options.

          pic  This file provides proper definitions for the macros PS
               and PE, needed for the pic(1) preprocessor.  They cen-
               ter each picture.  Use it only if your macro package
               doesn't provide proper definitions for those two macros
               (actually, most of them already do).

               A single macro is provided in this file, PSPIC, to
               include a PostScript graphic in a document.  The fol-
               lowing output devices support inclusion of PS images:
               -Tps, -Tdvi, -Thtml, and -Txhtml; for all other devices
               the image is replaced with a hollow rectangle of the
               same size.  This macro file is already loaded at
               start-up by troff so it isn't necessary to call it


                    .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 argu-
               ments may have scaling indicators attached; the default
               scaling indicator is~i.  This macro scales the graphic
               uniformly in the x and y~directions so that it is no
               more than width wide and height high.  Option -C cen-
               ters the graphic horizontally, which is the default.
               The -L and -R options cause the graphic to be left-
               aligned and right-aligned, respectively.  The -I option
               causes the graphic to be indented by~n (default scaling
               indicator is~m).

               For use of .PSPIC within a diversion it is recommended

     Page 4                    groff 1.22.4          (printed 5/24/22)

     GROFF_TMAC(5)          (9 September 2021)           GROFF_TMAC(5)

               to extend it with the following code, assuring that the
               diversion's width completely covers the image's width.

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

          ptx  A single macro is provided in this file, xx, for for-
               matting permuted index entries as produced by the GNU
               ptx(1) program.  In case you need a different format-
               ting, copy the macro into your document and adapt it to
               your needs.

               Use this for tracing macro calls.  It is only useful
               for debugging.  See groff_trace(7).

               Overrides the definition of standard troff characters
               and some groff characters for TTY devices.  The optical
               appearance is intentionally inferior compared to that
               of normal TTY formatting to allow processing with crit-
               ical equipment.

          www  Additions of elements known from the HTML format, as
               used in the internet (World Wide Web) pages; this
               includes URL links and mail addresses; see

          Classical roff systems were designed before the conventions
          of the modern C getopt(3) call evolved, and used a naming
          scheme for macro packages that looks odd to modern eyes.
          Macro packages were always included with the option -m; when
          this option was directly followed by its argument without an
          intervening space, this looked like a long option preceded
          by a single minus [em] a sensation in the computer stone
          age.  To make this invocation form work, classical troff
          macro packages used names that started with the letter
          [oq]m[cq], which was omitted in the naming of the macro

          For example, the macro package for the man pages was called
          man, while its macro file So it could be activated
          by the argument an to option -m, or -man for short.

          For similar reasons, macro packages that did not start with
          an [oq]m[cq] had a leading [oq]m[cq] added in the documenta-
          tion and in speech; for example, the package corresponding

     Page 5                    groff 1.22.4          (printed 5/24/22)

     GROFF_TMAC(5)          (9 September 2021)           GROFF_TMAC(5)

          to tmac.doc was called mdoc in the documentation, although a
          more suitable name would be doc. For, when omitting the
          space between the option and its argument, the command-line
          option for activating this package reads -mdoc.

          To cope with all situations, actual versions of groff(1) are
          smart about both naming schemes by providing two macro files
          for the inflicted macro packages; one with a leading
          [oq]m[cq] the other one without it.  So in groff, the man
          macro package may be specified as one of the following four

               sh# groff -m man
               sh# groff -man
               sh# groff -mman
               sh# groff -m an

          Recent packages that do not start with [oq]m[cq] do not use
          an additional [oq]m[cq] in the documentation.  For example,
          the www macro package may be specified only as one of the
          two methods:

               sh# groff -m www
               sh# groff -mwww

          Obviously, variants like -mmwww would not make much sense.

          A second strange feature of classical troff was to name
          macro files in the form In modern operating sys-
          tems, the type of a file is specified as a postfix, the file
          name extension.  Again, groff copes with this situation by
          searching both anything.tmac and tmac.anything if only
          anything is specified.

          The easiest way to find out which macro packages are avail-
          able on a system is to check the man~page groff(1), or the
          contents of the tmac directories.

          In groff, most macro packages are described in~man pages
          called groff_I]name](7), with a leading [oq]m[cq] for the
          classical packages.

          There are several ways to use a macro package in a document.
          The classical way is to specify the troff/groff option -m
          name at run-time; this makes the contents of the macro pack-
          age name available.  In groff, the file name.tmac is
          searched within the tmac path; if not found, is
          searched for instead.

          Alternatively, it is also possible to include a macro file
          by adding the request .so filename into the document; the

     Page 6                    groff 1.22.4          (printed 5/24/22)

     GROFF_TMAC(5)          (9 September 2021)           GROFF_TMAC(5)

          argument must be the full file name of an existing file,
          possibly with the directory where it is kept.  In groff,
          this was improved by the similar request .mso package, which
          added searching in the tmac path, just like option -m does.

          Note that in order to resolve the .so and .mso requests, the
          roff preprocessor soelim(1) must be called if the files to
          be included need preprocessing.  This can be done either
          directly by a pipeline on the command line or by using the
          troff/groff option -s.  man calls soelim automatically.

          For example, suppose a macro file is stored as


          and is used in some document called docu.roff.

          At run-time, the formatter call for this is

               sh# groff -m macros docu.roff

          To include the macro file directly in the document either

               .mso macros.tmac

          is used or

               .so /usr/:share/:groff/:1.22.4/:tmac/macros.tmac

          In both cases, the formatter should be called with option -s
          to invoke soelim.

               sh# groff -s docu.roff

          If you want to write your own groff macro file, call it
          whatever.tmac and put it in a directory in the tmac path;
          see section [lq]Files[rq] below.  Then documents can include
          it with the .mso request or the option -m.

          A roff(7) document is a text file that is enriched by prede-
          fined formatting constructs, such as requests, escape
          sequences, strings, numeric registers, and macros from a
          macro package.  These elements are described in roff(7).

          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 begin-
          ning of the document or in a separate file.

          Macros without arguments are just like strings.  But the
          full power of macros reveals when arguments are passed with

     Page 7                    groff 1.22.4          (printed 5/24/22)

     GROFF_TMAC(5)          (9 September 2021)           GROFF_TMAC(5)

          a macro call.  Within the macro definition, the arguments
          are available as the escape sequences [rs]$1, Ellipsis],
          [rs]$9, [rs]$[Ellipsis]], [rs]$*, and [rs]$@, the name under
          which the macro was called is in [rs]$0, and the number of
          arguments is in register [rs]n[.$]; see groff(7).

        Copy-in Mode
          The phase when groff reads a macro is called copy-in mode or
          copy mode in roff-talk.  This is comparable to the
          C~preprocessing phase during the development of a program
          written in the C~language.

          In this phase, groff interprets all backslashes; that means
          that all escape sequences in the macro body are interpreted
          and replaced by their value.  For constant expressions, this
          is wanted, but strings and registers that might change
          between calls of the macro must be protected from being
          evaluated.  This is most easily done by doubling the back-
          slash that introduces the escape sequence.  This doubling is
          most important for the positional parameters.  For example,
          to print information on the arguments that were passed to
          the macro to the terminal, define a macro named
          [oq].print_args[cq], say.

               .ds midpart was called with
               .de print_args
               .  tm @1] [rs]*[midpart] [rs][rs]n[.$] @2]
               .  tm [rs][rs]$*

          When calling this macro by

               .print_args arg1 arg2

          the following text is printed to the terminal:

               CI]print_args] was called with the following 2 arguments:
               arg1 arg2

          Let's analyze each backslash in the macro definition.  As
          the positional parameters and the number of arguments change
          with each call of the macro their leading backslash must be
          doubled, which results in [rs][rs]$* and [rs][rs][.$].  The
          same applies to the macro name because it could be called
          with an alias name, so [rs][rs]$0.

          On the other hand, midpart is a constant string, it does not
          change, so no doubling for [rs]*[midpart].  The [rs]f escape
          sequences are predefined groff elements for setting the font
          within the text.  Of course, this behavior does not change,
          so no doubling with [rs]f[I] and [rs]f[].

     Page 8                    groff 1.22.4          (printed 5/24/22)

     GROFF_TMAC(5)          (9 September 2021)           GROFF_TMAC(5)

        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) into a pair of .eo and .ec requests.
          Then the body in the macro definition is just like a normal
          part of the document [em] text enhanced by calls of
          requests, macros, strings, registers, etc.  For example, the
          code above can be written in a simpler way by

               .ds midpart was called with
               .de print_args
               .  tm @1] [rs]*[midpart] [rs]n[.$] @2]
               .  tm [rs]$*

          Unfortunately, draft mode cannot be used universally.
          Although it is good enough for defining 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
          +o    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 ([rs][rs]n[.$] == 0) [rs]
                    .    return
                    .  nop [rs])[rs][rs]$*[rs])

          +o    Write a comment macro that works both for copy-in and
               draft mode; for as escaping is off in draft mode, trou-
               ble might occur when normal comments are used.  For
               example, the following macro just ignores its argu-
               ments, so it acts like a comment line:

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

          +o    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 structur-

          +o    To increase readability, use groff's indentation

     Page 9                    groff 1.22.4          (printed 5/24/22)

     GROFF_TMAC(5)          (9 September 2021)           GROFF_TMAC(5)

               facility for requests and macro calls (arbitrary
               whitespace after the leading dot).

          Diversions can be used to implement quite advanced program-
          ming constructs.  They are comparable 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 they get their power when diversions are used dynami-
          cally 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 remain aware of the fact that diversions always store
          complete lines.  If diversions are used when the line buffer
          has not been flushed, strange results are produced; not
          knowing this, many people get desperate about diversions.
          To ensure that a diversion works, line breaks should be
          added at the right places.  To be on the secure side,
          enclose everything that has to do with diversions into a
          pair of line breaks; for example, by explicitly using .br
          requests.  This rule should be applied to diversion defini-
          tion, both inside and outside, and to all calls of diver-
          sions.  This is a bit of overkill, but it works nicely.

          [If you really need diversions which should ignore the cur-
          rent partial line, use environments to save the current par-
          tial 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 manipu-
          lated from within the macros.

          All macro package files must be named name.tmac to fully use
          the tmac mechanism. as with classical packages is
          possible as well, but deprecated.

          The macro files are kept in the tmac directories; a colon
          separated list of these constitutes the tmac path.

          The search sequence for macro files is (in that order):

          +o    the directories specified with troff/groff's -M
               command-line option

          +o    the directories given in the GROFF_TMAC_PATH

     Page 10                   groff 1.22.4          (printed 5/24/22)

     GROFF_TMAC(5)          (9 September 2021)           GROFF_TMAC(5)

               environment variable

          +o    the current directory (only if in unsafe mode, which is
               enabled by the -U command-line switch)

          +o    the home directory

          +o    a platform-specific directory, being


               in this installation

          +o    a site-specific (platform-independent) directory, being


               in this installation

          +o    the main tmac directory, being


               in this installation

               A colon separated list of additional tmac directories
               in which to search for macro files.  See the previous
               section for a detailed description.

          This document was written by Bernd Warken and Werner Lemberg

          Groff: The GNU Implementation of troff, by Trent A. Fisher
          and Werner Lemberg, is the primary groff manual.  You can
          browse it interactively with [lq]info groff[rq].

               an overview of the groff system.

               groff_mdoc(7), groff_me(7), groff_mm(7), groff_mom(7),
               groff_ms(7), groff_trace(7), groff_www(7).  the groff
               tmac macro packages.

               the groff language.

          The Filesystem Hierarchy Standard is available at the FHS
          web site

     Page 11                   groff 1.22.4          (printed 5/24/22)