2 .TH GROFF_TMAC @MAN5EXT@ "@MDATE@" "Groff Version @VERSION@"
4 groff_tmac \- macro files in the roff typesetting system
6 .\" The .SH was moved to this place to make `apropos' happy.
9 .\" --------------------------------------------------------------------
11 .\" --------------------------------------------------------------------
16 File position: <groff-source>/man/groff_tmac.man
18 Last update: 20 Oct 2002
20 This file is part of groff, the GNU roff type-setting system.
22 Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
23 written by Bernd Warken <bwarken@mayn.de> and Werner Lemberg
26 Permission is granted to copy, distribute and/or modify this document
27 under the terms of the GNU Free Documentation License, Version 1.1 or
28 any later version published by the Free Software Foundation; with the
29 Invariant Sections being this .ig-section and AUTHOR, with no
30 Front-Cover Texts, and with no Back-Cover Texts.
32 A copy of the Free Documentation License is included as a file called
33 FDL in the main directory of the groff source package.
36 .\" --------------------------------------------------------------------
38 .\" --------------------------------------------------------------------
49 .ds Ellipsis \&.\|.\|.\&\"
51 .\" Global static variables for inter-macro communication
54 .\" --------------------------------------------------------------------
55 .\" setup for the macro definitions below
57 .\" naming: namespace:cathegory_macro.variable_name (experimental)
59 .\" --------------------------------------------------------------------
60 .\" configuration of prompt for `.Shell_cmd'* macros
61 .ds groffer:Shell_cmd.prompt_text sh#\" prompt for shell commands
62 .ds groffer:Shell_cmd+.prompt_text >\" prompt on continuation lines
63 .ds groffer:Shell_cmd_base.prompt_font I\" font for prompts
65 .\" automatically determine setup from the configuration above
66 .als @f groffer:Shell_cmd_base.prompt_font\"
67 .als @t groffer:Shell_cmd.prompt_text\"
68 .als @t+ groffer:Shell_cmd+.prompt_text\"
69 .ds groffer:Shell_cmd.prompt \f[\*[@f]]\*[@t]\f[]\" needed
70 .ds groffer:Shell_cmd+.prompt \f[\*[@f]]\*[@t+]\f[]\" needed
71 .nr @w \w'\*[groffer:Shell_cmd.prompt]'\"
72 .nr @w+ \w'\*[groffer:Shell_cmd+.prompt]'\"
74 .\" Full prompt width is maximum of texts plus 1m
75 .nr groffer:Shell_cmd_base.prompt_width (\n[@w]>?\n[@w+]+1m)\" needed
84 .\"--------------------------------------------------------------------
85 .\" Ignore all arguments like a comment, even after a .eo call.
88 .c --------------------------------------------------------------------
93 . ds @tmp@ \fB\\$1\f[]\fI\\$2\f[]
95 . Text \\*[@tmp@]\fR\\$*\f[]
99 .c --------------------------------------------------------------------
100 .c .Env_var (<env_var_name> [<punct>])
102 .c Display an environment variable, with optional punctuation.
107 . Text \f[CB]\\$1\f[]\\$2
110 .c --------------------------------------------------------------------
111 .c .Error (<text>...)
113 .c Print error message to terminal and abort.
119 .c --------------------------------------------------------------------
121 . if r@+Example_font \
122 . Error previous .Example was not terminated by a ./Example
123 . nr @+Example_font \\n[.f]
129 .c --------------------------------------------------------------------
131 . if !r@+Example_font \
132 . Error no previous call to .Example
133 . ft \\n[@+Example_font]
140 .c --------------------------------------------------------------------
141 .c .Shell_cmd (<CR> [<CI>] ...)
143 .c A shell command line; display args alternating in fonts CR and CI.
146 .c .Shell_cmd "groffer --dpi 100 file"
147 .c result: `sh# groffer --dpi 100 file'
148 .c with 'sh#' in font I, the rest in CR
150 .c .Shell_cmd groffer\~--dpi\~100\~file
151 .c result: the same as above
153 .c .Shell_cmd "groffer --dpi=" value " file"
154 .c result: sh# groffer --dpi=value file
155 .c with `groffer --dpi=' and `file' in CR; `value' in CI
157 .c .Shell_cmd groffer\~--dpi= value \~file
158 .c result: the same as the previous example
161 . groffer:Shell_cmd_base "\*[groffer:Shell_cmd.prompt]" \\$@
163 .c --------------------------------------------------------------------
164 .c .Shell_cmd+ (<CR> [<CI>] ...)
166 .c A continuation line for .Shell_cmd.
169 . groffer:Shell_cmd_base "\*[groffer:Shell_cmd+.prompt]" \\$@
171 .c --------------------------------------------------------------------
172 .c .Shell_cmd_base (<prompt> [<CR> [<CI>] ...])
174 .c A shell command line; display args alternating in fonts CR and CI.
175 .c Internal, do not use directly.
177 .c Globals: read-only register @.Shell_cmd_width
179 .de groffer:Shell_cmd_base
180 . if (\\n[.$] <= 0) \
182 . nr @+font \\n[.f]\"
185 . c gap between prompt and command
186 . nr @+gap \\n[groffer:Shell_cmd_base.prompt_width]-\\w'\\*[@prompt]'\"
187 . ds @res \\*[@prompt]\h'\\n[@+gap]u'\"
190 . while (\\n[.$] > 0) \{\
191 . as @res \\f[\\*[@cf]]\\$1\"
213 .c --------------------------------------------------------------------
216 .c Treat the arguments as text, no matter how they look.
219 . if (\\n[.$] == 0) \
223 .c --------------------------------------------------------------------
224 .c .Topic ([<indent>])
226 .c A bulleted paragraph
237 .c --------------------------------------------------------------------
240 .c Continuation line for .TP header.
247 .c --------------------------------------------------------------------
249 . ds @tmp@ `\f(CR\\$1\f[]'
251 . Text \\*[@tmp@]\\$*
254 .c --------------------------------------------------------------------
256 . ds @tmp@ \f(CB\\$1\f[]
258 . Text \\*[@tmp@]\\$*
261 .c --------------------------------------------------------------------
263 . ds @tmp@ \f(CI\\$1\f[]
265 . Text \\*[@tmp@]\\$*
268 .c --------------------------------------------------------------------
270 . ds @tmp@ \f(CB\\$1\f[]
272 . Text .\\*[@tmp@]\\$*
275 .c --------------------------------------------------------------------
277 . ds @tmp@ \f[CB]\\$1\f[]
279 . Text \[rs]\\*[@tmp@]\\$*
282 .\" --------------------------------------------------------------------
284 .\" --------------------------------------------------------------------
288 type-setting system provides a set of macro packages suitable for
289 special kinds of documents.
291 Each macro package stores its macros and definitions in a file called
294 The name is deduced from
300 The tmac files are normal roff source documents, except that they
301 usually contain only definitions and setup commands, but no text.
303 All tmac files are kept in a single or a small number of directories,
309 .\" --------------------------------------------------------------------
310 .SH "GROFF MACRO PACKAGES"
311 .\" --------------------------------------------------------------------
314 provides all classical macro packages, some more full packages, and
315 some secondary packages for special purposes.
317 Note that it is not possible to use multiple primary macro packages at the
318 same time; saying e.g.\&
321 .Shell_cmd "groff \-m man \-m ms foo"
327 .Shell_cmd "groff \-m man foo \-m ms bar"
333 .\" --------------------------------------------------------------------
335 .\" --------------------------------------------------------------------
339 This is the classical macro package for UNIX manual pages
340 (man\~pages); it is quite handy and easy to use; see
341 .BR groff_man (@MAN7EXT@).
347 An alternative macro package for man\~pages mainly used in BSD
348 systems; it provides many new features, but it is not the standard for
350 .BR groff_mdoc (@MAN7EXT@).
353 .\" --------------------------------------------------------------------
355 .\" --------------------------------------------------------------------
357 The packages in this section provide a complete set of macros for
358 writing documents of any kind, up to whole books.
360 They are similar in functionality; it is a matter of taste which one
369 .BR groff_me (@MAN7EXT@).
377 .BR groff_mm (@MAN7EXT@).
384 macro package, only available in groff.
386 As this is not based on other packages, it can be freely designed.
388 So it is expected to become quite a nice, modern macro package.
391 .BR groff_mom (@MAN7EXT@).
399 .BR groff_ms (@MAN7EXT@).
402 .\" --------------------------------------------------------------------
403 .SS "Special Packages"
404 .\" --------------------------------------------------------------------
406 The macro packages in this section are not intended for stand-alone
407 usage, but can be used to add special functionality to any other
408 macro package or to plain groff.
413 Overrides the definition of standard troff characters and some groff
414 characters for tty devices.
416 The optical appearance is intentionally inferior compared to that of
417 normal tty formatting to allow processing with critical equipment.
422 Additions of elements known from the html format, as being used in the
423 internet (World Wide Web) pages; this includes URL links and mail
425 .BR groff_www (@MAN7EXT@).
428 .\" --------------------------------------------------------------------
430 .\" --------------------------------------------------------------------
432 In classical roff systems, there was a funny naming scheme for macro
433 packages, due to a simplistic design in option parsing.
435 Macro packages were always included by option
437 when this option was directly followed by its argument without an
438 intervening space, this looked like a long option preceded by a single
439 minus \[em] a sensation in the computer stone age.
441 To make this optically working for macro package names, all classical
442 macro packages choose a name that started with the letter
444 which was omitted in the naming of the macro file.
448 For example, the macro package for the man pages was called
452 So it could be activated by the argument
462 For similar reasons, macro packages that did not start with an
466 added in the documentation and in talking; for example, the package
471 in the documentation, although a more suitable name would be
473 For, when omitting the space between the option and its argument, the
474 command line option for activating this package reads
479 To cope with all situations, actual versions of
480 .BR groff (@MAN1EXT@)
481 are smart about both naming schemes by providing two macro files
482 for the inflicted macro packages; one with a leading
484 the other one without it.
490 macro package may be specified as on of the following four methods:
493 .Shell_cmd "groff\~\-m\~man"
494 .Shell_cmd "groff\~\-man"
495 .Shell_cmd "groff\~\-mman"
496 .Shell_cmd "groff\~\-m\~an"
500 Recent packages that do not start with
502 do not use an additional
504 in the documentation.
508 macro package may be specified only as one of the two methods:
511 .Shell_cmd "groff\~\-m\~www"
512 .Shell_cmd "groff\~\-mwww"
516 Obviously, variants like
518 would not make much sense.
522 A second strange feature of classical troff was to name macro files
525 In modern operating systems, the type of a file is specified as
526 postfix, the file name extension.
528 Again, groff copes with this situation by searching both
538 The easiest way to find out which macro packages are available on a
539 system is to check the man\~page
540 .BR groff (@MAN1EXT@),
541 or the contents of the
549 most macro packages are described in\~man pages called
550 .BR groff_\f[I]name\f[] (@MAN7EXT@),
553 for the classical packages.
556 .\" --------------------------------------------------------------------
558 .\" --------------------------------------------------------------------
560 There are several ways to use a macro package in a document.
562 The classical way is to specify the troff/groff option
565 at run-time; this makes the contents of the macro package
571 is searched within the tmac path; if not found,
573 will be searched for instead.
577 Alternatively, it is also possible to include a macro file by adding
581 into the document; the argument must be the full file name of an
582 existing file, possibly with the directory where it is kept.
584 In groff, this was improved by the similar request
587 which added searching in the tmac path, just like option
593 Note that in order to resolve the
597 requests, the roff preprocessor
598 .BR soelim (@MAN1EXT@)
599 must be called if the files to be included need preprocessing.
601 This can be done either directly by a pipeline on the command line or
602 by using the troff/groff option
606 calls soelim automatically.
610 For example, suppose a macro file is stored as
611 .I @MACRODIR@/macros.tmac
612 and is used in some document called
617 At run-time, the formatter call for this is
620 .Shell_cmd "groff\~\-m\~" "macrofile\~document.roff"
624 To include the macro file directly in the document either
628 . Text .mso macrofile.tmac
636 . Text .so @MACRODIR@/macros.tmac
641 In both cases, the formatter is called with
643 .Shell_cmd "troff\~\-s\~" docu.roff
647 If you want to write your own groff macro file, call it
649 and put it in some directory of the tmac path, see section
651 Then documents can include it with the
653 request or the option
658 .\" --------------------------------------------------------------------
660 .\" --------------------------------------------------------------------
662 .\" This section does not fit into the framework of this document.
664 There is a convention that is supported by many modern roff
669 described in the following.
672 If the first line in a document is a comment, the first word (after the
673 comment characters and a blank) constitutes the
676 That means that the letters of this word are interpreted as
677 abbreviations for those preprocessor commands that should be run
678 when formatting the document.
680 Mostly, only the letters corresponding to the options for the
681 preprocessors are recognized,
701 .BR roff (@MAN7EXT@)).
705 Besides being a good reminder for the user, some formatters (like the
707 program) are even able to automatically start the preprocessors
708 specified in the preprocessor word, but do not bet on this.
714 program handles some preprocessors automatically, such that in
715 man\~pages only the following characters should be used:
723 .\" --------------------------------------------------------------------
725 .\" --------------------------------------------------------------------
729 document is a text file that is enriched by predefined formatting
730 constructs, such as requests, escape sequences, strings, numeric
731 registers, and macros from a macro package.
733 These elements are described in
734 .BR roff (@MAN7EXT@).
738 To give a document a personal style, it is most useful to extend the
739 existing elements by defining some macros for repeating tasks; the best
740 place for this is near the beginning of the document or in a separate
745 Macros without arguments are just like strings.
747 But the full power of macros reveals when arguments are passed with a
750 Within the macro definition, the arguments are available as the escape
755 .BR $[ \*[Ellipsis] ] ,
759 the name under which the macro was called is in
761 and the number of arguments is in register
764 .BR groff (@MAN7EXT@).
767 .\" --------------------------------------------------------------------
769 .\" --------------------------------------------------------------------
771 The phase when groff reads a macro is called
775 This is comparable to the C\~preprocessing phase during the development
776 of a program written in the C\~language.
780 In this phase, groff interprets all backslashes; that means that all
781 escape sequences in the macro body are interpreted and replaced by
784 For constant expression, this is wanted, but strings and registers
785 that might change between calls of the macro must be protected from
788 This is most easily done by doubling the backslash that introduces the
791 This doubling is most important for the positional parameters.
793 For example, to print information on the arguments that were passed to
794 the macro to the terminal, define a macro named `.print_args',
799 .ds @1 \[rs]f[I]\[rs]\[rs]$0\[rs]f[]\"
802 . Text .ds midpart was called with
803 . Text .de print_args
804 . Text .\~\~tm\~\*[@1]\~\[rs]\[rs]*[midpart]\~\[rs]\[rs]n[.$]\~\*[@2]
805 . Text .\~\~tm\~\[rs]\[rs]$*
813 When calling this macro by
816 . Text .print_args arg1 arg2
819 the following text is printed to the terminal:
821 . Text \f[CI]print_args\f[] was called with the following 2 arguments:
827 Let's analyze each backslash in the macro definition.
829 As the positional parameters and the number of arguments will change
830 with each call of the macro their leading backslash must be doubled,
835 The same applies to the macro name because it could be called with an
843 is a constant string, it will not change, so no doubling for
844 .IR \[rs]*[midpart] .
847 escape sequences are predefined groff elements for setting the font
850 Of course, this behavior will not change, so no doubling with
856 .\" --------------------------------------------------------------------
858 .\" --------------------------------------------------------------------
860 Writing groff macros is easy when the escaping mechanism is temporarily
863 In groff, this is done by enclosing the macro definition(s) into a
870 Then the body in the macro definition is just like a normal part of
871 the document \[em] text enhanced by calls of requests, macros,
872 strings, registers, etc.
874 For example, the code above can be written in a simpler way by
878 .ds @1 \[rs]f[I]\[rs]$0\[rs]f[]\"
882 . Text .ds midpart was called with
883 . Text .de print_args
884 . Text .\~\~tm\~\*[@1]\~\[rs]*[midpart]\~\[rs]n[.$]\~\*[@2]
885 . Text .\~\~tm\~\[rs]$*
894 Unfortunately, draft mode cannot be used universally.
896 Although it is good enough for defining normal macros, draft mode
897 will fail with advanced applications, such as indirectly defined
898 strings, registers, etc.
900 An optimal way is to define and test all macros in draft mode and then
901 do the backslash doubling as a final step; do not forget to remove the
906 .\" --------------------------------------------------------------------
907 .SS "Tips for Macro Definitions"
908 .\" --------------------------------------------------------------------
911 Start every line with a dot, for example, by using the groff request
913 for text lines, or write your own macro that handles also text lines
919 . Text .\~\~if (\[rs]\[rs]n[.$] == 0)\~\[rs]
920 . Text .\~\~\~\~return
921 . Text .\~nop\~\[rs])\[rs]\[rs]$*[rs]\)
926 Write a comment macro that works both for copy-in and draft mode; for
927 as escaping is off in draft mode, trouble might occur when normal
930 For example, the following macro just ignores its arguments, so it
931 acts like a comment line:
937 . Text .c\~This\~is\~like\~a\~comment\~line.
941 In long macro definitions, make ample use of comment lines or empty
942 lines for a better structuring.
945 To increase readability, use groff's indentation facility for requests
946 and macro calls (arbitrary whitespace after the leading dot).
949 .\" --------------------------------------------------------------------
951 .\" --------------------------------------------------------------------
953 Diversions can be used to realize quite advanced programming
956 They are comparable to pointers to large data structures in the
957 C\~programming language, but their usage is quite different.
961 In their simplest form, diversions are multi-line strings, but
962 they get their power when diversions are used dynamically within macros.
964 The information stored in a diversion can be retrieved by calling the
965 diversion just like a macro.
969 Most of the problems arising with diversions can be avoided if you are
970 conscious about the fact that diversions always deal with complete
973 If diversions are used when the line buffer has not been flashed,
974 strange results are produced; not knowing this, many people get
975 desperate about diversions.
977 To ensure that a diversion works, line breaks should be added at the
980 To be on the secure side, enclose everything that has to do with
981 diversions into a pair of line breaks; for example, by amply using
985 This rule should be applied to diversion definition, both inside and
986 outside, and to all calls of diversions.
988 This is a bit of overkill, but it works nicely.
992 [If you really need diversions which should ignore the current partial
993 line, use environments to save the current partial line and/\:or use the
999 The most powerful feature using diversions is to start a diversion
1000 within a macro definition and end it within another macro.
1002 Then everything between each call of this macro pair is stored within
1003 the diversion and can be manipulated from within the macros.
1006 .\" --------------------------------------------------------------------
1008 .\" --------------------------------------------------------------------
1010 All macro names must be named
1012 to fully use the tmac mechanism.
1015 as with classical packages is possible as well, but deprecated.
1019 The macro files are kept in the
1020 .IR "tmac directories" ;
1021 a colon separated list of these constitutes the
1026 The search sequence for macro files is (in that order):
1029 the directories specified with troff/groff's
1034 the directories given in the
1035 .Env_var $GROFF_TMAC_PATH
1036 environment variable
1039 the current directory (only if in unsafe mode, which is enabled by the
1041 command line switch)
1047 a platform-specific directory, being
1049 in this installation
1052 a site-specific (platform-independent) directory, being
1054 in this installation
1057 the main tmac directory, being
1059 in this installation
1062 .\" --------------------------------------------------------------------
1064 .\" --------------------------------------------------------------------
1067 .Env_var $GROFF_TMAC_PATH
1068 A colon separated list of additional tmac directories in which to search
1071 See the previous section for a detailed description.
1074 .\" --------------------------------------------------------------------
1076 .\" --------------------------------------------------------------------
1078 Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
1081 This document is distributed under the terms of the FDL (GNU Free
1082 Documentation License) version 1.1 or later.
1084 You should have received a copy of the FDL on your system, it is also
1085 available on-line at the
1086 .URL http://\:www.gnu.org/\:copyleft/\:fdl.html "GNU copyleft site" .
1089 This document is part of
1091 the GNU roff distribution.
1094 .MTO bwarken@mayn.de "Bernd Warken" ;
1096 .MTO wl@gnu.org "Werner Lemberg" .
1099 .\" --------------------------------------------------------------------
1101 .\" --------------------------------------------------------------------
1103 A complete reference for all parts of the groff system is found in the
1109 .BR groff (@MAN1EXT@)
1110 an overview of the groff system.
1113 .BR groff_man (@MAN7EXT@),
1115 .BR groff_mdoc (@MAN7EXT@),
1117 .BR groff_me (@MAN7EXT@),
1119 .BR groff_mm (@MAN7EXT@),
1121 .BR groff_mom (@MAN7EXT@),
1123 .BR groff_ms (@MAN7EXT@),
1125 .BR groff_www (@MAN7EXT@).
1126 the groff tmac macro packages.
1129 .BR groff (@MAN7EXT@)
1134 The Filesystem Hierarchy Standard is available at the
1135 .URL http://\:www.pathname.com/\:fhs/ "FHS web site" .
1137 .\" Local Variables: