Chapter 1
Outline of the Code

   1.1 TeX4ht
   1.2 Support for ProTex
   1.3 Support for httex
   1.4 First Pass
      Start Preamble
      End Preamble
      Selecting Preamble
   1.5 LaTeX at First Pass
   1.6 Second Pass
   1.7 Copyright Note
   1.8 Category Codes
   1.9 Ifs
   1.10 User File Requests
   1.11 Usepackage Interface for LaTeX
   1.12 Utilities

1.1 TeX4ht

<..tex4ht..>
 \ifnum\the\catcode‘\%=14\else\expandafter\edef\csname
   \string:RestoreCatcodes\endcsname{\catcode‘\%=\the
   \catcode‘\%}\catcode‘\%=14\fi
 <.copyright.>
 \ifx  \Preamble\UnDef  \else
    \csname expand:after\endcsname{\csname
        BeforeTeXIVht\endcsname\let\BeforeTeXIVht=\UnDef}
 \fi
 <.save cat codes.>
 <.ifs for TeX4ht.>
 <.check if latex.>
 \ifx  \Preamble\UnDef
     \ifx \PLATFORM\:UnDef \else
         \message{ [\PLATFORM] }\let\PLATFORM=\:UnDef\fi
     <.early utilities.>
     <.first pass.>
     <.first pass for latex.>
     \expandafter\ifx \csname tex4ht\endcsname\relax
        \let\:temp=\empty
     \else
        <.temp := auto load Preamble.>
     \fi
     \let\:tempc=\:temp
     <.def early latex ifOption.>
     \pend:def\:tempc{\:RestoreCatcodes }
     \append:def\:tempc{\endinput}
     \let\:temp=\:tempc
     \expandafter\:temp
 \fi
 <.second pass.>
 \ifx \Hinput\:UnDef \else
   \Hinput{tex4ht2}
   <.load protex.>
 \fi
 <.TeXivht = user file requests.>
 <.html-end of style file.>
 \rmv:ifs  \let\rmv:ifs=\:UnDef
 \:RestoreCatcodes    \TeXivht
 \endinput
  -_-_-

<..load sub tex4ht styles..>
 \ifHtml      \def\:tempa{\:Hinclude}
 \else
     \:CheckOption{th4}\if:Option  \def\:tempa{\input th4.4ht}
     \else  \let\:tempa=\empty \fi
 \fi
 \:CheckOption{core} \if:Option  \let\:tempa=\empty \fi
 \:CheckOption{base} \if:Option  \let\:tempa=\empty \fi
 \:tempa
 -_-_-

We have in amsmath

<..utilities..>
 \def\HLet#1{%
    \expandafter\ifx
       \csname o:\expandafter\:gobble\string#1:\endcsname\relax
       <.save old def of macro.>%
    \fi
    <.selector between old and new def.>%
    \expandafter\let
    \csname n:\expandafter\:gobble\string#1:\endcsname}
 -_-_-

The original definition of \..... is stored in \o:...:, and the new one in \n:....:. The selector is outside the \ifx so that the \HLet will work also on macros restored with \HRestore.

<..utilities..>+
 \def\HRestore#1{\relax
    \expandafter\ifx
       \csname o:\expandafter\:gobble\string#1:\endcsname\relax
         \:warning{\string\HRestore\noexpand#1?}%
    \else
       \expand:after{\let#1=}\csname o:\expandafter
           \:gobble\string#1:\endcsname
    \fi}%
 -_-_-

Don’t erase the o:...:, just in case a saving with let is done before restoring.

<..save old def of macro..>
 \expandafter\let
    \csname o:\expandafter\:gobble\string#1:\endcsname=#1%
 -_-_-

<..selector between old and new def..>
 \edef#1{\noexpand\ifx \noexpand\EndPicture\noexpand\:UnDef
    \noexpand\expandafter \expandafter\noexpand
       \csname n:\expandafter\:gobble\string#1:\endcsname
    \noexpand\else \noexpand\expandafter \expandafter\noexpand
       \csname o:\expandafter\:gobble\string#1:\endcsname
  \noexpand\fi}%
 -_-_-

1.2 Support for ProTex

<..first pass..>
 \NewConfigure{ProTex}[1]{\def\a:ProTex{#1}}
 -_-_-

<..load protex..>
 \ifx \a:ProTex\:UnDef
 \else \input ProTex.4ht \fi
 -_-_-

1.3 Support for httex

<..temp := auto load Preamble..>
 <.util for extracting options.>
 <.options from /tex4ht.>
 \expandafter\expandafter\expandafter
    \:temp\csname tex4ht\endcsname <.par del.>%
 \ifx \:temp\relax
    <.temp := load tex /Preample.>
    \if:latex \let\:temp=\empty \fi
 \else
    \if:latex
       \let\config:file=\:temp  \let\:temp=\empty
    \else
       \edef\:temp{\noexpand\input \:temp\space}
 \fi \fi
 -_-_-

<..extract tex4ht options..>
 \ifx \:temp\relax
    \let\:tempd=\:temp
    \let\:tempc=\empty \config:opt #1,#2,<.par del.>%
 \else     \:temp
    \let\:tempd=\:temp
    \let\:tempc=\empty \config:opt #2,<.par del.>%
 \fi
 \let\config:opt=\:tempc
 \let\:temp=\:tempd
 -_-_-

<..util for extracting options..>
 \def\:tempc#1#2.#3<.par del.>{\edef\:tempa{#3}\edef\:temp{%
    #1\ifx \:tempa\empty  .cfg\fi}}
 \def\config:opt#1,#2<.par del.>{\def\:temp{#1}\ifx \:temp\empty
    \else \ifx \:tempc\empty
          \def\:tempc{#1}%
       \else
          \append:def\:tempc{,#1}
    \fi\fi
    \def\:temp{#2}\ifx \:temp\empty
    \else \def\:temp{\config:opt #2<.par del.>}\fi
    \:temp}
 -_-_-

<..temp := load tex /Preample..>
 \ifx \config:opt\:UnDef
    \edef\config:opt{\ifx \config:file\empty html\fi}\fi
 \def\:temp{\expandafter\expandafter\expandafter
    \Preamble\expandafter{\config:opt}\EndPreamble}
 -_-_-

1.4 First Pass

<..first pass..>+
 \ifx \Log:Needs\:UnDef \else
    \:warning{Again ‘\noexpand\input tex4ht.sty’?}\fi
 <.check that TeX4ht is not loaded after protex.>  still necessary?
 <.define for /Preamble.>
 <.define /Preamble.>
 -_-_-

<..check if latex..>
 \expandafter\ifx \csname @latex@error\endcsname\relax
     \:latexfalse  \tracingstats=1
 \else
    \if:latex\else <.usepackage for latex.>\fi
    \:latextrue
    \ifx \:providesfile \:UnDef
       \let\:providesfile\@providesfile
       \def\@providesfile#1{%
          \expandafter\ifx\csname @filelist\endcsname\relax
                \let\@providesfile\:providesfile
          \else \xdef\@filelist{\@filelist,#1}%
          \fi
          \:providesfile{#1}%
       }
    \fi
 \fi
 -_-_-

Start Preamble

<..define /Preamble..>
 \def\:Preamble{\ifx \:next[%
   \def\Preamble[##1]##2{\egroup
     <./def/Preamble(@@2).>\input ##1
     }
   \else
   \def\Preamble##1{\egroup <./def/Preamble(@@1).>%
                   \input <.TeX4ht name.>.sty }
   \fi        \let\:Preamble=\:UnDef     \Preamble  }
 \def\Preamble{\bgroup  \catcode‘\@=12   \catcode‘\_=8  \catcode‘\^=7
   \futurelet\:next\:Preamble}
 -_-_-

With the following definitions we can replace \input tex4ht.sty \Htmltrue .... \Htmlfalse \Preamble{html,...} with \input tex4ht.sty \Htmltrue .... \Preamble{...} for defining html-enabled code between the \input and the \Preamble. That is, for using code that employs the \ifHtml command.

<../def/Preamble(@@1)..>
 <.def :CheckOption.>%
 \ifHtml  \Htmlfalse
      \def\Preamble{html,##1}\else \def\Preamble{##1}\fi
 <.config options for /usepackage and httex.>%
 <.extract Hinclude.>%
 -_-_-

<../def/Preamble(@@2)..>
 <.def :CheckOption.>%
 \ifHtml  \Htmlfalse
      \def\Preamble{html,##2}\else \def\Preamble{##2}\fi
 <.config options for /usepackage and httex.>%
 <.extract Hinclude.>%
 -_-_-

End Preamble

<..define /Preamble..>+
 \def\EndPreamble{\b:Preamble \global\let\missing:endpream\empty
   \csname <.live.>\file:id\endcsname \B:DY}
 \def\B:DY{<.html paragraph breaks at entry to file.>%
   \HtmlEnv \IgnorePar \IgnoreIndent {\ht:everypar{}\leavevmode}\a:BODY
   \csname a:@BODY\endcsname}
 \def\missing:endpream{\:warning{Missing \string\EndPreamble}}
 -_-_-

<..close html doc..>
 \missing:endpream
 -_-_-

<..define /Preamble..>+
 \NewConfigure{@HTML}[1]{\concat:config\a:@HTML{#1}}
 \let\a:@HTML=\empty
 -_-_-

<..needs preamble..>
 \:tempb
 -_-_-

<..html config util..>
 \NewConfigure{Preamble}{2}
 -_-_-

<..remove garbage..>
 \ifHtml \else \let\EndPreamble=\empty \fi
 -_-_-

Selecting Preamble

<..def :CheckOption..>
 \def\:CheckOption####1{\def\:temp{####1}%
    \:Optionfalse
    \expandafter\:ScanOptions\Preamble,,//}
 \def\:ScanOptions####1,####2//{\def\:next{####1}%
    \ifx        \:next\empty
    \else \ifx  \:temp\:next   \:Optiontrue   \let\:next=\relax
    \else \def\:next{\:ScanOptions####2//}%
    \fi  \fi  \:next }
 -_-_-

<..Hinput Configs..>
 \def\:temp{\def\ifOption##1}
 \expandafter\expandafter\expandafter\:temp
    \expandafter{\Preamble,,//\if:Option
    <.ifOption true.>\else <.ifOption false.>\fi  \tmp:toks=}
 \pend:defI\ifOption{\def\:temp{##1}\:Optionfalse\:ScanOptions}
 -_-_-

<..ifOption false..>
 \def\:temp{%
    \def\:temp{\the\tmp:toks}%
    \afterassignment\:temp \tmp:toks=}%
 \afterassignment\:temp
 -_-_-

<..ifOption true..>
 \def\:temp{\the\tmp:toks
    \def\:temp{\tmp:toks={}}%
    \afterassignment\:temp \tmp:toks=}%
 \afterassignment\:temp
 -_-_-

The \ifOption is implemented through a token list variable to allow for nesting in macros and if statements. The older definition hid the \if under \ifOption and exposed just the \else and \fi.

<..new ifs..>
 \:tempa{if:Option}
 -_-_-

The following code defines \ifOption just for flags defined in the comamnd line (that is, flags known the first time tex4ht.sty is loaded). It doesn’t yet see those options introduced by \Preamble and the *.4ht files.

<..def early latex ifOption..>
 \ifx \config:opt\:UnDef \else
    \ifx\tmp:toks\:UnDeF    \csname newtoks\endcsname\tmp:toks\fi
    \def\:temp{\def\ifOption##1}
    \expandafter\expandafter\expandafter\:temp
         \expandafter{\config:opt,,//\if:Option
    <.ifOption true.>\else <.ifOption false.>\fi  \tmp:toks=}
    \pend:defI\ifOption{\def\:temp{##1}\:Optionfalse\:ScanOptions}
 \fi
 -_-_-

1.5 LaTeX at First Pass

<..first pass for latex..>
 \if:latex
    <.try taking care of hyperref.sty.>
    <.early latex subs/sups.>
 \fi
 <.hook at usepackage.>
 -_-_-

The following is a temporary patch, waiting fo a fix in hyperref.sty.

<..try taking care of hyperref.sty..>
 \expandafter\def\csname [email protected]\endcsname{tex4ht}
 -_-_-

<..hook at usepackage..>
 \let\:onefilewithoptions\@onefilewithoptions
 \def\@onefilewithoptions#1[{%
    \let\:temp\@reset@ptions
    \def\@reset@ptions{%
       \let\@reset@ptions\:temp
       <.cats for usepackage.>\a:usepackage
       <.recall usepackage cats.>}%
    \:onefilewithoptions#1[}
 \def\a:usepackage{\input usepackage.4ht }
 -_-_-

<..cats for usepackage..>
 \edef\TivhTcats{%
    \catcode‘:=\the\catcode‘:%
    \catcode‘@=\the\catcode‘@}%
 \catcode‘\:=11 \catcode‘\@=11
 -_-_-

<..recall usepackage cats..>
 \TivhTcats
 -_-_-

1.6 Second Pass

The definitions of the configurations should be ready before \Hinput is called for loading their values. The cross references also need to be resolved at that point (for the TITLE+, and possibly other usages).

<..second pass..>
 <.html option.>                  should be first
 <.html+nohtml common to TeX4ht and protex.>
 <.utilities.>
 <.cross references.>
 \ifHtml
    <.Hinput Configs.>
    \Hinput{Preamble}  \ht:special{t4ht.\:html}
    <.scripting commands.>
    <.html Configure’s.>
    \Hinput{tex4ht}
    <.hook on end.>
 \fi
 <.divisions.>
 <.files.>
 <.cut points.>
 <.imports.>
 <.lists.>
 <.blocs for tocs.>
 \ifHtml
    <.halign-based tables.>
 \fi
 <.streams.>
 <.gif.>
 <.fonts.>
 <.math.>
 <.core tex.>
 <.at doc start.>  after Preamble
 \ifHtml
    <.dvi-based hooks.>
    <.more html tex.>
 \fi
 <.local env.>                     after accents, {\vrb:tt\‘} in particular
 \ifx\beginL\@undefined \else
    \ifHtml
       <.e tex.>
       \Hinput{etex4ht}
 \fi\fi
 <.load sub tex4ht styles.>
 <.debug.>
 <.remove garbage.>
 \ifHtml <.start html doc.> \fi   should be last
 -_-_-

1.7 Copyright Note

<..TeX4ht copyright..>
 %
 % This work may be distributed and/or modified under the
 % conditions of the LaTeX Project Public License, either
 % version 1.3c of this license or (at your option) any
 % later version. The latest version of this license is in
 %   http://www.latex-project.org/lppl.txt
 % and version 1.3c or later is part of all distributions
 % of LaTeX version 2005/12/01 or later.
 %
 % This work has the LPPL maintenance status "maintained".
 %
 % The Current Maintainer of this work
 % is the TeX4ht Project <http://tug.org/tex4ht>.
 %
 % If you modify this program, changing the
 % version identification would be appreciated.-_-_-

<..TeX4ht copywrite..>
 <.TeX4ht copyright.>\immediate\write-1{version 2014-07-02-18:09}
 -_-_-

<..copyright..>
 % tex4ht.sty (2014-07-02-18:09), generated from tex4ht-sty.tex
 % Copyright (C) 1996-2009 Eitan M. Gurari
 <.TeX4ht copywrite.>
 -_-_-

1.8 Category Codes

<..save cat codes..>
 \expandafter\edef\csname :RestoreCatcodes\endcsname{%
    \expandafter\ifx \csname :RestoreCatcodes\endcsname\relax\else
       \csname :RestoreCatcodes\endcsname \fi
    \ifnum \the\catcode‘\ =10 \else
       \catcode‘\noexpand\ =\the\catcode‘\ \fi
    \ifnum \the\catcode‘<=12 \else
       \catcode‘\noexpand <=\the\catcode‘<\fi
    \ifnum \the\catcode‘>=12 \else
       \catcode‘\noexpand >=\the\catcode‘>\fi
    \ifnum \the\catcode‘\?=12 \else
       \catcode‘\noexpand \?=\the\catcode‘\?\fi
    \ifnum \the\catcode‘+=12 \else
       \catcode‘\noexpand +=\the\catcode‘+\fi
    \ifnum \the\catcode‘*=12 \else
       \catcode‘\noexpand *=\the\catcode‘*\fi
    \ifnum \the\catcode‘;=12 \else
       \catcode‘\noexpand ;=\the\catcode‘;\fi
    \ifnum \the\catcode‘~=13 \else
       \catcode‘\noexpand ~=\the\catcode‘~\fi
    \ifnum \the\catcode‘$=3 \else
       \catcode‘\noexpand $=\the\catcode‘$\fi
    \ifnum \the\catcode‘&=4 \else
       \catcode‘\noexpand &=\the\catcode‘&\fi
    \ifnum \the\catcode‘\#=6 \else
       \catcode‘\noexpand \#=\the\catcode‘\#\fi
    \catcode‘\noexpand :=\the\catcode‘:%
    \catcode‘\noexpand "=\the\catcode‘"%
    \catcode‘\noexpand @=\the\catcode‘@%
    \catcode‘\noexpand _=\the\catcode‘_%
    \catcode‘\noexpand ^=\the\catcode‘^%
    \catcode‘\noexpand |=\the\catcode‘|%
    \csname no:restore\endcsname
    <.sp and sb for catcode 13.>%
    \let\expandafter\noexpand\csname :RestoreCatcodes\endcsname=
                                    \noexpand\UnDefcS}
 \catcode‘~=13  \catcode‘$=3   \catcode‘&=4  \catcode‘\#=6
 \catcode‘\:=11 \catcode‘\@=11 \catcode‘;=12 \catcode‘\ =10
 \catcode‘\<=12 \catcode‘\>=12 \catcode‘+=12 \catcode‘*=12
 \catcode‘\?=12
 <.record external sub-sup.>
 \catcode‘\^=7 \catcode‘\|=12  \catcode‘"=12
 -_-_-

1.9 Ifs

<..ifs for TeX4ht..>
     \def\:temp{\csname newif\endcsname}
     \def\:tempa#1{%
        \expandafter\ifx \csname #1\endcsname\relax
           \expandafter\:temp   \csname #1\endcsname
        \fi}
 <.new ifs.>
     \def\:tempa#1{%
        \expandafter\ifx \csname #1\endcsname\relax
           \expandafter\:temp   \csname #1\endcsname
           \expandafter\expandafter\expandafter\expandafter\expandafter
              \def\expandafter\expandafter\expandafter
              \rmv:ifs\expandafter{\rmv:ifs
              \expandafter\let \csname #1\endcsname = \:UnDef}
        \fi}
     \let\rmv:ifs=\empty
 <.temp tex ifs.>
 -_-_-

The temporary ifs are needed only for loading time to allow TeX to scan material that will not be loaded.

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

1.10 User File Requests

<..TeXivht = user file requests..>
 \def\:usersty#1,#2<.par del.>{\def\:temp{#1}%
    \ifx \:temp\empty \else
       \expandafter\ifx \csname #1\endcsname\relax
          \expandafter\let \csname #1\endcsname=\empty
          \input #1
       \fi
       \def\:temp{#2}\expandafter\:temp
    \fi}
 \edef\TeXivht{\expandafter\ifx \csname TeXivht\endcsname\relax
   \else \noexpand\:usersty\TeXivht,<.par del.>\fi
   \let\noexpand\TeXivht=\noexpand\:UnDef
   \let\noexpand\:usersty=\noexpand\:UnDef  }
 -_-_-

1.11 Usepackage Interface for LaTeX

<..usepackage for latex..>
 \ifx \@currname\empty
    <.requires /Preamble.../EndPreamble.>
 \else
    <.TeX4ht loaded with /usepackage.>
 \fi
 -_-_-

Three ways for loading TeX4ht in LaTeX

  1. With \usepackage{tex4ht}.
    \usepackage{tex4ht} 
    \begin{document} 

    It assumes a configuration file named atex4ht.cfg’. If none is offered, the folowing code is available.

    \Preamble{html} 
       \begin{document} 
    \EndPreamble 

  2. With \usepackage[file-name]{tex4ht}. As before, but with a configuration file file-name, instead of in latex4ht.cfg. The extension .cfg is assumed, if none is provided.

  3. With inline (instead of off-line) configurartion file, e.g., like \input tex4ht.sty \Preamble{html} \begin{document} \EndPreamble

The indirection below on \enddocument is needed for AmsTeX; there the command is defined as outer.

<..TeX4ht loaded with /usepackage..>
 \ProvidesPackage{tex4ht}
 \let\config:file=\empty
 <.options from /usepackage.>
 \DeclareOption*{\load:cfg}
 \ProcessOptions
 \let\o:document=\document
 \def\document{%
    <.check irregularities.>%
    \expandafter\let\csname enddocument\endcsname=\empty
    \end{document}%
    <.protect AtBeginDocument.>%
    \let\document=\o:document
    \let\:latex@error=\@latex@error
    \def\@latex@error##1{\:latex@error{##1 in ‘\config:file’}}%
    <.load latex /Preample.>%
    \let\@latex@error=\:latex@error
 }
 -_-_-

<..check irregularities..>
 \let\ht:empty=\:UnDef
 \def\:temp{}\ifx \:temp\empty \else
   \gdef\:temp{}\ifx \:temp\empty \else
      \:warning{Redefined \string\empty?}
      \global\let\ht:empty=\empty \gdef\empty{}%
 \fi\fi
 -_-_-

<..load latex /Preample..>
 <./document recall sub/sup.>%
 \ifx \config:file\empty
    \def\:temp{<.default latex cfg file.>}%
 \else
    \def\:temp{<.user config file.>}%
 \fi \:temp
 -_-_-

<..early Configure..>
 <.concat config.>
 \NewConfigure{AtBeginDocument}[2]{%
    \def\:temp{#1#2}\ifx \:temp\empty
      \concat:config\a:AtBeginDocument{}
      \concat:config\b:AtBeginDocument{}%
    \else
      \concat:config\a:AtBeginDocument{#1\relax}%
      \concat:config\b:AtBeginDocument{#2\relax}%
    \fi
    \global\let\a:AtBeginDocument=\a:AtBeginDocument
    \global\let\b:AtBeginDocument=\b:AtBeginDocument
 }
 \Configure{AtBeginDocument}{}{}
 -_-_-

<..protect AtBeginDocument..>
 \let\:begindocumenthook=\@begindocumenthook
 \def\@begindocumenthook{\csname a:AtBeginDocument\endcsname
 \:begindocumenthook \csname b:AtBeginDocument\endcsname }%
 -_-_-

In optional parameters, the first one is assumed to be a file name. A fake file name should be inserted, when we want none.

<..default latex cfg file..>
 \ifx \config:opt\:UnDef
    \edef\config:opt{\ifx \config:file\empty html\fi}\fi
 \expandafter\Preamble\expandafter{\config:opt
    }\csname begin\endcsname{document}\EndPreamble
 -_-_-

\begin is defined as outer in texi, hence thr \csname.

<..default tex cfg file..>
 \ifx \config:opt\:UnDef
    \edef\config:opt{\ifx \config:file\empty html\fi}\fi
 \expandafter\Preamble\expandafter{\config:opt
    }\EndPreamble
 -_-_-

<..user config file..>
 \input \config:file\relax
 -_-_-

<..config options for /usepackage and httex..>
 \ifx \config:opt\:UnDef
    \let\:temp=\Preamble
 \else
    \expandafter\expandafter\expandafter\def
    \expandafter\expandafter\expandafter\:temp
    \expandafter\expandafter\expandafter{%
    \expandafter\config:opt\expandafter,\Preamble}%
 \fi
 \let\Preamble=\empty
 \expandafter\set:Preamble\:temp,<.par del.>%
 -_-_-

The following removes duplications in \Preamble. Important, in particular, when 4ht configuration files are included in the list of options.

<..define for /Preamble..>
 \def\set:Preamble#1,#2<.par del.>{%
    \def\:temp{#1}\ifx \:temp\empty \else
       \:CheckOption{#1}\if:Option \else
           \ifx \Preamble\empty \def\Preamble{#1}%
           \else                \append:def\Preamble{,#1}%
    \fi \fi \fi
    \def\:temp{#2}\ifx \:temp\empty \let\set:Preamble=\:UnDef
    \else  \expand:after{\set:Preamble#2<.par del.>}\fi
 }
 -_-_-

\ProcessOptions calls \cfg:fl repeatedly for each option.

Empty, or Cfg File

<..options from /usepackage..>
 \def\load:cfg{<.2nd option.>%
    \def\:temp{\expandafter\cfg:fl\CurrentOption.<.par del.>}%
    \def\:tempa{html}\ifx \:tempa\CurrentOption \let\:temp=\load:cfg \fi
    \def\:tempa{xhtml}\ifx \:tempa\CurrentOption \let\:temp=\load:cfg \fi
    \def\:tempa{htm}\ifx \:tempa\CurrentOption \let\:temp=\load:cfg \fi
    \def\:tempa{htm3}\ifx \:tempa\CurrentOption \let\:temp=\load:cfg \fi
    \def\:tempa{htm4}\ifx \:tempa\CurrentOption \let\:temp=\load:cfg \fi
    \def\:tempa{htm5}\ifx \:tempa\CurrentOption \let\:temp=\load:cfg \fi
    \:temp
 }
 \def\cfg:fl#1.#2<.par del.>{\edef\:tempa{#2}\edef\config:file{%
    \CurrentOption \ifx \:tempa\empty  .cfg\fi}}
 -_-_-

<..options from /tex4ht..>
 \def\:temp#1,#2<.par del.>{%
    \def\:temp{\:tempc{#1}#1.<.par del.>}%
    \def\:tempb{#1}\ifx   \:tempb\empty  \let\:temp=\relax \fi
    \def\:tempa{html}\ifx \:tempa\:tempb \let\:temp=\relax \fi
    \def\:tempa{xhtml}\ifx\:tempa\:tempb \let\:temp=\relax \fi
    \def\:tempa{htm}\ifx  \:tempa\:tempb \let\:temp=\relax \fi
    \def\:tempa{htm3}\ifx \:tempa\:tempb \let\:temp=\relax \fi
    \def\:tempa{htm4}\ifx \:tempa\:tempb \let\:temp=\relax \fi
    \def\:tempa{htm5}\ifx \:tempa\:tempb \let\:temp=\relax \fi
    <.extract tex4ht options.>%
 }
 -_-_-

First Option for /Preamble

<..2nd option..>
 \def\load:cfg{\let\config:opt=\CurrentOption
    <.options 3....>}%
 -_-_-

Non-First Option for /Preamble

<..options 3.....>
 \def\load:cfg{\edef\config:opt{\config:opt,\CurrentOption}}%
 -_-_-

The following case arises for loading the file with the \input tex4ht.sty command.

<..requires /Preamble.../EndPreamble..>
 \def\:temp{\ifx \HCode\:UnDef
    \:warning{Missing \string\Preamble...\string\EndPreamble?}\fi}
 \edef\:tempa{%
   \noexpand\expandafter
   \noexpand\expandafter
   \noexpand\expandafter
   \noexpand            \def
   \noexpand\expandafter
   \noexpand\expandafter
   \noexpand\expandafter
   \expandafter\noexpand\csname enddocument\endcsname
   \noexpand\expandafter
   \noexpand\expandafter
   \noexpand\expandafter
                       {\noexpand        \expandafter
                        \noexpand        \:temp
            \expandafter\noexpand \csname enddocument\endcsname
                       }%
 }  \:tempa
 -_-_-

1.12 Utilities

<..html utilities..>
 \csname newskip\endcsname\tmp:dim
 -_-_-

<..early utilities..>
 <.def Configure.>
 <.early Configure.>
 -_-_-

<..utilities..>+
           <.general utilities.>
 \ifHtml <.html utilities.> \fi
 -_-_-

There are files, like mathml.4ht, that need to be loaded piecewise because the configuration commands might vary during the loading time. For instance, the \Configure{cases} uses two parameters in plain tex, and the go up into four parameters in amstex.

<..first pass..>+
 \let\:Hincl=\empty
 \def\Hinclude[#1]#2{\xdef\:Hincl{\:Hincl{#1}{#2}}}
 -_-_-

The following extracts \Hinclude frm preamble. For instance, \Preamble{mathml.4ht,foo.4ht,...} is the same as \Hinclude[*]{mathml.4ht}\Hinclude{foo.4ht}\Preamble{...}. The file extensions must be .4ht.

<..extract Hinclude..>
 \def\:temp####1.4ht####2<.par del.>{\def\:temp{####2}%
   \ifx \:temp\empty
     \def\:temp{th4}\ifx \:temp\Preamble \else
       \ht:special{t4ht@[}%
       \input tex4ht.4ht   \ht:special{t4ht@]}%
   \fi \fi}%
 \expandafter\:temp\Preamble.4ht<.par del.>%
 \expandafter\xtrct:hin\Preamble,,<.par del.>%
 <.redefine Hinclud.>%
 -_-_-

<..define for /Preamble..>+
 \def\xtrct:hin#1,{\def\:temp{#1}\ifx \:temp\empty
    \def\xtrct:hin##1<.par del.>{\let\xtrct:hin=\:UnDef}\else
       \def\:tempa##1.4ht##2<.par del.>{%
          \def\:temp{\Hinclude[*]{##1.4ht}}\def\:tempa{##2}}%
       \expandafter\:tempa\:temp .4ht<.par del.>%
       \ifx \:tempa\empty \else \:temp   \fi
    \fi  \xtrct:hin}
 -_-_-

Until \Preamble is encountered, \Hinclude requrests ‘vertiv=cal’ 4ht files (html4,html0, mathml, unicode,...), during \Preamble if requests ‘horizontal’ files (latex, plain,etc), and after the \Preamble it is undefined.

<..redefine Hinclud..>
 \:Hinclude
 -_-_-

<..define for /Preamble..>+
 \def\Use:N{0}
 \let\:USE=\empty
 \def\:Use#1{\:USe #1,,\HAdvance\Use:N by 1 }
 \def\:USe#1,{\def\:temp{#1}\ifx\:temp\empty
      \edef\:temp{\noexpand\append:def\noexpand\:USE{\let\expandafter
       \noexpand\csname Use:\Use:N\endcsname\noexpand\:UnDef}}\:temp
    \else
      \edef\:temp{\noexpand\append:def\noexpand\:USE{\expandafter
       \noexpand\csname Use:\Use:N\endcsname}}\:temp
    \append:def\:USE{{#1}}%
    \expandafter\:USe\fi}
 \def\:Hinclude{%
    \def\Hinclude{\afterassignment\:Use
       \expandafter\def\csname Use:\Use:N\endcsname ####1}%
    \def\:Hinclude{\ifx \:USE \empty
        \let\Hinclude=\:UnDef
        \let\:Hinclude=\:UnDef
        \let\:Use=\:UnDef
        \let\:USe=\:UnDef
        \let\:USE=\:UnDef
      \else
       \pend:def\:USE{\let\:USE=\empty}%
       \expand:after{\:USE \:Hinclude}\fi}%
 }
 -_-_-

Do we want the push/pop below?

<..Hinput Configs..>+
 \let\:Hin=\empty
 \def\Hinput#1{\PushStack\:Hinputs\:Hin \def\:Hin{#1}%
    \expandafter\:Hinput\:Hincl{}{}\PopStack\:Hinputs\:Hin}
 \def\:Hinput#1#2{\def\:temp{#2}\ifx \:temp\empty \else
      \let\:temp=\empty   \def\:tempa{*}\def\:tempb{#1}%
      \ifx \:tempa\:tempb \def\:temp{\input #2}%
      \else \ifx \:Hin\:tempb  \def\:temp{\input #2}%
      \else \def\:tempb{#1.4ht}\ifx \:Hin\:tempb \def\:temp{\input #2}%
      \fi\fi\fi
    \expand:after{\:temp
      <.system NewConfigure.>\:Hinput}\fi}
 -_-_-

<..html utilities..>+
 \def\exit:ifnot#1{%
    \edef\:temp{\def\noexpand\:temp####1,\:Hin,####2..//{%
       \noexpand\if !####2!\noexpand\else
       \noexpand\expandafter\noexpand\:gobble\noexpand\fi
       }\noexpand\:temp,#1,\:Hin,..//}\:temp\endinput }
 -_-_-

<..html utilities..>+
    \catcode‘\@=0
    \catcode‘\\=12
 @def@ConfigureHinput{%
    @def@:temp##1{%
       @def@:temp{##1}@ifx@:temp@:Hin @else @:tempb @fi }%
    @def@:tempb{@fi@bgroup @no:catcodes0{255}{12}%
       @no:catcodes{101}{101}{11}%
       @no:catcodes{109}{109}{11}%
       @no:catcodes{112}{112}{11}%
       @no:catcodes{116}{116}{11}%
       @no:catcodes{121}{121}{11}%
       @:tempa}
    @def@:tempa##1\empty\empty\empty\empty\empty\empty{@egroup}%
    @:temp
 }
    @catcode‘@\=0
    \catcode‘\@=11
 -_-_-

<..early utilities..>+
 \catcode‘\#=12   \def\#{#}   \catcode‘\#=6
 -_-_-

The starred command is for immediate expansion

Can we avoid the following file?

<..general utilities..>
 \immediate\openout15=\jobname.tmp
 \bgroup \escapechar=‘\\
    \immediate\write15{\def\string\Jobname{\jobname}}
 \egroup
 \immediate\closeout15
 \input \jobname.tmp
 
 \def\get:input#1{%
    \openin15=#1
    \ifeof15  \closein15  \:warning{No file #1}%
    \else     \closein15  \expand:after{\input #1 }%
    \fi}
 -_-_-

<..general utilities..>+
 \def\if:notempty#1#2{%
    \def\:temp{#1}\ifx \:temp\empty \else \expand:after{#2}\fi }
 -_-_-