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