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: 07 Feb 2006
19 This file is part of groff, the GNU roff type-setting system.
21 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006
22 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 .\" --------------------------------------------------------------------
40 .do nr groff_tmac_C \n[.C]
52 .ds Ellipsis \&.\|.\|.\&\"
54 .\" Global static variables for inter-macro communication
57 .\" --------------------------------------------------------------------
58 .\" setup for the macro definitions below
60 .\" naming: namespace:cathegory_macro.variable_name (experimental)
62 .\" --------------------------------------------------------------------
63 .\" configuration of prompt for `.Shell_cmd'* macros
64 .ds groffer:Shell_cmd.prompt_text sh#\" prompt for shell commands
65 .ds groffer:Shell_cmd+.prompt_text >\" prompt on continuation lines
66 .ds groffer:Shell_cmd_base.prompt_font I\" font for prompts
68 .\" automatically determine setup from the configuration above
69 .als @f groffer:Shell_cmd_base.prompt_font\"
70 .als @t groffer:Shell_cmd.prompt_text\"
71 .als @t+ groffer:Shell_cmd+.prompt_text\"
72 .ds groffer:Shell_cmd.prompt \f[\*[@f]]\*[@t]\f[]\" needed
73 .ds groffer:Shell_cmd+.prompt \f[\*[@f]]\*[@t+]\f[]\" needed
74 .nr @w \w'\*[groffer:Shell_cmd.prompt]'\"
75 .nr @w+ \w'\*[groffer:Shell_cmd+.prompt]'\"
77 .\" Full prompt width is maximum of texts plus 1m
78 .nr groffer:Shell_cmd_base.prompt_width (\n[@w]>?\n[@w+]+1m)\" needed
87 .\"--------------------------------------------------------------------
88 .\" Ignore all arguments like a comment, even after a .eo call.
91 .c --------------------------------------------------------------------
96 . ds @tmp@ \fB\\$1\f[]\fI\\$2\f[]
98 . Text \\*[@tmp@]\fR\\$*\f[]
102 .c --------------------------------------------------------------------
103 .c .Env_var (<env_var_name> [<punct>])
105 .c Display an environment variable, with optional punctuation.
110 . Text \f[CB]\\$1\f[]\\$2
113 .c --------------------------------------------------------------------
114 .c .Error (<text>...)
116 .c Print error message to terminal and abort.
122 .c --------------------------------------------------------------------
124 . if r@+Example_font \
125 . Error previous .Example was not terminated by a ./Example
126 . nr @+Example_font \\n[.f]
132 .c --------------------------------------------------------------------
134 . if !r@+Example_font \
135 . Error no previous call to .Example
136 . ft \\n[@+Example_font]
143 .c --------------------------------------------------------------------
144 .c .Shell_cmd (<CR> [<CI>] ...)
146 .c A shell command line; display args alternating in fonts CR and CI.
149 .c .Shell_cmd "groffer --dpi 100 file"
150 .c result: `sh# groffer --dpi 100 file'
151 .c with 'sh#' in font I, the rest in CR
153 .c .Shell_cmd groffer\~--dpi\~100\~file
154 .c result: the same as above
156 .c .Shell_cmd "groffer --dpi=" value " file"
157 .c result: sh# groffer --dpi=value file
158 .c with `groffer --dpi=' and `file' in CR; `value' in CI
160 .c .Shell_cmd groffer\~--dpi= value \~file
161 .c result: the same as the previous example
164 . groffer:Shell_cmd_base "\*[groffer:Shell_cmd.prompt]" \\$@
166 .c --------------------------------------------------------------------
167 .c .Shell_cmd+ (<CR> [<CI>] ...)
169 .c A continuation line for .Shell_cmd.
172 . groffer:Shell_cmd_base "\*[groffer:Shell_cmd+.prompt]" \\$@
174 .c --------------------------------------------------------------------
175 .c .Shell_cmd_base (<prompt> [<CR> [<CI>] ...])
177 .c A shell command line; display args alternating in fonts CR and CI.
178 .c Internal, do not use directly.
180 .c Globals: read-only register @.Shell_cmd_width
182 .de groffer:Shell_cmd_base
183 . if (\\n[.$] <= 0) \
185 . nr @+font \\n[.f]\"
188 . c gap between prompt and command
189 . nr @+gap \\n[groffer:Shell_cmd_base.prompt_width]-\\w'\\*[@prompt]'\"
190 . ds @res \\*[@prompt]\h'\\n[@+gap]u'\"
193 . while (\\n[.$] > 0) \{\
194 . as @res \\f[\\*[@cf]]\\$1\"
216 .c --------------------------------------------------------------------
219 .c Treat the arguments as text, no matter how they look.
222 . if (\\n[.$] == 0) \
226 .c --------------------------------------------------------------------
227 .c .Topic ([<indent>])
229 .c A bulleted paragraph
240 .c --------------------------------------------------------------------
243 .c Continuation line for .TP header.
250 .c --------------------------------------------------------------------
252 . ds @tmp@ `\f(CR\\$1\f[]'
254 . Text \\*[@tmp@]\\$*
257 .c --------------------------------------------------------------------
259 . ds @tmp@ \f(CB\\$1\f[]
261 . Text \\*[@tmp@]\\$*
264 .c --------------------------------------------------------------------
266 . ds @tmp@ \f(CI\\$1\f[]
268 . Text \\*[@tmp@]\\$*
271 .c --------------------------------------------------------------------
273 . ds @tmp@ \f(CB\\$1\f[]
275 . Text .\\*[@tmp@]\\$*
278 .c --------------------------------------------------------------------
280 . ds @tmp@ \f[CB]\\$1\f[]
282 . Text \[rs]\\*[@tmp@]\\$*
285 .\" --------------------------------------------------------------------
287 .\" --------------------------------------------------------------------
291 type-setting system provides a set of macro packages suitable for
292 special kinds of documents.
294 Each macro package stores its macros and definitions in a file called
297 The name is deduced from
303 The tmac files are normal roff source documents, except that they
304 usually contain only definitions and setup commands, but no text.
306 All tmac files are kept in a single or a small number of directories,
312 .\" --------------------------------------------------------------------
313 .SH "GROFF MACRO PACKAGES"
314 .\" --------------------------------------------------------------------
317 provides all classical macro packages, some more full packages, and
318 some secondary packages for special purposes.
320 Note that it is not possible to use multiple primary macro packages at the
321 same time; saying e.g.\&
324 .Shell_cmd "groff \-m man \-m ms foo"
330 .Shell_cmd "groff \-m man foo \-m ms bar"
336 .\" --------------------------------------------------------------------
338 .\" --------------------------------------------------------------------
342 This is the classical macro package for UNIX manual pages
343 (man\~pages); it is quite handy and easy to use; see
344 .BR groff_man (@MAN7EXT@).
351 An alternative macro package for man\~pages mainly used in BSD
352 systems; it provides many new features, but it is not the standard for
354 .BR groff_mdoc (@MAN7EXT@).
357 .\" --------------------------------------------------------------------
359 .\" --------------------------------------------------------------------
361 The packages in this section provide a complete set of macros for
362 writing documents of any kind, up to whole books.
364 They are similar in functionality; it is a matter of taste which one
373 .BR groff_me (@MAN7EXT@).
381 .BR groff_mm (@MAN7EXT@).
388 macro package, only available in groff.
390 As this is not based on other packages, it can be freely designed.
392 So it is expected to become quite a nice, modern macro package.
395 .BR groff_mom (@MAN7EXT@).
403 .BR groff_ms (@MAN7EXT@).
406 .\" --------------------------------------------------------------------
407 .SS "Special Packages"
408 .\" --------------------------------------------------------------------
410 The macro packages in this section are not intended for stand-alone
411 usage, but can be used to add special functionality to any other
412 macro package or to plain groff.
417 This file adds support for French localization of the main macro packages
418 (me, mom, mm, and ms).
420 It should be used as the last macro package on the command line.
424 .Shell_cmd "groff -ms -mfr foo.ms > foo.ps"
429 sets the input encoding to latin-9 to get proper support of the `oe'
435 This macro file is already loaded at start-up by
437 so it isn't necessary to call it explicitly.
439 It provides an interface to set the paper size on the command line with
440 the option \f[B]\%\-dpaper=\f[]\f[I]size\f[].
444 are the same as the predefined
446 values in the DESC file (only lowercase; see
447 .BR groff_font (@MAN5EXT@)
453 (ell) character denotes landscape orientation.
461 Most output drivers need additional command line switches
465 to override the default paper length and orientation as set in the driver
468 For example, use the following for PS output on A4 paper in landscape
472 .Shell_cmd "groff \-Tps \-dpaper=a4l \-P\-pa4 \-P\-l \-ms foo.ms > foo.ps"
477 This file provides proper definitions for the macros
482 .BR @g@pic (@MAN1EXT@)
485 They will center each picture.
487 Use it only if your macro package doesn't provide proper definitions
488 for those two macros (actually, most of them already have).
493 A single macro is provided in this file,
495 to include a PostScript graphic in a document.
497 It makes only sense for output devices which support inclusion of PS
503 the file is then loaded automatically.
508 \&\fB.PSPIC\fP [\fB\-L\fP|\fB-R\fP|\fB\-I\fP \fIn\fP]\ \fI\|file\fP [\fIwidth\fP [\fIheight\fP]]
513 is the name of the file containing the illustration;
517 give the desired width and height of the graphic.
523 arguments may have scaling indicators attached;
524 the default scaling indicator is\~\c
527 This macro will scale the graphic uniformly
528 in the x and y\~directions so that it is no more than
535 By default, the graphic will be horizontally centered.
541 options cause the graphic to be left-aligned and right-aligned,
546 option causes the graphic to be indented by\~\c
548 (default scaling indicator is\~\c
554 Use this for tracing macro calls.
556 It is only useful for debugging.
559 .BR groff_trace (@MAN7EXT@) .
564 Overrides the definition of standard troff characters and some groff
565 characters for tty devices.
567 The optical appearance is intentionally inferior compared to that of
568 normal tty formatting to allow processing with critical equipment.
573 Additions of elements known from the html format, as being used in the
574 internet (World Wide Web) pages; this includes URL links and mail
576 .BR groff_www (@MAN7EXT@).
579 .\" --------------------------------------------------------------------
581 .\" --------------------------------------------------------------------
583 In classical roff systems, there was a funny naming scheme for macro
584 packages, due to a simplistic design in option parsing.
586 Macro packages were always included by option
588 when this option was directly followed by its argument without an
589 intervening space, this looked like a long option preceded by a single
590 minus \[em] a sensation in the computer stone age.
592 To make this optically working for macro package names, all classical
593 macro packages choose a name that started with the letter
595 which was omitted in the naming of the macro file.
599 For example, the macro package for the man pages was called
603 So it could be activated by the argument
613 For similar reasons, macro packages that did not start with an
617 added in the documentation and in talking; for example, the package
622 in the documentation, although a more suitable name would be
624 For, when omitting the space between the option and its argument, the
625 command line option for activating this package reads
630 To cope with all situations, actual versions of
631 .BR groff (@MAN1EXT@)
632 are smart about both naming schemes by providing two macro files
633 for the inflicted macro packages; one with a leading
635 the other one without it.
641 macro package may be specified as on of the following four methods:
644 .Shell_cmd "groff\~\-m\~man"
645 .Shell_cmd "groff\~\-man"
646 .Shell_cmd "groff\~\-mman"
647 .Shell_cmd "groff\~\-m\~an"
651 Recent packages that do not start with
653 do not use an additional
655 in the documentation.
659 macro package may be specified only as one of the two methods:
662 .Shell_cmd "groff\~\-m\~www"
663 .Shell_cmd "groff\~\-mwww"
667 Obviously, variants like
669 would not make much sense.
673 A second strange feature of classical troff was to name macro files
676 In modern operating systems, the type of a file is specified as
677 postfix, the file name extension.
679 Again, groff copes with this situation by searching both
689 The easiest way to find out which macro packages are available on a
690 system is to check the man\~page
691 .BR groff (@MAN1EXT@),
692 or the contents of the
700 most macro packages are described in\~man pages called
701 .BR groff_\f[I]name\f[] (@MAN7EXT@),
704 for the classical packages.
707 .\" --------------------------------------------------------------------
709 .\" --------------------------------------------------------------------
711 There are several ways to use a macro package in a document.
713 The classical way is to specify the troff/groff option
716 at run-time; this makes the contents of the macro package
722 is searched within the tmac path; if not found,
724 will be searched for instead.
728 Alternatively, it is also possible to include a macro file by adding
732 into the document; the argument must be the full file name of an
733 existing file, possibly with the directory where it is kept.
735 In groff, this was improved by the similar request
738 which added searching in the tmac path, just like option
744 Note that in order to resolve the
748 requests, the roff preprocessor
749 .BR soelim (@MAN1EXT@)
750 must be called if the files to be included need preprocessing.
752 This can be done either directly by a pipeline on the command line or
753 by using the troff/groff option
757 calls soelim automatically.
761 For example, suppose a macro file is stored as
762 .I @MACRODIR@/macros.tmac
763 and is used in some document called
768 At run-time, the formatter call for this is
771 .Shell_cmd "groff\~\-m\~" "macrofile\~document.roff"
775 To include the macro file directly in the document either
779 . Text .mso macrofile.tmac
787 . Text .so @MACRODIR@/macros.tmac
792 In both cases, the formatter is called with
794 .Shell_cmd "groff\~\-s\~" docu.roff
798 If you want to write your own groff macro file, call it
800 and put it in some directory of the tmac path, see section
802 Then documents can include it with the
804 request or the option
809 .\" --------------------------------------------------------------------
811 .\" --------------------------------------------------------------------
813 .\" This section does not fit into the framework of this document.
815 There is a convention that is supported by many modern roff
820 described in the following.
823 If the first line in a document is a comment, the first word (after the
824 comment characters and a blank) constitutes the
827 That means that the letters of this word are interpreted as
828 abbreviations for those preprocessor commands that should be run
829 when formatting the document.
831 Mostly, only the letters corresponding to the options for the
832 preprocessors are recognized,
852 .BR roff (@MAN7EXT@)).
856 Besides being a good reminder for the user, some formatters (like the
858 program) are even able to automatically start the preprocessors
859 specified in the preprocessor word, but do not bet on this.
865 program handles some preprocessors automatically, such that in
866 man\~pages only the following characters should be used:
874 .\" --------------------------------------------------------------------
876 .\" --------------------------------------------------------------------
880 document is a text file that is enriched by predefined formatting
881 constructs, such as requests, escape sequences, strings, numeric
882 registers, and macros from a macro package.
884 These elements are described in
885 .BR roff (@MAN7EXT@).
889 To give a document a personal style, it is most useful to extend the
890 existing elements by defining some macros for repeating tasks; the best
891 place for this is near the beginning of the document or in a separate
896 Macros without arguments are just like strings.
898 But the full power of macros reveals when arguments are passed with a
901 Within the macro definition, the arguments are available as the escape
906 .BR $[ \*[Ellipsis] ] ,
910 the name under which the macro was called is in
912 and the number of arguments is in register
915 .BR groff (@MAN7EXT@).
918 .\" --------------------------------------------------------------------
920 .\" --------------------------------------------------------------------
922 The phase when groff reads a macro is called
926 This is comparable to the C\~preprocessing phase during the development
927 of a program written in the C\~language.
931 In this phase, groff interprets all backslashes; that means that all
932 escape sequences in the macro body are interpreted and replaced by
935 For constant expression, this is wanted, but strings and registers
936 that might change between calls of the macro must be protected from
939 This is most easily done by doubling the backslash that introduces the
942 This doubling is most important for the positional parameters.
944 For example, to print information on the arguments that were passed to
945 the macro to the terminal, define a macro named `.print_args',
950 .ds @1 \[rs]f[I]\[rs]\[rs]$0\[rs]f[]\"
953 . Text .ds midpart was called with
954 . Text .de print_args
955 . Text .\~\~tm\~\*[@1]\~\[rs]\[rs]*[midpart]\~\[rs]\[rs]n[.$]\~\*[@2]
956 . Text .\~\~tm\~\[rs]\[rs]$*
964 When calling this macro by
968 . Text .print_args arg1 arg2
972 the following text is printed to the terminal:
976 . Text \f[CI]print_args\f[] was called with the following 2 arguments:
982 Let's analyze each backslash in the macro definition.
984 As the positional parameters and the number of arguments will change
985 with each call of the macro their leading backslash must be doubled,
990 The same applies to the macro name because it could be called with an
998 is a constant string, it will not change, so no doubling for
999 .IR \[rs]*[midpart] .
1002 escape sequences are predefined groff elements for setting the font
1005 Of course, this behavior will not change, so no doubling with
1011 .\" --------------------------------------------------------------------
1013 .\" --------------------------------------------------------------------
1015 Writing groff macros is easy when the escaping mechanism is temporarily
1018 In groff, this is done by enclosing the macro definition(s) into a
1025 Then the body in the macro definition is just like a normal part of
1026 the document \[em] text enhanced by calls of requests, macros,
1027 strings, registers, etc.
1029 For example, the code above can be written in a simpler way by
1033 .ds @1 \[rs]f[I]\[rs]$0\[rs]f[]\"
1037 . Text .ds midpart was called with
1038 . Text .de print_args
1039 . Text .\~\~tm\~\*[@1]\~\[rs]*[midpart]\~\[rs]n[.$]\~\*[@2]
1040 . Text .\~\~tm\~\[rs]$*
1049 Unfortunately, draft mode cannot be used universally.
1051 Although it is good enough for defining normal macros, draft mode
1052 will fail with advanced applications, such as indirectly defined
1053 strings, registers, etc.
1055 An optimal way is to define and test all macros in draft mode and then
1056 do the backslash doubling as a final step; do not forget to remove the
1061 .\" --------------------------------------------------------------------
1062 .SS "Tips for Macro Definitions"
1063 .\" --------------------------------------------------------------------
1066 Start every line with a dot, for example, by using the groff request
1068 for text lines, or write your own macro that handles also text lines
1074 . Text .\~\~if (\[rs]\[rs]n[.$] == 0)\~\[rs]
1075 . Text .\~\~\~\~return
1076 . Text .\~nop\~\[rs])\[rs]\[rs]$*[rs]\)
1081 Write a comment macro that works both for copy-in and draft mode; for
1082 as escaping is off in draft mode, trouble might occur when normal
1085 For example, the following macro just ignores its arguments, so it
1086 acts like a comment line:
1092 . Text .c\~This\~is\~like\~a\~comment\~line.
1096 In long macro definitions, make ample use of comment lines or empty
1097 lines for a better structuring.
1100 To increase readability, use groff's indentation facility for requests
1101 and macro calls (arbitrary whitespace after the leading dot).
1104 .\" --------------------------------------------------------------------
1106 .\" --------------------------------------------------------------------
1108 Diversions can be used to realize quite advanced programming
1111 They are comparable to pointers to large data structures in the
1112 C\~programming language, but their usage is quite different.
1116 In their simplest form, diversions are multi-line strings, but
1117 they get their power when diversions are used dynamically within macros.
1119 The information stored in a diversion can be retrieved by calling the
1120 diversion just like a macro.
1124 Most of the problems arising with diversions can be avoided if you are
1125 conscious about the fact that diversions always deal with complete
1128 If diversions are used when the line buffer has not been flashed,
1129 strange results are produced; not knowing this, many people get
1130 desperate about diversions.
1132 To ensure that a diversion works, line breaks should be added at the
1135 To be on the secure side, enclose everything that has to do with
1136 diversions into a pair of line breaks; for example, by amply using
1140 This rule should be applied to diversion definition, both inside and
1141 outside, and to all calls of diversions.
1143 This is a bit of overkill, but it works nicely.
1147 [If you really need diversions which should ignore the current partial
1148 line, use environments to save the current partial line and/\:or use the
1154 The most powerful feature using diversions is to start a diversion
1155 within a macro definition and end it within another macro.
1157 Then everything between each call of this macro pair is stored within
1158 the diversion and can be manipulated from within the macros.
1161 .\" --------------------------------------------------------------------
1163 .\" --------------------------------------------------------------------
1165 All macro names must be named
1167 to fully use the tmac mechanism.
1170 as with classical packages is possible as well, but deprecated.
1174 The macro files are kept in the
1175 .IR "tmac directories" ;
1176 a colon separated list of these constitutes the
1181 The search sequence for macro files is (in that order):
1184 the directories specified with troff/groff's
1189 the directories given in the
1190 .Env_var $GROFF_TMAC_PATH
1191 environment variable
1194 the current directory (only if in unsafe mode, which is enabled by the
1196 command line switch)
1202 a platform-specific directory, being
1204 in this installation
1207 a site-specific (platform-independent) directory, being
1209 in this installation
1212 the main tmac directory, being
1214 in this installation
1217 .\" --------------------------------------------------------------------
1219 .\" --------------------------------------------------------------------
1222 .Env_var $GROFF_TMAC_PATH
1223 A colon separated list of additional tmac directories in which to search
1226 See the previous section for a detailed description.
1229 .\" --------------------------------------------------------------------
1231 .\" --------------------------------------------------------------------
1233 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006
1234 Free Software Foundation, Inc.
1237 This document is distributed under the terms of the FDL (GNU Free
1238 Documentation License) version 1.1 or later.
1240 You should have received a copy of the FDL on your system, it is also
1241 available on-line at the
1242 .URL http://\:www.gnu.org/\:copyleft/\:fdl.html "GNU copyleft site" .
1245 This document is part of
1247 the GNU roff distribution.
1250 .MTO bwarken@mayn.de "Bernd Warken" ;
1252 .MTO wl@gnu.org "Werner Lemberg" .
1255 .\" --------------------------------------------------------------------
1257 .\" --------------------------------------------------------------------
1259 A complete reference for all parts of the groff system is found in the
1266 .BR groff (@MAN1EXT@)
1267 an overview of the groff system.
1271 .BR groff_man (@MAN7EXT@),
1273 .BR groff_mdoc (@MAN7EXT@),
1275 .BR groff_me (@MAN7EXT@),
1277 .BR groff_mm (@MAN7EXT@),
1279 .BR groff_mom (@MAN7EXT@),
1281 .BR groff_ms (@MAN7EXT@),
1283 .BR groff_trace (@MAN7EXT@),
1285 .BR groff_www (@MAN7EXT@).
1286 the groff tmac macro packages.
1290 .BR groff (@MAN7EXT@)
1295 The Filesystem Hierarchy Standard is available at the
1296 .URL http://\:www.pathname.com/\:fhs/ "FHS web site" .
1298 .cp \n[groff_tmac_C]
1300 .\" Local Variables: