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