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 .\" --------------------------------------------------------------------
45 .do if d www:lenstr .nx
54 .if '\*[.T]'html' .nr www-html 1
56 .\" set up www-image-template
58 .if !d www-image-template \
59 . ds www-image-template
62 . \" remove the title command when we are generating images for html
63 . \" (stops a title accidentally appearing inside an image)
73 .\" --------------------------------------------------------------------
74 .\" Test for `.substring'; result in register `www.substring_ok'.
75 .\" The automated break points in .URL addresses are only added if
76 .\" this register is non-zero.
78 .nr www:substring_ok 0
79 .de www:@test_substring
83 . substring \\$0:s 1 1
84 . if !'\\*[\\$0:s]'b' \{\
89 . substring \\$0:s 0 0
90 . if !'\\*[\\$0:s]'a' \{\
95 . substring \\$0:s 1 -1
96 . if !'\\*[\\$0:s]'bcdefg' \{\
100 . nr www:substring_ok 1
104 .rm www:@test_substring
107 .\" --------------------------------------------------------------------
109 .\" --------------------------------------------------------------------
111 .\" --------------------------------------------------------------------
114 .\" Space before paragraph. Use \n[PD] if it exists.
118 . ie r PD .sp \\n[PD]u
119 . el .sp \\n[www:pd]u
123 .\" --------------------------------------------------------------------
124 .\" www:error (<test>...)
126 .\" Print error message
129 . tm \\n[.F]:\\n[.c]: macro error: \\$*
131 .als www:error www-error
133 .\" --------------------------------------------------------------------
134 .\" www:lenstr (<register_name> <string_name>)
136 .\" Store length of string named <string_name> into register named
140 . if !(\\n[.$] == 2) \{\
141 . tm .\\$0 expects 2 arguments.
144 . length \\$0:n x\\*[\\$2]
145 . nr \\$1 (\\n[\\$0:n]-1)
148 .\" --------------------------------------------------------------------
149 .\" www:splitstr (<name>)
151 .\" Add a space character between any two adjacent characters in string
152 .\" <name> and restore result into the string variable <name>; space
153 .\" characters are first replaced by the word `space'.
156 . if !(\\n[.$] == 1) \
157 . www:error .\\$0 expects 1 argument.
160 . ds \\$0:r "\\*[\\$1]\""
163 . ds \\$0:c "\\*[\\$0:r]\""
164 . substring \\$0:c 0 0\"
165 . ie '\\*[\\$0:c]' ' \
166 . as \\$0:s " space\""
168 . as \\$0:s " \\*[\\$0:c]\""
169 . www:lenstr \\$0:n \\$0:r
170 . if (\\n[\\$0:n] <= 1) \{\
173 . substring \\$0:r 1 -1\"
175 . if !'\\*[\\$0:s]'' \
176 . substring \\$0:s 1 -1
177 . ds \\$1 \\*[\\$0:s]
183 .\" --------------------------------------------------------------------
184 .\" www:url_breaks (<string_name>)
186 .\" Add `\:' (possible break point) within URL strings after `/'.
188 .\" Smart about multiple `/', existing `\:', and space characters;
189 .\" does not set a break point if less than 5 characters would go to
193 . if !(\\n[.$] == 1) \
194 . www:error .\\$0 expects 1 argument.
195 . if !\n[www:substring_ok] \
197 . ds \\$0:s "\\*[\\$1]\""
198 . www:splitstr \\$0:s
199 . www:url_breaks_splitted \\$0:s \\*[\\$0:s]
200 . ds \\$1 "\\*[\\$0:s]\""
203 .\" --------------------------------------------------------------------
204 .\" www:url_breaks_splitted (<result> <char> [<char>...])
206 .\" Add `\:' within URL strings, but arguments are a splitted string.
208 .\" Arguments: >=2: <result> <char> [<char>...]
210 .de www:url_breaks_splitted
211 . nr \\$0:min 5 \" minimal number of characters for next line
213 . www:error .\\$0 expects at least 2 arguments.
218 . while !\\n[\\$0:done] \{\
219 . if (\\n[.$] <= 0) \{\
223 . if '\\$1'space' \{\
228 . if (\\n[.$] < \\n[\\$0:min]) \{\
238 . \" we are at a `/' character
241 . if (\\n[.$] == 0) \{\
247 . if \\n[\\$0:done] \
249 . if (\\n[.$] < \\n[\\$0:min]) \
255 . ds \\*[\\$0:res] \\*[\\$0:s]\"
259 .\" --------------------------------------------------------------------
261 .\" --------------------------------------------------------------------
263 .\" --------------------------------------------------------------------
266 .\" the main auxiliary macro for the HTML interface
269 . if \\n[www-html] \{\
270 . \" was implemented via .nop \&\X^html:\\$*^ but
271 . \" is now implemented using HTML-NS to utilize code factoring.
273 . \" the `\&' makes the vertical mode leave, so to say
281 .\" an auxiliary macro for HTML (without following space)
284 . nop \X^html:\\$*^\c
287 .\" emit a HTML tag after shutting down a (possibly open) paragraph
290 . if \\n[www-html] \{\
291 . \" the `\&' makes the vertical mode leave, so to say
292 . nop \&\X^html</p>:\\$*^
295 .\" --------------------------------------------------------------------
298 .\" Automatic heading level cut off.
300 .\" N is the depth limit of automatically linked headings. So a depth
301 .\" of 2 would cause grohtml to generate a list of links for `.NH 1'
302 .\" and `.NH 2' but not for `.NH 3'.
308 .\" --------------------------------------------------------------------
309 .\" BCL foreground background active not-visited visited
312 . HTML <body text=\\$1 bgcolor=\\$2 link=\\$3 alink=\\$4 vlink=\\$5>
314 .\" --------------------------------------------------------------------
318 . HTML <body background=\\$1>
320 .\" --------------------------------------------------------------------
321 .\" URL url [description] [after]
322 .\" if description is absent then the url becomes the anchor text
326 . www:url_breaks \\$0:adr
327 . ie \\n[www-html] \{\
331 . ds \\$0:after \&\\$3
333 . HTML-NS <a href="\\$1">\\$1</a>
335 . HTML-NS <a href="\\$1">\\$2</a>
336 . nop \\*[\\$0:after]
340 . if !r ps4html .ad l
342 . nop \%\[la]\m[blue]\f[C]\\*[\\$0:adr]\f[]\m[]\[ra]\\$3
344 . nop \m[blue]\\$2\m[] \%\[la]\f[C]\\*[\\$0:adr]\f[]\[ra]\\$3
349 .\" --------------------------------------------------------------------
350 .\" FTP url description [after]
355 .\" --------------------------------------------------------------------
356 .\" MTO address description [after]
358 .\" ADDRESS is the email address (without the `mailto:' prefix).
360 .\" DESCRIPTION is the optional name. If an empty argument is given,
361 .\" ADDRESS is used instead.
363 .\" AFTER is optional stuff printed immediately after ADDRESS
364 .\" (resp. DESCRIPTION).
368 .\" Foobar has been written by
369 .\" .MTO fred@foo.bar "Fredrick Bloggs" .
372 . ie \\n[www-html] \{\
374 . URL mailto:\\$1 \\$1 "\\$3"
376 . URL mailto:\\$1 "\\$2" "\\$3"
380 . nop \%\m[blue]\f[C]\\$1\f[]\m[]\\$3
382 . nop \m[blue]\\$2\m[] \%\[la]\f[C]\\$1\f[]\[ra]\\$3
385 .\" --------------------------------------------------------------------
388 .\" Generate an html name NAME.
391 . HTML <a name="\\$1"></a>
393 .\" --------------------------------------------------------------------
394 .\" IMG [-R|-L|-C] filename [width] [height]
396 .\" Include an image of any type (will only work for -Thtml).
398 .\" Alignment is centered by default (-C).
399 .\" Default value for WIDTH is 1i.
400 .\" If HEIGHT is not given, WIDTH is used as the height.
403 . ie \\n[www-html] \{\
405 . DEVTAG ".right-image"
408 . DEVTAG ".left-image"
410 . DEVTAG ".centered-image"
415 . nr www-height \\n[www-width]
418 . HTML <img src="\\$1" alt="Image \\$1" \
419 width=\\n[www-width] height=\\n[www-height]>
422 . nop \[la]\f[C]\\$1\f[]\[ra]
424 .\" --------------------------------------------------------------------
425 .\" PIMG [-R|-L|-C] filename [width] [height]
427 .\" Include a png image. It will work for -Tps and -Thtml.
428 .\" The default value for WIDTH and HEIGHT is zero; the default
429 .\" alignment is centering (-C).
431 .\" Note: This macro can only be used with the `-U' option of groff,
432 .\" activating unsafe mode, if not used with -Thtml; the PNG image
433 .\" is then converted to the EPS format using netpbm utilities.
436 . ie \\n[www-html] \{\
438 . DEVTAG ".right-image"
441 . DEVTAG ".left-image"
443 . DEVTAG ".centered-image"
448 . nr www-width (\\$3 * 100 / 240)
450 . nr www-height (\\$4 * 100 / 240)
451 . ie (\\n[www-width] == 0) \{\
452 . ie (\\n[www-height] == 0) \
453 . HTML <img src="\\$2" alt="Image \\$2">
455 . HTML <img src="\\$1" alt="Image \\$2" height=\\n[www-height]>
458 . ie (\\n[www-height] == 0) \
459 . HTML <img src="\\$2" alt="Image \\$2" width=\\n[www-width]>
461 . HTML <img src="\\$2" alt="Image \\$2" width=\\n[www-width] \
462 height=\\n[www-height]>
467 . www-make-unique-name
468 . sy pngtopnm \\$2 | pnmcrop -white | @PNMTOPS_NOSETPAGE@ -noturn > \\*[www-unique-name].eps
470 . PSPIC \\*[www-unique-name].eps \\$3 \\$4
472 . PSPIC \\$1 \\*[www-unique-name].eps \\$3 \\$4
477 .\" --------------------------------------------------------------------
478 .\" auxiliary definitions for MPIMG
480 .nr www-left-ll-trap 0
481 .nr www-left-po-trap 0
482 .nr www-right-ll-trap 0
484 .de www-finish-left-po
485 . po -(\\n[www-left-indent]u + \\n[www-image-gap]u)
486 . wh \\n[www-left-po-trap]u
487 . nr www-left-indent 0
490 .\" called when the -R picture is finished
491 .de www-finish-right-ll
492 . ll +(\\n[www-right-indent]u + \\n[www-image-gap]u)
493 . \" now see whether we need to inline www-finish-left-ll
494 . if (\\n[www-left-ll-trap]u > 0) \
495 . if ((\\n[www-right-ll-trap]u + 1v) >= \\n[www-left-ll-trap]u) \{\
496 . mk www-left-po-trap
497 . nr www-left-po-trap +1v
498 . wh \\n[www-left-po-trap]u www-finish-left-po
499 . ll +\\n[www-left-indent]u
500 . wh \\n[www-left-ll-trap]u
501 . nr www-left-ll-trap 0
503 . \" and see whether we need to inline www-finish-left-po
504 . if (\\n[www-left-po-trap]u > 0) \
505 . if ((\\n[www-right-ll-trap]u + 1v) >= \\n[www-left-po-trap]u) \{\
506 . po -\\n[www-left-indent]u
507 . wh \\n[www-left-po-trap]u
508 . nr www-left-indent 0
510 . wh \\n[www-right-ll-trap]u
511 . nr www-right-ll-trap 0
514 .de www-finish-left-ll
515 . if (\\n[www-right-ll-trap] > 0) \
516 . if ((\\n[www-left-ll-trap] + 1v) >= \\n[www-right-ll-trap]) \{\
517 . ll +\\n[www-right-indent]u
518 . nr www-right-ll-trap 0
520 . mk www-left-po-trap
521 . nr www-left-po-trap +1v
522 . wh \\n[www-left-po-trap]u www-finish-left-po
523 . ll +(\\n[www-left-indent]u + \\n[www-image-gap]u)
524 . wh \\n[www-left-ll-trap]u
525 . nr www-left-ll-trap 0
527 .\" --------------------------------------------------------------------
528 .\" MPIMG [-R|-L] [-G gap] filename [width [height]]
530 .\" Include a png image and wrap text around it. It will work for
531 .\" -Tps and -Thtml. The default value for WIDTH is 1i; default value
532 .\" for HEIGHT is WIDTH; the default alignment is left (-L).
533 .\" -G is used to insert a gap between the text and the image.
535 .\" Note: This macro can only be used with the `-U' option of groff,
536 .\" activating unsafe mode, if not used with -Thtml; the PNG image
537 .\" is then converted to the EPS format using netpbm utilities.
540 .nr www-htmlimage-gap 0
543 . nr www-image-just 1
545 . while (\\n[.$] > 0) \{\
547 . nr www-image-just 1
552 . nr www-image-just 0
557 . nr www-image-gap \\$2
558 . nr www-htmlimage-gap (\\$2 * 100 / 240)
567 . nr www-height \\n[www-width]
570 . nr www-width (\\n[www-width] * 100 / 240)
571 . nr www-height (\\n[www-height] * 100 / 240)
573 . ie \\n[www-html] \{\
574 . ie !\\n[www-image-just] \
575 . HTML <img src="\\$1" alt="Image \\$1" hspace=\\n[www-htmlimage-gap] \
576 align=right width=\\n[www-width] height=\\n[www-height]>
578 . HTML <img src="\\$1" alt="Image \\$1" hspace=\\n[www-htmlimage-gap] \
579 align=left width=\\n[www-width] height=\\n[www-height]>
583 . www-make-unique-name
584 . sy pngtopnm \\$1 | pnmcrop -white | @PNMTOPS_NOSETPAGE@ -noturn > \\*[www-unique-name].eps
585 . ie !\\n[www-image-just] \{\
586 . \" we must now disable a possible left image trap
588 . if (\\n[www-left-ll-trap] > 0) \
589 . wh \\n[www-left-ll-trap]u
590 . if (\\n[www-left-po-trap] > 0) \
591 . wh \\n[www-left-po-trap]u
592 . PSPIC -R \\*[www-unique-name].eps \\$2 \\$3
594 . nr www-right-indent \\n[ps-deswid]u
595 . \" we want to have some space between text and image,
596 . \" so the line length must be shorter
597 . ll -(\\n[www-right-indent]u + \\n[www-image-gap]u)
598 . mk www-right-ll-trap
599 . nr www-right-ll-trap +(\\n[ps-desht]u - 1v)
600 . wh \\n[www-right-ll-trap]u www-finish-right-ll
601 . \" now restore possible left trap
602 . if (\\n[www-left-ll-trap] > 0) \
603 . wh \\n[www-left-ll-trap]u www-finish-left-ll
604 . if (\\n[www-left-po-trap] > 0) \
605 . wh \\n[www-left-po-trap]u
608 . \" we must now disable a possible right image trap
609 . if (\\n[www-right-ll-trap] > 0) \
610 . wh \\n[www-right-ll-trap]u
611 . PSPIC -L \\*[www-unique-name].eps \\$2 \\$3
613 . nr www-left-indent \\n[ps-deswid]u
614 . \" increase offset by gap
615 . po +(\\n[www-left-indent]u + \\n[www-image-gap]u)
616 . \" decrease line length by gap
617 . ll -(\\n[www-left-indent]u + \\n[www-image-gap]u)
618 . mk www-left-ll-trap
619 . nr www-left-ll-trap +(\\n[ps-desht]u - 1v)
620 . wh \\n[www-left-ll-trap]u www-finish-left-ll
621 . \" now restore possible right trap
622 . if (\\n[www-right-ll-trap] > 0) \
623 . wh \\n[www-right-ll-trap]u www-finish-right-ll
628 .\" --------------------------------------------------------------------
631 .\" Begin heading. Heading level is N.
637 .\" If your heading contains URL, FTP, MTO macros you might wish to
638 .\" disable automatic links to headings. This can be done via `-P-l'
639 .\" from the command line or by using a cakk to `.HX 0'.
641 .nr www-heading-no -1
645 . nr www-heading-no 1
647 . nr www-heading-no \\$1
648 . DEVTAG-NH \\n[www-heading-no]
652 . if (\\n[www-heading-no] == -1) \
653 . www-error "HnE found without a corresponding HnS"
656 .\" --------------------------------------------------------------------
659 .\" Emit the automatically collected links derived from
660 .\" section/numbered headings at this position.
665 .\" --------------------------------------------------------------------
668 .\" Produce a horizontal line.
673 .\" --------------------------------------------------------------------
676 .\" Suppresses the generation of the top and bottom rules which grohtml
677 .\" emits by default.
680 . DEVTAG ".no-auto-rule"
683 .\" www-end-nowhere - end of input trap called to finish diversion.
686 . if !\\n[www-html] \
690 .\" --------------------------------------------------------------------
693 .\" Generate an HTML title only. This differs from the -ms .TL macro
694 .\" which generates both an HTML title and an H1 heading.
696 .\" This is useful when an author wishes to use a HTML title as search
697 .\" engine fodder but a graphic title in the document.
699 .\" The macro terminates when a space or break is seen (.sp, .br).
703 . if !\\n[www-html] \
705 . it 2 www-end-nowhere
708 .\" --------------------------------------------------------------------
709 .\" auxiliary definitions for ULS / ULE
711 .ds www-level1 \[bu]\ \ \"
712 .ds www-level2 \[sq]\ \ \"
713 .ds www-level3 \[ci]\ \ \"
718 .\" Auxiliary macro for ULS.
722 . if (\\n[www-level] > 3) \
723 . www-error "too many levels of indentation (\\n[www-level])"
726 .\" Auxiliary macro for ULE.
729 . if !\\n[www-level] \
730 . www-error "trying to terminate a list which does not exist"
733 .\" --------------------------------------------------------------------
736 .\" Start an unordered list.
743 . if (\\n[www-level] == 1) \
744 . nr www-depth \\n[.i]
745 . nr www-depth +\w'\\*[www-level\\n[www-level]]'u
748 .\" --------------------------------------------------------------------
751 .\" End an unordered list.
757 . nr www-depth -\w'\\*[www-level\\n[www-level]]'u
762 .\" --------------------------------------------------------------------
765 .\" Insert a list item.
773 . ti -\w'\\*[www-level\\n[www-level]]'u
774 . nop \\*[www-level\\n[www-level]]\c
777 .\" --------------------------------------------------------------------
778 .\" DC l text [color]
780 .\" L is the letter to be dropped and enlarged.
782 .\" TEXT is the following text whose height the first letter should not
785 .\" COLOR is the optional color of the dropped letter (default black).
788 . ds www-dropcolor black
790 . ds www-dropcolor \\$3
791 . ie '\*(.T'html' \{\
792 . www-make-unique-name
793 . MPIMG -L \\*[www-unique-name].png "(\\n[.v] * 2u)"
797 . www-make-unique-name
798 . \" To avoid interferences with another DC macro call which is located
799 . \" very near to the current one, we draw the glyph on a separate page.
800 . \" Otherwise it could theoretically happen that the dropped capital
805 . nop \O[5i\\*[www-unique-name].png]\O[1]
806 . nop \m[\\*[www-dropcolor]]\s[40]\O[3]\\$1\O[4]
817 . nr dcht ((\\n[.v] + \\n[rst]) * \\n[.ps] / \\n[rst])
818 . char \[dcap] \m[\\*[www-dropcolor]]\s'\\n[dcht]u'\\$1
819 . nop \v'\\n[.v]u'\\[dcap]\v'-\\n[.v]u'\c
826 .\" --------------------------------------------------------------------
827 .\" Setup around HTML-IMAGE and friends
829 .\" now set up TS, TE, EQ, EN default macros
831 .do if !d TS .do ds TS HTML-IMAGE
832 .do if !d TE .do ds TE HTML-IMAGE-END
833 .do if !d EQ .do ds EQ HTML-IMAGE
834 .do if !d EN .do ds EN HTML-IMAGE-END
836 .\" supplementary macros used by other macro sets
838 .\" here are some tags specially for -Tps or -Thtml when invoked by
839 .\" pre-html to generate png images from postscript.
841 .\" --------------------------------------------------------------------
842 .\" HTML-DO-IMAGE - tells troff to issue an image marker which can be
843 .\" read back by pre-html
847 . nop \O[5\\$2\\$1.png]\O[1]\O[3]
849 . nop \O[5\\$2\\$1.png]\O[0]\O[3]
851 .\" --------------------------------------------------------------------
852 .\" HTML-IMAGE-END - terminates an image for html
856 . nop \O[4]\O[2]\O[0]
858 . nop \O[4]\O[2]\O[1]
863 .\" --------------------------------------------------------------------
864 .\" www-make-unique-name - generates another unique name in string
865 .\" `www-unique-name'
867 .de www-make-unique-name
869 . ds www-unique-name \\*[www-image-template]\\n[www-png-no]
871 .\" --------------------------------------------------------------------
872 .\" HTML-IMAGE and friends tell grohtml that this region of text needs
873 .\" to be rendered as an image.
876 . \" generates a centered image
877 . www-make-unique-name
878 . HTML-DO-IMAGE \\*[www-unique-name] c
882 . www-make-unique-name
883 . HTML-DO-IMAGE \\*[www-unique-name] r
887 . www-make-unique-name
888 . HTML-DO-IMAGE \\*[www-unique-name] l
891 .de HTML-IMAGE-INLINE
892 . www-make-unique-name
893 . HTML-DO-IMAGE \\*[www-unique-name] i
896 .\" --------------------------------------------------------------------
899 .\" Generate multiple output files containing the html.
900 .\" A file is split whenever a .SH or .NH 1 is encountered.
901 .\" The argument to JOBNAME is the file stem for future output files.
904 . DEVTAG .job-name \\$1
906 .\" --------------------------------------------------------------------
909 .\" Adds information to the <head> </head> section of the html
911 .\" --------------------------------------------------------------------
913 . DEVTAG .head "\\$*"
915 .\" --------------------------------------------------------------------
917 .\" --------------------------------------------------------------------
925 .\" start of some code
941 .if r ps4html .nop \O[0]
946 .\" --------------------------------------------------------------------
948 .\" --------------------------------------------------------------------