1 .TH GROFF_TMAC @MAN5EXT@ "@MDATE@" "Groff Version @VERSION@"
3 groff_tmac \- macro files in the roff typesetting system
5 .\" The .SH was moved to this place to make `apropos' happy.
8 .\" --------------------------------------------------------------------
10 .\" --------------------------------------------------------------------
15 File position: <groff-source>/man/groff_tmac.man
17 Last update: 15 Jul 2003
19 This file is part of groff, the GNU roff type-setting system.
21 Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
22 written by Bernd Warken <bwarken@mayn.de> and Werner Lemberg
25 Permission is granted to copy, distribute and/or modify this document
26 under the terms of the GNU Free Documentation License, Version 1.1 or
27 any later version published by the Free Software Foundation; with the
28 Invariant Sections being this .ig-section and AUTHOR, with no
29 Front-Cover Texts, and with no Back-Cover Texts.
31 A copy of the Free Documentation License is included as a file called
32 FDL in the main directory of the groff source package.
35 .\" --------------------------------------------------------------------
37 .\" --------------------------------------------------------------------
39 .do nr groff_tmac_C \n[.C]
51 .ds Ellipsis \&.\|.\|.\&\"
53 .\" Global static variables for inter-macro communication
56 .\" --------------------------------------------------------------------
57 .\" setup for the macro definitions below
59 .\" naming: namespace:cathegory_macro.variable_name (experimental)
61 .\" --------------------------------------------------------------------
62 .\" configuration of prompt for `.Shell_cmd'* macros
63 .ds groffer:Shell_cmd.prompt_text sh#\" prompt for shell commands
64 .ds groffer:Shell_cmd+.prompt_text >\" prompt on continuation lines
65 .ds groffer:Shell_cmd_base.prompt_font I\" font for prompts
67 .\" automatically determine setup from the configuration above
68 .als @f groffer:Shell_cmd_base.prompt_font\"
69 .als @t groffer:Shell_cmd.prompt_text\"
70 .als @t+ groffer:Shell_cmd+.prompt_text\"
71 .ds groffer:Shell_cmd.prompt \f[\*[@f]]\*[@t]\f[]\" needed
72 .ds groffer:Shell_cmd+.prompt \f[\*[@f]]\*[@t+]\f[]\" needed
73 .nr @w \w'\*[groffer:Shell_cmd.prompt]'\"
74 .nr @w+ \w'\*[groffer:Shell_cmd+.prompt]'\"
76 .\" Full prompt width is maximum of texts plus 1m
77 .nr groffer:Shell_cmd_base.prompt_width (\n[@w]>?\n[@w+]+1m)\" needed
86 .\"--------------------------------------------------------------------
87 .\" Ignore all arguments like a comment, even after a .eo call.
90 .c --------------------------------------------------------------------
95 . ds @tmp@ \fB\\$1\f[]\fI\\$2\f[]
97 . Text \\*[@tmp@]\fR\\$*\f[]
101 .c --------------------------------------------------------------------
102 .c .Env_var (<env_var_name> [<punct>])
104 .c Display an environment variable, with optional punctuation.
109 . Text \f[CB]\\$1\f[]\\$2
112 .c --------------------------------------------------------------------
113 .c .Error (<text>...)
115 .c Print error message to terminal and abort.
121 .c --------------------------------------------------------------------
123 . if r@+Example_font \
124 . Error previous .Example was not terminated by a ./Example
125 . nr @+Example_font \\n[.f]
131 .c --------------------------------------------------------------------
133 . if !r@+Example_font \
134 . Error no previous call to .Example
135 . ft \\n[@+Example_font]
142 .c --------------------------------------------------------------------
143 .c .Shell_cmd (<CR> [<CI>] ...)
145 .c A shell command line; display args alternating in fonts CR and CI.
148 .c .Shell_cmd "groffer --dpi 100 file"
149 .c result: `sh# groffer --dpi 100 file'
150 .c with 'sh#' in font I, the rest in CR
152 .c .Shell_cmd groffer\~--dpi\~100\~file
153 .c result: the same as above
155 .c .Shell_cmd "groffer --dpi=" value " file"
156 .c result: sh# groffer --dpi=value file
157 .c with `groffer --dpi=' and `file' in CR; `value' in CI
159 .c .Shell_cmd groffer\~--dpi= value \~file
160 .c result: the same as the previous example
163 . groffer:Shell_cmd_base "\*[groffer:Shell_cmd.prompt]" \\$@
165 .c --------------------------------------------------------------------
166 .c .Shell_cmd+ (<CR> [<CI>] ...)
168 .c A continuation line for .Shell_cmd.
171 . groffer:Shell_cmd_base "\*[groffer:Shell_cmd+.prompt]" \\$@
173 .c --------------------------------------------------------------------
174 .c .Shell_cmd_base (<prompt> [<CR> [<CI>] ...])
176 .c A shell command line; display args alternating in fonts CR and CI.
177 .c Internal, do not use directly.
179 .c Globals: read-only register @.Shell_cmd_width
181 .de groffer:Shell_cmd_base
182 . if (\\n[.$] <= 0) \
184 . nr @+font \\n[.f]\"
187 . c gap between prompt and command
188 . nr @+gap \\n[groffer:Shell_cmd_base.prompt_width]-\\w'\\*[@prompt]'\"
189 . ds @res \\*[@prompt]\h'\\n[@+gap]u'\"
192 . while (\\n[.$] > 0) \{\
193 . as @res \\f[\\*[@cf]]\\$1\"
215 .c --------------------------------------------------------------------
218 .c Treat the arguments as text, no matter how they look.
221 . if (\\n[.$] == 0) \
225 .c --------------------------------------------------------------------
226 .c .Topic ([<indent>])
228 .c A bulleted paragraph
239 .c --------------------------------------------------------------------
242 .c Continuation line for .TP header.
249 .c --------------------------------------------------------------------
251 . ds @tmp@ `\f(CR\\$1\f[]'
253 . Text \\*[@tmp@]\\$*
256 .c --------------------------------------------------------------------
258 . ds @tmp@ \f(CB\\$1\f[]
260 . Text \\*[@tmp@]\\$*
263 .c --------------------------------------------------------------------
265 . ds @tmp@ \f(CI\\$1\f[]
267 . Text \\*[@tmp@]\\$*
270 .c --------------------------------------------------------------------
272 . ds @tmp@ \f(CB\\$1\f[]
274 . Text .\\*[@tmp@]\\$*
277 .c --------------------------------------------------------------------
279 . ds @tmp@ \f[CB]\\$1\f[]
281 . Text \[rs]\\*[@tmp@]\\$*
284 .\" --------------------------------------------------------------------
286 .\" --------------------------------------------------------------------
290 type-setting system provides a set of macro packages suitable for
291 special kinds of documents.
293 Each macro package stores its macros and definitions in a file called
296 The name is deduced from
302 The tmac files are normal roff source documents, except that they
303 usually contain only definitions and setup commands, but no text.
305 All tmac files are kept in a single or a small number of directories,
311 .\" --------------------------------------------------------------------
312 .SH "GROFF MACRO PACKAGES"
313 .\" --------------------------------------------------------------------
316 provides all classical macro packages, some more full packages, and
317 some secondary packages for special purposes.
319 Note that it is not possible to use multiple primary macro packages at the
320 same time; saying e.g.\&
323 .Shell_cmd "groff \-m man \-m ms foo"
329 .Shell_cmd "groff \-m man foo \-m ms bar"
335 .\" --------------------------------------------------------------------
337 .\" --------------------------------------------------------------------
341 This is the classical macro package for UNIX manual pages
342 (man\~pages); it is quite handy and easy to use; see
343 .BR groff_man (@MAN7EXT@).
349 An alternative macro package for man\~pages mainly used in BSD
350 systems; it provides many new features, but it is not the standard for
352 .BR groff_mdoc (@MAN7EXT@).
355 .\" --------------------------------------------------------------------
357 .\" --------------------------------------------------------------------
359 The packages in this section provide a complete set of macros for
360 writing documents of any kind, up to whole books.
362 They are similar in functionality; it is a matter of taste which one
371 .BR groff_me (@MAN7EXT@).
379 .BR groff_mm (@MAN7EXT@).
386 macro package, only available in groff.
388 As this is not based on other packages, it can be freely designed.
390 So it is expected to become quite a nice, modern macro package.
393 .BR groff_mom (@MAN7EXT@).
401 .BR groff_ms (@MAN7EXT@).
404 .\" --------------------------------------------------------------------
405 .SS "Special Packages"
406 .\" --------------------------------------------------------------------
408 The macro packages in this section are not intended for stand-alone
409 usage, but can be used to add special functionality to any other
410 macro package or to plain groff.
415 This macro file is already loaded at start-up by
417 so it isn't necessary to call it explicitly.
419 It provides an interface to set the paper size on the command line with
420 the option \f[B]\%\-dpaper=\f[]\f[I]size\f[].
424 are the same as the predefined
426 values in the DESC file (only lowercase; see
427 .BR groff_font (@MAN5EXT@)
433 (ell) character denotes landscape orientation.
441 Most output drivers need additional command line switches
445 to override the default paper length and orientation as set in the driver
448 For example, use the following for PS output on A4 paper in landscape
452 .Shell_cmd "groff \-Tps \-dpaper=a4l \-P\-pa4 \-P\-l \-ms foo.ms > foo.ps"
457 A single macro is provided in this file,
459 to include a PostScript graphic in a document.
461 It makes only sense for output devices which support inclusion of PS
467 the file is then loaded automatically.
472 \&\fB.PSPIC\fP [\fB\-L\fP|\fB-R\fP|\fB\-I\fP \fIn\fP]\ \fI\|file\fP [\fIwidth\fP [\fIheight\fP]]
477 is the name of the file containing the illustration;
481 give the desired width and height of the graphic.
487 arguments may have scaling indicators attached;
488 the default scaling indicator is\~\c
491 This macro will scale the graphic uniformly
492 in the x and y\~directions so that it is no more than
499 By default, the graphic will be horizontally centered.
505 options cause the graphic to be left-aligned and right-aligned,
510 option causes the graphic to be indented by\~\c
512 (default scaling indicator is\~\c
517 Overrides the definition of standard troff characters and some groff
518 characters for tty devices.
520 The optical appearance is intentionally inferior compared to that of
521 normal tty formatting to allow processing with critical equipment.
526 Additions of elements known from the html format, as being used in the
527 internet (World Wide Web) pages; this includes URL links and mail
529 .BR groff_www (@MAN7EXT@).
532 .\" --------------------------------------------------------------------
534 .\" --------------------------------------------------------------------
536 In classical roff systems, there was a funny naming scheme for macro
537 packages, due to a simplistic design in option parsing.
539 Macro packages were always included by option
541 when this option was directly followed by its argument without an
542 intervening space, this looked like a long option preceded by a single
543 minus \[em] a sensation in the computer stone age.
545 To make this optically working for macro package names, all classical
546 macro packages choose a name that started with the letter
548 which was omitted in the naming of the macro file.
552 For example, the macro package for the man pages was called
556 So it could be activated by the argument
566 For similar reasons, macro packages that did not start with an
570 added in the documentation and in talking; for example, the package
575 in the documentation, although a more suitable name would be
577 For, when omitting the space between the option and its argument, the
578 command line option for activating this package reads
583 To cope with all situations, actual versions of
584 .BR groff (@MAN1EXT@)
585 are smart about both naming schemes by providing two macro files
586 for the inflicted macro packages; one with a leading
588 the other one without it.
594 macro package may be specified as on of the following four methods:
597 .Shell_cmd "groff\~\-m\~man"
598 .Shell_cmd "groff\~\-man"
599 .Shell_cmd "groff\~\-mman"
600 .Shell_cmd "groff\~\-m\~an"
604 Recent packages that do not start with
606 do not use an additional
608 in the documentation.
612 macro package may be specified only as one of the two methods:
615 .Shell_cmd "groff\~\-m\~www"
616 .Shell_cmd "groff\~\-mwww"
620 Obviously, variants like
622 would not make much sense.
626 A second strange feature of classical troff was to name macro files
629 In modern operating systems, the type of a file is specified as
630 postfix, the file name extension.
632 Again, groff copes with this situation by searching both
642 The easiest way to find out which macro packages are available on a
643 system is to check the man\~page
644 .BR groff (@MAN1EXT@),
645 or the contents of the
653 most macro packages are described in\~man pages called
654 .BR groff_\f[I]name\f[] (@MAN7EXT@),
657 for the classical packages.
660 .\" --------------------------------------------------------------------
662 .\" --------------------------------------------------------------------
664 There are several ways to use a macro package in a document.
666 The classical way is to specify the troff/groff option
669 at run-time; this makes the contents of the macro package
675 is searched within the tmac path; if not found,
677 will be searched for instead.
681 Alternatively, it is also possible to include a macro file by adding
685 into the document; the argument must be the full file name of an
686 existing file, possibly with the directory where it is kept.
688 In groff, this was improved by the similar request
691 which added searching in the tmac path, just like option
697 Note that in order to resolve the
701 requests, the roff preprocessor
702 .BR soelim (@MAN1EXT@)
703 must be called if the files to be included need preprocessing.
705 This can be done either directly by a pipeline on the command line or
706 by using the troff/groff option
710 calls soelim automatically.
714 For example, suppose a macro file is stored as
715 .I @MACRODIR@/macros.tmac
716 and is used in some document called
721 At run-time, the formatter call for this is
724 .Shell_cmd "groff\~\-m\~" "macrofile\~document.roff"
728 To include the macro file directly in the document either
732 . Text .mso macrofile.tmac
740 . Text .so @MACRODIR@/macros.tmac
745 In both cases, the formatter is called with
747 .Shell_cmd "groff\~\-s\~" docu.roff
751 If you want to write your own groff macro file, call it
753 and put it in some directory of the tmac path, see section
755 Then documents can include it with the
757 request or the option
762 .\" --------------------------------------------------------------------
764 .\" --------------------------------------------------------------------
766 .\" This section does not fit into the framework of this document.
768 There is a convention that is supported by many modern roff
773 described in the following.
776 If the first line in a document is a comment, the first word (after the
777 comment characters and a blank) constitutes the
780 That means that the letters of this word are interpreted as
781 abbreviations for those preprocessor commands that should be run
782 when formatting the document.
784 Mostly, only the letters corresponding to the options for the
785 preprocessors are recognized,
805 .BR roff (@MAN7EXT@)).
809 Besides being a good reminder for the user, some formatters (like the
811 program) are even able to automatically start the preprocessors
812 specified in the preprocessor word, but do not bet on this.
818 program handles some preprocessors automatically, such that in
819 man\~pages only the following characters should be used:
827 .\" --------------------------------------------------------------------
829 .\" --------------------------------------------------------------------
833 document is a text file that is enriched by predefined formatting
834 constructs, such as requests, escape sequences, strings, numeric
835 registers, and macros from a macro package.
837 These elements are described in
838 .BR roff (@MAN7EXT@).
842 To give a document a personal style, it is most useful to extend the
843 existing elements by defining some macros for repeating tasks; the best
844 place for this is near the beginning of the document or in a separate
849 Macros without arguments are just like strings.
851 But the full power of macros reveals when arguments are passed with a
854 Within the macro definition, the arguments are available as the escape
859 .BR $[ \*[Ellipsis] ] ,
863 the name under which the macro was called is in
865 and the number of arguments is in register
868 .BR groff (@MAN7EXT@).
871 .\" --------------------------------------------------------------------
873 .\" --------------------------------------------------------------------
875 The phase when groff reads a macro is called
879 This is comparable to the C\~preprocessing phase during the development
880 of a program written in the C\~language.
884 In this phase, groff interprets all backslashes; that means that all
885 escape sequences in the macro body are interpreted and replaced by
888 For constant expression, this is wanted, but strings and registers
889 that might change between calls of the macro must be protected from
892 This is most easily done by doubling the backslash that introduces the
895 This doubling is most important for the positional parameters.
897 For example, to print information on the arguments that were passed to
898 the macro to the terminal, define a macro named `.print_args',
903 .ds @1 \[rs]f[I]\[rs]\[rs]$0\[rs]f[]\"
906 . Text .ds midpart was called with
907 . Text .de print_args
908 . Text .\~\~tm\~\*[@1]\~\[rs]\[rs]*[midpart]\~\[rs]\[rs]n[.$]\~\*[@2]
909 . Text .\~\~tm\~\[rs]\[rs]$*
917 When calling this macro by
921 . Text .print_args arg1 arg2
925 the following text is printed to the terminal:
929 . Text \f[CI]print_args\f[] was called with the following 2 arguments:
935 Let's analyze each backslash in the macro definition.
937 As the positional parameters and the number of arguments will change
938 with each call of the macro their leading backslash must be doubled,
943 The same applies to the macro name because it could be called with an
951 is a constant string, it will not change, so no doubling for
952 .IR \[rs]*[midpart] .
955 escape sequences are predefined groff elements for setting the font
958 Of course, this behavior will not change, so no doubling with
964 .\" --------------------------------------------------------------------
966 .\" --------------------------------------------------------------------
968 Writing groff macros is easy when the escaping mechanism is temporarily
971 In groff, this is done by enclosing the macro definition(s) into a
978 Then the body in the macro definition is just like a normal part of
979 the document \[em] text enhanced by calls of requests, macros,
980 strings, registers, etc.
982 For example, the code above can be written in a simpler way by
986 .ds @1 \[rs]f[I]\[rs]$0\[rs]f[]\"
990 . Text .ds midpart was called with
991 . Text .de print_args
992 . Text .\~\~tm\~\*[@1]\~\[rs]*[midpart]\~\[rs]n[.$]\~\*[@2]
993 . Text .\~\~tm\~\[rs]$*
1002 Unfortunately, draft mode cannot be used universally.
1004 Although it is good enough for defining normal macros, draft mode
1005 will fail with advanced applications, such as indirectly defined
1006 strings, registers, etc.
1008 An optimal way is to define and test all macros in draft mode and then
1009 do the backslash doubling as a final step; do not forget to remove the
1014 .\" --------------------------------------------------------------------
1015 .SS "Tips for Macro Definitions"
1016 .\" --------------------------------------------------------------------
1019 Start every line with a dot, for example, by using the groff request
1021 for text lines, or write your own macro that handles also text lines
1027 . Text .\~\~if (\[rs]\[rs]n[.$] == 0)\~\[rs]
1028 . Text .\~\~\~\~return
1029 . Text .\~nop\~\[rs])\[rs]\[rs]$*[rs]\)
1034 Write a comment macro that works both for copy-in and draft mode; for
1035 as escaping is off in draft mode, trouble might occur when normal
1038 For example, the following macro just ignores its arguments, so it
1039 acts like a comment line:
1045 . Text .c\~This\~is\~like\~a\~comment\~line.
1049 In long macro definitions, make ample use of comment lines or empty
1050 lines for a better structuring.
1053 To increase readability, use groff's indentation facility for requests
1054 and macro calls (arbitrary whitespace after the leading dot).
1057 .\" --------------------------------------------------------------------
1059 .\" --------------------------------------------------------------------
1061 Diversions can be used to realize quite advanced programming
1064 They are comparable to pointers to large data structures in the
1065 C\~programming language, but their usage is quite different.
1069 In their simplest form, diversions are multi-line strings, but
1070 they get their power when diversions are used dynamically within macros.
1072 The information stored in a diversion can be retrieved by calling the
1073 diversion just like a macro.
1077 Most of the problems arising with diversions can be avoided if you are
1078 conscious about the fact that diversions always deal with complete
1081 If diversions are used when the line buffer has not been flashed,
1082 strange results are produced; not knowing this, many people get
1083 desperate about diversions.
1085 To ensure that a diversion works, line breaks should be added at the
1088 To be on the secure side, enclose everything that has to do with
1089 diversions into a pair of line breaks; for example, by amply using
1093 This rule should be applied to diversion definition, both inside and
1094 outside, and to all calls of diversions.
1096 This is a bit of overkill, but it works nicely.
1100 [If you really need diversions which should ignore the current partial
1101 line, use environments to save the current partial line and/\:or use the
1107 The most powerful feature using diversions is to start a diversion
1108 within a macro definition and end it within another macro.
1110 Then everything between each call of this macro pair is stored within
1111 the diversion and can be manipulated from within the macros.
1114 .\" --------------------------------------------------------------------
1116 .\" --------------------------------------------------------------------
1118 All macro names must be named
1120 to fully use the tmac mechanism.
1123 as with classical packages is possible as well, but deprecated.
1127 The macro files are kept in the
1128 .IR "tmac directories" ;
1129 a colon separated list of these constitutes the
1134 The search sequence for macro files is (in that order):
1137 the directories specified with troff/groff's
1142 the directories given in the
1143 .Env_var $GROFF_TMAC_PATH
1144 environment variable
1147 the current directory (only if in unsafe mode, which is enabled by the
1149 command line switch)
1155 a platform-specific directory, being
1157 in this installation
1160 a site-specific (platform-independent) directory, being
1162 in this installation
1165 the main tmac directory, being
1167 in this installation
1170 .\" --------------------------------------------------------------------
1172 .\" --------------------------------------------------------------------
1175 .Env_var $GROFF_TMAC_PATH
1176 A colon separated list of additional tmac directories in which to search
1179 See the previous section for a detailed description.
1182 .\" --------------------------------------------------------------------
1184 .\" --------------------------------------------------------------------
1186 Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
1189 This document is distributed under the terms of the FDL (GNU Free
1190 Documentation License) version 1.1 or later.
1192 You should have received a copy of the FDL on your system, it is also
1193 available on-line at the
1194 .URL http://\:www.gnu.org/\:copyleft/\:fdl.html "GNU copyleft site" .
1197 This document is part of
1199 the GNU roff distribution.
1202 .MTO bwarken@mayn.de "Bernd Warken" ;
1204 .MTO wl@gnu.org "Werner Lemberg" .
1207 .\" --------------------------------------------------------------------
1209 .\" --------------------------------------------------------------------
1211 A complete reference for all parts of the groff system is found in the
1217 .BR groff (@MAN1EXT@)
1218 an overview of the groff system.
1221 .BR groff_man (@MAN7EXT@),
1223 .BR groff_mdoc (@MAN7EXT@),
1225 .BR groff_me (@MAN7EXT@),
1227 .BR groff_mm (@MAN7EXT@),
1229 .BR groff_mom (@MAN7EXT@),
1231 .BR groff_ms (@MAN7EXT@),
1233 .BR groff_www (@MAN7EXT@).
1234 the groff tmac macro packages.
1237 .BR groff (@MAN7EXT@)
1242 The Filesystem Hierarchy Standard is available at the
1243 .URL http://\:www.pathname.com/\:fhs/ "FHS web site" .
1245 .cp \n[groff_tmac_C]
1247 .\" Local Variables: