# groff_tmac(5) - man - 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 roff typesetting system

## DESCRIPTION
       The  [**roff**(7)](https://www.chedong.com/phpMan.php/man/roff/7/markdown)  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 ‘**T**_roff_**MAC**_ros_’.

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

## GROFF MACRO PACKAGES
       _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

       or

              _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 Pages
       _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)](https://www.chedong.com/phpMan.php/man/man/7/markdown).

       _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 **groff**___**[mdoc**(7)](https://www.chedong.com/phpMan.php/man/mdoc/7/markdown).

       _andoc_
       _mandoc_ Use this file in case you don't know whether the **man** macros or the **mdoc** package should
              be used.  Multiple man pages (in either format) can be handled.

### Full 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/me/7/markdown).

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

       _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)](https://www.chedong.com/phpMan.php/man/mom/7/markdown).

       _ms_     The classical _ms_ macro package; see **groff**___**[ms**(7)](https://www.chedong.com/phpMan.php/man/ms/7/markdown).

### Language-specific Packages
       _cs_     This  file adds support for Czech localization, including 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 (‘Rechtschreibreform’).  It should be used as the
              last macro package on the command line.

       _fr_     This file adds support for French localization, including the main macro packages (me,
              mom, mm, and ms).  Example:

                     _sh#_ groff -ms -mfr foo.ms > foo.ps

              Note that _fr.tmac_ sets the input encoding to latin-9 to get proper support of the ‘oe’
              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)](https://www.chedong.com/phpMan.php/man/mmse/7/markdown) (only in Swedish
              locales).  It should be used as the last macro package on the command line.

### Input Encodings
       _latin1_
       _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  pack‐
              ages don't work on EBCDIC hosts.

       _cp1047_ 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  architectures
              which are based on ASCII.

       Note  that it can happen that some input encoding characters are not available for a particu‐
       lar output device.  For example, 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 functionality to any other macro package or to plain groff.

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

       _ec_     Switch to the EC and TC font families.  To be used with [**grodvi**(1)](https://www.chedong.com/phpMan.php/man/grodvi/1/markdown) – this man page also
              gives more details of how to use it.

       _hdtbl_  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)](https://www.chedong.com/phpMan.php/man/tbl/1/markdown).  _hdtbl_ works only with the **-Tps** and
              **-Tpdf** output devices.  See **groff**___**[hdtbl**(7)](https://www.chedong.com/phpMan.php/man/hdtbl/7/markdown)**.**

       _papersize_
              This macro file is already loaded at start-up by **troff** so it isn't necessary  to  call
              it  explicitly.   It  provides  an interface to set the paper size on the command line
              with the option **-dpaper=**_size_.  Possible values for _size_ are the same as the predefined
              **papersize**  values in the DESC file (only lowercase; see **groff**___**[font**(5)](https://www.chedong.com/phpMan.php/man/font/5/markdown) for more) except
              **a7**–**d7**.  An appended **l** (ell) character denotes landscape  orientation.   Examples:  **a4**,
              **c3l**, **letterl**.

              Most  output  drivers  need additional command-line switches **-p** and **-l** to override the
              default paper length and orientation as set in the driver-specific DESC file.  For ex‐
              ample, use the following for PS output on A4 paper in landscape orientation:

              _sh#_ groff -Tps -dpaper=a4l -P-pa4 -P-l -ms foo.ms > foo.ps

       _pdfpic_ A  single  macro  is provided in this file, **PSPIC**, to include a PDF graphic in a docu‐
              ment, 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 **PDF**‐‐
              **PIC**, nothing gets lost by that.  The options of **PDFPIC** are identical to the **PSDIF**  op‐
              tions.

       _pic_    This  file provides proper definitions for the macros **PS** and **PE**, needed for the [**pic**(1)](https://www.chedong.com/phpMan.php/man/pic/1/markdown)
              preprocessor.  They center each picture.  Use it only if your  macro  package  doesn't
              provide proper definitions for those two macros (actually, most of them already do).

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

              Syntax:

                     **.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  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** centers the graphic horizontally, which is the default.
              The **-L** and **-R** options cause the graphic to be left-aligned and right-aligned,  respec‐
              tively.  The **-I** option causes the graphic to be indented by _n_ (default scaling indica‐
              tor is **m**).

              For use of **.PSPIC** within a diversion it is recommended to extend 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
                     ..

       _ptx_    A  single macro is provided in this file, **xx**, for formatting permuted index entries as
              produced by the GNU [**ptx**(1)](https://www.chedong.com/phpMan.php/man/ptx/1/markdown) program.  In case you need a different formatting, copy the
              macro into your document and adapt it to your needs.

       _trace_  Use   this   for  tracing  macro  calls.   It  is  only  useful  for  debugging.   See
              **groff**___**[trace**(7)](https://www.chedong.com/phpMan.php/man/trace/7/markdown)**.**

       _tty-char_
              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 critical 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 **groff**___**[www**(7)](https://www.chedong.com/phpMan.php/man/www/7/markdown).

## NAMING
       Classical  roff  systems  were designed 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  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  sin‐
       gle  minus — a sensation in the computer stone age.  To make this invocation form work, clas‐
       sical troff macro packages used names that started with the letter ‘m’, which was omitted  in
       the naming of the macro file.

       For  example,  the  macro  package  for  the  man  pages was called _man_, while its macro file
       _tmac.an_.  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 ‘m’ had a leading ‘m’ added in
       the  documentation  and  in  speech;  for  example, the package corresponding 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 activat‐
       ing this package reads **-mdoc**.

       To cope with all situations, actual versions of [**groff**(1)](https://www.chedong.com/phpMan.php/man/groff/1/markdown) are smart about both naming  schemes
       by  providing  two  macro  files for the inflicted macro packages; one with a leading ‘m’ the
       other one without it.  So in _groff_, the _man_ macro package may be specified as one of the fol‐
       lowing four methods:

              _sh#_ groff -m man
              _sh#_ groff -man
              _sh#_ groff -mman
              _sh#_ groff -m an

       Recent packages that do not start with ‘m’ do not use an additional ‘m’ 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  _tmac._name.
       In  modern operating systems, the type of a file is specified as a postfix, the file name ex‐
       tension.  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 available on a system is to check the
       man page [**groff**(1)](https://www.chedong.com/phpMan.php/man/groff/1/markdown), or the contents of the _tmac_ directories.

       In _groff_, most macro packages are described in man pages called **groff**[__name_(7)](https://www.chedong.com/phpMan.php/man/name/7/markdown), with a leading
       ‘m’ for the classical packages.

## INCLUSION
       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 package _name_
       available.   In  groff,  the  file  name_.tmac_ is searched within the tmac path; if not found,
       _tmac._name is searched for instead.

       Alternatively, it is also possible to include a macro file by adding the request **.so** _filename_
       into the document; the 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)](https://www.chedong.com/phpMan.php/man/soelim/1/markdown) 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

              _/usr/share/groff/1.22.4/tmac/macros.tmac_

       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  direc‐
       tory  in  the  tmac  path; see section “Files” below.  Then documents can include it with the
       **.mso** request or the option **-m**.

## 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  reveals  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)](https://www.chedong.com/phpMan.php/man/groff/7/markdown).

### 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  pro‐
       tected  from being evaluated.  This is most easily done by doubling the backslash that intro‐
       duces 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 ter‐
       minal, define a macro named ‘.print_args’, say.

              .ds midpart was called with
              .de print_args
              .  tm \f[I]\\$0\f[] \*[midpart] \\n[.$] arguments:
              .  tm \\$*
              ..

       When calling this macro by

              .print_args arg1 arg2

       the following text is printed to the terminal:

              _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 dou‐
       bled, which results in \\_$*_ and \\_[.$]_.  The same applies to the macro name because it  could
       be called with an alias name, so \\_$0_.

       On  the  other  hand,  _midpart_  is  a constant string, it does not change, so no doubling for
       \_*[midpart]_.  The \_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 \_f[I]_ and
       \_f[]_.

### 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 —  text  enhanced
       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
              .de print_args
              .  tm \f[I]\$0\f[] \*[midpart] \n[.$] arguments:
              .  tm \$*
              ..
              .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-in and draft mode; for as  escaping  is
              off  in  draft  mode, trouble might occur when normal comments 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 they get their power when  di‐
       versions  are used dynamically within macros.  The (formatted) information stored in a diver‐
       sion 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 ap‐
       plied 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.

## FILES
       All macro package files must be named name_.tmac_ to fully use the tmac  mechanism.   _tmac._name
       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):

       •      the directories specified with troff/groff's **-M** command-line option

       •      the directories given in the _GROFF_TMAC_PATH_ environment variable

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

       •      the home directory

       •      a platform-specific directory, being

                     _/usr/lib/groff/site-tmac_

              in this installation

       •      a site-specific (platform-independent) directory, being

                     _/usr/share/groff/site-tmac_

              in this installation

       •      the main tmac directory, being

                     _/usr/share/groff/1.22.4/tmac_

              in this installation

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

## AUTHORS
       This document was written by Bernd Warken ⟨<groff-bernd.warken-72@web.de>⟩ and  Werner  Lemberg
       ⟨<wl@gnu.org>⟩.

## 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)](https://www.chedong.com/phpMan.php/man/groff/1/markdown)
              an overview of the groff system.

       **groff**___**[man**(7)](https://www.chedong.com/phpMan.php/man/man/7/markdown),
       **groff**___**[mdoc**(7)](https://www.chedong.com/phpMan.php/man/mdoc/7/markdown),
       **groff**___**[me**(7)](https://www.chedong.com/phpMan.php/man/me/7/markdown),
       **groff**___**[mm**(7)](https://www.chedong.com/phpMan.php/man/mm/7/markdown),
       **groff**___**[mom**(7)](https://www.chedong.com/phpMan.php/man/mom/7/markdown),
       **groff**___**[ms**(7)](https://www.chedong.com/phpMan.php/man/ms/7/markdown),
       **groff**___**[trace**(7)](https://www.chedong.com/phpMan.php/man/trace/7/markdown),
       **groff**___**[www**(7)](https://www.chedong.com/phpMan.php/man/www/7/markdown).
              the groff tmac macro packages.

       [**groff**(7)](https://www.chedong.com/phpMan.php/man/groff/7/markdown)
              the groff language.

       The Filesystem Hierarchy Standard is available at the FHS web site  ⟨<http://www.pathname.com/>
       fhs/⟩.



groff 1.22.4                                23 March 2022                              [GROFF_TMAC(5)](https://www.chedong.com/phpMan.php/man/GROFFTMAC/5/markdown)
