2 www.tmac - macro package for adding HTML elements to roff documents.
4 File position: <groff_source_top>/tmac/www.tmac
5 Installed position: groff's main macro directory.
7 ------------------------------------------------------------------------
9 ------------------------------------------------------------------------
11 This file is part of groff, the GNU roff type-setting system.
13 Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
14 written by Gaius Mulley <gaius@glam.ac.uk>, with additions by
15 Werner Lemberg <wl@gnu.org> and Bernd Warken <bwarken@mayn.de>.
17 groff is free software; you can redistribute it and/or modify it under
18 the terms of the GNU General Public License as published by the Free
19 Software Foundation; either version 2, or (at your option) any later
22 groff is distributed in the hope that it will be useful, but WITHOUT
23 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 You should have received a copy of the GNU General Public License
28 along with groff; see the file COPYING. If not, write to the Free
29 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
33 ------------------------------------------------------------------------
35 ------------------------------------------------------------------------
37 A simple set of macros to provide HTML documents with basic
38 www functionality. It should work with any macro set.
41 .\" --------------------------------------------------------------------
43 .\" --------------------------------------------------------------------
49 .if '\*[.T]'html' .nr www-html 1
51 .\" set up www-image-template
53 .if !d www-image-template \
54 . ds www-image-template
57 . \" remove the title command when we are generating images for html
58 . \" (stops a title accidentally appearing inside an image)
68 .\" --------------------------------------------------------------------
69 .\" Test for `.substring'; result in register `www.substring_ok'.
70 .\" The automated break points in .URL addresses are only added if
71 .\" this register is non-zero.
73 .nr www:substring_ok 0
74 .de www:@test_substring
78 . substring \\$0:s 1 1
79 . if !'\\*[\\$0:s]'b' \{\
84 . substring \\$0:s 0 0
85 . if !'\\*[\\$0:s]'a' \{\
90 . substring \\$0:s 1 -1
91 . if !'\\*[\\$0:s]'bcdefg' \{\
95 . nr www:substring_ok 1
99 .rm www:@test_substring
102 .\" --------------------------------------------------------------------
104 .\" --------------------------------------------------------------------
106 .\" --------------------------------------------------------------------
107 .\" www:error (<test>...)
109 .\" Print error message
112 . tm \\n[.F]:\\n[.c]: macro error: \\$*
114 .als www:error www-error
116 .\" --------------------------------------------------------------------
117 .\" www:lenstr (<register_name> <string_name>)
119 .\" Store length of string named <string_name> into register named
123 . if !(\\n[.$] == 2) \{\
124 . tm .\\$0 expects 2 arguments.
127 . length \\$0:n x\\*[\\$2]
128 . nr \\$1 (\\n[\\$0:n]-1)
131 .\" --------------------------------------------------------------------
132 .\" www:splitstr (<name>)
134 .\" Add a space character between any two adjacent characters in string
135 .\" <name> and restore result into the string variable <name>; space
136 .\" characters are first replaced by the word `space'.
139 . if !(\\n[.$] == 1) \
140 . www:error .\\$0 expects 1 argument.
143 . ds \\$0:r "\\*[\\$1]\""
146 . ds \\$0:c "\\*[\\$0:r]\""
147 . substring \\$0:c 0 0\"
148 . ie '\\*[\\$0:c]' ' \
149 . as \\$0:s " space\""
151 . as \\$0:s " \\*[\\$0:c]\""
152 . www:lenstr \\$0:n \\$0:r
153 . if (\\n[\\$0:n] <= 1) \{\
156 . substring \\$0:r 1 -1\"
158 . if !'\\*[\\$0:s]'' \
159 . substring \\$0:s 1 -1
160 . ds \\$1 \\*[\\$0:s]
166 .\" --------------------------------------------------------------------
167 .\" www:url_breaks (<string_name>)
169 .\" Add `\:' (possible break point) within URL strings after `/'.
171 .\" Smart about multiple `/', existing `\:', and space characters;
172 .\" does not set a break point if less than 5 characters would go to
176 . if !(\\n[.$] == 1) \
177 . www:error .\\$0 expects 1 argument.
178 . if !\n[www:substring_ok] \
180 . ds \\$0:s "\\*[\\$1]\""
181 . www:splitstr \\$0:s
182 . www:url_breaks_splitted \\$0:s \\*[\\$0:s]
183 . ds \\$1 "\\*[\\$0:s]\""
186 .\" --------------------------------------------------------------------
187 .\" www:url_breaks_splitted (<result> <char> [<char>...])
189 .\" Add `\:' within URL strings, but arguments are a splitted string.
191 .\" Arguments: >=2: <result> <char> [<char>...]
193 .de www:url_breaks_splitted
194 . nr \\$0:min 5 \" minimal number of characters for next line
196 . www:error .\\$0 expects at least 2 arguments.
201 . while !\\n[\\$0:done] \{\
202 . if (\\n[.$] <= 0) \{\
206 . if '\\$1'space' \{\
211 . if (\\n[.$] < \\n[\\$0:min]) \{\
221 . \" we are at a `/' character
224 . if (\\n[.$] == 0) \{\
230 . if \\n[\\$0:done] \
232 . if (\\n[.$] < \\n[\\$0:min]) \
238 . ds \\*[\\$0:res] \\*[\\$0:s]\"
242 .\" --------------------------------------------------------------------
244 .\" --------------------------------------------------------------------
246 .\" --------------------------------------------------------------------
247 .\" HTML (<address> <description> [<punctuation>])
249 .\" the main auxiliary macro for the HTML interface
252 . if \\n[www-html] \{\
253 . \" the following line makes the vertical mode leave, so to say
259 .\" an auxiliary macro for HTML (without following space)
263 . nop \X^html:\\$*^\c
265 .\" --------------------------------------------------------------------
268 .\" Automatic heading level cut off.
270 .\" N is the depth limit of automatically linked headings. So a depth
271 .\" of 2 would cause grohtml to generate a list of links for `.NH 1'
272 .\" and `.NH 2' but not for `.NH 3'.
278 .\" --------------------------------------------------------------------
279 .\" BCL foreground background active not-visited visited
282 . HTML <body text=\\$1 bgcolor=\\$2 link=\\$3 alink=\\$4 vlink=\\$5>
284 .\" --------------------------------------------------------------------
288 . HTML <body background=\\$1>
290 .\" --------------------------------------------------------------------
291 .\" URL url [description] [after]
292 .\" if description is absent then the url becomes the anchor text
296 . www:url_breaks \\$0:adr
297 . ie \\n[www-html] \{\
299 . HTML <a href="\\$1">\\$1</a>\\$3
301 . HTML <a href="\\$1">\\$2</a>\\$3
304 . if !r ps4html .ad l
306 . nop \%\[la]\m[blue]\f[C]\\*[\\$0:adr]\f[]\m[]\[ra]\\$3
308 . nop \m[blue]\\$2\m[] \%\[la]\f[C]\\*[\\$0:adr]\f[]\[ra]\\$3
313 .\" --------------------------------------------------------------------
314 .\" FTP url description [after]
319 .\" --------------------------------------------------------------------
320 .\" MTO address description [after]
322 .\" ADDRESS is the email address (without the `mailto:' prefix).
324 .\" DESCRIPTION is the optional name. If an empty argument is given,
325 .\" ADDRESS is used instead.
327 .\" AFTER is optional stuff printed immediately after ADDRESS
328 .\" (resp. DESCRIPTION).
332 .\" Foobar has been written by
333 .\" .MTO fred@foo.bar "Fredrick Bloggs" .
336 . ie \\n[www-html] \{\
338 . URL mailto:\\$1 \\$1 "\\$3"
340 . URL mailto:\\$1 "\\$2" "\\$3"
344 . nop \%\m[blue]\f[C]\\$1\f[]\m[]\\$3
346 . nop \m[blue]\\$2\m[] \%\[la]\f[C]\\$1\f[]\[ra]\\$3
349 .\" --------------------------------------------------------------------
352 .\" Generate an html name NAME.
355 . HTML <a name="\\$1"></a>
357 .\" --------------------------------------------------------------------
358 .\" IMG [-R|-L|-C] filename [width] [height]
360 .\" Include an image of any type (will only work for -Thtml).
362 .\" Alignment is centered by default (-C).
363 .\" Default value for WIDTH is 1i.
364 .\" If HEIGHT is not given, WIDTH is used as the height.
367 . ie \\n[www-html] \{\
369 . HTML-TAG ".right-image"
372 . HTML-TAG ".left-image"
374 . HTML-TAG ".centered-image"
379 . nr www-height \\n[www-width]
382 . HTML <img src="\\$1" width=\\n[www-width] height=\\n[www-height]>
385 . nop \[la]\f[C]\\$1\f[]\[ra]
387 .\" --------------------------------------------------------------------
390 .\" Emit a tag for grohtml. This is an internal macro.
393 . if \\n[www-html] \{\
394 . \" the following line makes the vertical mode leave, so to say
396 . nop \X^html-tag:\\$*^
399 .\" --------------------------------------------------------------------
402 .\" Emit a tag for grohtml (without a space). This is an internal macro.
406 . nop \X^html-tag:\\$*^\c
408 .\" --------------------------------------------------------------------
409 .\" PIMG [-R|-L|-C] filename [width] [height]
411 .\" Include a png image. It will work for -Tps and -Thtml.
412 .\" The default value for WIDTH and HEIGHT is zero; the default
413 .\" alignment is centering (-C).
415 .\" Note: This macro can only be used with the `-U' option of groff,
416 .\" activating unsafe mode, if not used with -Thtml; the PNG image
417 .\" is then converted to the EPS format using netpbm utilities.
420 . ie \\n[www-html] \{\
422 . HTML-TAG ".right-image"
425 . HTML-TAG ".left-image"
427 . HTML-TAG ".centered-image"
432 . nr www-width (\\$3 * 100 / 240)
434 . nr www-height (\\$4 * 100 / 240)
435 . ie (\\n[www-width] == 0) \{\
436 . ie (\\n[www-height] == 0) \
437 . HTML <img src="\\$2">
439 . HTML <img src="\\$1" height=\\n[www-height]>
442 . ie (\\n[www-height] == 0) \
443 . HTML <img src="\\$2" width=\\n[www-width]>
445 . HTML <img src="\\$2" width=\\n[www-width] height=\\n[www-height]>
450 . www-make-unique-name
451 . sy pngtopnm \\$2 | pnmcrop -white | @PNMTOPS_NOSETPAGE@ -noturn > \\*[www-unique-name].eps
453 . PSPIC \\*[www-unique-name].eps \\$3 \\$4
455 . PSPIC \\$1 \\*[www-unique-name].eps \\$3 \\$4
460 .\" --------------------------------------------------------------------
461 .\" auxiliary definitions for MPIMG
463 .nr www-left-ll-trap 0
464 .nr www-left-po-trap 0
465 .nr www-right-ll-trap 0
467 .de www-finish-left-po
468 . po -(\\n[www-left-indent]u + \\n[www-image-gap]u)
469 . wh \\n[www-left-po-trap]u
470 . nr www-left-indent 0
473 .\" called when the -R picture is finished
474 .de www-finish-right-ll
475 . ll +(\\n[www-right-indent]u + \\n[www-image-gap]u)
476 . \" now see whether we need to inline www-finish-left-ll
477 . if (\\n[www-left-ll-trap]u > 0) \
478 . if ((\\n[www-right-ll-trap]u + 1v) >= \\n[www-left-ll-trap]u) \{\
479 . mk www-left-po-trap
480 . nr www-left-po-trap +1v
481 . wh \\n[www-left-po-trap]u www-finish-left-po
482 . ll +\\n[www-left-indent]u
483 . wh \\n[www-left-ll-trap]u
484 . nr www-left-ll-trap 0
486 . \" and see whether we need to inline www-finish-left-po
487 . if (\\n[www-left-po-trap]u > 0) \
488 . if ((\\n[www-right-ll-trap]u + 1v) >= \\n[www-left-po-trap]u) \{\
489 . po -\\n[www-left-indent]u
490 . wh \\n[www-left-po-trap]u
491 . nr www-left-indent 0
493 . wh \\n[www-right-ll-trap]u
494 . nr www-right-ll-trap 0
497 .de www-finish-left-ll
498 . if (\\n[www-right-ll-trap] > 0) \
499 . if ((\\n[www-left-ll-trap] + 1v) >= \\n[www-right-ll-trap]) \{\
500 . ll +\\n[www-right-indent]u
501 . nr www-right-ll-trap 0
503 . mk www-left-po-trap
504 . nr www-left-po-trap +1v
505 . wh \\n[www-left-po-trap]u www-finish-left-po
506 . ll +(\\n[www-left-indent]u + \\n[www-image-gap]u)
507 . wh \\n[www-left-ll-trap]u
508 . nr www-left-ll-trap 0
510 .\" --------------------------------------------------------------------
511 .\" MPIMG [-R|-L] [-G gap] filename [width [height]]
513 .\" Include a png image and wrap text around it. It will work for
514 .\" -Tps and -Thtml. The default value for WIDTH is 1i; default value
515 .\" for HEIGHT is WIDTH; the default alignment is left (-L).
516 .\" -G is used to insert a gap between the text and the image.
518 .\" Note: This macro can only be used with the `-U' option of groff,
519 .\" activating unsafe mode, if not used with -Thtml; the PNG image
520 .\" is then converted to the EPS format using netpbm utilities.
523 .nr www-htmlimage-gap 0
526 . nr www-image-just 1
528 . while (\\n[.$] > 0) \{\
530 . nr www-image-just 1
535 . nr www-image-just 0
540 . nr www-image-gap \\$2
541 . nr www-htmlimage-gap (\\$2 * 100 / 240)
550 . nr www-height \\n[www-width]
553 . nr www-width (\\n[www-width] * 100 / 240)
554 . nr www-height (\\n[www-height] * 100 / 240)
556 . ie \\n[www-html] \{\
557 . ie !\\n[www-image-just] \
558 . HTML <img src="\\$1" hspace=\\n[www-htmlimage-gap] \
559 align=right width=\\n[www-width] height=\\n[www-height]>
561 . HTML <img src="\\$1" hspace=\\n[www-htmlimage-gap] \
562 align=left width=\\n[www-width] height=\\n[www-height]>
566 . www-make-unique-name
567 . sy pngtopnm \\$1 | pnmcrop -white | @PNMTOPS_NOSETPAGE@ -noturn > \\*[www-unique-name].eps
568 . ie !\\n[www-image-just] \{\
569 . \" we must now disable a possible left image trap
571 . if (\\n[www-left-ll-trap] > 0) \
572 . wh \\n[www-left-ll-trap]u
573 . if (\\n[www-left-po-trap] > 0) \
574 . wh \\n[www-left-po-trap]u
575 . PSPIC -R \\*[www-unique-name].eps \\$2 \\$3
577 . nr www-right-indent \\n[ps-deswid]u
578 . \" we want to have some space between text and image,
579 . \" so the line length must be shorter
580 . ll -(\\n[www-right-indent]u + \\n[www-image-gap]u)
581 . mk www-right-ll-trap
582 . nr www-right-ll-trap +(\\n[ps-desht]u - 1v)
583 . wh \\n[www-right-ll-trap]u www-finish-right-ll
584 . \" now restore possible left trap
585 . if (\\n[www-left-ll-trap] > 0) \
586 . wh \\n[www-left-ll-trap]u www-finish-left-ll
587 . if (\\n[www-left-po-trap] > 0) \
588 . wh \\n[www-left-po-trap]u
591 . \" we must now disable a possible right image trap
592 . if (\\n[www-right-ll-trap] > 0) \
593 . wh \\n[www-right-ll-trap]u
594 . PSPIC -L \\*[www-unique-name].eps \\$2 \\$3
596 . nr www-left-indent \\n[ps-deswid]u
597 . \" increase offset by gap
598 . po +(\\n[www-left-indent]u + \\n[www-image-gap]u)
599 . \" decrease line length by gap
600 . ll -(\\n[www-left-indent]u + \\n[www-image-gap]u)
601 . mk www-left-ll-trap
602 . nr www-left-ll-trap +(\\n[ps-desht]u - 1v)
603 . wh \\n[www-left-ll-trap]u www-finish-left-ll
604 . \" now restore possible right trap
605 . if (\\n[www-right-ll-trap] > 0) \
606 . wh \\n[www-right-ll-trap]u www-finish-right-ll
611 .\" --------------------------------------------------------------------
614 .\" Begin heading. Heading level is N.
620 .\" If your heading contains URL, FTP, MTO macros you might wish to
621 .\" disable automatic links to headings. This can be done via `-P-l'
622 .\" from the command line or by using a cakk to `.HX 0'.
624 .nr www-heading-no -1
628 . nr www-heading-no 1
630 . nr www-heading-no \\$1
631 . HTML-TAG ".NH \\n[www-heading-no]"
635 . if (\\n[www-heading-no] == -1) \
636 . www-error "HnE found without a corresponding HnS"
639 .\" --------------------------------------------------------------------
642 .\" Emit the automatically collected links derived from
643 .\" section/numbered headings at this position.
648 .\" --------------------------------------------------------------------
651 .\" Produce a horizontal line
654 . ie \\n[www-html] \{\
661 .\" --------------------------------------------------------------------
664 .\" Suppresses the generation of the top and bottom rules which grohtml
665 .\" emits by default.
668 . HTML-TAG ".no-auto-rule"
671 .\" www-end-nowhere - end of input trap called to finish diversion.
676 .\" --------------------------------------------------------------------
679 .\" Generate an HTML title only. This differs from the -ms .TL macro
680 .\" which generates both an HTML title and a H1 heading.
682 .\" This is useful when an author wishes to use a HTML title as search
683 .\" engine fodder but a graphic title in the document.
685 .\" The macro terminates when a space or break is seen (.sp, .br).
688 . HTML-TAG ".html-tl"
689 . if !\\n[www-html] \{\
691 . it 2 www-end-nowhere
695 .\" --------------------------------------------------------------------
696 .\" auxiliary definitions for ULS / ULE
698 .ds www-level1 \[bu]\ \ \"
699 .ds www-level2 \[sq]\ \ \"
700 .ds www-level3 \[ci]\ \ \"
705 .\" Auxiliary macro for ULS.
709 . if (\\n[www-level] > 3) \
710 . www-error "too many levels of indentation (\\n[www-level])"
713 .\" Auxiliary macro for ULE.
716 . if !\\n[www-level] \
717 . www-error "trying to terminate a list which does not exist"
720 .\" --------------------------------------------------------------------
723 .\" Start an unordered list.
730 . if (\\n[www-level] == 1) \
731 . nr www-depth \\n[.i]
732 . nr www-depth +\w'\\*[www-level\\n[www-level]]'u
735 .\" --------------------------------------------------------------------
738 .\" End an unordered list.
744 . nr www-depth -\w'\\*[www-level\\n[www-level]]'u
749 .\" --------------------------------------------------------------------
752 .\" Insert a list item.
759 . ti -\w'\\*[www-level\\n[www-level]]'u
760 . nop \\*[www-level\\n[www-level]]\c
763 .\" --------------------------------------------------------------------
764 .\" DC l text [color]
766 .\" L is the letter to be dropped and enlarged.
768 .\" TEXT is the following text whose height the first letter should not
771 .\" COLOR is the optional color of the dropped letter (default black).
774 . ds www-dropcolor black
776 . ds www-dropcolor \\$3
777 . ie '\*(.T'html' \{\
778 . www-make-unique-name
779 . MPIMG -L \\*[www-unique-name].png "(\\n[.v] * 2u)"
783 . www-make-unique-name
784 . \" To avoid interferences with another DC macro call which is located
785 . \" very near to the current one, we draw the glyph on a separate page.
786 . \" Otherwise it could theoretically happen that the dropped capital
791 . nop \O[5i\\*[www-unique-name].png]\O[1]
792 . nop \m[\\*[www-dropcolor]]\s[40]\O[3]\\$1\O[4]
803 . nr dcht ((\\n[.v] + \\n[rst]) * \\n[.ps] / \\n[rst])
804 . char \[dcap] \m[\\*[www-dropcolor]]\s'\\n[dcht]u'\\$1
805 . nop \v'\\n[.v]u'\\[dcap]\v'-\\n[.v]u'\c
812 .\" --------------------------------------------------------------------
813 .\" Setup around HTML-IMAGE and friends
815 .\" now set up TS, TE, EQ, EN default macros
817 .do if !d TS .do ds TS HTML-IMAGE
818 .do if !d TE .do ds TE HTML-IMAGE-END
819 .do if !d EQ .do ds EQ HTML-IMAGE
820 .do if !d EN .do ds EN HTML-IMAGE-END
822 .\" supplementary macros used by other macro sets
824 .\" here are some tags specially for -Tps or -Thtml when invoked by
825 .\" pre-html to generate png images from postscript.
827 .\" --------------------------------------------------------------------
828 .\" HTML-DO-IMAGE - tells troff to issue an image marker which can be
829 .\" read back by pre-html
833 . nop \O[5\\$2\\$1.png]\O[1]\O[3]
835 . nop \O[5\\$2\\$1.png]\O[0]\O[3]
837 .\" --------------------------------------------------------------------
838 .\" HTML-IMAGE-END - terminates an image for html
842 . nop \O[4]\O[2]\O[0]
844 . nop \O[4]\O[2]\O[1]
849 .\" --------------------------------------------------------------------
850 .\" www-make-unique-name - generates another unique name in string
851 .\" `www-unique-name'
853 .de www-make-unique-name
855 . ds www-unique-name \\*[www-image-template]\\n[www-png-no]
857 .\" --------------------------------------------------------------------
858 .\" HTML-IMAGE and friends tell grohtml that this region of text needs
859 .\" to be rendered as an image.
862 . \" generates a centered image
863 . www-make-unique-name
864 . HTML-DO-IMAGE \\*[www-unique-name] c
868 . www-make-unique-name
869 . HTML-DO-IMAGE \\*[www-unique-name] r
873 . www-make-unique-name
874 . HTML-DO-IMAGE \\*[www-unique-name] l
877 .de HTML-IMAGE-INLINE
878 . www-make-unique-name
879 . HTML-DO-IMAGE \\*[www-unique-name] i
882 .\" --------------------------------------------------------------------
885 .\" Generate multiple output files containing the html.
886 .\" A file is split whenever a .SH or .NH 1 is encountered.
887 .\" The argument to JOBNAME is the file stem for future output files.
890 . HTML-TAG .job-name \\$1
892 .\" --------------------------------------------------------------------
894 .\" --------------------------------------------------------------------
902 .\" start of some code
918 .if r ps4html .nop \O[0]
923 .\" --------------------------------------------------------------------
925 .\" --------------------------------------------------------------------