
\'import{ref.zmm}
\'import{ctr.zmm}

\: iref#2, lref#2, enref#2, aref#2.
\: evn{spacing}
\: evn{itemize}   \item \items \intermezzo \itemskip
\: bf#1 it#1 v#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

\'def{"zmm::html::justify"}{justify}


\'${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{aref#2}{\<a class="extern" href="\1">{\2}}
   \'def{enref#2}{\<a name="\1">{\2}}

   \'def{iref_quiet#2}{\<a class="quiet" href="#\1">{\2}}
   \'def{lref_quiet#2}{\<a class="quiet" href="\1">{\2}}

   \'set{"zbgen-text-level"}{50}
   \'set{"zbgen-text-size"}{0}

   \'set{%{zbgen}{text}{level}}{
      {53}{30pt}
      {52}{20pt}
      {51}{15pt}
      {50}{12pt}
      {49}{10pt}
      {48}{9pt}
      {47}{8pt}
   }
}


\'${roff}{
   \'def{iref#2}{\it{\2}}
   \'def{aref#2}{\it{\2}}
   \'def{lref#2}{\it{\2}}
   \'def{enref#2}{\2}
}

\'set{_p_classes}{\'vanish{
      \'set{_tmp}{\'if{\"zbgen-text-size"}{\"zbgen-text-size"}{\"zbgen-text-level"}}
   }class="default L\_tmp"}

\'formatted{
   \'env{spacing}{
      {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{\$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}}
      \'def{it#1}{\<i>{\1}}
      \'def{v#1}{\<tt>{\1}}
      \'def{m#1}{\<tt>{\1}}
      \'def{tt#1}{\<tt>{\1}}

      \'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#1}{\<a class="local" href="\1.html">{\1}}
      \'def{sibref#2}{\<a class="local" href="\1.html">{\2}}
      \'def{sibref#3}{\<a class="local" href="\1.html#\2">{\3}}
   }
   {roff}{
      \'def{bf#1}{\@{\\fB}\1\@{\\fP}}
      \'def{it#1}{\@{\\fI}\1\@{\\fP}}
      \'def{v#1}{\@{\\fC}\1\@{\\fP}}
      \'def{m#1}{\@{\\fC}\1\@{\\fP}}
      \'def{tt#1}{\@{\\fC}\1\@{\\fP}}

      \'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#1}{\bf{\1}}
      \'def{sibref#2}{\bf{\2}}
      \'def{sibref#3}{\bf{\3}}
   }
}

\'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}{
      {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}
      {smallertext}{0}      \: decreases font size in paragraphs.
   }{
      \'${html}{
         \'setx{$w1}{\'f{*}{\$w1}{\$f1}}
         \'setx{$w2}{\'f{*}{\$w2}{\$f2}}
      }

      \'setx{$w3}{\'f{+}{\$w1}{\$w2}}

      \'if{\$smallertext}{
         \'setx{"zbgen-text-level"}{\'let{\"zbgen-text-level"-1}}
      }{}

      \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}
      \'if{\$smallertext}{
         \'setx{"zbgen-text-level"}{\'let{\"zbgen-text-level"+1}}
      }{}
   }

   \'${html}{
      \'def{itemskip}{
         \_itemend
         \<tr>{\<td width=\$w1>{\~}\<td width=\$w2>{\~}\<td>{}}
      }
   }
   \'${roff}{
      \'def{itemskip}{
         \_itemend
         \@{\P}
      }
   }

   \'def{intermezzo#1}{

      \_itemend

      \_itemaccount{0}{0}
      \'if{\$contiguous}
         {}
         {\itemskip}
      \'${html}{
         \<tr>{\<td colspan=3>{\1}}
      }
      \'${roff}{
         \1
      }
   }

   \'def{item#1}{

      \_itemend

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

      \'if{\'let{\$itemcount && !\$contiguous}}
         {\itemskip}
         {}

      \'${html}{
         \'if{\$compact}
         {  \@{<tr>}
            \<td width=\$w1 valign="top" class=\$align>{\_item}
            \<td width=\$w2>{\~}
         }
         {  \<tr>{\<td colspan=3>{\_item}}
         }
      }
      \'${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{\'let{\$itemcount && !\$contiguous}}
         {\itemskip}
         {}
      \'${html}{
         \'apply{_#1{\<tr>{\<td colspan=3 class=\$align>{\!1}}}
         }{\_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{\'let{\$itemcount && !\$contiguous}}
         {\itemskip}
         {}
      \'${html}{
         \@{<tr>}
         \<td width=\$w1 valign="top" class=\$align>{\_putitemmark}
         \<td width=\$w2>{\~}
      }
      \'${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:\&{\"zmm::html::justify"}">}}
            {  \@{<tr>}
               \<td width=\$w1>{\~}
               \<td width=\$w2>{\~}
               \@{<td><div style="text-align:\&{\"zmm::html::justify"}">}
            }
      }
      \'${roff}{
         \'if{\$compact}
            {\@{\N}}
            {\@{\N\\&\N.br\N}}
      }
   }

   \'def{_itemend}{
      \'if{\'eqt{eq}{\'f{%}{\ctrput{_itemcheck\ctrput{_envlevel}}}{7}}{3}}{
         \_itemaccount{4}{0}
         \'setx{$itemcount}{\'f{+}{\$itemcount}{1}}
         \'${html}{
            \@{</div></td></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}{\'f{%}{\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}{\'textmap{{number}{roman}}{\'f{+}{\$itemcount}{1}}}
         {ROMAN}{\'textmap{{number}{roman}{word}{ucase}}{\'f{+}{\$itemcount}{1}}}
         {abc}{\'textmap{{number}{alpha}}{\'f{+}{\$itemcount}{1}}}
         {ABC}{\'textmap{{number}{alpha}{word}{ucase}}{\'f{+}{\$itemcount}{1}}}
         {arabic}{\'f{+}{\$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""!>
}

\'def{"gen::html-style-optional"}{
   body {
      text-align: \"zmm::html::justify";
      color: #001111;
      background: white;
      margin-left: 8%;
      margin-right: 8%;
      font-family: Helvetica, Univers, Verdana, sans-serif;
   }

   p.default  {
      font-family: Helvetica, Univers, Verdana, sans-serif;
      text-align: \"zmm::html::justify";
   }

   p.L53 { font-size: \%{zbgen}{text}{level}{53}; }
   p.L52 { font-size: \%{zbgen}{text}{level}{52}; }
   p.L51 { font-size: \%{zbgen}{text}{level}{51}; }
   p.L50 { font-size: \%{zbgen}{text}{level}{50}; }
   p.L49 { font-size: \%{zbgen}{text}{level}{49}; }
   p.L48 { font-size: \%{zbgen}{text}{level}{48}; }
   p.L47 { font-size: \%{zbgen}{text}{level}{47}; }

   td {
      font-family: Helvetica, Univers, Verdana, sans-serif;
      text-align: \"zmm::html::justify";
   }

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

   .left    { text-align: left; align: left; }
   .right   { text-align: right; align: right; }
   .center  { text-align: center; align: center; }
}
\:^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   \'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; }
}
\@{
   div.copy

{  font-size: 12pt;
   font-family: monospace;
   text-align: left;
   white-space: pre;
   margin-left: 2em;
   margin-top: 1em;
   margin-bottom: 1em;

}
   div.indent

{  margin-left: 8%;
   margin-right: 0%;
}
}}
\:^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   }

\'${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_classes!>}

\: 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_classes style="margin-top:0em; margin-bottom:0em"!>
         }

\: ole style caption paragraph. deprecated.

         \'def{cpar#1}{
            \<p \_p_classes!>
            \bf{\1}
            \|
         }

\: old style caption carry on paragraph.

         \'def{ccar#1}{
            \<p \_p_classes style="margin-top:0em; margin-bottom:0em"!>
            \bf{\1}
            \|
         }


\: paragraph.

         \'def{par#1}{
            \<p \_p_classes style="margin-bottom:0">{\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 \_p_classes style="margin-top:0em; margin-bottom:0em">{\1}
         }

\: caption paragraph.

         \'def{cpar#2}{
            \<p \_p_classes style="margin-bottom:0">{
               \bf{\1}\|
               \2
            }
         }

\: caption carry on paragraph.

         \'def{ccar#2}{
            \<p \_p_classes style="margin-top:0em; 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.

      }
   }
}

