groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Groff] more html macros needed


From: Gaius Mulley
Subject: Re: [Groff] more html macros needed
Date: Thu, 03 Jan 2002 14:36:36 +0000

Werner writes:

> Gaius, can you provide something?

here is an attempt, I'm sure it can be improved upon though.
I've included a couple of other goodies which might be interesting?

PNG-IMAGE - include a png image (should work for postscript too). User
            must specify -U though.
MARGIN-PNG-IMAGE place an image at the left or right hand side of the
                 page and wrap text around it. Again postscript users
                 must specify -U.
DROPCAP   - an html & ps version of Ted's dropcap macro, thanks Ted!

<HTML-H   - start heading
HTML-H>   - end heading
(also renamed UL macros to <UL and UL>)
here is the complete www.tmac for people to test/improve/modify.

enjoy
Gaius

ps. documentation to follow


---------------------------------------------------
trivial example for DROPCAP
---------------------------------------------------
.LP
.defcolor darkred rgb 0.65f 0.1f 0.2f
.LP
.<UL
.LI
item 1
.LI
item 2
.UL>
.DROPCAP T "his is the GNU groff" darkred
document formatting system.  The version number
is given in the file VERSION.
Included in this release
are implementations of troff, pic, eqn, tbl,
grn, refer, -man, -mdoc, and -ms macros, and drivers for PostScript, TeX
dvi format, HP LaserJet 4 printers, Canon CAPSL printers, HTML format
(still alpha), and typewriter-like devices.  Also included is a modified
version of the Berkeley -me macros, an enhanced version of the X11
xditview previewer, and an implementation of the -mm macros contributed
by Joergen Haegg (address@hidden).
---------------------------------------------------
example of an extended heading
---------------------------------------------------
.LP
.HTMLINDEX 0 
.<HTML-H 2
Here is an extended heading
.MAILTO address@hidden "Fredrick Bloggs" .
The
.FTP "groff" ftp://ftp.ffii.org/pub/groff/devel/groff-current.tar.gz
archive.
.HTML-H>
.LP
And back to normality again

---------------------------------------------------
.\" www.tmac
.\"
.\" A simple set of macros to provide HTML documents with basic
.\" www functionality.  It should work with any macro set.
.\"
.nr _C \n(.C
.cp 0
.
.nr www-html 0
.if '\*[.T]'html' .nr www-html 1
.
.if r ps4html \{\
.  \" remove the title command when we are generating images for html
.  \" (stops a title accidentally appearing inside an image)
.  tl ````
.  rm tl
.  de tl
.  .
.\}
.
.\" error macro taken from s.tmac
.de @error
.tm \\n(.F:\\n(.c: macro error: \\$*
..
.\"
.\" the main auxiliary macro for the HTML interface
.\"
.de HTML
.  if \\n[www-html] \{\
.    \" the following line makes the vertical mode leave, so to say
.    nop \&
.    nop \X^html:\\$*^
.  \}
..
.\"
.\"
.\"
.de HTMLINDEX
.  if \\n[www-html] \
.    nop \X^index:\\$*^
..
.\"
.\"  BODYCOLOR - $1 is foreground color
.\"              $2 is background color
.\"              $3 is the color of an active hypertext link
.\"              $4 is the color of a hypertext link not yet visited
.\"              $5 is the color of a visited hypertext link
.\"
.de BODYCOLOR
.  HTML <body text=\\$1 bgcolor=\\$2 link=\\$3 alink=\\$4 vlink=\\$5>
..
.\"
.\" BACKGROUND - $1 is the background image file
.\"
.de BACKGROUND
.  HTML <body background=\\$1>
..
.\"
.\"  URL - $1 is the classical underlined blue text
.\"        $2 is the url
.\"        $3 is optional stuff printed immediately after $3
.\"
.de URL
.  ie \\n[www-html] \
.    HTML <a href="\\$2">\\$1</a>\\$3
.  el \
.    nop \m[blue]\\$1\mP \%\[la]\fC\\$2\fP\[ra]\\$3
..
.\"
.\"  FTP - $1 is the classical underlined blue text
.\"        $2 is the ftp url
.\"        $3 is optional stuff printed immediately after $2
.\"
.de FTP
.  ie \\n[www-html] \
.    HTML <a href=\\$2>\\$1</a>\\$3
.  el \
.    nop \m[blue]\\$1\mP \%\[la]\fC\\$2\fP\[ra]\\$3
..
.\"
.\" MAILTO - generate html email reference
.\"          $1 is the email address (without the `mailto:' prefix)
.\"          $2 is the optional name
.\"          $3 is optional stuff printed immediately after $2 (resp. $1)
.\"
.\"          example:
.\"
.\"            Foobar has been written by
.\"            .MAILTO address@hidden "Fredrick Bloggs" .
.\"
.de MAILTO
.  ie \\n[www-html] \{\
.    ie '\\$2'' \
.      HTML "<a href=mailto:\\$1>\\$1</a>\\$3"
.    el \
.      HTML "<a href=mailto:\\$1>\\$2</a>\\$3"
.  \}
.  el \{\
.    ie '\\$2'' \
.      nop \m[blue]\fC\\$1\fP\mP\\$3
.    el \
.      nop \m[blue]\\$2\mP \%\[la]\fC\\$1\fP\[ra]\\$3
.  \}
..
.\"
.\" TAG - generate an html name $1
.\"
.de TAG
.  HTML <a name="\\$1"></a>
..
.\"
.\" IMAGE - reference an image
.\"         $1 is the image file
.\"         $2 is the alignment -R, -L or -C (centered by default)
.\"         $3 is the width (default if absent is 400 pixels)
.\"         $4 is the height (default if absent is the width)
.\"
.de IMAGE
.  ie \\n[www-html] \{\
.    ie '\\$2'-R' \
.      HTML-TAG ".right-image"
.    el \{\
.      ie '\\$2'-L' \
.        HTML-TAG ".left-image"
.      el \
.        HTML-TAG ".centered-image"
.    \}
.    nr www-width 400
.    if !'\\$3'' \
.      nr www-width \\$3
.    nr www-height \\n[www-width]
.    if !'\\$4'' \
.      nr www-height \\$4
.    HTML <img src="\\$1" width=\\n[www-width] height=\\n[www-height]>
.  \}
.  el .nop \[la]\fC\\$1\fP\[ra]
..
.\"
.\" HTML-TAG - emit a tag for the grohtml
.\"
.de HTML-TAG
.  if \\n[www-html] \{\
.    \" the following line makes the vertical mode leave, so to say
.    nop \&
.    nop \X^html-tag:\\$*^
.  \}
..
.\"
.\" PNG-IMAGE - reference a png image
.\"             $1 is the alignment -R, -L or -C
.\"             $2 is the image file
.\"             $3 is the width (optional, no default value)
.\"             $4 is the height (optional, no default value)
.\"
.de PNG-IMAGE
.  ie \\n[www-html] \{\
.    ie '\\$1'-R' \
.      HTML-TAG ".right-image"
.    el \{\
.      ie '\\$1'-L' \
.        HTML-TAG ".left-image"
.      el \
.        HTML-TAG ".centered-image"
.    \}
.    nr www-width 0
.    nr www-height 0
.    if !'\\$3'' \
.      nr www-width \\$3*100/240
.    if !'\\$4'' \
.      nr www-height \\$4*100/240
.    ie \\n[www-width]==0 \{\
.       ie \\n[www-height]==0 .HTML <img src="\\$2">
.       el .HTML <img src="\\$1" height=\\n[www-height]>
.    \}
.    el \{\
.       ie \\n[www-height]==0 .HTML <img src="\\$2" width=\\n[www-width]>
.       el .HTML <img src="\\$2" width=\\n[www-width] height=\\n[www-height]>
.    \}
.  \}
.  el \{\
.    if !r ps4html \{\
.       www-make-unique-name
.       sy pngtopnm \\$2 | pnmcrop -white | pnmtops -noturn > 
\\*[HTML-UNIQUE-NAME].eps
.       if '\\$1'-L' .PSPIC -L \\*[HTML-UNIQUE-NAME].eps \\$3 \\$4
.       if '\\$1'-R' .PSPIC -R \\*[HTML-UNIQUE-NAME].eps \\$3 \\$4
.       if '\\$1'-C' .PSPIC -I \\*[HTML-UNIQUE-NAME].eps \\$3 \\$4
.    \}
.  \}
..
.nr www-left-ll-trap 0
.nr www-left-po-trap 0
.nr www-right-ll-trap 0
.de www-finish-left-po
.   po -\\n[www-left-indent]u
.   wh \\n[www-left-po-trap]u
.   nr www-left-indent 0
..
.de www-finish-right-ll
.   ll +\\n[www-right-indent]u
.\" now see whether we need to inline www-finish-left-ll
.   if \\n[www-left-ll-trap]u>0 .if 
\\n[www-right-ll-trap]u+1v>=\\n[www-left-ll-trap]u \{\
.      mk www-left-po-trap
.      nr www-left-po-trap \\n[www-left-po-trap]+1v
.      wh \\n[www-left-po-trap]u www-finish-left-po
.      ll +\\n[www-left-indent]u
.      wh \\n[www-left-ll-trap]u
.      nr www-left-ll-trap 0
.   \}
.\" and see whether we need to inline www-finish-left-po
.   if \\n[www-left-po-trap]u>0 .if 
\\n[www-right-ll-trap]u+1v>=\\n[www-left-po-trap]u \{\
.      po -\\n[www-left-indent]u
.      wh \\n[www-left-po-trap]u
.      nr www-left-indent 0
.   \}
.   wh \\n[www-right-ll-trap]u
.   nr www-right-ll-trap 0
..
.de www-finish-left-ll
.   if \\n[www-right-ll-trap]>0 .if 
\\n[www-left-ll-trap]+1v>=\\n[www-right-ll-trap] \{\
.      ll +\\n[www-right-indent]u
.      nr www-right-ll-trap 0
.   \}
.   mk www-left-po-trap
.   nr www-left-po-trap \\n[www-left-po-trap]+1v
.   wh \\n[www-left-po-trap]u www-finish-left-po
.   ll +\\n[www-left-indent]u
.   wh \\n[www-left-ll-trap]u
.   nr www-left-ll-trap 0
..
.\"
.\" MARGIN-PNG-IMAGE - reference a png image
.\"                    $1 is the alignment -R, -L  (left by default)
.\"                    $2 is the image file
.\"                    $3 is the width in inches (default 100 pixels)
.\"                    $4 is the height in inches (default $3)
.\"
.de MARGIN-PNG-IMAGE
.  nr HTMLWIDTH 1i
.  if !'\\$3'' \{\
.    nr HTMLWIDTH \\$3u
.  \}
.  nr HTMLHEIGHT \\n[HTMLWIDTH]
.  if !'\\$4'' \{\
.    nr HTMLHEIGHT \\$4u
.  \}
.  nr HTMLWIDTH \\n[HTMLWIDTH]*100/240
.  nr HTMLHEIGHT \\n[HTMLHEIGHT]*100/240
.  ie \\n[www-html] \{\
.    ie '\\$1'-R' .HTML <img src="\\$2" align=right width=\\n[HTMLWIDTH] 
height=\\n[HTMLHEIGHT]>
.    el .HTML <img src="\\$2" align=left width=\\n[HTMLWIDTH] 
height=\\n[HTMLHEIGHT]>
.  \}
.  el \{\
.    if !r ps4html \{\
.       www-make-unique-name
.       sy pngtopnm \\$2 | pnmcrop -white | pnmtops -noturn > 
\\*[HTML-UNIQUE-NAME].eps
.       ie '\\$1'-R' \{\
.\"       we must now disable a possible left image trap
.         sp -1
.         if \\n[www-left-ll-trap]>0 .wh \\n[www-left-ll-trap]u
.         if \\n[www-left-po-trap]>0 .wh \\n[www-left-po-trap]u
.         PSPIC -R \\*[HTML-UNIQUE-NAME].eps \\$3 \\$4
.         sp -\\n[ps-desht]u
.         nr www-right-indent \\n[ps-deswid]u
.         ll -\\n[www-right-indent]u
.         mk www-right-ll-trap
.         nr www-right-ll-trap \\n[www-right-ll-trap]u+\\n[ps-desht]u-1v
.         wh \\n[www-right-ll-trap]u www-finish-right-ll
.\"       now restore possible left trap
.         if \\n[www-left-ll-trap]>0 .wh \\n[www-left-ll-trap]u 
www-finish-left-ll
.         if \\n[www-left-po-trap]>0 .wh \\n[www-left-po-trap]u
.       \}
.       el \{\
.\"       we must now disable a possible right image trap
.         if \\n[www-right-ll-trap]>0 .wh \\n[www-right-ll-trap]u
.         PSPIC -L \\*[HTML-UNIQUE-NAME].eps \\$3 \\$4
.         sp -\\n[ps-desht]u
.         nr www-left-indent \\n[ps-deswid]u
.         po +\\n[www-left-indent]u
.         ll -\\n[www-left-indent]u
.         mk www-left-ll-trap
.         nr www-left-ll-trap \\n[www-left-ll-trap]u+\\n[ps-desht]u-1v
.         wh \\n[www-left-ll-trap]u www-finish-left-ll
.\"       now restore possible right trap
.         if \\n[www-right-ll-trap]>0 .wh \\n[www-right-ll-trap]u 
www-finish-right-ll
.       \}
.    \}
.  \}
..
.\"
.\"  HTML-H - begin heading. Heading level is $1
.\"           if your heading contains URL, FTP, MAILTO macros
.\"           you might wish to disable automatic links to headings.
.\"           This can be done via: -P-l from the command line
.\"           or by using the macro .HTMLINDEX 0 
.\"
.nr www-heading-no -1
.de <HTML-H
.  ie '\\$1'' .nr www-heading-no 1
.  el .nr www-heading-no \\$1
.  HTML-TAG ".NH \\n[www-heading-no]"
..
.\" HTML-H> - end a heading
.de HTML-H>
.  if \\n[www-heading-no]==-1 address@hidden "HTML-H> found without a 
corresponding <HTML-H"
.  br
..
.\"
.\" LINKS - emit the automatically collected links derived from
.\"         section/numbered headings at this position.
.\"
.de LINKS
.  HTML-TAG ".links"
..
.\"
.\" LINE - produce a horizontal line
.\"
.de LINE
.  ti 0
.  HTML <hr>
..
.\"
.\"  NO-AUTO-RULE - suppresses the generation of the top and bottom rules
.\"                 which grohtml emits by default.
.\"
.de NO-AUTO-RULE
.  HTML-TAG ".no-auto-rule"
..
.\"
.\"  www-end-nowhere - end of input trap called to finish diversion.
.\"
.de www-end-nowhere
.  di
..
.\"
.\"  HTML-TL - generate a HTML title only
.\"            which differs from the -ms .TL which generates
.\"            both a HTML title and a H1 heading.
.\"            This is useful when an author wishes to use a HTML title
.\"            as search engine fodder but use a graphic in the document.
.\"
.de HTML-TL
.  HTML-TAG ".html-tl"
.  if !\\n[www-html] \{\
.    di www-nowhere
.    it 2 www-end-nowhere
.  \}
..
.
.ds www-level1 \[bu]\ \ \"
.ds www-level2 \[sq]\ \ \"
.ds www-level3 \[ci]\ \ \"
.nr www-level 0
.
.\"
.\" auxiliary macro for <UL
.\"
.de www-push-level
.  nr www-level +1
.  if (\\n[www-level] > 3) \
.    @error "too many levels of indentation (\\n[www-level])"
..
.\"
.\" auxiliary macro for UL>
.\"
.de www-pop-level
.  if !\\n[www-level] \
.    @error "trying to terminate a list which does not exist"
.  nr www-level -1
.  HTML "</ul>"
..
.\"
.\" start an unordered list
.\"
.de <UL
.  www-push-level
.  ie \\n[www-html] \
.    HTML "<ul>"
.  el \{\
.    br
.    in +\w'\\*[www-level\\n[www-level]]'
.  \}
..
.\"
.\" end an unordered list
.\"
.de UL>
.  ie \\n[www-html] \
.    HTML "</ul>"
.  el \{\
.    br
.    in -\w'\\*[www-level\\n[www-level]]'
.  \}
.  www-pop-level
..
.\"
.\" insert a list item
.\"
.de LI
.  ie \\n[www-html] \
.    HTML "<li>"
.  el \{\
.    br
.    ti -\w'\\*[www-level\\n[www-level]]'
.    nop \\*[www-level\\n[www-level]]\c
.  \}
..
.\"
.\"  DROPCAP - $1 is the letter to be dropped and enlarged
.\"            $2 is the following text whose height the first
.\"               letter should not exceed
.\"            $3 is the optional color of the dropped letter
.\"               (default black)
.\"
.de DROPCAP
.  ds www-dropcolor black
.  if !'\\$3'' .ds www-dropcolor \\$3
.  ie '\*(.T'html' \{\
.      www-make-unique-name
.      MARGIN-PNG-IMAGE -L \\*[www-unique-name].png 0 \\n[.v]*2
.  \}
.  el \{\
.      ie r ps4html \{\
.          www-make-unique-name
.          nop \O[3]\O[5i\\*[www-unique-name].png]\O[0]\O[1]
\\m[\\*[www-dropcolor]]\\s[40]\\$1\\s0
.          nop \O[2]\O[1]\O[4]
.      \}
.      el \{\
.          nr dummy \\w'\\$1'u
.          nr dcht (\\n[.v]+\\n[rst])*\\n[.ps]/\\n[rst]
.          char \[dcap] \\m[\\*[www-dropcolor]]\\s'\\n[dcht]u'\\$1\\s0
\\v'\\n[.v]u'\\[dcap]\\v'-\\n[.v]u'\c
'ti \w'\\[dcap]'u
.     \}
.  \}
\\mP\\$2
..
.\"
.\" supplementary macros used by other macro sets
.\"
.\" here are some tags specially for -Tps or -Thtml when invoked by pre-html
.\" to generate png images from postscript.
.\"
.\" www-do-image - tells troff to issue an image marker which can be
.\"                read back by pre-html
.\"
.de www-do-image
.  if r ps4html \
.    nop \O[3]\O[5\\$2\\$1.png]\O[0]\O[1]
.  if \\n[www-html] \
.    nop \O[3]\O[5\\$2\\$1.png]\O[0]
..
.\"
.\" HTML-IMAGE-END - terminates an image for html
.\"
.de HTML-IMAGE-END
.  if r ps4html \
.    nop \O[2]\O[1]\O[4]
.  if \\n[www-html] \
.    nop \O[2]\O[1]\O[4]
..
.
.nr www-png-no 0
.
.\"
.\" www-make-unique-name - generates another unique name in string
.\"                        `www-unique-name'
.\"
.de www-make-unique-name
.  nr www-png-no +1
.  ds www-unique-name \\n[.F]-auto-\\n[www-png-no]\"
..
.\"
.\" HTML-IMAGE - is the same name as a tag generated from eqn/tbl/pic.
.\"              Although the tags generated via the preprocessor
.\"              are given image names by pre-html and troff.
.\"              The macros below can only be invoked by *other macro sets*
.\"              not user troff input since the contents of macro sets are
.\"              not seen by pre-html.
.\"
.de HTML-IMAGE
.  \" generates a centered image
.  www-make-unique-name
.  www-do-image \\*[www-unique-name] c
..
.
.de HTML-IMAGE-RIGHT
.  www-make-unique-name
.  www-do-image \\*[www-unique-name] r
..
.
.de HTML-IMAGE-LEFT
.  www-make-unique-name
.  www-do-image \\*[www-unique-name] l
..
.
.de HTML-IMAGE-INLINE
.  www-make-unique-name
.  www-do-image \\*[www-unique-name] i
..
.
.
.if \\n[www-html] \{\
.   nh
.   nr HY 0
.\}
.cp \n(_C
.
.\" EOF

reply via email to

[Prev in Thread] Current Thread [Next in Thread]