Chapter 3
Html Environment

   3.1 Initiating
   3.2 TEX Parameters
   3.3 Paragraphs

3.1 Initiating

The \special{t4ht.\:html} gives the extension to the root file. To be recognized, Must appear before the openning of any file, and outputing of any content.

<..html option..>
 \def\:tempa#1#2#3#4<.par del.>{#1#2#3}
 \:CheckOption{htm}     \if:Option
    \edef\:html{\expandafter\:tempa\:html\empty\empty<.par del.>}
    <.base 2 names for htm.>
 \else \:CheckOption{htm5}     \if:Option
    \edef\:html{\expandafter\:tempa\:html\empty\empty<.par del.>}
    <.base 5 names for htm.>
 \else \:CheckOption{htm4}     \if:Option
    \edef\:html{\expandafter\:tempa\:html\empty\empty<.par del.>}
    <.base 4 names for htm.>
 \else \:CheckOption{htm3}     \if:Option
    \edef\:html{\expandafter\:tempa\:html\empty\empty<.par del.>}
    <.base 3 names for htm.>
 \else   \:CheckOption{xhtml} \if:Option
    \let\j:bname=\jobname
 \else   \:CheckOption{html}
    \if:Option  \let\j:bname=\jobname \fi
 \fi \fi \fi \fi \fi
 \if:Option
       \ht:special{t4ht.\:html} 
    <.default html env.>
    <.disregard html:par from protex.>
    <.html TeX4ht protex.>
 \fi
 -_-_-

<..first pass..>+
 \NewConfigure{ext}[1]{%
    \def\:temp##1ext=##2,##3<.par del.>{%
       \if !##2!\edef\:html{#1}%
       \else \edef\:html{##2}\fi}%
    \expandafter\:temp\Preamble ,ext=,<.par del.>
 }
 \Configure{ext}{html}
 -_-_-

<..base 2 names for htm..>
 \def\:temp#1#2#3<.par del.>{\def\j:bname{#1\ifx ?#2\else #2\fi}}
 \expandafter\:temp \jobname ?<.par del.>
 -_-_-

<..base 3 names for htm..>
 \def\:temp#1#2#3#4<.par del.>{\def\j:bname{#1\ifx ?#2\else
    #2\ifx ?#3\else #3\fi\fi}}
 \expandafter\:temp \jobname ??<.par del.>
 -_-_-

<..base 4 names for htm..>
 \def\:temp#1#2#3#4#5<.par del.>{\def\j:bname{#1\ifx ?#2\else
    #2\ifx ?#3\else #3\ifx ?#4\else #4\fi\fi\fi}}
 \expandafter\:temp \jobname ???<.par del.>
 -_-_-

<..base 5 names for htm..>
 \def\:temp#1#2#3#4#5#6<.par del.>{\def\j:bname{#1\ifx ?#2\else
    #2\ifx ?#3\else #3\ifx ?#4\else #4\ifx ?#5\else #5\fi\fi\fi\fi}}
 \expandafter\:temp \jobname ????<.par del.>
 -_-_-

3.2 TEX Parameters

\html:rightskip is already defined in AlProTex, but we need it early here.

<..def /HtmlEnv..>
 \def\html:rightskip{\rightskip=\z@ plus 0.5\hsize  minus0.5\hsize }
 \def\HtmlEnv{%
    \html:rightskip  <.html penalties.>%
    \def\magnification{%
       \def\:temp{\:warning{Insert \string\magnification
                            =\the\tmp:cnt\space before tex4ht}}%
       \afterassignment\:temp\tmp:cnt}%
    \ht:everypar{\HtmlPar}}
 \let\HtmlPar=\empty
 -_-_-

The \output variable might hold a script with a \par, as is the case in LaTeX.

<..def /HtmlEnv..>+
 \edef\:temp{%
    \output={\noexpand\SaveEverypar \noexpand\ht:everypar{}\the\output
          \noexpand\RecallEverypar}}
 \:temp
 -_-_-

Inhibit streching and shrinking of spaces between words to help tex4ht, and let flexibility in line length to compensate for fixed spaces and discouraged word breaks.

<..html penalties..>
 \frenchspacing        no extra space after punctuation marks
 \let\nonfrenchspacing=\relax
 \spaceskip=\z@        override inter word glue
 \xspaceskip=\z@       same but for words ending with punctuation marks
 \linepenalty=0        charged on each line break
 \adjdemerits=0        charged on adj lines of diff length
 \pretolerance=10000   max penalty pts per line without hyphenation
 \hyphenpenalty=10000  for line break within word
 \exhyphenpenalty=10000for line break after hyphen
 \clubpenalty=0        for page break after first line of parag
 \widowpenalty=0       for page break before last line of parag
 \interlinepenalty=50  for page break within a paragraph
 \displaywidowpenalty=0
 \predisplaypenalty=-10
 \postdisplaypenalty=1000
 \abovedisplayskip=30pt plus 10pt
 \belowdisplayskip=\abovedisplayskip
 \abovedisplayshortskip=\abovedisplayskip
 \belowdisplayshortskip=\abovedisplayskip
 -_-_-

We don’t want a page break after a display, because the \aftergroup material for the equation may be detached from the equation. A possible prolem for math into figures.

<..default html env..>
 <.def /HtmlEnv.>
 \edef\:temp{\meaning\everypar}
 \edef\:tempa{\string\everypar}
 \ifx \:temp\:tempa
    \let\ht:everypar=\everypar
 \else
    \:warning{nonprimitive \string\everypar}
 \fi
 \edef\NoHtmlEnv{%
    \sfcode ‘\noexpand\noexpand\noexpand\.3000  nonfrenchspacing
    \sfcode ‘\noexpand\noexpand\noexpand\?3000
    \sfcode ‘\noexpand\noexpand\noexpand\!3000
    \sfcode ‘\noexpand\noexpand\noexpand\:2000
    \sfcode ‘\noexpand\noexpand\noexpand\;1500
    \sfcode ‘\noexpand\noexpand\noexpand\,1250
    \rightskip=\the\rightskip
    \spaceskip=\the\spaceskip
    \xspaceskip=\the\xspaceskip
    \linepenalty=\the\linepenalty
    \adjdemerits=\the\adjdemerits
    \pretolerance=\the\pretolerance
    \hyphenpenalty=\the\hyphenpenalty
    \exhyphenpenalty=\the\exhyphenpenalty
    \clubpenalty=\the\clubpenalty
    \widowpenalty=\the\widowpenalty
    \interlinepenalty=\the\interlinepenalty
    \displaywidowpenalty=\the\displaywidowpenalty
    \predisplaypenalty=\the\predisplaypenalty
    \postdisplaypenalty=\the\postdisplaypenalty
    \abovedisplayskip=\the\abovedisplayskip
    \belowdisplayskip=\the\belowdisplayskip
    \abovedisplayshortskip=\the\abovedisplayshortskip
    \belowdisplayshortskip=\the\belowdisplayshortskip
    \noexpand\ht:everypar{\noexpand\the\noexpand\ht:everypar}}
 -_-_-

<..activate html env..>
 \edef\NoHtmlEnv{\NoHtmlEnv}%
 \append:def\NoHtmlEnv{\SUBOff \SUPOff}\HtmlEnv
 -_-_-

<..html utilities..>+
 \let\:noindent=\noindent
 \def\noindent{\ifx \EndPicture\:UnDef
      \ifvmode  \IgnoreIndent\leavevmode\fi
    \else \:noindent \fi}
 -_-_-

3.3 Paragraphs

We want to push specials at start of lines, and merge the space before and after specials.

<..html utilities..>+
 \let\skip:Par=\empty
 -_-_-

<..html paragraph breaks at entry to file..>
 \def\HtmlPar{\HtmlPar:Off{%
    \if:nopar \ShowPar \ShowIndent
       \ifx \skip:Par\empty\else \hskip -\parindent \skip:Par\fi
    \else
      \if:removeindent \ShowIndent \hskip -\parindent \a:Par
      \else
         \ifdim \parindent>\z@ \hskip -\parindent \fi
         \html:par
         \ifdim \parindent>\z@ \hskip  \parindent \fi
    \fi\fi \relax
 }}%
 -_-_-

<..general utilities..>+
 \def\IgnorePar{\ifx \EndPicture\:UnDef \Protect\gl:nopartrue \fi}
 \def\ShowPar{\ifx \EndPicture\:UnDef \Protect\gl:noparfalse \fi}
 \def\IgnoreIndent{\ifx \EndPicture\:UnDef
    \Protect\gl:removeindenttrue \fi}
 \def\ShowIndent{\ifx \EndPicture\:UnDef
    \Protect\gl:removeindentfalse \fi}
 \def\gl:nopartrue{\global\:nopartrue}
 \def\gl:noparfalse{\global\:noparfalse}
 \def\gl:removeindenttrue{\global\:removeindenttrue}
 \def\gl:removeindentfalse{\global\:removeindentfalse}
 \def\HtmlParOff{\global\let\HtmlPar:Off=\:gobble}
 \def\HtmlParOn{\gdef\HtmlPar:Off##1{##1}}
 \HtmlParOn
 -_-_-

<..new ifs..>+
 \:tempa{if:removeindent}
 \:tempa{if:nopar}
 -_-_-

<..first pass..>+
 \def\c:HtmlPar:#1#2#3#4{%
    \def\:temp{#3}\ifx \:temp\empty \c:def\a:Par{#1}\else
      \c:def\a:Par{#1\Next:EndP{#3}}\fi
    \def\:temp{#4}\ifx \:temp\empty \c:def\html:par{#2}\else
      \c:def\html:par{#2\Next:EndP{#4}}\fi
 }
 \def\EndP{\Protect\par:end}
 \let\par:end=\empty
 \def\Next:EndP{\Protect\next:endp}
 \def\next:endp#1{\gdef\par:end{#1\global\let\par:end=\empty}}
 \def\SaveHtmlPar{\PushMacro\a:Par \PushMacro\html:par}
 \def\RecallHtmlPar{\PopMacro\a:Par \PopMacro\html:par}
 -_-_-

The following is neded for debugging, to detect skipped paragraps. Delete it, or just make it active for debugging mode!!!!!

<..shared config..>
 \NewConfigure{HtmlPar*}[2]{%
    \def\:temp{#2}\ifx \:temp\empty \c:def\skip:Par{#1}\else
      \c:def\skip:Par{#1\Next:EndP{#2}}\fi}
 -_-_-

<..first pass..>+
 \def\gl:let{\global\let}
 \def\EndP:cnt{0}
 \def\SaveEndP{%
    \expandafter\gl:let\csname \EndP:cnt :sv\endcsname =\par:end
    \gl:let\par:end=\empty
    \gHAdvance \EndP:cnt by 1 }
 \def\RecallEndP{%
    \ifnum \EndP:cnt>0
      \gHAdvance \EndP:cnt by -1
      \expand:after{\gl:let\par:end=}\csname\EndP:cnt :sv\endcsname
    \else
      \:warning{extra \string\RecallEndP}
    \fi}
 -_-_-

<..disregard html:par from protex..>
 \ifx \html:par\:UnDef \let\html:par=\empty \fi
 -_-_-

User’s input, and the following in case of no such input, determine how files will initially treat paragraphs.

Display math formulas can be in-line or between paragraph. The “.nopar” is for forced paragraph starts after the end of in-line display paragraphs. HTML 4.0 requires opening of such paragraphs.

<..html paragraph breaks at entry to fileNO..>
 \Configure{HtmlPar}{\sva:Par}{\svhtml:par} {}{}
 -_-_-

<..empty html paragraph breaks..>
 \Configure{HtmlPar}{}{}{}{}%
 -_-_-

<..general utilities..>+
 \def\SaveEverypar{%
    \expandafter\ifx\csname ht:everypar\endcsname\relax
       \expand:after{\expandafter\gdef\csname \n:list L\endcsname }%
            \expandafter{\expandafter\everypar
                         \expandafter{\the\everypar}}%
    \else
       \expand:after{\expandafter\gdef\csname \n:list L\endcsname }%
            \expandafter{\expandafter\ht:everypar
                         \expandafter{\the\ht:everypar}}%
    \fi
    \expandafter\xdef\csname \n:list X\endcsname{%
       \if:removeindent  \global\noexpand\:removeindenttrue
       \else             \global\noexpand\:removeindentfalse \fi
       \if:nopar         \global\noexpand\:nopartrue
       \else             \global\noexpand\:noparfalse \fi}%
    \HtmlEnv     \csname \n:list X\endcsname
                 \csname \n:list L\endcsname
    \gHAdvance\n:list by  1
 }
 \def\RecallEverypar{\ifnum \n:list<1
       \:warning{\noexpand\RecallEverypar without \noexpand\SaveEverypar}%
    \else
       \HtmlEnv
       \gHAdvance\n:list by -1
       \csname \n:list X\endcsname
       \csname \n:list L\endcsname
    \fi
 }
 \def\n:list{0}
 -_-_-