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: 13 Mar 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 .\" --------------------------------------------------------------------
48 .ds Ellipsis \&.\|.\|.\&\"
50 .\" Global static variables for inter-macro communication
53 .\" --------------------------------------------------------------------
54 .\" setup for the macro definitions below
56 .\" naming: namespace:cathegory_macro.variable_name (experimental)
58 .\" --------------------------------------------------------------------
59 .\" configuration of prompt for `.Shell_cmd'* macros
60 .ds groffer:Shell_cmd.prompt_text sh#\" prompt for shell commands
61 .ds groffer:Shell_cmd+.prompt_text >\" prompt on continuation lines
62 .ds groffer:Shell_cmd_base.prompt_font I\" font for prompts
64 .\" automatically determine setup from the configuration above
65 .als @f groffer:Shell_cmd_base.prompt_font\"
66 .als @t groffer:Shell_cmd.prompt_text\"
67 .als @t+ groffer:Shell_cmd+.prompt_text\"
68 .ds groffer:Shell_cmd.prompt \f[\*[@f]]\*[@t]\f[]\" needed
69 .ds groffer:Shell_cmd+.prompt \f[\*[@f]]\*[@t+]\f[]\" needed
70 .nr @w \w'\*[groffer:Shell_cmd.prompt]'\"
71 .nr @w+ \w'\*[groffer:Shell_cmd+.prompt]'\"
73 .\" Full prompt width is maximum of texts plus 1m
74 .nr groffer:Shell_cmd_base.prompt_width (\n[@w]>?\n[@w+]+1m)\" needed
83 .\"--------------------------------------------------------------------
84 .\" Ignore all arguments like a comment, even after a .eo call.
87 .c --------------------------------------------------------------------
92 . ds @tmp@ \fB\\$1\f[]\fI\\$2\f[]
94 . Text \\*[@tmp@]\fR\\$*\f[]
98 .c --------------------------------------------------------------------
99 .c .Env_var (<env_var_name> [<punct>])
101 .c Display an environment variable, with optional punctuation.
106 . Text \f[CB]\\$1\f[]\\$2
109 .c --------------------------------------------------------------------
110 .c .Error (<text>...)
112 .c Print error message to terminal and abort.
118 .c --------------------------------------------------------------------
120 . if r@+Example_font \
121 . Error previous .Example was not terminated by a ./Example
122 . nr @+Example_font \\n[.f]
128 .c --------------------------------------------------------------------
130 . if !r@+Example_font \
131 . Error no previous call to .Example
132 . ft \\n[@+Example_font]
139 .c --------------------------------------------------------------------
140 .c .Shell_cmd (<CR> [<CI>] ...)
142 .c A shell command line; display args alternating in fonts CR and CI.
145 .c .Shell_cmd "groffer --dpi 100 file"
146 .c result: `sh# groffer --dpi 100 file'
147 .c with 'sh#' in font I, the rest in CR
149 .c .Shell_cmd groffer\~--dpi\~100\~file
150 .c result: the same as above
152 .c .Shell_cmd "groffer --dpi=" value " file"
153 .c result: sh# groffer --dpi=value file
154 .c with `groffer --dpi=' and `file' in CR; `value' in CI
156 .c .Shell_cmd groffer\~--dpi= value \~file
157 .c result: the same as the previous example
160 . groffer:Shell_cmd_base "\*[groffer:Shell_cmd.prompt]" \\$@
162 .c --------------------------------------------------------------------
163 .c .Shell_cmd+ (<CR> [<CI>] ...)
165 .c A continuation line for .Shell_cmd.
168 . groffer:Shell_cmd_base "\*[groffer:Shell_cmd+.prompt]" \\$@
170 .c --------------------------------------------------------------------
171 .c .Shell_cmd_base (<prompt> [<CR> [<CI>] ...])
173 .c A shell command line; display args alternating in fonts CR and CI.
174 .c Internal, do not use directly.
176 .c Globals: read-only register @.Shell_cmd_width
178 .de groffer:Shell_cmd_base
179 . if (\\n[.$] <= 0) \
181 . nr @+font \\n[.f]\"
184 . c gap between prompt and command
185 . nr @+gap \\n[groffer:Shell_cmd_base.prompt_width]-\\w'\\*[@prompt]'\"
186 . ds @res \\*[@prompt]\h'\\n[@+gap]u'\"
189 . while (\\n[.$] > 0) \{\
190 . as @res \\f[\\*[@cf]]\\$1\"
212 .c --------------------------------------------------------------------
215 .c Treat the arguments as text, no matter how they look.
218 . if (\\n[.$] == 0) \
222 .c --------------------------------------------------------------------
223 .c .Topic ([<indent>])
225 .c A bulleted paragraph
236 .c --------------------------------------------------------------------
239 .c Continuation line for .TP header.
246 .c --------------------------------------------------------------------
248 . ds @tmp@ `\f(CR\\$1\f[]'
250 . Text \\*[@tmp@]\\$*
253 .c --------------------------------------------------------------------
255 . ds @tmp@ \f(CB\\$1\f[]
257 . Text \\*[@tmp@]\\$*
260 .c --------------------------------------------------------------------
262 . ds @tmp@ \f(CI\\$1\f[]
264 . Text \\*[@tmp@]\\$*
267 .c --------------------------------------------------------------------
269 . ds @tmp@ \f(CB\\$1\f[]
271 . Text .\\*[@tmp@]\\$*
274 .c --------------------------------------------------------------------
276 . ds @tmp@ \f[CB]\\$1\f[]
278 . Text \[rs]\\*[@tmp@]\\$*
281 .\" --------------------------------------------------------------------
283 .\" --------------------------------------------------------------------
287 type-setting system provides a set of macro packages suitable for
288 special kinds of documents.
290 Each macro package stores its macros and definitions in a file called
293 The name is deduced from
299 The tmac files are normal roff source documents, except that they
300 usually contain only definitions and setup commands, but no text.
302 All tmac files are kept in a single or a small number of directories,
308 .\" --------------------------------------------------------------------
309 .SH "GROFF MACRO PACKAGES"
310 .\" --------------------------------------------------------------------
313 provides all classical macro packages, some more full packages, and
314 some secondary packages for special purposes.
316 Note that it is not possible to use multiple primary macro packages at the
317 same time; saying e.g.\&
320 .Shell_cmd "groff \-m man \-m ms foo"
326 .Shell_cmd "groff \-m man foo \-m ms bar"
332 .\" --------------------------------------------------------------------
334 .\" --------------------------------------------------------------------
338 This is the classical macro package for UNIX manual pages
339 (man\~pages); it is quite handy and easy to use; see
340 .BR groff_man (@MAN7EXT@).
346 An alternative macro package for man\~pages mainly used in BSD
347 systems; it provides many new features, but it is not the standard for
349 .BR groff_mdoc (@MAN7EXT@).
352 .\" --------------------------------------------------------------------
354 .\" --------------------------------------------------------------------
356 The packages in this section provide a complete set of macros for
357 writing documents of any kind, up to whole books.
359 They are similar in functionality; it is a matter of taste which one
368 .BR groff_me (@MAN7EXT@).
376 .BR groff_mm (@MAN7EXT@).
383 macro package, only available in groff.
385 As this is not based on other packages, it can be freely designed.
387 So it is expected to become quite a nice, modern macro package.
390 .BR groff_mom (@MAN7EXT@).
398 .BR groff_ms (@MAN7EXT@).
401 .\" --------------------------------------------------------------------
402 .SS "Special Packages"
403 .\" --------------------------------------------------------------------
405 The macro packages in this section are not intended for stand-alone
406 usage, but can be used to add special functionality to any other
407 macro package or to plain groff.
412 This macro file is already loaded at start-up by
414 so it isn't necessary to call it explicitly.
416 It provides an interface to set the paper size on the command line with
417 the option \f[B]\%\-dpaper=\f[]\f[I]size\f[].
421 are the same as the predefined
423 values in the DESC file (only lowercase; see
424 .BR groff_font (@MAN5EXT@)
430 (ell) character denotes landscape orientation.
438 Most output drivers need additional command line switches
442 to override the default paper length and orientation as set in the driver
445 For example, use the following for PS output on A4 paper in landscape
449 .Shell_cmd "groff \-Tps \-dpaper=a4l \-P\-pa4 \-P\-l \-ms foo.ms > foo.ps"
454 A single macro is provided in this file,
456 to include a PostScript graphic in a document.
458 It makes only sense for output devices which support inclusion of PS
464 the file is then loaded automatically.
469 \&\fB.PSPIC\fP [\fB\-L\fP|\fB-R\fP|\fB\-I\fP \fIn\fP]\ \fI\|file\fP [\fIwidth\fP [\fIheight\fP]]
474 is the name of the file containing the illustration;
478 give the desired width and height of the graphic.
484 arguments may have scaling indicators attached;
485 the default scaling indicator is\~\c
488 This macro will scale the graphic uniformly
489 in the x and y\~directions so that it is no more than
496 By default, the graphic will be horizontally centered.
502 options cause the graphic to be left-aligned and right-aligned,
507 option causes the graphic to be indented by\~\c
509 (default scaling indicator is\~\c
514 Overrides the definition of standard troff characters and some groff
515 characters for tty devices.
517 The optical appearance is intentionally inferior compared to that of
518 normal tty formatting to allow processing with critical equipment.
523 Additions of elements known from the html format, as being used in the
524 internet (World Wide Web) pages; this includes URL links and mail
526 .BR groff_www (@MAN7EXT@).
529 .\" --------------------------------------------------------------------
531 .\" --------------------------------------------------------------------
533 In classical roff systems, there was a funny naming scheme for macro
534 packages, due to a simplistic design in option parsing.
536 Macro packages were always included by option
538 when this option was directly followed by its argument without an
539 intervening space, this looked like a long option preceded by a single
540 minus \[em] a sensation in the computer stone age.
542 To make this optically working for macro package names, all classical
543 macro packages choose a name that started with the letter
545 which was omitted in the naming of the macro file.
549 For example, the macro package for the man pages was called
553 So it could be activated by the argument
563 For similar reasons, macro packages that did not start with an
567 added in the documentation and in talking; for example, the package
572 in the documentation, although a more suitable name would be
574 For, when omitting the space between the option and its argument, the
575 command line option for activating this package reads
580 To cope with all situations, actual versions of
581 .BR groff (@MAN1EXT@)
582 are smart about both naming schemes by providing two macro files
583 for the inflicted macro packages; one with a leading
585 the other one without it.
591 macro package may be specified as on of the following four methods:
594 .Shell_cmd "groff\~\-m\~man"
595 .Shell_cmd "groff\~\-man"
596 .Shell_cmd "groff\~\-mman"
597 .Shell_cmd "groff\~\-m\~an"
601 Recent packages that do not start with
603 do not use an additional
605 in the documentation.
609 macro package may be specified only as one of the two methods:
612 .Shell_cmd "groff\~\-m\~www"
613 .Shell_cmd "groff\~\-mwww"
617 Obviously, variants like
619 would not make much sense.
623 A second strange feature of classical troff was to name macro files
626 In modern operating systems, the type of a file is specified as
627 postfix, the file name extension.
629 Again, groff copes with this situation by searching both
639 The easiest way to find out which macro packages are available on a
640 system is to check the man\~page
641 .BR groff (@MAN1EXT@),
642 or the contents of the
650 most macro packages are described in\~man pages called
651 .BR groff_\f[I]name\f[] (@MAN7EXT@),
654 for the classical packages.
657 .\" --------------------------------------------------------------------
659 .\" --------------------------------------------------------------------
661 There are several ways to use a macro package in a document.
663 The classical way is to specify the troff/groff option
666 at run-time; this makes the contents of the macro package
672 is searched within the tmac path; if not found,
674 will be searched for instead.
678 Alternatively, it is also possible to include a macro file by adding
682 into the document; the argument must be the full file name of an
683 existing file, possibly with the directory where it is kept.
685 In groff, this was improved by the similar request
688 which added searching in the tmac path, just like option
694 Note that in order to resolve the
698 requests, the roff preprocessor
699 .BR soelim (@MAN1EXT@)
700 must be called if the files to be included need preprocessing.
702 This can be done either directly by a pipeline on the command line or
703 by using the troff/groff option
707 calls soelim automatically.
711 For example, suppose a macro file is stored as
712 .I @MACRODIR@/macros.tmac
713 and is used in some document called
718 At run-time, the formatter call for this is
721 .Shell_cmd "groff\~\-m\~" "macrofile\~document.roff"
725 To include the macro file directly in the document either
729 . Text .mso macrofile.tmac
737 . Text .so @MACRODIR@/macros.tmac
742 In both cases, the formatter is called with
744 .Shell_cmd "groff\~\-s\~" docu.roff
748 If you want to write your own groff macro file, call it
750 and put it in some directory of the tmac path, see section
752 Then documents can include it with the
754 request or the option
759 .\" --------------------------------------------------------------------
761 .\" --------------------------------------------------------------------
763 .\" This section does not fit into the framework of this document.
765 There is a convention that is supported by many modern roff
770 described in the following.
773 If the first line in a document is a comment, the first word (after the
774 comment characters and a blank) constitutes the
777 That means that the letters of this word are interpreted as
778 abbreviations for those preprocessor commands that should be run
779 when formatting the document.
781 Mostly, only the letters corresponding to the options for the
782 preprocessors are recognized,
802 .BR roff (@MAN7EXT@)).
806 Besides being a good reminder for the user, some formatters (like the
808 program) are even able to automatically start the preprocessors
809 specified in the preprocessor word, but do not bet on this.
815 program handles some preprocessors automatically, such that in
816 man\~pages only the following characters should be used:
824 .\" --------------------------------------------------------------------
826 .\" --------------------------------------------------------------------
830 document is a text file that is enriched by predefined formatting
831 constructs, such as requests, escape sequences, strings, numeric
832 registers, and macros from a macro package.
834 These elements are described in
835 .BR roff (@MAN7EXT@).
839 To give a document a personal style, it is most useful to extend the
840 existing elements by defining some macros for repeating tasks; the best
841 place for this is near the beginning of the document or in a separate
846 Macros without arguments are just like strings.
848 But the full power of macros reveals when arguments are passed with a
851 Within the macro definition, the arguments are available as the escape
856 .BR $[ \*[Ellipsis] ] ,
860 the name under which the macro was called is in
862 and the number of arguments is in register
865 .BR groff (@MAN7EXT@).
868 .\" --------------------------------------------------------------------
870 .\" --------------------------------------------------------------------
872 The phase when groff reads a macro is called
876 This is comparable to the C\~preprocessing phase during the development
877 of a program written in the C\~language.
881 In this phase, groff interprets all backslashes; that means that all
882 escape sequences in the macro body are interpreted and replaced by
885 For constant expression, this is wanted, but strings and registers
886 that might change between calls of the macro must be protected from
889 This is most easily done by doubling the backslash that introduces the
892 This doubling is most important for the positional parameters.
894 For example, to print information on the arguments that were passed to
895 the macro to the terminal, define a macro named `.print_args',
900 .ds @1 \[rs]f[I]\[rs]\[rs]$0\[rs]f[]\"
903 . Text .ds midpart was called with
904 . Text .de print_args
905 . Text .\~\~tm\~\*[@1]\~\[rs]\[rs]*[midpart]\~\[rs]\[rs]n[.$]\~\*[@2]
906 . Text .\~\~tm\~\[rs]\[rs]$*
914 When calling this macro by
918 . Text .print_args arg1 arg2
922 the following text is printed to the terminal:
926 . Text \f[CI]print_args\f[] was called with the following 2 arguments:
932 Let's analyze each backslash in the macro definition.
934 As the positional parameters and the number of arguments will change
935 with each call of the macro their leading backslash must be doubled,
940 The same applies to the macro name because it could be called with an
948 is a constant string, it will not change, so no doubling for
949 .IR \[rs]*[midpart] .
952 escape sequences are predefined groff elements for setting the font
955 Of course, this behavior will not change, so no doubling with
961 .\" --------------------------------------------------------------------
963 .\" --------------------------------------------------------------------
965 Writing groff macros is easy when the escaping mechanism is temporarily
968 In groff, this is done by enclosing the macro definition(s) into a
975 Then the body in the macro definition is just like a normal part of
976 the document \[em] text enhanced by calls of requests, macros,
977 strings, registers, etc.
979 For example, the code above can be written in a simpler way by
983 .ds @1 \[rs]f[I]\[rs]$0\[rs]f[]\"
987 . Text .ds midpart was called with
988 . Text .de print_args
989 . Text .\~\~tm\~\*[@1]\~\[rs]*[midpart]\~\[rs]n[.$]\~\*[@2]
990 . Text .\~\~tm\~\[rs]$*
999 Unfortunately, draft mode cannot be used universally.
1001 Although it is good enough for defining normal macros, draft mode
1002 will fail with advanced applications, such as indirectly defined
1003 strings, registers, etc.
1005 An optimal way is to define and test all macros in draft mode and then
1006 do the backslash doubling as a final step; do not forget to remove the
1011 .\" --------------------------------------------------------------------
1012 .SS "Tips for Macro Definitions"
1013 .\" --------------------------------------------------------------------
1016 Start every line with a dot, for example, by using the groff request
1018 for text lines, or write your own macro that handles also text lines
1024 . Text .\~\~if (\[rs]\[rs]n[.$] == 0)\~\[rs]
1025 . Text .\~\~\~\~return
1026 . Text .\~nop\~\[rs])\[rs]\[rs]$*[rs]\)
1031 Write a comment macro that works both for copy-in and draft mode; for
1032 as escaping is off in draft mode, trouble might occur when normal
1035 For example, the following macro just ignores its arguments, so it
1036 acts like a comment line:
1042 . Text .c\~This\~is\~like\~a\~comment\~line.
1046 In long macro definitions, make ample use of comment lines or empty
1047 lines for a better structuring.
1050 To increase readability, use groff's indentation facility for requests
1051 and macro calls (arbitrary whitespace after the leading dot).
1054 .\" --------------------------------------------------------------------
1056 .\" --------------------------------------------------------------------
1058 Diversions can be used to realize quite advanced programming
1061 They are comparable to pointers to large data structures in the
1062 C\~programming language, but their usage is quite different.
1066 In their simplest form, diversions are multi-line strings, but
1067 they get their power when diversions are used dynamically within macros.
1069 The information stored in a diversion can be retrieved by calling the
1070 diversion just like a macro.
1074 Most of the problems arising with diversions can be avoided if you are
1075 conscious about the fact that diversions always deal with complete
1078 If diversions are used when the line buffer has not been flashed,
1079 strange results are produced; not knowing this, many people get
1080 desperate about diversions.
1082 To ensure that a diversion works, line breaks should be added at the
1085 To be on the secure side, enclose everything that has to do with
1086 diversions into a pair of line breaks; for example, by amply using
1090 This rule should be applied to diversion definition, both inside and
1091 outside, and to all calls of diversions.
1093 This is a bit of overkill, but it works nicely.
1097 [If you really need diversions which should ignore the current partial
1098 line, use environments to save the current partial line and/\:or use the
1104 The most powerful feature using diversions is to start a diversion
1105 within a macro definition and end it within another macro.
1107 Then everything between each call of this macro pair is stored within
1108 the diversion and can be manipulated from within the macros.
1111 .\" --------------------------------------------------------------------
1113 .\" --------------------------------------------------------------------
1115 All macro names must be named
1117 to fully use the tmac mechanism.
1120 as with classical packages is possible as well, but deprecated.
1124 The macro files are kept in the
1125 .IR "tmac directories" ;
1126 a colon separated list of these constitutes the
1131 The search sequence for macro files is (in that order):
1134 the directories specified with troff/groff's
1139 the directories given in the
1140 .Env_var $GROFF_TMAC_PATH
1141 environment variable
1144 the current directory (only if in unsafe mode, which is enabled by the
1146 command line switch)
1152 a platform-specific directory, being
1154 in this installation
1157 a site-specific (platform-independent) directory, being
1159 in this installation
1162 the main tmac directory, being
1164 in this installation
1167 .\" --------------------------------------------------------------------
1169 .\" --------------------------------------------------------------------
1172 .Env_var $GROFF_TMAC_PATH
1173 A colon separated list of additional tmac directories in which to search
1176 See the previous section for a detailed description.
1179 .\" --------------------------------------------------------------------
1181 .\" --------------------------------------------------------------------
1183 Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
1186 This document is distributed under the terms of the FDL (GNU Free
1187 Documentation License) version 1.1 or later.
1189 You should have received a copy of the FDL on your system, it is also
1190 available on-line at the
1191 .URL http://\:www.gnu.org/\:copyleft/\:fdl.html "GNU copyleft site" .
1194 This document is part of
1196 the GNU roff distribution.
1199 .MTO bwarken@mayn.de "Bernd Warken" ;
1201 .MTO wl@gnu.org "Werner Lemberg" .
1204 .\" --------------------------------------------------------------------
1206 .\" --------------------------------------------------------------------
1208 A complete reference for all parts of the groff system is found in the
1214 .BR groff (@MAN1EXT@)
1215 an overview of the groff system.
1218 .BR groff_man (@MAN7EXT@),
1220 .BR groff_mdoc (@MAN7EXT@),
1222 .BR groff_me (@MAN7EXT@),
1224 .BR groff_mm (@MAN7EXT@),
1226 .BR groff_mom (@MAN7EXT@),
1228 .BR groff_ms (@MAN7EXT@),
1230 .BR groff_www (@MAN7EXT@).
1231 the groff tmac macro packages.
1234 .BR groff (@MAN7EXT@)
1239 The Filesystem Hierarchy Standard is available at the
1240 .URL http://\:www.pathname.com/\:fhs/ "FHS web site" .
1242 .\" Local Variables: