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