* tmac/LOCALIZATION: New file.
[s-roff.git] / man / groff_tmac.man
blob4fb44b013cbe0c1d4fd32a1cf2d6191b77ab0a4b
1 .TH GROFF_TMAC @MAN5EXT@ "@MDATE@" "Groff Version @VERSION@"
2 .SH NAME
3 groff_tmac \- macro files in the roff typesetting system
4 .SH DESCRIPTION
5 .\" The .SH was moved to this place to make `apropos' happy.
8 .\" --------------------------------------------------------------------
9 .\" Legalize
10 .\" --------------------------------------------------------------------
12 .ig
13 groff_tmac.5
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
24 <wl@gnu.org>
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 .\" --------------------------------------------------------------------
37 .\" Setup
38 .\" --------------------------------------------------------------------
40 .do nr groff_tmac_C \n[.C]
41 .cp 0
43 .mso www.tmac
45 .if n \{\
46 .  mso tty-char.tmac
47 .  ftr CR R
48 .  ftr CI I
49 .  ftr CB B
50 .\}
52 .ds Ellipsis \&.\|.\|.\&\"
54 .\" Global static variables for inter-macro communication
55 .rr @+Example_font
57 .\" --------------------------------------------------------------------
58 .\" setup for the macro definitions below
59 .\"
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]'\"
76 .ft \*[@f]
77 .\" Full prompt width is maximum of texts plus 1m
78 .nr groffer:Shell_cmd_base.prompt_width (\n[@w]>?\n[@w+]+1m)\" needed
79 .ft
80 .rm @f
81 .rm @f+
82 .rm @t
83 .rm @t+
84 .rr @w
85 .rr @w+
87 .\"--------------------------------------------------------------------
88 .\" Ignore all arguments like a comment, even after a .eo call.
89 .de c
91 .c --------------------------------------------------------------------
92 .de BIR
93 .  ie (\\n[.$] < 3) \
94 .    BI \\$@
95 .  el \{\
96 .    ds @tmp@ \fB\\$1\f[]\fI\\$2\f[]
97 .    shift 2
98 .    Text \\*[@tmp@]\fR\\$*\f[]
99 .    rm @tmp@
100 .  \}
102 .c --------------------------------------------------------------------
103 .c .Env_var  (<env_var_name> [<punct>])
105 .c Display an environment variable, with optional punctuation.
107 .de Env_var
108 .  nh
109 .  SM
110 .  Text \f[CB]\\$1\f[]\\$2
111 .  hy
113 .c --------------------------------------------------------------------
114 .c .Error  (<text>...)
116 .c Print error message to terminal and abort.
118 .de Error
119 .  tm \\$*
120 .  ab
122 .c --------------------------------------------------------------------
123 .de Example
124 .  if r@+Example_font \
125 .    Error previous .Example was not terminated by a ./Example
126 .  nr @+Example_font \\n[.f]
127 .  nh
128 .  nf
129 .  RS
130 .  ft CR
132 .c --------------------------------------------------------------------
133 .de /Example
134 .  if !r@+Example_font \
135 .    Error no previous call to .Example
136 .  ft \\n[@+Example_font]
137 .  RE
138 .  fi
139 .  hy
140 .  rr @+Example_font
143 .c --------------------------------------------------------------------
144 .c .Shell_cmd  (<CR> [<CI>] ...)
146 .c A shell command line; display args alternating in fonts CR and CI.
148 .c Examples:
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
163 .de Shell_cmd
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.
171 .de 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) \
184 .    return
185 .  nr @+font \\n[.f]\"
186 .  ds @prompt \\$1\"
187 .  ft CR
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'\"
191 .  shift
192 .  ds @cf CR\"
193 .  while (\\n[.$] > 0) \{\
194 .    as @res \\f[\\*[@cf]]\\$1\"
195 .    shift
196 .    ie '\\*[@cf]'CR' \
197 .      ds @cf I\"
198 .    el \
199 .      ds @cf CR\"
200 .  \}
201 .  br
202 .  ad l
203 .  nh
204 .  nf
205 .  Text \\*[@res]\"
206 .  fi
207 .  hy
208 .  ad
209 .  br
210 .  ft \\n[@+font]
211 .  rr @+font
212 .  rr @+gap
213 .  rm @cf
214 .  rm @res
216 .c --------------------------------------------------------------------
217 .c .Text  (<text>...)
219 .c Treat the arguments as text, no matter how they look.
221 .de Text
222 .  if (\\n[.$] == 0) \
223 .    return
224 .  nop \)\\$*\)
226 .c --------------------------------------------------------------------
227 .c .Topic  ([<indent>])
229 .c A bulleted paragraph
231 .de Topic
232 .  ie (\\n[.$] = 0) \
233 .    ds @indent 2m\"
234 .  el \
235 .    ds @indent \\$1\"
236 .  TP \\*[@indent]
237 .  Text \[bu]
238 .  rm @indent
240 .c --------------------------------------------------------------------
241 .c .TP+  ()
243 .c Continuation line for .TP header.
245 .de TP+
246 .  br
247 .  ns
248 .  TP \\$1
250 .c --------------------------------------------------------------------
251 .de 'char
252 .  ds @tmp@ `\f(CR\\$1\f[]'
253 .  shift
254 .  Text \\*[@tmp@]\\$*
255 .  rm @tmp@
257 .c --------------------------------------------------------------------
258 .de option
259 .  ds @tmp@ \f(CB\\$1\f[]
260 .  shift 1
261 .  Text \\*[@tmp@]\\$*
262 .  rm @tmp@
264 .c --------------------------------------------------------------------
265 .de argument
266 .  ds @tmp@ \f(CI\\$1\f[]
267 .  shift 1
268 .  Text \\*[@tmp@]\\$*
269 .  rm @tmp@
271 .c --------------------------------------------------------------------
272 .de request
273 .  ds @tmp@ \f(CB\\$1\f[]
274 .  shift 1
275 .  Text .\\*[@tmp@]\\$*
276 .  rm @tmp@
278 .c --------------------------------------------------------------------
279 .de escape
280 .  ds @tmp@ \f[CB]\\$1\f[]
281 .  shift 1
282 .  Text \[rs]\\*[@tmp@]\\$*
283 .  rm @tmp@
285 .\" --------------------------------------------------------------------
286 .\" SH DESCRIPTION
287 .\" --------------------------------------------------------------------
290 .BR roff (@MAN7EXT@)
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
295 the package's
296 .BR "tmac file" .
297 The name is deduced from
298 .RB ` T\c
299 .IB roff MAC\c
300 .IR ros '.
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,
308 .B tmac
309 directories.
312 .\" --------------------------------------------------------------------
313 .SH "GROFF MACRO PACKAGES"
314 .\" --------------------------------------------------------------------
316 .I groff
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"
333 will fail.
336 .\" --------------------------------------------------------------------
337 .SS "Man\~Pages"
338 .\" --------------------------------------------------------------------
341 .B man
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@).
348 .B doc
349 .TP+
350 .B mdoc
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
353 man\~pages; see
354 .BR groff_mdoc (@MAN7EXT@).
357 .\" --------------------------------------------------------------------
358 .SS "Full Packages"
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
365 to use.
369 .B me
370 The classical
371 .I me
372 macro package; see
373 .BR groff_me (@MAN7EXT@).
377 .B mm
378 The semi-classical
379 .I mm
380 macro package; see
381 .BR groff_mm (@MAN7EXT@).
385 .B mom
386 The new
387 .I mom
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@).
399 .B ms
400 The classical
401 .I ms
402 macro package; see
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.
416 .B fr
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.
422 Example:
424 .Shell_cmd "groff -ms -mfr foo.ms > foo.ps"
427 Note that
428 .BR fr.tmac
429 sets the input encoding to latin-9 to get proper support of the `oe'
430 ligature.
434 .B papersize
435 This macro file is already loaded at start-up by
436 .B @g@troff
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[].
442 Possible values for
443 .I size
444 are the same as the predefined
445 .B papersize
446 values in the DESC file (only lowercase; see
447 .BR groff_font (@MAN5EXT@)
448 for more) except
449 .BR a7 - d7 .
451 An appended
452 .B l
453 (ell) character denotes landscape orientation.
455 Examples:
456 .BR a4 ,
457 .BR c3l ,
458 .BR letterl .
461 Most output drivers need additional command line switches
462 .B \-p
464 .B \-l
465 to override the default paper length and orientation as set in the driver
466 specific DESC file.
468 For example, use the following for PS output on A4 paper in landscape
469 orientation:
472 .Shell_cmd "groff \-Tps \-dpaper=a4l \-P\-pa4 \-P\-l \-ms foo.ms > foo.ps"
476 .B pic
477 This file provides proper definitions for the macros
478 .B PS
480 .BR PE ,
481 needed for the
482 .BR @g@pic (@MAN1EXT@)
483 preprocessor.
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).
492 .B pspic
493 A single macro is provided in this file,
494 .BR PSPIC ,
495 to include a PostScript graphic in a document.
497 It makes only sense for output devices which support inclusion of PS
498 images:
499 .BR \-Tps ,
500 .BR \-Tdvi ,
502 .BR \-Thtml ;
503 the file is then loaded automatically.
505 Syntax:
508 \&\fB.PSPIC\fP [\fB\-L\fP|\fB-R\fP|\fB\-I\fP \fIn\fP]\ \fI\|file\fP [\fIwidth\fP [\fIheight\fP]]
512 .I file
513 is the name of the file containing the illustration;
514 .I width
516 .I height
517 give the desired width and height of the graphic.
520 .I width
522 .I height
523 arguments may have scaling indicators attached;
524 the default scaling indicator is\~\c
525 .BR i .
527 This macro will scale the graphic uniformly
528 in the x and y\~directions so that it is no more than
529 .I width
530 wide
532 .I height
533 high.
535 By default, the graphic will be horizontally centered.
538 .BI \-L
540 .BI \-R
541 options cause the graphic to be left-aligned and right-aligned,
542 respectively.
545 .B \-I
546 option causes the graphic to be indented by\~\c
547 .I n
548 (default scaling indicator is\~\c
549 .BR m ).
553 .B trace
554 Use this for tracing macro calls.
556 It is only useful for debugging.
559 .BR groff_trace (@MAN7EXT@) .
563 .B tty-char
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.
572 .B www
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
575 addresses; see
576 .BR groff_www (@MAN7EXT@).
579 .\" --------------------------------------------------------------------
580 .SH NAMING
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
587 .option -m;
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
594 .'char m ,
595 which was omitted in the naming of the macro file.
599 For example, the macro package for the man pages was called
600 .IR man ,
601 while its macro file
602 .IR tmac.an .
603 So it could be activated by the argument
604 .I an
605 to option
606 .option -m ,
608 .option -man
609 for short.
613 For similar reasons, macro packages that did not start with an
614 .'char m
615 had a leading
616 .'char m
617 added in the documentation and in talking; for example, the package
618 corresponding to
619 .I tmac.doc
620 was called
621 .I mdoc
622 in the documentation, although a more suitable name would be
623 .IR doc .
624 For, when omitting the space between the option and its argument, the
625 command line option for activating this package reads
626 .option "-mdoc" .
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
634 .'char m ,
635 the other one without it.
637 So in
638 .IR groff ,
640 .I man
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
652 .'char m
653 do not use an additional
654 .'char m
655 in the documentation.
657 For example, the
658 .I www
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
668 .I -mmwww
669 would not make much sense.
673 A second strange feature of classical troff was to name macro files
674 according to
675 .BIR tmac. name .
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
680 .IB anything .tmac
682 .BI tmac. anything
683 if only
684 .I anything
685 is specified.
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
693 .I tmac
694 directories.
699 .IR groff ,
700 most macro packages are described in\~man pages called
701 .BR groff_\f[I]name\f[] (@MAN7EXT@),
702 with a leading
703 .'char m
704 for the classical packages.
707 .\" --------------------------------------------------------------------
708 .SH INCLUSION
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
714 .option \-m
715 .argument name
716 at run-time; this makes the contents of the macro package
717 .I name
718 available.
720 In groff, the file
721 .IB name .tmac
722 is searched within the tmac path; if not found,
723 .BI tmac. name
724 will be searched for instead.
728 Alternatively, it is also possible to include a macro file by adding
729 the request
730 .request so
731 .I filename
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
736 .request mso
737 .IR package ,
738 which added searching in the tmac path, just like option
739 .option -m
740 does.
744 Note that in order to resolve the
745 .request so
747 .request mso
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
754 .option \-s .
756 .I man
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
764 .IR docu.roff .
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
778 .Example
779 .  Text .mso macrofile.tmac
780 ./Example
783 is used or
786 .Example
787 .  Text .so @MACRODIR@/macros.tmac
788 ./Example
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
799 .IB whatever .tmac
800 and put it in some directory of the tmac path, see section
801 .BR FILES .
802 Then documents can include it with the
803 .request mso
804 request or the option
805 .option -m .
809 .\" --------------------------------------------------------------------
810 .SH CONVENTION
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
816 type-setters and
817 .BR man (1)
818 programs, the
819 .I preprocessor word
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
825 .B preprocessor
826 .BR word .
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,
833 .'char e
834 (for
835 .BR eqn ),
836 .\" 'char G ,
837 .\" 'char g ,
838 .'char p ,
839 (for
840 .BR pic ),
841 .'char R
842 (for
843 .BR refer ),
844 .'char s
845 (for
846 .BR soelim ),
848 .'char t
849 (for
850 .BR tbl ).
851 (see
852 .BR roff (@MAN7EXT@)).
856 Besides being a good reminder for the user, some formatters (like the
857 .BR man (1)
858 program) are even able to automatically start the preprocessors
859 specified in the preprocessor word, but do not bet on this.
864 .I man
865 program handles some preprocessors automatically, such that in
866 man\~pages only the following characters should be used:
867 .'char e ,
868 .'char p ,
870 .'char t .
874 .\" --------------------------------------------------------------------
875 .SH "WRITING MACROS"
876 .\" --------------------------------------------------------------------
879 .BR roff (@MAN7EXT@)
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
892 file.
896 Macros without arguments are just like strings.
898 But the full power of macros reveals when arguments are passed with a
899 macro call.
901 Within the macro definition, the arguments are available as the escape
902 sequences
903 .BR $1 ,
904 \*[Ellipsis],
905 .BR $9 ,
906 .BR $[ \*[Ellipsis] ] ,
907 .BR $* ,
909 .BR $@ ,
910 the name under which the macro was called is in
911 .BR $0 ,
912 and the number of arguments is in register
913 .BR \n[.$] ;
915 .BR groff (@MAN7EXT@).
918 .\" --------------------------------------------------------------------
919 .SS "Copy-in Mode"
920 .\" --------------------------------------------------------------------
922 The phase when groff reads a macro is called
923 .I "copy-in mode"
924 in roff-talk.
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
933 their value.
935 For constant expression, this is wanted, but strings and registers
936 that might change between calls of the macro must be protected from
937 being evaluated.
939 This is most easily done by doubling the backslash that introduces the
940 escape sequence.
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',
946 say.
950 .ds @1 \[rs]f[I]\[rs]\[rs]$0\[rs]f[]\"
951 .ds @2 arguments:\"
952 .Example
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]$*
957 .  Text ..
958 ./Example
959 .rm @1
960 .rm @2
964 When calling this macro by
967 .Example
968 .  Text .print_args arg1 arg2
969 ./Example
972 the following text is printed to the terminal:
975 .Example
976 .  Text \f[CI]print_args\f[] was called with the following 2 arguments:
977 arg1 arg2
978 ./Example
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,
986 which results in
987 .I \[rs]\[rs]$*
989 .IR \[rs]\[rs][.$] .
990 The same applies to the macro name because it could be called with an
991 alias name, so
992 .IR \[rs]\[rs]$0 .
996 On the other hand,
997 .I midpart
998 is a constant string, it will not change, so no doubling for
999 .IR \[rs]*[midpart] .
1001 .I \[rs]f
1002 escape sequences are predefined groff elements for setting the font
1003 within the text.
1005 Of course, this behavior will not change, so no doubling with
1006 .I \[rs]f[I]
1008 .IR \[rs]f[] .
1011 .\" --------------------------------------------------------------------
1012 .SS "Draft Mode"
1013 .\" --------------------------------------------------------------------
1015 Writing groff macros is easy when the escaping mechanism is temporarily
1016 disabled.
1018 In groff, this is done by enclosing the macro definition(s) into a
1019 pair of
1020 .B .eo
1022 .B .ec
1023 requests.
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[]\"
1034 .ds @2 arguments:\"
1035 .Example
1036 .  Text .eo
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]$*
1041 .  Text ..
1042 .  Text .ec
1043 ./Example
1044 .rm @1
1045 .rm @2
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
1057 .I .eo
1058 request.
1061 .\" --------------------------------------------------------------------
1062 .SS "Tips for Macro Definitions"
1063 .\" --------------------------------------------------------------------
1065 .Topic
1066 Start every line with a dot, for example, by using the groff request
1067 .B .nop
1068 for text lines, or write your own macro that handles also text lines
1069 with a leading dot.
1072 .Example
1073 .  Text .de Text
1074 .  Text .\~\~if (\[rs]\[rs]n[.$] == 0)\~\[rs]
1075 .  Text .\~\~\~\~return
1076 .  Text .\~nop\~\[rs])\[rs]\[rs]$*[rs]\)
1077 .  Text ..
1078 ./Example
1080 .Topic
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
1083 comments are used.
1085 For example, the following macro just ignores its arguments, so it
1086 acts like a comment line:
1089 .Example
1090 .  Text .de\~c
1091 .  Text ..
1092 .  Text .c\~This\~is\~like\~a\~comment\~line.
1093 ./Example
1095 .Topic
1096 In long macro definitions, make ample use of comment lines or empty
1097 lines for a better structuring.
1099 .Topic
1100 To increase readability, use groff's indentation facility for requests
1101 and macro calls (arbitrary whitespace after the leading dot).
1104 .\" --------------------------------------------------------------------
1105 .SS "Diversions"
1106 .\" --------------------------------------------------------------------
1108 Diversions can be used to realize quite advanced programming
1109 constructs.
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
1126 lines.
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
1133 right places.
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
1137 .B .br
1138 requests.
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
1149 .B .box
1150 request.]
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 .\" --------------------------------------------------------------------
1162 .SH FILES
1163 .\" --------------------------------------------------------------------
1165 All macro names must be named
1166 .IB name .tmac
1167 to fully use the tmac mechanism.
1169 .BI tmac. name
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
1177 .IR "tmac path" .
1181 The search sequence for macro files is (in that order):
1183 .Topic
1184 the directories specified with troff/groff's
1185 .B \-M
1186 command line option
1188 .Topic
1189 the directories given in the
1190 .Env_var $GROFF_TMAC_PATH
1191 environment variable
1193 .Topic
1194 the current directory (only if in unsafe mode, which is enabled by the
1195 .B \-U
1196 command line switch)
1198 .Topic
1199 the home directory
1201 .Topic
1202 a platform-specific directory, being
1203 .B @SYSTEMMACRODIR@
1204 in this installation
1206 .Topic
1207 a site-specific (platform-independent) directory, being
1208 .B @LOCALMACRODIR@
1209 in this installation
1211 .Topic
1212 the main tmac directory, being
1213 .B @MACRODIR@
1214 in this installation
1217 .\" --------------------------------------------------------------------
1218 .SH ENVIRONMENT
1219 .\" --------------------------------------------------------------------
1222 .Env_var $GROFF_TMAC_PATH
1223 A colon separated list of additional tmac directories in which to search
1224 for macro files.
1226 See the previous section for a detailed description.
1229 .\" --------------------------------------------------------------------
1230 .SH AUTHOR
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
1246 .IR groff ,
1247 the GNU roff distribution.
1249 It was written by
1250 .MTO bwarken@mayn.de "Bernd Warken" ;
1251 it is maintained by
1252 .MTO wl@gnu.org "Werner Lemberg" .
1255 .\" --------------------------------------------------------------------
1256 .SH "SEE ALSO"
1257 .\" --------------------------------------------------------------------
1259 A complete reference for all parts of the groff system is found in the
1260 groff
1261 .BR info (1)
1262 file.
1266 .BR groff (@MAN1EXT@)
1267 an overview of the groff system.
1271 .BR groff_man (@MAN7EXT@),
1272 .TP+
1273 .BR groff_mdoc (@MAN7EXT@),
1274 .TP+
1275 .BR groff_me (@MAN7EXT@),
1276 .TP+
1277 .BR groff_mm (@MAN7EXT@),
1278 .TP+
1279 .BR groff_mom (@MAN7EXT@),
1280 .TP+
1281 .BR groff_ms (@MAN7EXT@),
1282 .TP+
1283 .BR groff_trace (@MAN7EXT@),
1284 .TP+
1285 .BR groff_www (@MAN7EXT@).
1286 the groff tmac macro packages.
1290 .BR groff (@MAN7EXT@)
1291 the groff language.
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:
1301 .\" mode: nroff
1302 .\" End: