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: 27 Jul 2004
19 This file is part of groff, the GNU roff type-setting system.
21 Copyright (C) 2000, 2001, 2002, 2003, 2004 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@).
350 An alternative macro package for man\~pages mainly used in BSD
351 systems; it provides many new features, but it is not the standard for
353 .BR groff_mdoc (@MAN7EXT@).
356 .\" --------------------------------------------------------------------
358 .\" --------------------------------------------------------------------
360 The packages in this section provide a complete set of macros for
361 writing documents of any kind, up to whole books.
363 They are similar in functionality; it is a matter of taste which one
372 .BR groff_me (@MAN7EXT@).
380 .BR groff_mm (@MAN7EXT@).
387 macro package, only available in groff.
389 As this is not based on other packages, it can be freely designed.
391 So it is expected to become quite a nice, modern macro package.
394 .BR groff_mom (@MAN7EXT@).
402 .BR groff_ms (@MAN7EXT@).
405 .\" --------------------------------------------------------------------
406 .SS "Special Packages"
407 .\" --------------------------------------------------------------------
409 The macro packages in this section are not intended for stand-alone
410 usage, but can be used to add special functionality to any other
411 macro package or to plain groff.
416 This macro file is already loaded at start-up by
418 so it isn't necessary to call it explicitly.
420 It provides an interface to set the paper size on the command line with
421 the option \f[B]\%\-dpaper=\f[]\f[I]size\f[].
425 are the same as the predefined
427 values in the DESC file (only lowercase; see
428 .BR groff_font (@MAN5EXT@)
434 (ell) character denotes landscape orientation.
442 Most output drivers need additional command line switches
446 to override the default paper length and orientation as set in the driver
449 For example, use the following for PS output on A4 paper in landscape
453 .Shell_cmd "groff \-Tps \-dpaper=a4l \-P\-pa4 \-P\-l \-ms foo.ms > foo.ps"
458 This file provides proper definitions for the macros
463 .BR @g@pic (@MAN1EXT@)
466 They will center each picture.
468 Use it only if your macro package doesn't provide proper definitions
469 for those two macros (actually, most of them already have).
474 A single macro is provided in this file,
476 to include a PostScript graphic in a document.
478 It makes only sense for output devices which support inclusion of PS
484 the file is then loaded automatically.
489 \&\fB.PSPIC\fP [\fB\-L\fP|\fB-R\fP|\fB\-I\fP \fIn\fP]\ \fI\|file\fP [\fIwidth\fP [\fIheight\fP]]
494 is the name of the file containing the illustration;
498 give the desired width and height of the graphic.
504 arguments may have scaling indicators attached;
505 the default scaling indicator is\~\c
508 This macro will scale the graphic uniformly
509 in the x and y\~directions so that it is no more than
516 By default, the graphic will be horizontally centered.
522 options cause the graphic to be left-aligned and right-aligned,
527 option causes the graphic to be indented by\~\c
529 (default scaling indicator is\~\c
535 Use this for tracing macro calls.
537 It is only useful for debugging.
540 .BR groff_trace (@MAN7EXT@) .
545 Overrides the definition of standard troff characters and some groff
546 characters for tty devices.
548 The optical appearance is intentionally inferior compared to that of
549 normal tty formatting to allow processing with critical equipment.
554 Additions of elements known from the html format, as being used in the
555 internet (World Wide Web) pages; this includes URL links and mail
557 .BR groff_www (@MAN7EXT@).
560 .\" --------------------------------------------------------------------
562 .\" --------------------------------------------------------------------
564 In classical roff systems, there was a funny naming scheme for macro
565 packages, due to a simplistic design in option parsing.
567 Macro packages were always included by option
569 when this option was directly followed by its argument without an
570 intervening space, this looked like a long option preceded by a single
571 minus \[em] a sensation in the computer stone age.
573 To make this optically working for macro package names, all classical
574 macro packages choose a name that started with the letter
576 which was omitted in the naming of the macro file.
580 For example, the macro package for the man pages was called
584 So it could be activated by the argument
594 For similar reasons, macro packages that did not start with an
598 added in the documentation and in talking; for example, the package
603 in the documentation, although a more suitable name would be
605 For, when omitting the space between the option and its argument, the
606 command line option for activating this package reads
611 To cope with all situations, actual versions of
612 .BR groff (@MAN1EXT@)
613 are smart about both naming schemes by providing two macro files
614 for the inflicted macro packages; one with a leading
616 the other one without it.
622 macro package may be specified as on of the following four methods:
625 .Shell_cmd "groff\~\-m\~man"
626 .Shell_cmd "groff\~\-man"
627 .Shell_cmd "groff\~\-mman"
628 .Shell_cmd "groff\~\-m\~an"
632 Recent packages that do not start with
634 do not use an additional
636 in the documentation.
640 macro package may be specified only as one of the two methods:
643 .Shell_cmd "groff\~\-m\~www"
644 .Shell_cmd "groff\~\-mwww"
648 Obviously, variants like
650 would not make much sense.
654 A second strange feature of classical troff was to name macro files
657 In modern operating systems, the type of a file is specified as
658 postfix, the file name extension.
660 Again, groff copes with this situation by searching both
670 The easiest way to find out which macro packages are available on a
671 system is to check the man\~page
672 .BR groff (@MAN1EXT@),
673 or the contents of the
681 most macro packages are described in\~man pages called
682 .BR groff_\f[I]name\f[] (@MAN7EXT@),
685 for the classical packages.
688 .\" --------------------------------------------------------------------
690 .\" --------------------------------------------------------------------
692 There are several ways to use a macro package in a document.
694 The classical way is to specify the troff/groff option
697 at run-time; this makes the contents of the macro package
703 is searched within the tmac path; if not found,
705 will be searched for instead.
709 Alternatively, it is also possible to include a macro file by adding
713 into the document; the argument must be the full file name of an
714 existing file, possibly with the directory where it is kept.
716 In groff, this was improved by the similar request
719 which added searching in the tmac path, just like option
725 Note that in order to resolve the
729 requests, the roff preprocessor
730 .BR soelim (@MAN1EXT@)
731 must be called if the files to be included need preprocessing.
733 This can be done either directly by a pipeline on the command line or
734 by using the troff/groff option
738 calls soelim automatically.
742 For example, suppose a macro file is stored as
743 .I @MACRODIR@/macros.tmac
744 and is used in some document called
749 At run-time, the formatter call for this is
752 .Shell_cmd "groff\~\-m\~" "macrofile\~document.roff"
756 To include the macro file directly in the document either
760 . Text .mso macrofile.tmac
768 . Text .so @MACRODIR@/macros.tmac
773 In both cases, the formatter is called with
775 .Shell_cmd "groff\~\-s\~" docu.roff
779 If you want to write your own groff macro file, call it
781 and put it in some directory of the tmac path, see section
783 Then documents can include it with the
785 request or the option
790 .\" --------------------------------------------------------------------
792 .\" --------------------------------------------------------------------
794 .\" This section does not fit into the framework of this document.
796 There is a convention that is supported by many modern roff
801 described in the following.
804 If the first line in a document is a comment, the first word (after the
805 comment characters and a blank) constitutes the
808 That means that the letters of this word are interpreted as
809 abbreviations for those preprocessor commands that should be run
810 when formatting the document.
812 Mostly, only the letters corresponding to the options for the
813 preprocessors are recognized,
833 .BR roff (@MAN7EXT@)).
837 Besides being a good reminder for the user, some formatters (like the
839 program) are even able to automatically start the preprocessors
840 specified in the preprocessor word, but do not bet on this.
846 program handles some preprocessors automatically, such that in
847 man\~pages only the following characters should be used:
855 .\" --------------------------------------------------------------------
857 .\" --------------------------------------------------------------------
861 document is a text file that is enriched by predefined formatting
862 constructs, such as requests, escape sequences, strings, numeric
863 registers, and macros from a macro package.
865 These elements are described in
866 .BR roff (@MAN7EXT@).
870 To give a document a personal style, it is most useful to extend the
871 existing elements by defining some macros for repeating tasks; the best
872 place for this is near the beginning of the document or in a separate
877 Macros without arguments are just like strings.
879 But the full power of macros reveals when arguments are passed with a
882 Within the macro definition, the arguments are available as the escape
887 .BR $[ \*[Ellipsis] ] ,
891 the name under which the macro was called is in
893 and the number of arguments is in register
896 .BR groff (@MAN7EXT@).
899 .\" --------------------------------------------------------------------
901 .\" --------------------------------------------------------------------
903 The phase when groff reads a macro is called
907 This is comparable to the C\~preprocessing phase during the development
908 of a program written in the C\~language.
912 In this phase, groff interprets all backslashes; that means that all
913 escape sequences in the macro body are interpreted and replaced by
916 For constant expression, this is wanted, but strings and registers
917 that might change between calls of the macro must be protected from
920 This is most easily done by doubling the backslash that introduces the
923 This doubling is most important for the positional parameters.
925 For example, to print information on the arguments that were passed to
926 the macro to the terminal, define a macro named `.print_args',
931 .ds @1 \[rs]f[I]\[rs]\[rs]$0\[rs]f[]\"
934 . Text .ds midpart was called with
935 . Text .de print_args
936 . Text .\~\~tm\~\*[@1]\~\[rs]\[rs]*[midpart]\~\[rs]\[rs]n[.$]\~\*[@2]
937 . Text .\~\~tm\~\[rs]\[rs]$*
945 When calling this macro by
949 . Text .print_args arg1 arg2
953 the following text is printed to the terminal:
957 . Text \f[CI]print_args\f[] was called with the following 2 arguments:
963 Let's analyze each backslash in the macro definition.
965 As the positional parameters and the number of arguments will change
966 with each call of the macro their leading backslash must be doubled,
971 The same applies to the macro name because it could be called with an
979 is a constant string, it will not change, so no doubling for
980 .IR \[rs]*[midpart] .
983 escape sequences are predefined groff elements for setting the font
986 Of course, this behavior will not change, so no doubling with
992 .\" --------------------------------------------------------------------
994 .\" --------------------------------------------------------------------
996 Writing groff macros is easy when the escaping mechanism is temporarily
999 In groff, this is done by enclosing the macro definition(s) into a
1006 Then the body in the macro definition is just like a normal part of
1007 the document \[em] text enhanced by calls of requests, macros,
1008 strings, registers, etc.
1010 For example, the code above can be written in a simpler way by
1014 .ds @1 \[rs]f[I]\[rs]$0\[rs]f[]\"
1018 . Text .ds midpart was called with
1019 . Text .de print_args
1020 . Text .\~\~tm\~\*[@1]\~\[rs]*[midpart]\~\[rs]n[.$]\~\*[@2]
1021 . Text .\~\~tm\~\[rs]$*
1030 Unfortunately, draft mode cannot be used universally.
1032 Although it is good enough for defining normal macros, draft mode
1033 will fail with advanced applications, such as indirectly defined
1034 strings, registers, etc.
1036 An optimal way is to define and test all macros in draft mode and then
1037 do the backslash doubling as a final step; do not forget to remove the
1042 .\" --------------------------------------------------------------------
1043 .SS "Tips for Macro Definitions"
1044 .\" --------------------------------------------------------------------
1047 Start every line with a dot, for example, by using the groff request
1049 for text lines, or write your own macro that handles also text lines
1055 . Text .\~\~if (\[rs]\[rs]n[.$] == 0)\~\[rs]
1056 . Text .\~\~\~\~return
1057 . Text .\~nop\~\[rs])\[rs]\[rs]$*[rs]\)
1062 Write a comment macro that works both for copy-in and draft mode; for
1063 as escaping is off in draft mode, trouble might occur when normal
1066 For example, the following macro just ignores its arguments, so it
1067 acts like a comment line:
1073 . Text .c\~This\~is\~like\~a\~comment\~line.
1077 In long macro definitions, make ample use of comment lines or empty
1078 lines for a better structuring.
1081 To increase readability, use groff's indentation facility for requests
1082 and macro calls (arbitrary whitespace after the leading dot).
1085 .\" --------------------------------------------------------------------
1087 .\" --------------------------------------------------------------------
1089 Diversions can be used to realize quite advanced programming
1092 They are comparable to pointers to large data structures in the
1093 C\~programming language, but their usage is quite different.
1097 In their simplest form, diversions are multi-line strings, but
1098 they get their power when diversions are used dynamically within macros.
1100 The information stored in a diversion can be retrieved by calling the
1101 diversion just like a macro.
1105 Most of the problems arising with diversions can be avoided if you are
1106 conscious about the fact that diversions always deal with complete
1109 If diversions are used when the line buffer has not been flashed,
1110 strange results are produced; not knowing this, many people get
1111 desperate about diversions.
1113 To ensure that a diversion works, line breaks should be added at the
1116 To be on the secure side, enclose everything that has to do with
1117 diversions into a pair of line breaks; for example, by amply using
1121 This rule should be applied to diversion definition, both inside and
1122 outside, and to all calls of diversions.
1124 This is a bit of overkill, but it works nicely.
1128 [If you really need diversions which should ignore the current partial
1129 line, use environments to save the current partial line and/\:or use the
1135 The most powerful feature using diversions is to start a diversion
1136 within a macro definition and end it within another macro.
1138 Then everything between each call of this macro pair is stored within
1139 the diversion and can be manipulated from within the macros.
1142 .\" --------------------------------------------------------------------
1144 .\" --------------------------------------------------------------------
1146 All macro names must be named
1148 to fully use the tmac mechanism.
1151 as with classical packages is possible as well, but deprecated.
1155 The macro files are kept in the
1156 .IR "tmac directories" ;
1157 a colon separated list of these constitutes the
1162 The search sequence for macro files is (in that order):
1165 the directories specified with troff/groff's
1170 the directories given in the
1171 .Env_var $GROFF_TMAC_PATH
1172 environment variable
1175 the current directory (only if in unsafe mode, which is enabled by the
1177 command line switch)
1183 a platform-specific directory, being
1185 in this installation
1188 a site-specific (platform-independent) directory, being
1190 in this installation
1193 the main tmac directory, being
1195 in this installation
1198 .\" --------------------------------------------------------------------
1200 .\" --------------------------------------------------------------------
1203 .Env_var $GROFF_TMAC_PATH
1204 A colon separated list of additional tmac directories in which to search
1207 See the previous section for a detailed description.
1210 .\" --------------------------------------------------------------------
1212 .\" --------------------------------------------------------------------
1214 Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
1217 This document is distributed under the terms of the FDL (GNU Free
1218 Documentation License) version 1.1 or later.
1220 You should have received a copy of the FDL on your system, it is also
1221 available on-line at the
1222 .URL http://\:www.gnu.org/\:copyleft/\:fdl.html "GNU copyleft site" .
1225 This document is part of
1227 the GNU roff distribution.
1230 .MTO bwarken@mayn.de "Bernd Warken" ;
1232 .MTO wl@gnu.org "Werner Lemberg" .
1235 .\" --------------------------------------------------------------------
1237 .\" --------------------------------------------------------------------
1239 A complete reference for all parts of the groff system is found in the
1246 .BR groff (@MAN1EXT@)
1247 an overview of the groff system.
1251 .BR groff_man (@MAN7EXT@),
1253 .BR groff_mdoc (@MAN7EXT@),
1255 .BR groff_me (@MAN7EXT@),
1257 .BR groff_mm (@MAN7EXT@),
1259 .BR groff_mom (@MAN7EXT@),
1261 .BR groff_ms (@MAN7EXT@),
1263 .BR groff_trace (@MAN7EXT@),
1265 .BR groff_www (@MAN7EXT@).
1266 the groff tmac macro packages.
1270 .BR groff (@MAN7EXT@)
1275 The Filesystem Hierarchy Standard is available at the
1276 .URL http://\:www.pathname.com/\:fhs/ "FHS web site" .
1278 .cp \n[groff_tmac_C]
1280 .\" Local Variables: