
\: iref#2, lref#2, enref#2, aref#2.
\: evn{spacing}
\: evn{itemize}   \item \items \intermezzo \itemskip
\: bf#1 it#1 v#1 vbf#1 tt#1
\: ftinc#2 ftdec#2
\: httpref#1 sibref#2
\: (deprecated) par car cpar#1 ccar#1
\: par#1 car#1 cpar#2 ccar#2
\: verbatim#1 verbatix#1
\: publanch#1 publref#1


\${html}{
\def{_spacer#2}{
   \<spacer type=block width=\1 height=\2!>
}
\def{_anch#2}{\<a name="\1">{\2}}
\def{iref#2}{\<a class="intern" href="#\1">{\2}}
\def{lref#2}{\<a class="local" href="\1">{\2}}
\def{lref_quiet#2}{\<a class="quiet" href="\1">{\2}}
\def{aref#2}{\<a class="extern" href="\1">{\2}}
\def{iref_quiet#2}{\<a class="quiet" href="#\1">{\2}}
\def{enref#2}{\<a name="\1">{\2}}
}
\${roff}{
   \def{iref#2}{\2}
   \def{aref#2}{\2}
   \def{lref#2}{\2}
   \def{enref#2}{\2}
}
\${txt}{
   \def{iref#2}{\2}
   \def{aref#2}{\2}
   \def{lref#2}{\2}
   \def{enref#2}{\2}
}

\formatted{
   \env{spacing}{
      \apply{_#2\!{{\if{\defined{lkey}{\1}}{}{\def{\1}{\2}}}}}{
         {$top}{0}         \: not yet functional.
         {$bottom}{0}      \: not yet functional.
         {$left}{0}        \: only for indent.
         {$pleft}{0}       \: only for indent, not yet in troff.
         {$right}{0}       \: only for shrinking.
         {$f}{3}
      }
      \${roff}{
         \apply{_#1\!{{\setx{$\1}{\f{div}{\$\1}{\$f}}}}}
         { {top}{bottom}{right}{left}
         }
      }
      \${html}{
         \<div style="
            \if{\$top}{margin-top:\$top\,mm;}{}
            \if{\$bottom}{margin-bottom:\$bottom\,mm;}{}
            \if{\$left}{margin-left:\$left\,mm;}{}
            \if{\$pleft}{margin-left:\$pleft%;}{}
            \if{\$right}{margin-right:\$right\,mm;}{}
         ">
      }
      \${roff}{
         \if{\$left}{\@{\N.in +}\$left\@{m\N}}{}
         \if{\$right}{\@{\N.ll -}\$right\@{m\N}}{}
      }
   }{
      \${html}{\</div>}
      \${roff}{
         \if{\$left}{\@{\N.in -}\$left\@{m\N}}{}
         \if{\$right}{\@{\N.ll +}\$right\@{m\N}}{}
      }
   }
}

\switch{\__device__}{
   {html}{
      \def{bf#1}{\@{<b>}\1\@{</b>}}
      \def{vbf#1}{\@{<tt><b>}\1\@{</b></tt>}}
      \def{it#1}{\@{<i>}\1\@{</i>}}
      \def{v#1}{\@{<tt>}\1\@{</tt>}}
      \def{m#1}{\@{<tt>}\1\@{</tt>}}
      \def{tt#1}{\@{<tt>}\1\@{</tt>}}

      \def{ftinc#2}{\2}
      \def{ftdec#2}{\2}

      \def{httpref#1}{\<a class="extern" href="\1">{\1}}
      \def{httpref#2}{\<a class="extern" href="\1">{\2}}
      \def{sibref#2}{\<a class="local" href="\1.html">{\2}}
   }
   {roff}{
      \def{bf#1}{\@{\\fB}\1\@{\\fP}}
      \def{it#1}{\@{\\fI}\1\@{\\fP}}
      \def{v#1}{\@{\\fC}\1\@{\\fR}}
      \def{vbf#1}{\@{\\fB\\fC}\1\@{\\fR\\fP}}
      \def{m#1}{\@{\\fC}\1\@{\\fR}}
      \def{tt#1}{\1}

      \def{ftinc#2}{\@{\\s+\1}\2\@{\\s-\1}}
      \def{ftdec#2}{\@{\\s-\1}\2\@{\\s+\1}}

      \def{httpref#1}{\1}
      \def{httpref#2}{\1}  \: the url-encoded thing.
      \def{sibref#2}{\bf{\2}}
   }
}

\switch{\__device__}{
   {html}{
      \special{
         {60}  {&lt;}      \: less than sign
         {62}  {&gt;}      \: greater than sign
         {38}  {&amp;}     \: ampersand

         {-1} {&nbsp;}     \: the zoem escape \~
         {-2} {<br>}       \: the zoem escape \|
         {-3} {-}          \: the zoem escape \-
      }

      \constant{
         {bullet}{*}
      }
   }
   {roff}{
      \special{
         {34}  {"}         \: double quote is special in second layer only
         {34}  {""}        \: double quote is special in second layer only
         {46}  {\\&.}      \: a dot.
         {96}  {\\&`}      \: backquote.
         {39}  {\\&'}      \: quote

         {92}  {\\e}       \: backslash (default troff escape character).
                           \: escaping by backslash may fail in
                           \: diversions [for old roffs].

         {-1} {\\ }        \: the zoem escape \~
         {-2} {\!N.br\!N}  \: the zoem escape \|
         {-3} {\\-}        \: the zoem escape \-
      }
      \constant{
         {bullet}{\\(bu}
      }
   }
}

\formatted{

   \env{itemize}{

      \apply{_#2\!{{\if{\defined{lkey}{\1}}{}{\def{\1}{\2}}}}}{
         {$contiguous}{0}       \: no paragraph skips
         {$compact}{0}          \: item and description on same line.
         {$w1}{2}               \: width of item column in m's.
         {$w2}{1}               \: width of separating column in m's.
         {$f1}{16}              \: correction factor for html.
         {$f2}{8}               \: correction factor for html.
         {$mark}{\*{bullet}}
         {$margintop}{1}        \: NOTE anonalous unit (ems). mq.
         {$align}{left}         \: the way item is aligned.
         {$debug}{0}
         {$lp}{}                \: left parenthesis
         {$rp}{}                \: right parenthesis
         {$type}{mark}          \: affects \item. mark/roman/abc/arabic
         {$itemcount}{0}
      }

      \${html}{
         \setx{$w1}{\f{*}{\$w1}{\$f1}}
         \setx{$w2}{\f{*}{\$w2}{\$f2}}
      }

      \setx{$w3}{\"+"{\$w1}{\$w2}}

      \ctrinc{_envlevel}
      \ctrset{_itemcheck\ctrput{_envlevel}}{0}

      \${html}{
         \<div style="margin-top:$margintop\,em">
         \<table
            cellspacing="0" border=\$debug
            cellpadding="0" summary="itemize">
      }
      \${roff}{
         \if{\$margintop}{\@{\P}}{}
      }
   }{
      \_itemend
      \${html}{\</table>\@{\n}\</div>}
      \_itemaccount{0}{0}
      \ctrdec{_envlevel}
   }

   \${html}{
      \def{itemskip}{
         \_itemend
         \@{\N<tr>\I\N<td width=\&{\$w1}>}\~
         \@{\N</td>\N<td width=\&{\$w2}>}\~
         \@{\N</td>\N<td>}
         \@{\N</td>\J\N</tr>}
      }
   }
   \${roff}{
      \def{itemskip}{
         \_itemend
         \@{\P}
      }
   }

   \def{intermezzo#1}{

      \_itemend

      \_itemaccount{0}{0}
      \if{\$contiguous}
         {}
         {\itemskip}
      \${html}{
         \@{\N<tr>\I\N<td colspan=3>\I\N}
         \1
         \@{\J\N</td>\J\N</tr>}
      }
      \${roff}{
         \1
      }
   }

   \def{item#1}{

      \_itemend

      \set{_item}{\1}
      \_itemaccount{1}{1}

      \if{\and{\$itemcount}{\not{\$contiguous}}}
         {\itemskip}
         {}

      \${html}{
         \if{\$compact}
         {  \@{\N<tr>\I\N}
            \@{<td width=\&{\$w1} valign="top" align="\&{\$align}">\I\N}
               \_item
            \@{\J\N</td>\N<td width=\&{\$w2}>}\~\@{</td>\N}
            \: mq nbsp
         }
         {  \@{\N<tr>\I\N<td colspan=3>\I\N}
               \_item
            \@{\J\N</td>\J\N</tr>\N}
         }
      }
      \${roff}{
         \: compact/not compact is accounted for by \_itemdef.
         \if{\cmp{eq}{\$align}{left}}
            {\@{\+{2}.ZI }\$w3\@{m "}\1\@{"\+{1}}}
            {\@{\+{2}.ZJ }\$w1\@{m }\$w2\@{m "}\1\@{"\+{1}}}
      }
      \_itemdef
   }

   \def{items#1}{

      \_itemend

      \set{_items}{\1}
      \_itemaccount{1}{1}

      \if{\$compact}{
         \write{stderr}{txt}{
            \`[`itemize: compact not supported with items#1\|\`]`
         }
         \exit
      }{}
      \if{\and{\$itemcount}{\not{\$contiguous}}}
         {\itemskip}
         {}
      \${html}{
         \apply{
            _#1{
               \@{\N<tr>\I\N<td colspan=3 align=\"}\$align\@{\">\I\N}
                  \!1
               \@{\J\N</td>\J\N</tr>\N}
            }
         }{
            \_items
         }
      }
      \${roff}{
         \: compact/not compact is accounted for by \_itemdef.
         \apply{
            _#1{
               \if{\cmp{eq}{\$align}{left}}
                  {\@{\N\+{2}.ZI }\$w3\@{m "}\!1\@{"\+{1}}}
                  {\@{\N\+{2}.ZJ }\$w1\@{m }\$w2\@{m "}\!1\@{"\+{1}}}
               \@{\N\\&\N'in -}\$w3\@{m\N}
            }
         }{
            \_items
         }
         \@{\N'in\s+}\$w3\@{m\N}
      }
      \_itemdef
   }

   \def{item}{

      \_itemend

      \_itemaccount{1}{1}
      \if{\and{\$itemcount}{\not{\$contiguous}}}
         {\itemskip}
         {}
      \${html}{
         \@{\N<tr>\I\N<td width=\&{\$w1} valign="top" align="\&{\$align}">\I\N}
            \_putitemmark
         \@{\J\N</td>\N<td width=\&{\$w2}>}\~\@{</td>}
         \: mq nbsp
      }
      \${roff}{
         \if{\cmp{eq}{\$align}{left}}
            {\@{\N.ZI }\$w3\@{m \"}\_putitemmark\@{\"}}
            {\@{\N.ZJ }\$w1\@{m }\$w2\@{m }"\_putitemmark"}
      }
      \_itemdef
   }

   \def{_itemdef}{
      \_itemaccount{2}{3}
      \${html}{
         \if{\$compact}
            {  \@{<td><div style="text-align:justify">\I\N}}
            {  \@{<tr>\I\N<td width=\&{\$w1}>\I\N}
                  \~
               \@{\J\N</td><td width=\&{\$w2}>\I\N}
                  \~
                \@{\J\N</td>\N<td><div style="text-align:justify">\N\I}
            }
      }
      \${roff}{
         \if{\$compact}
            {\@{\N}}
            {\@{\N\\&\N.br\N}}
      }
   }

   \def{_itemend}{
      \if{\eqt{eq}{\"%"{\ctrput{_itemcheck\ctrput{_envlevel}}}{7}}{3}}{
         \_itemaccount{4}{0}
         \setx{$itemcount}{\"+"{\$itemcount}{1}}
         \${html}{
            \@{\J\N</div></td>\J\N</tr>}
         }
         \${roff}{\@{\N.in\s-}\$w3\@{m\N}}
      }{}
   }

   \def{_itemaccount#2}{
      \: add \1, check that the result % 7 == \2.
      \ctradd{_itemcheck\ctrput{_envlevel}}{\1}
      \if{\eqt{ne}{\"%"{\ctrput{_itemcheck\ctrput{_envlevel}}}{7}}{\2}}{
         \write{stderr}{txt}{\`[`
### Error in itemize: expect corrupt output (no further insights, sorry).
### Checksum: \ctrput{_itemcheck\ctrput{_envlevel}}
\`]`
         }
      }{
      }
   }

   \def{_putitemmark}{
      \$lp
      \switch{\$type}{
         {mark}{\$mark}
         {roman}{\roman{\"+"{\$itemcount}{1}}}
         {ROMAN}{\ucase{\roman{\"+"{\$itemcount}{1}}}}
         {abc}{\alpha{\"+"{\$itemcount}{1}}}
         {ABC}{\ucase{alpha{\"+"{\$itemcount}{1}}}}
         {arabic}{\"+"{\$itemcount}{1}}
         {?}
      }
      \$rp
   }
}


\${html}{

   \def{"html::charset"}{ISO-8859-1}
   \def{"gen::html-meta"}{
<META http-equiv="Content-Type" content="text/html; charset=\"html::charset"">
   }
   \: NOTE: this is not put in at scope; caller has to do that.

   \def{"gen::html-style-optional"}{
\@{
   body
   {  text-align: justify;
 \I   color: #001111;
      background: white;
      margin-left: 8%;
      margin-right: 8%;
 \J}

   h3 { margin-top:1em; }
   h2 { margin-top:2em; }
}
   }
\:^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   \def{"gen::html-style-required"}{
\@{
   a:link            { text-decoration: none; }
   a:active          { text-decoration: none; }
   a:visited         { text-decoration: none; }

   a:link { color: #1111aa; }
   a:active { color: #1111aa; }
   a:visited { color: #111166; }
   a.local:link { color: #11aa11; }
   a.local:active { color: #11aa11; }
   a.local:visited { color: #116611; }
   a.intern:link { color: #1111aa; }
   a.intern:active { color: #1111aa; }
   a.intern:visited { color: #111166; }
   a.extern:link { color: #aa1111; }
   a.extern:active { color: #aa1111; }
   a.extern:visited { color: #661111; }
   a.quiet:link { color: black; }
   a.quiet:active { color: black; }
   a.quiet:visited { color: black; }
}
\@{\Ndiv.copy
{  font-size: 12pt;
\I font-family: monospace;
   text-align: left;
   white-space: pre;
   margin-left: 2em;
   margin-top: 1em;
   margin-bottom: 1em;

\J}
div.indent
{\Imargin-left: 8%;
   margin-right: 0%;
\J}
}
}
\:^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   }

\${roff}{
   \def{"generic::troff-defs"}{
\@{\N
.po 2m
.de ZI
.\\" Zoem Indent/Itemize macro I.
.br
'in +\\\\$1
.nr xa 0
.nr xa -\\\\$1
.nr xb \\\\$1
.nr xb -\\\\w'\\\\$2'
\\h'|\\\\n(xau'\\\\$2\\h'\\\\n(xbu'\\\\
..
.de ZJ
.br
.\\" Zoem Indent/Itemize macro II.
'in +\\\\$1
'in +\\\\$2
.nr xa 0
.nr xa -\\\\$2
.nr xa -\\\\w'\\\\$3'
.nr xb \\\\$2
\\h'|\\\\n(xau'\\\\$3\\h'\\\\n(xbu'\\\\
..\N}
   }
}

\formatted{

   \switch{\__device__}{

      {html}{

\: plain ole style paragraph (deprecated)

         \def{par}{
            \@{\P<p style="text-align:justify">\N}
         }

\: ole style carry on paragraph. more or less html specific; it seems to be
\: needed after e.g. verbatim environment. deprecated.

         \def{car}{
            \@{\P<p style="text-align:justify; margin-top:0em">\N}
         }

\: ole style caption paragraph. deprecated.

         \def{cpar#1}{
            \@{\P<p style="text-align:justify">\N}
            \bf{\1} \@{\N} \|
         }

\: old style caption carry on paragraph.

         \def{ccar#1}{
            \@{<p style="text-align:justify; margin-top:0em; margin-bottom:0em">\N}
               \@{\N} \bf{\1} \|
         }


\: paragraph.

         \def{par#1}{
            \<p style="text-align:justify; margin-bottom:0">
               \@{\N}\1
            \<>
         }

\: carry on paragraph. more or less html specific; it seems to be needed
\: after e.g. verbatim environment. only  use if spacing matters to you,
\: otherwise better suffer and wait  for more generic (html client side)
\: solutions.

         \def{car#1}{
            \<p style="text-align:justify; margin-bottom:0 margin-bottom:0em">
               \@{\N}\1
            \<>
         }

\: caption paragraph.

         \def{cpar#2}{
            \<p style="text-align:justify; margin-bottom:0">
               \bf{\1} \| \2
            \<>
         }

\: caption carry on paragraph.

         \def{ccar#2}{
            \<p style="text-align:justify; margin-bottom:0 margin-bottom:0em">
               \bf{\1} \| \2
            \<>
         }

         \def{verbatim#1}{
            \: \@{\N<div class=copy>\w}\1
            \@{\N<pre>\w}\1
            \@{\W</pre>\N}
         }
         \def{verbatix#1}{\verbatim{\1}}
      }

      {roff}{
         \def{par}{\@{\P}}
         \def{car}{\@{\N}}
         \def{cpar#1}{\@{\P}\bf{\1}\@{\N}\|}
         \def{ccar#1}{\@{\N}\bf{\1}\@{\N}\|}

         \def{par#1}{\@{\P}\1}
         \def{car#1}{\@{\N}\1}
         \def{cpar#2}{\@{\P}\bf{\1}\|\2\@{\N}}
         \def{ccar#2}{\@{\N}\bf{\1}\|\2\@{\N}}

         \: the non-non-breaking variant of verbatim

         \def{verbatix#1}{
            \@{\P.nf \\fC\N\w}
            \1
            \@{\W\N.fi \\fR\P}
         }

         \def{verbatim#1}{
            \@{\P.di ZV\N.in 0\N.nf \\fC\N\w}
            \1
            \@{\W\N.fi \\fR\N.in\N.di\N.ne \\n(dnu\N}
            \@{\N.nf \\fC\N.ZV\N.fi \\fR\P}
         }

         \: Jan van der Steen is to blame for this :)

         \: .di ZV      new diversion named ZV.
         \: .in 0       set indent to 0.
         \: .nf \fC     no fill (no adjustment), fixed width font?

         \: .fi \fR     fill on, Roman font.
         \: .in         previous indent.
         \: .di         end of diversion (ZV).

         \: .ne \n(dnu  need 'dn' vspace (vsize of most recent diversion).
         \: .nf \fC     set no fill mode, fixed width font.
         \: .ZV         do diversion.
         \: .fi \fR     fill mode on, Roman font.

      }
   }
}

\formatted{
   \def{publanch#1}{
      \ctrinc{publanch}
      \write{\__fnbase__.zmr}{copy}{
         \!refload
            {\1}
            {1}
            {Ref}
            {\ctrput{publanch}}
            {[\ctrput{publanch}]}
            {}
            \`n`
      }
      \${html}{\_anch{\1}{[\ctrput{publanch}]}}
      \${roff}{[\ctrput{publanch}]}
   }
   \def{publref#1}{
      \${html}{\iref{\1}{[\refnumber{\1}]}}
      \${roff}{[\refnumber{\1}]}
   }
}

