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