Don't produce HTML files if utility programs are missing.
[s-roff.git] / tmac / www.tmac
blob22f829e1da77f6ad68ffdb20e774152c2a91a180
1 .\" www.tmac
2 .\"
3 .\" A simple set of macros to provide HTML documents with basic
4 .\" www functionality.  It should work with any macro set.
5 .\"
6 .nr _C \n(.C
7 .cp 0
9 .nr www-html 0
10 .if '\*[.T]'html' .nr www-html 1
12 .\" set up www-image-template
13 .\" (cannot do this in html.tmac as the image device must
14 .\"  also know about this string)
16 .if !d www-image-template \
17 .  ds www-image-template
19 .if r ps4html \{\
20 .  \" remove the title command when we are generating images for html
21 .  \" (stops a title accidentally appearing inside an image)
22 .  di www-notitle
23 .  tl ''''
24 .  di
25 .  rm tl
26 .  de tl
27 .  .
28 .\}
30 .de www-error
31 .  tm \\n[.F]:\\n[.c]: macro error: \\$*
33 .\"
34 .\" the main auxiliary macro for the HTML interface
35 .\"
36 .de HTML
37 .  if \\n[www-html] \{\
38 .    \" the following line makes the vertical mode leave, so to say
39 .    nop \&
40 .    nop \X^html:\\$*^
41 .  \}
43 .\"
44 .\" HX n
45 .\"
46 .\"   Automatic heading level cut off.
47 .\"
48 .\"   N is the depth limit of automatically linked headings.  So a depth
49 .\"   of 2 would cause grohtml to generate a list of links for `.NH 1' and
50 .\"   `.NH 2' but not for `.NH 3'.
51 .\"
52 .de HX
53 .  if \\n[www-html] \
54 .    nop \X^index:\\$*^
56 .\"
57 .\" BCL foreground background active not-visited visited
58 .\"
59 .de BCL
60 .  HTML <body text=\\$1 bgcolor=\\$2 link=\\$3 alink=\\$4 vlink=\\$5>
62 .\"
63 .\" BGIMG imagefile
64 .\"
65 .de BGIMG
66 .  HTML <body background=\\$1>
68 .\"
69 .\" URL url description [after]
70 .\"
71 .de URL
72 .  ie \\n[www-html] \
73 .    HTML <a href="\\$1">\\$2</a>\\$3
74 .  el \
75 .    nop \m[blue]\\$2\m[] \%\[la]\f[C]\\$1\f[]\[ra]\\$3
77 .\"
78 .\" FTP url description [after]
79 .\"
80 .\"   Same as UTL.
81 .\"
82 .als FTP URL
83 .\"
84 .\" MTO address description [after]
85 .\"
86 .\"   ADDRESS is the email address (without the `mailto:' prefix).
87 .\"
88 .\"   DESCRIPTION is the optional name.  If an empty argument is given,
89 .\"   ADDRESS is used instead.
90 .\"
91 .\"   AFTER is optional stuff printed immediately after ADDRESS
92 .\"   (resp. DESCRIPTION).
93 .\"
94 .\"     Example:
95 .\"
96 .\"       Foobar has been written by
97 .\"       .MTO fred@foo.bar "Fredrick Bloggs" .
98 .\"
99 .de MTO
100 .  ie \\n[www-html] \{\
101 .    ie '\\$2'' \
102 .      URL mailto:\\$1 \\$1 "\\$3"
103 .    el \
104 .      URL mailto:\\$1 "\\$2" "\\$3"
105 .  \}
106 .  el \{\
107 .    ie '\\$2'' \
108 .      nop \%\m[blue]\f[C]\\$1\f[]\m[]\\$3
109 .    el \
110 .      nop \m[blue]\\$2\m[] \%\[la]\f[C]\\$1\f[]\[ra]\\$3
111 .  \}
114 .\" TAG name
116 .\"   Generate an html name NAME.
118 .de TAG
119 .  HTML <a name="\\$1"></a>
122 .\" IMG [-R|-L|-C] filename [width] [height]
124 .\"   Include an image of any type (will only work for -Thtml).
126 .\"   Alignment is centered by default (-C).
127 .\"   Default value for WIDTH is 1i.
128 .\"   If HEIGHT is not given, WIDTH is used as the height.
130 .de IMG
131 .  ie \\n[www-html] \{\
132 .    ie '\\$2'-R' \
133 .      HTML-TAG ".right-image"
134 .    el \{\
135 .      ie '\\$2'-L' \
136 .        HTML-TAG ".left-image"
137 .      el \
138 .        HTML-TAG ".centered-image"
139 .    \}
140 .    nr www-width 100
141 .    if !'\\$3'' \
142 .      nr www-width \\$3
143 .    nr www-height \\n[www-width]
144 .    if !'\\$4'' \
145 .      nr www-height \\$4
146 .    HTML <img src="\\$1" width=\\n[www-width] height=\\n[www-height]>
147 .  \}
148 .  el \
149 .    nop \[la]\f[C]\\$1\f[]\[ra]
152 .\" HTML-TAG
154 .\"   Emit a tag for grohtml.  This is an internal macro.
156 .de HTML-TAG
157 .  if \\n[www-html] \{\
158 .    \" the following line makes the vertical mode leave, so to say
159 .    nop \&
160 .    nop \X^html-tag:\\$*^
161 .  \}
164 .\" PIMG  [-R|-L|-C] filename [width] [height]
166 .\"   Include a png image.  It will work for -Tps and -Thtml.
167 .\"   The default value for WIDTH and HEIGHT is zero; the default
168 .\"   alignment is centering (-C).
170 .\" Note: This macro can only be used with the `-U' option of groff,
171 .\"       activating unsafe mode, if not used with -Thtml; the PNG image
172 .\"       is then converted to the EPS format using netpbm utilities.
174 .de PIMG
175 .  ie \\n[www-html] \{\
176 .    ie '\\$1'-R' \
177 .      HTML-TAG ".right-image"
178 .    el \{\
179 .      ie '\\$1'-L' \
180 .        HTML-TAG ".left-image"
181 .      el \
182 .        HTML-TAG ".centered-image"
183 .    \}
184 .    nr www-width 0
185 .    nr www-height 0
186 .    if !'\\$3'' \
187 .      nr www-width (\\$3 * 100 / 240)
188 .    if !'\\$4'' \
189 .      nr www-height (\\$4 * 100 / 240)
190 .    ie (\\n[www-width] == 0) \{\
191 .      ie (\\n[www-height] == 0) \
192 .        HTML <img src="\\$2">
193 .      el \
194 .        HTML <img src="\\$1" height=\\n[www-height]>
195 .    \}
196 .    el \{\
197 .      ie (\\n[www-height] == 0) \
198 .        HTML <img src="\\$2" width=\\n[www-width]>
199 .      el \
200 .        HTML <img src="\\$2" width=\\n[www-width] height=\\n[www-height]>
201 .    \}
202 .  \}
203 .  el \{\
204 .    if !r ps4html \{\
205 .      www-make-unique-name
206 .      sy pngtopnm \\$2 | pnmcrop -white | pnmtops -noturn > \\*[www-unique-name].eps
207 .      PSPIC \\$1 \\*[www-unique-name].eps \\$3 \\$4
208 .    \}
209 .  \}
212 .nr www-left-ll-trap 0
213 .nr www-left-po-trap 0
214 .nr www-right-ll-trap 0
216 .de www-finish-left-po
217 .  po -\\n[www-left-indent]u
218 .  wh \\n[www-left-po-trap]u
219 .  nr www-left-indent 0
222 .de www-finish-right-ll
223 .  ll +\\n[www-right-indent]u
224 .  \" now see whether we need to inline www-finish-left-ll
225 .  if (\\n[www-left-ll-trap]u > 0) \
226 .    if ((\\n[www-right-ll-trap]u + 1v) >= \\n[www-left-ll-trap]u) \{\
227 .      mk www-left-po-trap
228 .      nr www-left-po-trap +1v
229 .      wh \\n[www-left-po-trap]u www-finish-left-po
230 .      ll +\\n[www-left-indent]u
231 .      wh \\n[www-left-ll-trap]u
232 .      nr www-left-ll-trap 0
233 .    \}
234 .  \" and see whether we need to inline www-finish-left-po
235 .  if (\\n[www-left-po-trap]u > 0) \
236 .    if ((\\n[www-right-ll-trap]u + 1v) >= \\n[www-left-po-trap]u) \{\
237 .      po -\\n[www-left-indent]u
238 .      wh \\n[www-left-po-trap]u
239 .      nr www-left-indent 0
240 .    \}
241 .  wh \\n[www-right-ll-trap]u
242 .  nr www-right-ll-trap 0
245 .de www-finish-left-ll
246 .  if (\\n[www-right-ll-trap] > 0) \
247 .    if ((\\n[www-left-ll-trap] + 1v) >= \\n[www-right-ll-trap]) \{\
248 .      ll +\\n[www-right-indent]u
249 .      nr www-right-ll-trap 0
250 .    \}
251 .  mk www-left-po-trap
252 .  nr www-left-po-trap +1v
253 .  wh \\n[www-left-po-trap]u www-finish-left-po
254 .  ll +\\n[www-left-indent]u
255 .  wh \\n[www-left-ll-trap]u
256 .  nr www-left-ll-trap 0
259 .\" MPIMG [-R|-L] filename [width] [height]
261 .\"   Include a png image and wrap text around it.  It will work for
262 .\"   -Tps and -Thtml.  The default value for WIDTH is 1i; default value
263 .\"   for HEIGHT is WIDTH; the default alignment is left (-L).
265 .\" Note: This macro can only be used with the `-U' option of groff,
266 .\"       activating unsafe mode, if not used with -Thtml; the PNG image
267 .\"       is then converted to the EPS format using netpbm utilities.
269 .de MPIMG
270 .  nr www-width 1i
271 .  if !'\\$3'' \
272 .    nr www-width \\$3
273 .  nr www-height \\n[www-width]
274 .  if !'\\$4'' \
275 .    nr www-height \\$4
276 .  nr www-width (\\n[www-width] * 100 / 240)
277 .  nr www-height (\\n[www-height] * 100 / 240)
278 .  ie \\n[www-html] \{\
279 .    ie '\\$1'-R' \
280 .      HTML <img src="\\$2" align=right width=\\n[www-width] height=\\n[www-height]>
281 .    el \
282 .      HTML <img src="\\$2" align=left width=\\n[www-width] height=\\n[www-height]>
283 .  \}
284 .  el \{\
285 .    if !r ps4html \{\
286 .      www-make-unique-name
287 .      sy pngtopnm \\$2 | pnmcrop -white | pnmtops -noturn > \\*[www-unique-name].eps
288 .      ie '\\$1'-R' \{\
289 .        \" we must now disable a possible left image trap
290 .        sp -1
291 .        if (\\n[www-left-ll-trap] > 0) \
292 .          wh \\n[www-left-ll-trap]u
293 .        if (\\n[www-left-po-trap] > 0) \
294 .          wh \\n[www-left-po-trap]u
295 .        PSPIC -R \\*[www-unique-name].eps \\$3 \\$4
296 .        sp -\\n[ps-desht]u
297 .        nr www-right-indent \\n[ps-deswid]u
298 .        ll -\\n[www-right-indent]u
299 .        mk www-right-ll-trap
300 .        nr www-right-ll-trap +(\\n[ps-desht]u - 1v)
301 .        wh \\n[www-right-ll-trap]u www-finish-right-ll
302 .        \" now restore possible left trap
303 .        if (\\n[www-left-ll-trap] > 0) \
304 .          wh \\n[www-left-ll-trap]u www-finish-left-ll
305 .        if (\\n[www-left-po-trap] > 0) \
306 .          wh \\n[www-left-po-trap]u
307 .      \}
308 .      el \{\
309 .        \" we must now disable a possible right image trap
310 .        if (\\n[www-right-ll-trap] > 0) \
311 .          wh \\n[www-right-ll-trap]u
312 .        PSPIC -L \\*[www-unique-name].eps \\$3 \\$4
313 .        sp -\\n[ps-desht]u
314 .        nr www-left-indent \\n[ps-deswid]u
315 .        po +\\n[www-left-indent]u
316 .        ll -\\n[www-left-indent]u
317 .        mk www-left-ll-trap
318 .        nr www-left-ll-trap +(\\n[ps-desht]u - 1v)
319 .        wh \\n[www-left-ll-trap]u www-finish-left-ll
320 .        \" now restore possible right trap
321 .        if (\\n[www-right-ll-trap] > 0) \
322 .          wh \\n[www-right-ll-trap]u www-finish-right-ll
323 .      \}
324 .    \}
325 .  \}
328 .\" HnS n
330 .\"   Begin heading.  Heading level is N.
332 .\" HnE
334 .\"   End heading.
336 .\" If your heading contains URL, FTP, MTO macros you might wish to
337 .\" disable automatic links to headings.  This can be done via `-P-l'
338 .\" from the command line or by using a cakk to `.HX 0'.
340 .nr www-heading-no -1
342 .de HnS
343 .  ie '\\$1'' \
344 .    nr www-heading-no 1
345 .  el \
346 .    nr www-heading-no \\$1
347 .  HTML-TAG ".NH \\n[www-heading-no]"
350 .de HnE
351 .  if (\\n[www-heading-no] == -1) \
352 .    www-error "HnE found without a corresponding HnS"
353 .  br
356 .\" LK
358 .\"   Emit the automatically collected links derived from
359 .\"   section/numbered headings at this position.
361 .de LK
362 .  HTML-TAG ".links"
365 .\" HR
367 .\"   Produce a horizontal line
369 .de HR
370 .  ie \\n[www-html] \{\
371 .    ti 0
372 .    HTML <hr>
373 .  \}
374 .  el \
375 .    sp
378 .\" NHR
380 .\"  Suppresses the generation of the top and bottom rules which grohtml
381 .\"  emits by default.
383 .de NHR
384 .  HTML-TAG ".no-auto-rule"
387 .\" www-end-nowhere - end of input trap called to finish diversion.
389 .de www-end-nowhere
390 .  di
393 .\" HTL
395 .\"   Generate an HTML title only.  This differs from the -ms .TL macro
396 .\"   which generates both an HTML title and a H1 heading.
398 .\"   This is useful when an author wishes to use a HTML title as search
399 .\"   engine fodder but a graphic title in the document.
401 .\"   The macro terminates when a space or break is seen (.sp, .br).
403 .de HTL
404 .  HTML-TAG ".html-tl"
405 .  if !\\n[www-html] \{\
406 .    di www-nowhere
407 .    it 2 www-end-nowhere
408 .  \}
411 .ds www-level1 \[bu]\ \ \"
412 .ds www-level2 \[sq]\ \ \"
413 .ds www-level3 \[ci]\ \ \"
414 .nr www-level 0
415 .nr www-depth 0
418 .\" Auxiliary macro for ULS.
420 .de www-push-level
421 .  nr www-level +1
422 .  if (\\n[www-level] > 3) \
423 .    www-error "too many levels of indentation (\\n[www-level])"
426 .\" Auxiliary macro for ULE.
428 .de www-pop-level
429 .  if !\\n[www-level] \
430 .    www-error "trying to terminate a list which does not exist"
431 .  nr www-level -1
434 .\" ULS
436 .\"   Start an unordered list.
438 .de ULS
439 .  www-push-level
440 .  ie \\n[www-html] \
441 .    HTML "<ul>"
442 .  el \{\
443 .    if (\\n[www-level] == 1) \
444 .      nr www-depth \\n[.i]
445 .    nr www-depth +\w'\\*[www-level\\n[www-level]]'u
446 .  \}
449 .\" ULE
451 .\"   End an unordered list.
453 .de ULE
454 .  ie \\n[www-html] \
455 .    HTML "</ul>"
456 .  el \{\
457 .    nr www-depth -\w'\\*[www-level\\n[www-level]]'u
458 .    in \\n[www-depth]
459 .  \}
460 .  www-pop-level
463 .\" LI
465 .\"   Insert a list item.
467 .de LI
468 .  ie \\n[www-html] \
469 .    HTML "<li>"
470 .  el \{\
471 .    in \\n[www-depth]u
472 .    ti -\w'\\*[www-level\\n[www-level]]'u
473 .    nop \\*[www-level\\n[www-level]]\c
474 .  \}
477 .\" DC l text [color]
479 .\"   L is the letter to be dropped and enlarged.
481 .\"   TEXT is the following text whose height the first letter should not
482 .\"   exceed.
484 .\"   COLOR is the optional color of the dropped letter (default black).
486 .de DC
487 .  ds www-dropcolor black
488 .  if !'\\$3'' \
489 .    ds www-dropcolor \\$3
490 .  ie '\*(.T'html' \{\
491 .    www-make-unique-name
492 .    MPIMG -L \\*[www-unique-name].png "(\\n[.v] * 2u)"
493 .  \}
494 .  el \{\
495 .    ie r ps4html \{\
496 .      www-make-unique-name
497 .      nop \O[5i\\*[www-unique-name].png]\O[1]
498 .      nop \\m[\\*[www-dropcolor]]\\s[40]\O[3]\\$1\O[4]\\s0
499 .      nop \O[2]\O[1]
500 .    \}
501 .    el \{\
502 .      nr dummy \\w'\\$1'u
503 .      nr dcht ((\\n[.v] + \\n[rst]) * \\n[.ps] / \\n[rst])
504 .      char \[dcap] \\m[\\*[www-dropcolor]]\\s'\\n[dcht]u'\\$1\\s0
505 .      nop \\v'\\n[.v]u'\\[dcap]\\v'-\\n[.v]u'\c
506 '      ti \w'\\[dcap]'u
507 .    \}
508 .  \}
509 .  nop \\m[]\\$2
512 .\" now set up TS, TE, EQ, EN default macros
514 .do if !d TS .do ds TS HTML-IMAGE
515 .do if !d TE .do ds TE HTML-IMAGE-END
516 .do if !d EQ .do ds EQ HTML-IMAGE
517 .do if !d EN .do ds EN HTML-IMAGE-END
519 .\" supplementary macros used by other macro sets
521 .\" here are some tags specially for -Tps or -Thtml when invoked by pre-html
522 .\" to generate png images from postscript.
524 .\" HTML-DO-IMAGE - tells troff to issue an image marker which can be
525 .\"                 read back by pre-html
527 .de HTML-DO-IMAGE
528 .  if r ps4html \
529 .    nop \O[5\\$2\\$1.png]\O[1]\O[3]
530 .  if \\n[www-html] \
531 .    nop \O[5\\$2\\$1.png]\O[0]\O[3]
534 .\" HTML-IMAGE-END - terminates an image for html
536 .de HTML-IMAGE-END
537 .  if r ps4html \
538 .    nop \O[4]\O[2]\O[0]
539 .  if \\n[www-html] \
540 .    nop \O[4]\O[2]\O[1]
543 .nr www-png-no 0
546 .\" www-make-unique-name - generates another unique name in string
547 .\"                        `www-unique-name'
549 .de www-make-unique-name
550 .  nr www-png-no +1
551 .  ds www-unique-name \\*[www-image-template]\\n[www-png-no]
554 .\" HTML-IMAGE and friends tell grohtml that this region of text needs
555 .\"            to be rendered as an image.
557 .de HTML-IMAGE
558 .  \" generates a centered image
559 .  www-make-unique-name
560 .  HTML-DO-IMAGE \\*[www-unique-name] c
563 .de HTML-IMAGE-RIGHT
564 .  www-make-unique-name
565 .  HTML-DO-IMAGE \\*[www-unique-name] r
568 .de HTML-IMAGE-LEFT
569 .  www-make-unique-name
570 .  HTML-DO-IMAGE \\*[www-unique-name] l
573 .de HTML-IMAGE-INLINE
574 .  www-make-unique-name
575 .  HTML-DO-IMAGE \\*[www-unique-name] i
578 .if \n[www-html] \{\
579 .   nh
580 .   nr HY 0
582 .if r ps4html .nop \O[0]
583 .cp \n(_C
585 .\" now set
586 .\" EOF