Merge from vendor branch OPENSSH:
[dragonfly.git] / contrib / groff-1.19 / man / groff_tmac.man
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.
6 .
7 .
8 .\" --------------------------------------------------------------------
9 .\" Legalize
10 .\" --------------------------------------------------------------------
11 .
12 .ig
13 groff_tmac.5
14
15 File position: <groff-source>/man/groff_tmac.man
16
17 Last update: 15 Jul 2003
18
19 This file is part of groff, the GNU roff type-setting system.
20
21 Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
22 written by Bernd Warken <bwarken@mayn.de> and Werner Lemberg
23 <wl@gnu.org>
24
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.
30
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.
33 ..
34 .
35 .\" --------------------------------------------------------------------
36 .\" Setup
37 .\" --------------------------------------------------------------------
38 .
39 .do nr groff_tmac_C \n[.C]
40 .cp 0
41 .
42 .mso www.tmac
43 .
44 .if n \{\
45 .  mso tty-char.tmac
46 .  ftr CR R
47 .  ftr CI I
48 .  ftr CB B
49 .\}
50 .
51 .ds Ellipsis \&.\|.\|.\&\"
52 .
53 .\" Global static variables for inter-macro communication
54 .rr @+Example_font
55 .
56 .\" --------------------------------------------------------------------
57 .\" setup for the macro definitions below
58 .\"
59 .\" naming:  namespace:cathegory_macro.variable_name  (experimental)
60 .
61 .\" --------------------------------------------------------------------
62 .\" configuration of prompt for `.Shell_cmd'* macros
63 .ds groffer:Shell_cmd.prompt_text sh#\"    prompt for shell commands
64 .ds groffer:Shell_cmd+.prompt_text >\"     prompt on continuation lines
65 .ds groffer:Shell_cmd_base.prompt_font I\" font for prompts
66 .
67 .\" automatically determine setup from the configuration above
68 .als @f groffer:Shell_cmd_base.prompt_font\"
69 .als @t groffer:Shell_cmd.prompt_text\"
70 .als @t+ groffer:Shell_cmd+.prompt_text\"
71 .ds groffer:Shell_cmd.prompt \f[\*[@f]]\*[@t]\f[]\"            needed
72 .ds groffer:Shell_cmd+.prompt \f[\*[@f]]\*[@t+]\f[]\"          needed
73 .nr @w \w'\*[groffer:Shell_cmd.prompt]'\"
74 .nr @w+ \w'\*[groffer:Shell_cmd+.prompt]'\"
75 .ft \*[@f]
76 .\" Full prompt width is maximum of texts plus 1m
77 .nr groffer:Shell_cmd_base.prompt_width (\n[@w]>?\n[@w+]+1m)\" needed
78 .ft
79 .rm @f
80 .rm @f+
81 .rm @t
82 .rm @t+
83 .rr @w
84 .rr @w+
85 .
86 .\"--------------------------------------------------------------------
87 .\" Ignore all arguments like a comment, even after a .eo call.
88 .de c
89 ..
90 .c --------------------------------------------------------------------
91 .de BIR
92 .  ie (\\n[.$] < 3) \
93 .    BI \\$@
94 .  el \{\
95 .    ds @tmp@ \fB\\$1\f[]\fI\\$2\f[]
96 .    shift 2
97 .    Text \\*[@tmp@]\fR\\$*\f[]
98 .    rm @tmp@
99 .  \}
100 ..
101 .c --------------------------------------------------------------------
102 .c .Env_var  (<env_var_name> [<punct>])
103 .c
104 .c Display an environment variable, with optional punctuation.
105 .c
106 .de Env_var
107 .  nh
108 .  SM
109 .  Text \f[CB]\\$1\f[]\\$2
110 .  hy
111 ..
112 .c --------------------------------------------------------------------
113 .c .Error  (<text>...)
114 .c
115 .c Print error message to terminal and abort.
116 .c
117 .de Error
118 .  tm \\$*
119 .  ab
120 ..
121 .c --------------------------------------------------------------------
122 .de Example
123 .  if r@+Example_font \
124 .    Error previous .Example was not terminated by a ./Example
125 .  nr @+Example_font \\n[.f]
126 .  nh
127 .  nf
128 .  RS
129 .  ft CR
130 ..
131 .c --------------------------------------------------------------------
132 .de /Example
133 .  if !r@+Example_font \
134 .    Error no previous call to .Example
135 .  ft \\n[@+Example_font]
136 .  RE
137 .  fi
138 .  hy
139 .  rr @+Example_font
140 ..
141 .
142 .c --------------------------------------------------------------------
143 .c .Shell_cmd  (<CR> [<CI>] ...)
144 .c
145 .c A shell command line; display args alternating in fonts CR and CI.
146 .c
147 .c Examples:
148 .c   .Shell_cmd "groffer --dpi 100 file"
149 .c     result: `sh#  groffer --dpi 100 file'
150 .c             with 'sh#' in font I, the rest in CR
151 .c
152 .c   .Shell_cmd groffer\~--dpi\~100\~file
153 .c     result: the same as above
154 .c
155 .c   .Shell_cmd "groffer --dpi=" value " file"
156 .c     result: sh#  groffer --dpi=value file
157 .c             with `groffer --dpi=' and `file' in CR; `value' in CI
158 .c
159 .c   .Shell_cmd groffer\~--dpi= value \~file
160 .c     result: the same as the previous example
161 .c
162 .de Shell_cmd
163 .  groffer:Shell_cmd_base "\*[groffer:Shell_cmd.prompt]" \\$@
164 ..
165 .c --------------------------------------------------------------------
166 .c .Shell_cmd+  (<CR> [<CI>] ...)
167 .c
168 .c A continuation line for .Shell_cmd.
169 .c
170 .de Shell_cmd+
171 .  groffer:Shell_cmd_base "\*[groffer:Shell_cmd+.prompt]" \\$@
172 ..
173 .c --------------------------------------------------------------------
174 .c .Shell_cmd_base  (<prompt> [<CR> [<CI>] ...])
175 .c
176 .c A shell command line; display args alternating in fonts CR and CI.
177 .c Internal, do not use directly.
178 .c
179 .c Globals: read-only register @.Shell_cmd_width
180 .c
181 .de groffer:Shell_cmd_base
182 .  if (\\n[.$] <= 0) \
183 .    return
184 .  nr @+font \\n[.f]\"
185 .  ds @prompt \\$1\"
186 .  ft CR
187 .  c gap between prompt and command
188 .  nr @+gap \\n[groffer:Shell_cmd_base.prompt_width]-\\w'\\*[@prompt]'\"
189 .  ds @res \\*[@prompt]\h'\\n[@+gap]u'\"
190 .  shift
191 .  ds @cf CR\"
192 .  while (\\n[.$] > 0) \{\
193 .    as @res \\f[\\*[@cf]]\\$1\"
194 .    shift
195 .    ie '\\*[@cf]'CR' \
196 .      ds @cf I\"
197 .    el \
198 .      ds @cf CR\"
199 .  \}
200 .  br
201 .  ad l
202 .  nh
203 .  nf
204 .  Text \\*[@res]\"
205 .  fi
206 .  hy
207 .  ad
208 .  br
209 .  ft \\n[@+font]
210 .  rr @+font
211 .  rr @+gap
212 .  rm @cf
213 .  rm @res
214 ..
215 .c --------------------------------------------------------------------
216 .c .Text  (<text>...)
217 .c
218 .c Treat the arguments as text, no matter how they look.
219 .c
220 .de Text
221 .  if (\\n[.$] == 0) \
222 .    return
223 .  nop \)\\$*\)
224 ..
225 .c --------------------------------------------------------------------
226 .c .Topic  ([<indent>])
227 .c
228 .c A bulleted paragraph
229 .c
230 .de Topic
231 .  ie (\\n[.$] = 0) \
232 .    ds @indent 2m\"
233 .  el \
234 .    ds @indent \\$1\"
235 .  TP \\*[@indent]
236 .  Text \[bu]
237 .  rm @indent
238 ..
239 .c --------------------------------------------------------------------
240 .c .TP+  ()
241 .c
242 .c Continuation line for .TP header.
243 .c
244 .de TP+
245 .  br
246 .  ns
247 .  TP \\$1
248 ..
249 .c --------------------------------------------------------------------
250 .de 'char
251 .  ds @tmp@ `\f(CR\\$1\f[]'
252 .  shift
253 .  Text \\*[@tmp@]\\$*
254 .  rm @tmp@
255 ..
256 .c --------------------------------------------------------------------
257 .de option
258 .  ds @tmp@ \f(CB\\$1\f[]
259 .  shift 1
260 .  Text \\*[@tmp@]\\$*
261 .  rm @tmp@
262 ..
263 .c --------------------------------------------------------------------
264 .de argument
265 .  ds @tmp@ \f(CI\\$1\f[]
266 .  shift 1
267 .  Text \\*[@tmp@]\\$*
268 .  rm @tmp@
269 ..
270 .c --------------------------------------------------------------------
271 .de request
272 .  ds @tmp@ \f(CB\\$1\f[]
273 .  shift 1
274 .  Text .\\*[@tmp@]\\$*
275 .  rm @tmp@
276 ..
277 .c --------------------------------------------------------------------
278 .de escape
279 .  ds @tmp@ \f[CB]\\$1\f[]
280 .  shift 1
281 .  Text \[rs]\\*[@tmp@]\\$*
282 .  rm @tmp@
283 ..
284 .\" --------------------------------------------------------------------
285 .\" SH DESCRIPTION
286 .\" --------------------------------------------------------------------
287 .
288 The
289 .BR roff (@MAN7EXT@)
290 type-setting system provides a set of macro packages suitable for
291 special kinds of documents.
292 .
293 Each macro package stores its macros and definitions in a file called
294 the package's
295 .BR "tmac file" .
296 The name is deduced from
297 .RB ` T\c
298 .IB roff MAC\c
299 .IR ros '.
300 .
301 .P
302 The tmac files are normal roff source documents, except that they
303 usually contain only definitions and setup commands, but no text.
304 .
305 All tmac files are kept in a single or a small number of directories,
306 the
307 .B tmac
308 directories.
309 .
310 .
311 .\" --------------------------------------------------------------------
312 .SH "GROFF MACRO PACKAGES"
313 .\" --------------------------------------------------------------------
314 .
315 .I groff
316 provides all classical macro packages, some more full packages, and
317 some secondary packages for special purposes.
318 .
319 Note that it is not possible to use multiple primary macro packages at the
320 same time; saying e.g.\&
321 .
322 .IP
323 .Shell_cmd "groff \-m man \-m ms foo"
324 .
325 .P
326 or
327 .
328 .IP
329 .Shell_cmd "groff \-m man foo \-m ms bar"
330 .
331 .P
332 will fail.
333 .
334 .
335 .\" --------------------------------------------------------------------
336 .SS "Man\~Pages"
337 .\" --------------------------------------------------------------------
338 .
339 .TP
340 .B man
341 This is the classical macro package for UNIX manual pages
342 (man\~pages); it is quite handy and easy to use; see
343 .BR groff_man (@MAN7EXT@).
344 .
345 .TP
346 .B doc
347 .TP+
348 .B mdoc
349 An alternative macro package for man\~pages mainly used in BSD
350 systems; it provides many new features, but it is not the standard for
351 man\~pages; see
352 .BR groff_mdoc (@MAN7EXT@).
353 .
354 .
355 .\" --------------------------------------------------------------------
356 .SS "Full Packages"
357 .\" --------------------------------------------------------------------
358 .
359 The packages in this section provide a complete set of macros for
360 writing documents of any kind, up to whole books.
361 .
362 They are similar in functionality; it is a matter of taste which one
363 to use.
364 .
365 .
366 .TP
367 .B me
368 The classical
369 .I me
370 macro package; see
371 .BR groff_me (@MAN7EXT@).
372 .
373 .
374 .TP
375 .B mm
376 The semi-classical
377 .I mm
378 macro package; see
379 .BR groff_mm (@MAN7EXT@).
380 .
381 .
382 .TP
383 .B mom
384 The new
385 .I mom
386 macro package, only available in groff.
387 .
388 As this is not based on other packages, it can be freely designed.
389 .
390 So it is expected to become quite a nice, modern macro package.
391 .
392 See
393 .BR groff_mom (@MAN7EXT@).
394 .
395 .
396 .TP
397 .B ms
398 The classical
399 .I ms
400 macro package; see
401 .BR groff_ms (@MAN7EXT@).
402 .
403 .
404 .\" --------------------------------------------------------------------
405 .SS "Special Packages"
406 .\" --------------------------------------------------------------------
407 .
408 The macro packages in this section are not intended for stand-alone
409 usage, but can be used to add special functionality to any other
410 macro package or to plain groff.
411 .
412 .
413 .TP
414 .B papersize
415 This macro file is already loaded at start-up by
416 .B @g@troff
417 so it isn't necessary to call it explicitly.
418 .
419 It provides an interface to set the paper size on the command line with
420 the option \f[B]\%\-dpaper=\f[]\f[I]size\f[].
421 .
422 Possible values for
423 .I size
424 are the same as the predefined
425 .B papersize
426 values in the DESC file (only lowercase; see
427 .BR groff_font (@MAN5EXT@)
428 for more) except
429 .BR a7 - d7 .
430 .
431 An appended
432 .B l
433 (ell) character denotes landscape orientation.
434 .
435 Examples:
436 .BR a4 ,
437 .BR c3l ,
438 .BR letterl .
439 .
440 .IP
441 Most output drivers need additional command line switches
442 .B \-p
443 and
444 .B \-l
445 to override the default paper length and orientation as set in the driver
446 specific DESC file.
447 .
448 For example, use the following for PS output on A4 paper in landscape
449 orientation:
450 .
451 .IP
452 .Shell_cmd "groff \-Tps \-dpaper=a4l \-P\-pa4 \-P\-l \-ms foo.ms > foo.ps"
453 .
454 .
455 .TP
456 .B pspic
457 A single macro is provided in this file,
458 .BR PSPIC ,
459 to include a PostScript graphic in a document.
460 .
461 It makes only sense for output devices which support inclusion of PS
462 images:
463 .BR \-Tps ,
464 .BR \-Tdvi ,
465 and
466 .BR \-Thtml ;
467 the file is then loaded automatically.
468 .
469 Syntax:
470 .RS
471 .IP
472 \&\fB.PSPIC\fP [\fB\-L\fP|\fB-R\fP|\fB\-I\fP \fIn\fP]\ \fI\|file\fP [\fIwidth\fP [\fIheight\fP]]
473 .RE
474 .
475 .IP
476 .I file
477 is the name of the file containing the illustration;
478 .I width
479 and
480 .I height
481 give the desired width and height of the graphic.
482 .
483 The
484 .I width
485 and
486 .I height
487 arguments may have scaling indicators attached;
488 the default scaling indicator is\~\c
489 .BR i .
490 .
491 This macro will scale the graphic uniformly
492 in the x and y\~directions so that it is no more than
493 .I width
494 wide
495 and
496 .I height
497 high.
498 .
499 By default, the graphic will be horizontally centered.
500 .
501 The
502 .BI \-L
503 and
504 .BI \-R
505 options cause the graphic to be left-aligned and right-aligned,
506 respectively.
507 .
508 The
509 .B \-I
510 option causes the graphic to be indented by\~\c
511 .I n
512 (default scaling indicator is\~\c
513 .BR m ).
514 .
515 .TP
516 .B tty-char
517 Overrides the definition of standard troff characters and some groff
518 characters for tty devices.
519 .
520 The optical appearance is intentionally inferior compared to that of
521 normal tty formatting to allow processing with critical equipment.
522 .
523 .
524 .TP
525 .B www
526 Additions of elements known from the html format, as being used in the
527 internet (World Wide Web) pages; this includes URL links and mail
528 addresses; see
529 .BR groff_www (@MAN7EXT@).
530 .
531 .
532 .\" --------------------------------------------------------------------
533 .SH NAMING
534 .\" --------------------------------------------------------------------
535 .
536 In classical roff systems, there was a funny naming scheme for macro
537 packages, due to a simplistic design in option parsing.
538 .
539 Macro packages were always included by option
540 .option -m;
541 when this option was directly followed by its argument without an
542 intervening space, this looked like a long option preceded by a single
543 minus \[em] a sensation in the computer stone age.
544 .
545 To make this optically working for macro package names, all classical
546 macro packages choose a name that started with the letter
547 .'char m ,
548 which was omitted in the naming of the macro file.
549 .
550 .
551 .P
552 For example, the macro package for the man pages was called
553 .IR man ,
554 while its macro file
555 .IR tmac.an .
556 So it could be activated by the argument
557 .I an
558 to option
559 .option -m ,
560 or
561 .option -man
562 for short.
563 .
564 .
565 .P
566 For similar reasons, macro packages that did not start with an
567 .'char m
568 had a leading
569 .'char m
570 added in the documentation and in talking; for example, the package
571 corresponding to
572 .I tmac.doc
573 was called
574 .I mdoc
575 in the documentation, although a more suitable name would be
576 .IR doc .
577 For, when omitting the space between the option and its argument, the
578 command line option for activating this package reads
579 .option "-mdoc" .
580 .
581 .
582 .P
583 To cope with all situations, actual versions of
584 .BR groff (@MAN1EXT@)
585 are smart about both naming schemes by providing two macro files
586 for the inflicted macro packages; one with a leading
587 .'char m ,
588 the other one without it.
589 .
590 So in
591 .IR groff ,
592 the
593 .I man
594 macro package may be specified as on of the following four methods:
595 .
596 .IP
597 .Shell_cmd "groff\~\-m\~man"
598 .Shell_cmd "groff\~\-man"
599 .Shell_cmd "groff\~\-mman"
600 .Shell_cmd "groff\~\-m\~an"
601 .
602 .
603 .P
604 Recent packages that do not start with
605 .'char m
606 do not use an additional
607 .'char m
608 in the documentation.
609 .
610 For example, the
611 .I www
612 macro package may be specified only as one of the two methods:
613 .
614 .IP
615 .Shell_cmd "groff\~\-m\~www"
616 .Shell_cmd "groff\~\-mwww"
617 .
618 .
619 .P
620 Obviously, variants like
621 .I -mmwww
622 would not make much sense.
623 .
624 .
625 .P
626 A second strange feature of classical troff was to name macro files
627 according to
628 .BIR tmac. name .
629 In modern operating systems, the type of a file is specified as
630 postfix, the file name extension.
631 .
632 Again, groff copes with this situation by searching both
633 .IB anything .tmac
634 and
635 .BI tmac. anything
636 if only
637 .I anything
638 is specified.
639 .
640 .
641 .P
642 The easiest way to find out which macro packages are available on a
643 system is to check the man\~page
644 .BR groff (@MAN1EXT@),
645 or the contents of the
646 .I tmac
647 directories.
648 .
649 .
650 .P
651 In
652 .IR groff ,
653 most macro packages are described in\~man pages called
654 .BR groff_\f[I]name\f[] (@MAN7EXT@),
655 with a leading
656 .'char m
657 for the classical packages.
658 .
659 .
660 .\" --------------------------------------------------------------------
661 .SH INCLUSION
662 .\" --------------------------------------------------------------------
663 .
664 There are several ways to use a macro package in a document.
665 .
666 The classical way is to specify the troff/groff option
667 .option \-m
668 .argument name
669 at run-time; this makes the contents of the macro package
670 .I name
671 available.
672 .
673 In groff, the file
674 .IB name .tmac
675 is searched within the tmac path; if not found,
676 .BI tmac. name
677 will be searched for instead.
678 .
679 .
680 .P
681 Alternatively, it is also possible to include a macro file by adding
682 the request
683 .request so
684 .I filename
685 into the document; the argument must be the full file name of an
686 existing file, possibly with the directory where it is kept.
687 .
688 In groff, this was improved by the similar request
689 .request mso
690 .IR package ,
691 which added searching in the tmac path, just like option
692 .option -m
693 does.
694 .
695 .
696 .P
697 Note that in order to resolve the
698 .request so
699 and
700 .request mso
701 requests, the roff preprocessor
702 .BR soelim (@MAN1EXT@)
703 must be called if the files to be included need preprocessing.
704 .
705 This can be done either directly by a pipeline on the command line or
706 by using the troff/groff option
707 .option \-s .
708 .
709 .I man
710 calls soelim automatically.
711 .
712 .
713 .P
714 For example, suppose a macro file is stored as
715 .I @MACRODIR@/macros.tmac
716 and is used in some document called
717 .IR docu.roff .
718 .
719 .
720 .P
721 At run-time, the formatter call for this is
722 .
723 .IP
724 .Shell_cmd "groff\~\-m\~" "macrofile\~document.roff"
725 .
726 .
727 .P
728 To include the macro file directly in the document either
729 .
730 .IP
731 .Example
732 .  Text .mso macrofile.tmac
733 ./Example
734 .
735 .P
736 is used or
737 .
738 .IP
739 .Example
740 .  Text .so @MACRODIR@/macros.tmac
741 ./Example
742 .
743 .
744 .P
745 In both cases, the formatter is called with
746 .IP
747 .Shell_cmd "groff\~\-s\~" docu.roff
748 .
749 .
750 .P
751 If you want to write your own groff macro file, call it
752 .IB whatever .tmac
753 and put it in some directory of the tmac path, see section
754 .BR FILES .
755 Then documents can include it with the
756 .request mso
757 request or the option
758 .option -m .
759 .
760 .
761 .ig
762 .\" --------------------------------------------------------------------
763 .SH CONVENTION
764 .\" --------------------------------------------------------------------
765 .
766 .\" This section does not fit into the framework of this document.
767 .
768 There is a convention that is supported by many modern roff
769 type-setters and
770 .BR man (1)
771 programs, the
772 .I preprocessor word
773 described in the following.
774 .
775 .P
776 If the first line in a document is a comment, the first word (after the
777 comment characters and a blank) constitutes the
778 .B preprocessor
779 .BR word .
780 That means that the letters of this word are interpreted as
781 abbreviations for those preprocessor commands that should be run
782 when formatting the document.
783 .
784 Mostly, only the letters corresponding to the options for the
785 preprocessors are recognized,
786 .'char e
787 (for
788 .BR eqn ),
789 .\" 'char G ,
790 .\" 'char g ,
791 .'char p ,
792 (for
793 .BR pic ),
794 .'char R
795 (for
796 .BR refer ),
797 .'char s
798 (for
799 .BR soelim ),
800 and
801 .'char t
802 (for
803 .BR tbl ).
804 (see
805 .BR roff (@MAN7EXT@)).
806 .
807 .
808 .P
809 Besides being a good reminder for the user, some formatters (like the
810 .BR man (1)
811 program) are even able to automatically start the preprocessors
812 specified in the preprocessor word, but do not bet on this.
813 .
814 .
815 .P
816 The
817 .I man
818 program handles some preprocessors automatically, such that in
819 man\~pages only the following characters should be used:
820 .'char e ,
821 .'char p ,
822 and
823 .'char t .
824 .
825 .
826 ..
827 .\" --------------------------------------------------------------------
828 .SH "WRITING MACROS"
829 .\" --------------------------------------------------------------------
830 .
831 A
832 .BR roff (@MAN7EXT@)
833 document is a text file that is enriched by predefined formatting
834 constructs, such as requests, escape sequences, strings, numeric
835 registers, and macros from a macro package.
836 .
837 These elements are described in
838 .BR roff (@MAN7EXT@).
839 .
840 .
841 .P
842 To give a document a personal style, it is most useful to extend the
843 existing elements by defining some macros for repeating tasks; the best
844 place for this is near the beginning of the document or in a separate
845 file.
846 .
847 .
848 .P
849 Macros without arguments are just like strings.
850 .
851 But the full power of macros reveals when arguments are passed with a
852 macro call.
853 .
854 Within the macro definition, the arguments are available as the escape
855 sequences
856 .BR $1 ,
857 \*[Ellipsis],
858 .BR $9 ,
859 .BR $[ \*[Ellipsis] ] ,
860 .BR $* ,
861 and
862 .BR $@ ,
863 the name under which the macro was called is in
864 .BR $0 ,
865 and the number of arguments is in register
866 .BR \n[.$] ;
867 see
868 .BR groff (@MAN7EXT@).
869 .
870 .
871 .\" --------------------------------------------------------------------
872 .SS "Copy-in Mode"
873 .\" --------------------------------------------------------------------
874 .
875 The phase when groff reads a macro is called
876 .I "copy-in mode"
877 in roff-talk.
878 .
879 This is comparable to the C\~preprocessing phase during the development
880 of a program written in the C\~language.
881 .
882 .
883 .P
884 In this phase, groff interprets all backslashes; that means that all
885 escape sequences in the macro body are interpreted and replaced by
886 their value.
887 .
888 For constant expression, this is wanted, but strings and registers
889 that might change between calls of the macro must be protected from
890 being evaluated.
891 .
892 This is most easily done by doubling the backslash that introduces the
893 escape sequence.
894 .
895 This doubling is most important for the positional parameters.
896 .
897 For example, to print information on the arguments that were passed to
898 the macro to the terminal, define a macro named `.print_args',
899 say.
900 .
901 .
902 .P
903 .ds @1 \[rs]f[I]\[rs]\[rs]$0\[rs]f[]\"
904 .ds @2 arguments:\"
905 .Example
906 .  Text .ds midpart was called with
907 .  Text .de print_args
908 .  Text .\~\~tm\~\*[@1]\~\[rs]\[rs]*[midpart]\~\[rs]\[rs]n[.$]\~\*[@2]
909 .  Text .\~\~tm\~\[rs]\[rs]$*
910 .  Text ..
911 ./Example
912 .rm @1
913 .rm @2
914 .
915 .
916 .P
917 When calling this macro by
918 .
919 .P
920 .Example
921 .  Text .print_args arg1 arg2
922 ./Example
923 .
924 .P
925 the following text is printed to the terminal:
926 .
927 .P
928 .Example
929 .  Text \f[CI]print_args\f[] was called with the following 2 arguments:
930 arg1 arg2
931 ./Example
932 .
933 .
934 .P
935 Let's analyze each backslash in the macro definition.
936 .
937 As the positional parameters and the number of arguments will change
938 with each call of the macro their leading backslash must be doubled,
939 which results in
940 .I \[rs]\[rs]$*
941 and
942 .IR \[rs]\[rs][.$] .
943 The same applies to the macro name because it could be called with an
944 alias name, so
945 .IR \[rs]\[rs]$0 .
946 .
947 .
948 .P
949 On the other hand,
950 .I midpart
951 is a constant string, it will not change, so no doubling for
952 .IR \[rs]*[midpart] .
953 The
954 .I \[rs]f
955 escape sequences are predefined groff elements for setting the font
956 within the text.
957 .
958 Of course, this behavior will not change, so no doubling with
959 .I \[rs]f[I]
960 and
961 .IR \[rs]f[] .
962 .
963 .
964 .\" --------------------------------------------------------------------
965 .SS "Draft Mode"
966 .\" --------------------------------------------------------------------
967 .
968 Writing groff macros is easy when the escaping mechanism is temporarily
969 disabled.
970 .
971 In groff, this is done by enclosing the macro definition(s) into a
972 pair of
973 .B .eo
974 and
975 .B .ec
976 requests.
977 .
978 Then the body in the macro definition is just like a normal part of
979 the document \[em] text enhanced by calls of requests, macros,
980 strings, registers, etc.
981 .
982 For example, the code above can be written in a simpler way by
983 .
984 .
985 .P
986 .ds @1 \[rs]f[I]\[rs]$0\[rs]f[]\"
987 .ds @2 arguments:\"
988 .Example
989 .  Text .eo
990 .  Text .ds midpart was called with
991 .  Text .de print_args
992 .  Text .\~\~tm\~\*[@1]\~\[rs]*[midpart]\~\[rs]n[.$]\~\*[@2]
993 .  Text .\~\~tm\~\[rs]$*
994 .  Text ..
995 .  Text .ec
996 ./Example
997 .rm @1
998 .rm @2
999 .
1000 .
1001 .P
1002 Unfortunately, draft mode cannot be used universally.
1003 .
1004 Although it is good enough for defining normal macros, draft mode
1005 will fail with advanced applications, such as indirectly defined
1006 strings, registers, etc.
1007 .
1008 An optimal way is to define and test all macros in draft mode and then
1009 do the backslash doubling as a final step; do not forget to remove the
1010 .I .eo
1011 request.
1012 .
1013 .
1014 .\" --------------------------------------------------------------------
1015 .SS "Tips for Macro Definitions"
1016 .\" --------------------------------------------------------------------
1017 .
1018 .Topic
1019 Start every line with a dot, for example, by using the groff request
1020 .B .nop
1021 for text lines, or write your own macro that handles also text lines
1022 with a leading dot.
1023 .
1024 .IP
1025 .Example
1026 .  Text .de Text
1027 .  Text .\~\~if (\[rs]\[rs]n[.$] == 0)\~\[rs]
1028 .  Text .\~\~\~\~return
1029 .  Text .\~nop\~\[rs])\[rs]\[rs]$*[rs]\)
1030 .  Text ..
1031 ./Example
1032 .
1033 .Topic
1034 Write a comment macro that works both for copy-in and draft mode; for
1035 as escaping is off in draft mode, trouble might occur when normal
1036 comments are used.
1037 .
1038 For example, the following macro just ignores its arguments, so it
1039 acts like a comment line:
1040 .
1041 .IP
1042 .Example
1043 .  Text .de\~c
1044 .  Text ..
1045 .  Text .c\~This\~is\~like\~a\~comment\~line.
1046 ./Example
1047 .
1048 .Topic
1049 In long macro definitions, make ample use of comment lines or empty
1050 lines for a better structuring.
1051 .
1052 .Topic
1053 To increase readability, use groff's indentation facility for requests
1054 and macro calls (arbitrary whitespace after the leading dot).
1055 .
1056 .
1057 .\" --------------------------------------------------------------------
1058 .SS "Diversions"
1059 .\" --------------------------------------------------------------------
1060 .
1061 Diversions can be used to realize quite advanced programming
1062 constructs.
1063 .
1064 They are comparable to pointers to large data structures in the
1065 C\~programming language, but their usage is quite different.
1066 .
1067 .
1068 .P
1069 In their simplest form, diversions are multi-line strings, but
1070 they get their power when diversions are used dynamically within macros.
1071 .
1072 The information stored in a diversion can be retrieved by calling the
1073 diversion just like a macro.
1074 .
1075 .
1076 .P
1077 Most of the problems arising with diversions can be avoided if you are
1078 conscious about the fact that diversions always deal with complete
1079 lines.
1080 .
1081 If diversions are used when the line buffer has not been flashed,
1082 strange results are produced; not knowing this, many people get
1083 desperate about diversions.
1084 .
1085 To ensure that a diversion works, line breaks should be added at the
1086 right places.
1087 .
1088 To be on the secure side, enclose everything that has to do with
1089 diversions into a pair of line breaks; for example, by amply using
1090 .B .br
1091 requests.
1092 .
1093 This rule should be applied to diversion definition, both inside and
1094 outside, and to all calls of diversions.
1095 .
1096 This is a bit of overkill, but it works nicely.
1097 .
1098 .
1099 .P
1100 [If you really need diversions which should ignore the current partial
1101 line, use environments to save the current partial line and/\:or use the
1102 .B .box
1103 request.]
1104 .
1105 .
1106 .P
1107 The most powerful feature using diversions is to start a diversion
1108 within a macro definition and end it within another macro.
1109 .
1110 Then everything between each call of this macro pair is stored within
1111 the diversion and can be manipulated from within the macros.
1112 .
1113 .
1114 .\" --------------------------------------------------------------------
1115 .SH FILES
1116 .\" --------------------------------------------------------------------
1117 .
1118 All macro names must be named
1119 .IB name .tmac
1120 to fully use the tmac mechanism.
1121 .
1122 .BI tmac. name
1123 as with classical packages is possible as well, but deprecated.
1124 .
1125 .
1126 .P
1127 The macro files are kept in the
1128 .IR "tmac directories" ;
1129 a colon separated list of these constitutes the
1130 .IR "tmac path" .
1131 .
1132 .
1133 .P
1134 The search sequence for macro files is (in that order):
1135 .
1136 .Topic
1137 the directories specified with troff/groff's
1138 .B \-M
1139 command line option
1140 .
1141 .Topic
1142 the directories given in the
1143 .Env_var $GROFF_TMAC_PATH
1144 environment variable
1145 .
1146 .Topic
1147 the current directory (only if in unsafe mode, which is enabled by the
1148 .B \-U
1149 command line switch)
1150 .
1151 .Topic
1152 the home directory
1153 .
1154 .Topic
1155 a platform-specific directory, being
1156 .B @SYSTEMMACRODIR@
1157 in this installation
1158 .
1159 .Topic
1160 a site-specific (platform-independent) directory, being
1161 .B @LOCALMACRODIR@
1162 in this installation
1163 .
1164 .Topic
1165 the main tmac directory, being
1166 .B @MACRODIR@
1167 in this installation
1168 .
1169 .
1170 .\" --------------------------------------------------------------------
1171 .SH ENVIRONMENT
1172 .\" --------------------------------------------------------------------
1173 .
1174 .TP
1175 .Env_var $GROFF_TMAC_PATH
1176 A colon separated list of additional tmac directories in which to search
1177 for macro files.
1178 .
1179 See the previous section for a detailed description.
1180 .
1181 .
1182 .\" --------------------------------------------------------------------
1183 .SH AUTHOR
1184 .\" --------------------------------------------------------------------
1185 .
1186 Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
1187 .
1188 .P
1189 This document is distributed under the terms of the FDL (GNU Free
1190 Documentation License) version 1.1 or later.
1191 .
1192 You should have received a copy of the FDL on your system, it is also
1193 available on-line at the
1194 .URL http://\:www.gnu.org/\:copyleft/\:fdl.html "GNU copyleft site" .
1195 .
1196 .P
1197 This document is part of
1198 .IR groff ,
1199 the GNU roff distribution.
1200 .
1201 It was written by
1202 .MTO bwarken@mayn.de "Bernd Warken" ;
1203 it is maintained by
1204 .MTO wl@gnu.org "Werner Lemberg" .
1205 .
1206 .
1207 .\" --------------------------------------------------------------------
1208 .SH "SEE ALSO"
1209 .\" --------------------------------------------------------------------
1210 .
1211 A complete reference for all parts of the groff system is found in the
1212 groff
1213 .BR info (1)
1214 file.
1215 .
1216 .TP
1217 .BR groff (@MAN1EXT@)
1218 an overview of the groff system.
1219 .
1220 .TP
1221 .BR groff_man (@MAN7EXT@),
1222 .TP+
1223 .BR groff_mdoc (@MAN7EXT@),
1224 .TP+
1225 .BR groff_me (@MAN7EXT@),
1226 .TP+
1227 .BR groff_mm (@MAN7EXT@),
1228 .TP+
1229 .BR groff_mom (@MAN7EXT@),
1230 .TP+
1231 .BR groff_ms (@MAN7EXT@),
1232 .TP+
1233 .BR groff_www (@MAN7EXT@).
1234 the groff tmac macro packages.
1235 .
1236 .TP
1237 .BR groff (@MAN7EXT@)
1238 the groff language.
1239 .
1240 .
1241 .P
1242 The Filesystem Hierarchy Standard is available at the
1243 .URL http://\:www.pathname.com/\:fhs/ "FHS web site" .
1244 .
1245 .cp \n[groff_tmac_C]
1246 .
1247 .\" Local Variables:
1248 .\" mode: nroff
1249 .\" End: