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