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: 21 Aug 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.
318 .\" --------------------------------------------------------------------
320 .\" --------------------------------------------------------------------
324 This is the classical macro package for UNIX manual pages
325 (man\~pages); it is quite handy and easy to use; see
326 .BR groff_man (@MAN7EXT@).
332 An alternative macro package for man\~pages mainly used in BSD
333 systems; it provides many new features, but it is not the standard for
335 .BR groff_mdoc (@MAN7EXT@).
338 .\" --------------------------------------------------------------------
340 .\" --------------------------------------------------------------------
342 The packages in this section provide a complete set of macros for
343 writing documents of any kind, up to whole books.
345 They are similar in functionality; it is a matter of taste which one
354 .BR groff_me (@MAN7EXT@).
362 .BR groff_mm (@MAN7EXT@).
369 macro package, only available in groff.
371 As this is not based on other packages, it can be freely designed.
373 So it is expected to become quite a nice, modern macro package.
376 .BR groff_mom (@MAN7EXT@).
384 .BR groff_ms (@MAN7EXT@).
387 .\" --------------------------------------------------------------------
388 .SS "Special Packages"
389 .\" --------------------------------------------------------------------
391 The macro packages in this section are not intended for stand-alone
392 usage, but can be used to add special functionality to any other
393 macro package or to plain groff.
398 Overrides the definition of standard troff characters and some groff
399 characters for tty devices.
401 The optical appearance is intentionally inferior compared to that of
402 normal tty formatting to allow processing with critical equipment.
407 Additions of elements known from the html format, as being used in the
408 internet (World Wide Web) pages; this includes URL links and mail
410 .BR groff_www (@MAN7EXT@).
413 .\" --------------------------------------------------------------------
415 .\" --------------------------------------------------------------------
417 In classical roff systems, there was a funny naming scheme for macro
418 packages, due to a simplistic design in option parsing.
420 Macro packages were always included by option
422 when this option was directly followed by its argument without an
423 intervening space, this looked like a long option preceded by a single
424 minus \[em] a sensation in the computer stone age.
426 To make this optically working for macro package names, all classical
427 macro packages choose a name that started with the letter
429 which was omitted in the naming of the macro file.
433 For example, the macro package for the man pages was called
437 So it could be activated by the argument
447 For similar reasons, macro packages that did not start with an
451 added in the documentation and in talking; for example, the package
456 in the documentation, although a more suitable name would be
458 For, when omitting the space between the option and its argument, the
459 command line option for activating this package reads
464 To cope with all situations, actual versions of
465 .BR groff (@MAN1EXT@)
466 are smart about both naming schemes by providing two macro files
467 for the inflicted macro packages; one with a leading
469 the other one without it.
475 macro package may be specified as on of the following four methods:
478 .Shell_cmd "groff\~\-m\~man"
479 .Shell_cmd "groff\~\-man"
480 .Shell_cmd "groff\~\-mman"
481 .Shell_cmd "groff\~\-m\~an"
485 Recent packages that do not start with
487 do not use an additional
489 in the documentation.
493 macro package may be specified only as one of the two methods:
496 .Shell_cmd "groff\~\-m\~www"
497 .Shell_cmd "groff\~\-mwww"
501 Obviously, variants like
503 would not make much sense.
507 A second strange feature of classical troff was to name macro files
510 In modern operating systems, the type of a file is specified as
511 postfix, the file name extension.
513 Again, groff copes with this situation by searching both
523 The easiest way to find out which macro packages are available on a
524 system is to check the man\~page
525 .BR groff (@MAN1EXT@),
526 or the contents of the
534 most macro packages are described in\~man pages called
535 .BR groff_\f[I]name\f[] (@MAN7EXT@),
538 for the classical packages.
541 .\" --------------------------------------------------------------------
543 .\" --------------------------------------------------------------------
545 There are several ways to use a macro package in a document.
547 The classical way is to specify the troff/groff option
550 at run-time; this makes the contents of the macro package
556 is searched within the tmac path; if not found,
558 will be searched for instead.
562 Alternatively, it is also possible to include a macro file by adding
566 into the document; the argument must be the full file name of an
567 existing file, possibly with the directory where it is kept.
569 In groff, this was improved by the similar request
572 which added searching in the tmac path, just like option
578 Note that in order to resolve the
582 requests, the roff preprocessor
583 .BR soelim (@MAN1EXT@)
584 must be called if the files to be included need preprocessing.
586 This can be done either directly by a pipeline on the command line or
587 by using the troff/groff option
591 calls soelim automatically.
595 For example, suppose a macro file is stored as
596 .I @MACRODIR@/macros.tmac
597 and is used in some document called
602 At run-time, the formatter call for this is
605 .Shell_cmd "groff\~\-m\~" "macrofile\~document.roff"
609 To include the macro file directly in the document either
613 . Text .mso macrofile.tmac
621 . Text .so @MACRODIR@/macros.tmac
626 In both cases, the formatter is called with
628 .Shell_cmd "troff\~\-s\~" docu.roff
632 If you want to write your own groff macro file, call it
634 and put it in some directory of the tmac path, see section
636 Then documents can include it with the
638 request or the option
643 .\" --------------------------------------------------------------------
645 .\" --------------------------------------------------------------------
647 .\" This section does not fit into the framework of this document.
649 There is a convention that is supported by many modern roff
654 described in the following.
657 If the first line in a document is a comment, the first word (after the
658 comment characters and a blank) constitutes the
661 That means that the letters of this word are interpreted as
662 abbreviations for those preprocessor commands that should be run
663 when formatting the document.
665 Mostly, only the letters corresponding to the options for the
666 preprocessors are recognized,
686 .BR roff (@MAN7EXT@)).
690 Besides being a good reminder for the user, some formatters (like the
692 program) are even able to automatically start the preprocessors
693 specified in the preprocessor word, but do not bet on this.
699 program handles some preprocessors automatically, such that in
700 man\~pages only the following characters should be used:
708 .\" --------------------------------------------------------------------
710 .\" --------------------------------------------------------------------
714 document is a text file that is enriched by predefined formatting
715 constructs, such as requests, escape sequences, strings, numeric
716 registers, and macros from a macro package.
718 These elements are described in
719 .BR roff (@MAN7EXT@).
723 To give a document a personal style, it is most useful to extend the
724 existing elements by defining some macros for repeating tasks; the best
725 place for this is near the beginning of the document or in a separate
730 Macros without arguments are just like strings.
732 But the full power of macros reveals when arguments are passed with a
735 Within the macro definition, the arguments are available as the escape
740 .BR $[ \*[Ellipsis] ] ,
744 the name under which the macro was called is in
746 and the number of arguments is in register
749 .BR groff (@MAN7EXT@).
752 .\" --------------------------------------------------------------------
754 .\" --------------------------------------------------------------------
756 The phase when groff reads a macro is called
760 This is comparable to the C\~preprocessing phase during the development
761 of a program written in the C\~language.
765 In this phase, groff interprets all backslashes; that means that all
766 escape sequences in the macro body are interpreted and replaced by
769 For constant expression, this is wanted, but strings and registers
770 that might change between calls of the macro must be protected from
773 This is most easily done by doubling the backslash that introduces the
776 This doubling is most important for the positional parameters.
778 For example, to print information on the arguments that were passed to
779 the macro to the terminal, define a macro named `.print_args',
784 .ds @1 \[rs]f[I]\[rs]\[rs]$0\[rs]f[]\"
787 . Text .ds midpart was called with
788 . Text .de print_args
789 . Text .\~\~tm\~\*[@1]\~\[rs]\[rs]*[midpart]\~\[rs]\[rs]n[.$]\~\*[@2]
790 . Text .\~\~tm\~\[rs]\[rs]$*
798 When calling this macro by
801 . Text .print_args arg1 arg2
804 the following text is printed to the terminal:
806 . Text \f[CI]print_args\f[] was called with the following 2 arguments:
812 Let's analyze each backslash in the macro definition.
814 As the positional parameters and the number of arguments will change
815 with each call of the macro their leading backslash must be doubled,
820 The same applies to the macro name because it could be called with an
828 is a constant string, it will not change, so no doubling for
829 .IR \[rs]*[midpart] .
832 escape sequences are predefined groff elements for setting the font
835 Of course, this behavior will not change, so no doubling with
841 .\" --------------------------------------------------------------------
843 .\" --------------------------------------------------------------------
845 Writing groff macros is easy when the escaping mechanism is temporarily
848 In groff, this is done by enclosing the macro definition(s) into a
855 Then the body in the macro definition is just like a normal part of
856 the document \[em] text enhanced by calls of requests, macros,
857 strings, registers, etc.
859 For example, the code above can be written in a simpler way by
863 .ds @1 \[rs]f[I]\[rs]$0\[rs]f[]\"
867 . Text .ds midpart was called with
868 . Text .de print_args
869 . Text .\~\~tm\~\*[@1]\~\[rs]*[midpart]\~\[rs]n[.$]\~\*[@2]
870 . Text .\~\~tm\~\[rs]$*
879 Unfortunately, draft mode cannot be used universally.
881 Although it is good enough for defining normal macros, draft mode
882 will fail with advanced applications, such as indirectly defined
883 strings, registers, etc.
885 An optimal way is to define and test all macros in draft mode and then
886 do the backslash doubling as a final step; do not forget to remove the
891 .\" --------------------------------------------------------------------
892 .SS "Tips for Macro Definitions"
893 .\" --------------------------------------------------------------------
896 Start every line with a dot, for example, by using the groff request
898 for text lines, or write your own macro that handles also text lines
904 . Text .\~\~if (\[rs]\[rs]n[.$] == 0)\~\[rs]
905 . Text .\~\~\~\~return
906 . Text .\~nop\~\[rs])\[rs]\[rs]$*[rs]\)
911 Write a comment macro that works both for copy-in and draft mode; for
912 as escaping is off in draft mode, trouble might occur when normal
915 For example, the following macro just ignores its arguments, so it
916 acts like a comment line:
922 . Text .c\~This\~is\~like\~a\~comment\~line.
926 In long macro definitions, make ample use of comment lines or empty
927 lines for a better structuring.
930 To increase readability, use groff's indentation facility for requests
931 and macro calls (arbitrary whitespace after the leading dot).
934 .\" --------------------------------------------------------------------
936 .\" --------------------------------------------------------------------
938 Diversions can be used to realize quite advanced programming
941 They are comparable to pointers to large data structures in the
942 C\~programming language, but their usage is quite different.
946 In their simplest form, diversions are multi-line strings, but
947 they get their power when diversions are used dynamically within macros.
949 The information stored in a diversion can be retrieved by calling the
950 diversion just like a macro.
954 Most of the problems arising with diversions can be avoided if you are
955 conscious about the fact that diversions always deal with complete
958 If diversions are used when the line buffer has not been flashed,
959 strange results are produced; not knowing this, many people get
960 desperate about diversions.
962 To ensure that a diversion works, line breaks should be added at the
965 To be on the secure side, enclose everything that has to do with
966 diversions into a pair of line breaks; for example, by amply using
970 This rule should be applied to diversion definition, both inside and
971 outside, and to all calls of diversions.
973 This is a bit of overkill, but it works nicely.
977 [If you really need diversions which should ignore the current partial
978 line, use environments to save the current partial line and/\:or use the
984 The most powerful feature using diversions is to start a diversion
985 within a macro definition and end it within another macro.
987 Then everything between each call of this macro pair is stored within
988 the diversion and can be manipulated from within the macros.
991 .\" --------------------------------------------------------------------
993 .\" --------------------------------------------------------------------
995 All macro names must be named
997 to fully use the tmac mechanism.
1000 as with classical packages is possible as well, but deprecated.
1004 The macro files are kept in the
1005 .IR "tmac directories" ;
1006 a colon separated list of these constitutes the
1011 The search sequence for macro files is (in that order):
1014 the directories specified with troff/groff's
1019 the directories given in the
1020 .Env_var $GROFF_TMAC_PATH
1021 environment variable
1024 the current directory (only if in unsafe mode, which is enabled by the
1026 command line switch)
1032 a platform-specific directory, being
1034 in this installation
1037 a site-specific (platform-independent) directory, being
1039 in this installation
1042 the main tmac directory, being
1044 in this installation
1047 .\" --------------------------------------------------------------------
1049 .\" --------------------------------------------------------------------
1052 .Env_var $GROFF_TMAC_PATH
1053 A colon separated list of additional tmac directories in which to search
1056 See the previous section for a detailed description.
1059 .\" --------------------------------------------------------------------
1061 .\" --------------------------------------------------------------------
1063 Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
1066 This document is distributed under the terms of the FDL (GNU Free
1067 Documentation License) version 1.1 or later.
1069 You should have received a copy of the FDL on your system, it is also
1070 available on-line at the
1071 .URL http://\:www.gnu.org/\:copyleft/\:fdl.html "GNU copyleft site" .
1074 This document is part of
1076 the GNU roff distribution.
1079 .MTO bwarken@mayn.de "Bernd Warken" ;
1081 .MTO wl@gnu.org "Werner Lemberg" .
1084 .\" --------------------------------------------------------------------
1086 .\" --------------------------------------------------------------------
1088 A complete reference for all parts of the groff system is found in the
1094 .BR groff (@MAN1EXT@)
1095 an overview of the groff system.
1098 .BR groff_man (@MAN7EXT@),
1100 .BR groff_mdoc (@MAN7EXT@),
1102 .BR groff_me (@MAN7EXT@),
1104 .BR groff_mm (@MAN7EXT@),
1106 .BR groff_mom (@MAN7EXT@),
1108 .BR groff_ms (@MAN7EXT@),
1110 .BR groff_www (@MAN7EXT@).
1111 the groff tmac macro packages.
1114 .BR groff (@MAN7EXT@)
1119 The Filesystem Hierarchy Standard is available at the
1120 .URL http://\:www.pathname.com/\:fhs/ "FHS web site" .
1122 .\" Local Variables: