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.
_s_h_# groff -m man -m ms foo
or
_s_h_# groff -m man foo -m ms bar
will fail.
_s_h_# groff -Tps -dpaper=a4l -P-pa4 -P-l -ms foo.ms > foo.ps
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 --mm, or --mmaann for short.
For similar reasons, macro packages that did not start with an `m' had a leading `m' added in the documentation and in talking; 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 activating this package reads --mmddoocc.
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 `m', the other one without it. So in groff, the man macro package may be specified as on of the following four methods:
_s_h_# groff -m man
_s_h_# groff -man
_s_h_# groff -mman
_s_h_# 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:
_s_h_# groff -m www
_s_h_# groff -mwww
Obviously, variants like -mmwww would not make much sense.
A second strange feature of classical troff was to name macro files according to ttmmaacc.._n_a_m_e. In modern operating systems, the type of a file is specified as 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 available 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__n_a_m_e(7) with a leading `m' for the classical packages.
Alternatively, it is also possible to include a macro file by adding the request .ssoo 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 .mmssoo package, which added searching in the tmac path, just like option --mm does.
Note that in order to resolve the .ssoo and .mmssoo 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 --ss. man calls soelim automatically.
For example, suppose a macro file is stored as /usr/share/tmac/macros.tmac and is used in some document called docu.roff.
At run-time, the formatter call for this is
_s_h_# groff -m _m_a_c_r_o_f_i_l_e _d_o_c_u_m_e_n_t_._r_o_f_f _<_/_p_r_e_> _<_b_r_>
To include the macro file directly in the document either
.mso macrofile.tmac
is used or
.so /usr/share/tmac/macros.tmac
In both cases, the formatter is called with
_s_h_# groff -s _d_o_c_u_._r_o_f_f _<_/_p_r_e_> _<_b_r_>
If you want to write your own groff macro file, call it whatever.tmac and put it in some directory of the tmac path, see section FILES. Then documents can include it with the .mmssoo request or the option --mm.
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 0; see groff(7)
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 expression, 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 backslash 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 `.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:
_p_r_i_n_t___a_r_g_s 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 will change with each call of the macro their leading backslash must be doubled, 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 will 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 will not change, so no doubling with \f[I] and \f[].
.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 defining normal macros, draft mode will fail 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.
.de Text . if (\\n[.$] == 0) \ . return . nop \)\\$*[rs] ..
.de c .. .c This is like a comment line.
In their simplest form, diversions are multi-line strings, but they get their power when diversions are used dynamically within macros. The 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 are conscious about the fact that diversions always deal with complete lines. If diversions are used when the line buffer has not been flashed, 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 amply 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.
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):
This document is distributed under the terms of the FDL (GNU Free
Documentation License) version 1.1 or later.
You should have received a copy of the FDL on your system, it is also
available on-line at the
GNU copyleft site
This document is part of
groff,
the GNU roff distribution.
It was written by
Bernd Warken
The Filesystem Hierarchy Standard is available at the
FHS web site SEE ALSO
A complete reference for all parts of the groff system is found in the
groff
info(1)
file.