Chapter 8
Subdivisions

   8.1 Interface
      /Configure
   8.2 Insertions at Boundaries of Logical Units
      Non Cut Ends
      Cut Ends
      Common Utilities
   8.3 Building Blocks
   8.4 Title
   8.5 Table of Contents
   8.6 Links
   8.7 Control Links on Section Heads
   8.8 Cut-Offs
   8.9 Hooks
   8.10 Utilities
   8.11 Configurations for CutAt

<..divisions..>
 <.elements for divs.>
 <.no trace sec config.>
 \ifHtml  <.html divs.>
    \:CheckOption{hooks+}  \if:Option
       \else \:CheckOption{hooks} \fi
    \if:Option  <.trace sec config.>\fi
 \fi
 <.tex divisions.>
 -_-_-

8.1 Interface

The first parameter of \Def:Section provides the command name, the second gives a non-parametric code that produces the title number, and the third gives a single-parameter code for producing the title itself.

<..elements for divs..>
 \long\def\NewSection#1#2{%
    \Def:Section#1{#2}{##1}%
    \edef\:temp{\expandafter\:gobble\string#1}%
    \Configure:Sec\:temp{}{}{}{}%
    \ConfigureToc{\expandafter\:gobble\string#1}{\empty}{\empty}{}{}}
 -_-_-

\NewSection\DocChapter {counter}

The parameter ##1 holds the title head.

<..endsection config..>
 \NewConfigure{end#1}[1]{\expandafter
    \def\csname a:end#1\endcsname{##1}}%
 \Configure{end#1}{}
 -_-_-

<..elements for divs..>+
 \def\Def:Section#1{%
    \edef\:tempc{{\expandafter\:gobble \string#1}}%
    <.Configure for sectioning command.>%
    \futurelet\:temp\ch:NewSec}
 \def\ch:NewSec{\if *\:temp\let\if:toc=\:gobble\expandafter\op:NewSec
                \else  \let\if:toc=\empty  \expand:after{\op:NewSec+}\fi}
 \def\op:NewSec#1{\expandafter\:NewSec\:tempc}
 <.def /:Every.>%
 \def\:NewSec#1#2{%
    <.endsection config.>%
    \expandafter\def\csname #1\endcsname{%
       \expand:after{\let\if:toc=}\csname if:#1toc\endcsname
       \:StartSec{#1}{#2}}%
    <.c:TITLE: for Sec.>%
    \expandafter\let\csname if:#1toc\endcsname=\if:toc
    <.initiate BeforeEvery/Every div.>%
    \expandafter\def\csname #1:ttl\endcsname##1}
 -_-_-

\Def:Section + \Configure = \NewSection

/Configure

<..no trace sec config..>
 \long\def\Configure:Sec#1#2#3#4#5{%
   \expandafter\ifx\csname c:#1\endcsname\relax \let\:tempa=\relax \else
   \def\:tempa{#4#5}\fi  \ifx\:tempa\empty \else
      <.conf for sec boundaries.>\fi
   \expandafter\ifx\csname a:#1\endcsname\relax \let\:tempa=\relax \else
   \def\:tempa{#2#3}\fi  \ifx\:tempa\empty \else
      \expandafter\def\csname a:#1\endcsname##1{#2}%
      \expandafter\def\csname b:#1\endcsname##1{#3}%
   \fi
 }
 -_-_-

Note that in \Configure{Section}{before}{after}{before head}{after head} a change occures only when before-after pair is not empty.

<..trace sec config..>
 \long\def\Configure:Sec#1#2#3#4#5{%
   \expandafter\ifx\csname c:#1\endcsname\relax \let\:tempa=\relax \else
   \def\:tempa{#4#5}\fi  \ifx\:tempa\empty \else
      <.conf for sec boundaries.>\fi
   \expandafter\ifx\csname a:#1\endcsname\relax \let\:tempa=\relax \else
   \def\:tempa{#2#3}\fi  \ifx\:tempa\empty \else
      <.conf for sec heads.>\fi
 }
 -_-_-

<..conf for sec heads..>
   \def\:tempa{#2}\ifx \:tempa\empty
      \expandafter\def\csname a:#1\endcsname
          ##1{\hbox{\a:trc #13:4\b:trc}#2\hbox{\c:trc #14:4\d:trc}}%
   \else
      \expandafter\def\csname a:#1\endcsname##1{#2}%
   \fi
   \def\:tempa{#3}\ifx \:tempa\empty
      \expandafter\def\csname b:#1\endcsname
          ##1{\hbox{\a:trc #13:4\b:trc}#3\hbox{\c:trc #14:4\d:trc}}%
   \else
      \expandafter\def\csname b:#1\endcsname##1{#3}%
 \fi
 -_-_-

<..conf for sec boundaries..>
 \expandafter\c:def\csname c:#1\endcsname{#4}%
 \expandafter\c:def\csname d:#1\endcsname{#5}%
 -_-_-

<..Configure for sectioning command..>
 \edef\:temp{\long\def\expandafter\noexpand \csname
     c:\expandafter\:gobble \string#1:\endcsname
       ####1####2####3####4{\noexpand
       \Configure:Sec\:tempc{####3}{####4}{####1}{####2}}%
    \noexpand\NewConfigure{CutAt\expandafter\:gobble \string#1}2%
    \noexpand\NewConfigure{+CutAt\expandafter\:gobble \string#1}2%
    }\:temp  \expandafter\Configure\:tempc{\empty}{}{\empty}{}%
 -_-_-

8.2 Insertions at Boundaries of Logical Units

Non Cut Ends

<..boundaries of non-cut sections..>
 \def\:tempa{#1}\noct:Close:Until
 \ifx \:tempb \empty \else
    \csname d:\ifx \found:\empty #1\else \found:\fi\endcsname \fi
 <.advance TitleCount.>\csname c:#1\endcsname
 -_-_-

Any need for \def\:tempa{#1}?

<..document end for non-cut logical units..>
 \Close:UntilEnd
 -_-_-

The following \Do:Close’s deal with sectioning unit at levels deeper than one we are openning. The sectioning unit at the latter level is closed with the code \csname d:\ifx \found:\empty #1\else \found:\fi\endcsname we just proccessed.

<..html divs..>
 \def\noct:Close:Until{%
    \let\:tempA=\sec:typ  \let\found:=\empty
    \let\:tempd=\:Sections    \noct:Check:Until
    \ifx \:tempb\sec:typ \expandafter\Do:Close  \fi
    \let\sec:typ=\:tempA
 }
 \def\noct:Check:Until{%
    \ifx \:tempd\empty  <.exit non-cut check-until.>\else
       \PopStack\:tempd\:tempb
       <.search non-cut end.>%
       \ifx \:tempb\sec:typ \else
          \expandafter\expandafter\expandafter\noct:Check:Until
    \fi\fi }
 -_-_-

We are about to open a new section unit, and we go as down as possible in the stack of already openned section units searching for the lowest unit in the stack that should be closed. The \found: variable holds the lowest oppened unit to be closed.

<..exit non-cut check-until..>
 \ifx \found:\empty  \let\:tempb\empty
 \else  \let\:tempb=\found: \let\sec:typ=\found:\fi
 -_-_-

<..search non-cut end..>
 \edef\:tempe{\:tempb,%
    \expandafter\ifx \csname a:end\:tempb\endcsname\relax \else
      \csname a:end\:tempb\endcsname \fi,,}%
 \expandafter\mod:typ\:tempe<.par del.>%
 -_-_-

<..html divs..>+
 \def\mod:typ#1,#2<.par del.>{%
    \def\:temp{#1}\ifx \:temp\empty\else
       \edef\:temp{\expandafter\expandafter\expandafter
          \:gobble\expandafter\string \csname #1\endcsname}%
       \ifx \sec:typ\:temp
            \let\found:=\:tempb  \let\:temp=\empty
       \else \def\:temp{\mod:typ#2<.par del.>}\fi
    \fi \:temp
 }
 -_-_-

Cut Ends

<..boundaries of cut sections..>
 \Configure{CutAt#1}{<.advance TitleCount.>\csname c:#1\endcsname
       }{\def\sec:typ{#1}\Close:Until \csname d:#1\endcsname}%
 -_-_-

<..html divs..>+
 \def\Close:Until{%
    \let\:tempd=\:Sections    \Check:Until
    \ifx \:tempb\sec:typ \expandafter\Do:Close  \fi
 }
 \def\Check:Until{
    \ifx \:tempd\empty  \let\:tempb=\empty \else
         \PopStack\:tempd\:tempb
        \ifx \:tempb\sec:typ \else
       \expandafter\expandafter\expandafter\Check:Until
    \fi\fi }
 -_-_-

Common Utilities

<..record sections hierarchy..>
 \PushStack\:Sections{#1}%
 -_-_-

<..html divs..>+
 \PushStack\:Sections{}%
 \PopStack\:Sections\:temp
 \def\Do:Close{%
    \PopStack\:Sections\:tempb
    \ifx \sec:typ\:tempb \else
       \csname d:\:tempb\endcsname
       \expandafter\Do:Close
    \fi
 }
 -_-_-

The following is for closing logical units at the end of the file, when they don’t have hypertext pages of their own.

<..html divs..>+
 \def\Close:UntilEnd{%
    \ifx \:Sections\empty  \let\:tempb=\empty
    \else  \PopStack\:Sections\:tempb  \fi
    \ifx \:tempb\empty \else
       \csname d:\:tempb\endcsname
       \expandafter\Close:UntilEnd
    \fi
 }
 -_-_-

8.3 Building Blocks

The \ref, \Tag, \@currentlabel, and \cur:th are for latex. Also note that label and \ref can appear within titles, and there we nullify them except within the titles themselves and tocs. One problem with the \ref is that they may cause nested links.

<..html divs..>+
 \def\:StartSec#1#2#3{%
    \def\title:chs##1##2{##2}%
    \def\sec:typ{#1}%
    <.delayed TocAt.>%
    \a:NoSection
    <.round ids between sections.>%
    <.button for cut at sect.>%
    <.BeforeEvery hook.>%
    \expandafter\ifx \csname a:#1\endcsname\relax  \else
       \csname a:#1\endcsname{#3}%
    \fi
    \b:NoSection \:Ttle{#1}{#2}{\csname #1:ttl\endcsname{#3}}%
    \a:NoSection
    \expandafter\ifx \csname b:#1\endcsname\relax   \else
       \csname b:#1\endcsname{#3}%
    \fi
    <.Every hook.>%
    \csname a:AfterTitle\endcsname   \b:NoSection
    \def\title:chs##1##2{##1}%
 }
 \def\title:chs#1#2{#1}
 -_-_-

<..shared config..>+
 \NewConfigure{NoSection}{2}
 -_-_-

The \par before |<Every hook|> is to ensure the use of \ShowPar. Well, the \par turned out to be a pain in cases we want no space at all. Hence, we took it out.

On the other hands, we try to make sectioning commands fixed points for labels. Hence, we try to reduce sensitivity of tocs to changes.

<..round ids between sections..>
 \ro:nd\html:lbl{1000}%
 -_-_-

8.4 Title

<..elements for divs..>+
 \def\:Ttle#1#2#3{%
    \html:addr
    <.hook for ref/label.>%
    {<.introduce ‘doTocEntry toc@1 (@2) (@3) (page no)’ to toc.>}%
    {<.typeset @3 and link to toc entry.>}%
 }
 \gHAssign\TitleCount=0   \global\let\mu:span=\TitleCount
 -_-_-

<..advance TitleCount..>
 \gHAdvance
    \TitleCount by 1 \global\let\mu:span=\TitleCount
 \expandafter\expandafter\expandafter\global \expandafter
                          \let\csname #1:Count\endcsname=\TitleCount
 -_-_-

For some reason (what it is?) we can’t put the set TitleMark together with the TitleConunt within CutAt–e.g., tex4ht-html32 screams at subsection about undefined TitleMark.

<..set TitleMark..>
 \expandafter
    \let\expandafter\TitleMark\csname #1HMark\endcsname
 -_-_-

<..tex divisions..>
 \def\ConfigureMark#1#2{\long\expandafter
    \def\csname #1HMark\endcsname{#2}}
 -_-_-

We nulify \Link, but this causes no problem because we are within a group.

well, \let\Link|=\no:lnk is a problem for \Configure{ref}, so we introduced the latter comamnd.

<..typeset the html sec title..>
 \csname a:InsertTitle\endcsname
 \csname InsertTitle\endcsname{#1}%
 -_-_-

Can’t use \Title. Already in maple2e.tex.

<..typeset @3 and link to toc entry..>
 <.href on sec head?.>%
 \no:lbl:idx \csname Modify#1Title\endcsname
 \html:sectoc{#3}%
 -_-_-

<..tex divisions..>+
 \let\no:lbl:idx=\empty
 \let\toc:lbl:idx=\empty
 -_-_-

8.5 Table of Contents

The \:writetoc command outputs the expansion of its parameter, and the page number, into the file. The expanded definition \edef provides records the parameter according to the conditions that exist when the command is encountered.

<..introduce ‘doTocEntry toc@1 (@2) (@3) (page no)’ to toc..>
 \escapechar=‘\\%
 \protect:wrtoc
 \csname Modify#1ToToc\endcsname
 \edef\:writetoc{\csname if:toc\endcsname{\the\:tokwrite
    {\string\doTocEntry
     \string\toc \expandafter\ifx\csname toToc:#1\endcsname\relax #1\else
        \csname toToc:#1\endcsname\fi
        {#2}{\html:tocsec{\ifx \TocTitle\:UnDef #3\else
        \TocTitle\fi}}{\the\:tokpage}\relax}}}%
 \:writetoc   \global\let\TocTitle=\:UnDef
 -_-_-

<..elements for divs..>+
 \NewConfigure{toToc}[2]{%
    \if !#2!\expandafter\let\csname toToc:#1\endcsname\:UnDef
    \else \if !#1!%
         \expandafter\let\csname IF:#2toc\expandafter\endcsname
              \csname if:#2toc\endcsname
         \expandafter\let\csname if:#2toc\endcsname\:gobble
    \else \edef\:temp{\string @}\edef\:tempa{\string#1}%
    \ifx \:temp\:tempa
          \expandafter\let\csname if:#2toc\endcsname\empty
    \else \edef\:temp{\string ?}%
    \ifx \:temp\:tempa
         \expandafter\let\csname if:#2toc\expandafter\endcsname
              \csname IF:#2toc\endcsname
    \else
      \expandafter\def\csname toToc:#1\endcsname{#2}%
    \fi\fi\fi\fi}
 -_-_-

<..elements for divs..>+
 \ifx \:tokwrite\:UnDef
    \csname newtoks\endcsname\:tokwrite
 \fi
 \ifx \:tokpage\:UnDef
    \csname newtoks\endcsname\:tokpage
 \fi
 \:tokpage={\folio}
 -_-_-

<..html latex divs..>
 
 -_-_-

<..elements for divs..>+
 \:tokwrite={\write\:tocout}
 -_-_-

<..html divs..>+
 \def\protect:wrtoc{%
    <.no Hnewline.>\PictureOff
    \def\%{\string\%}\a:writetoc}
 -_-_-

<..html config util..>+
 \NewConfigure{writetoc}[1]{\concat:config\a:writetoc{#1}}
 \let\a:writetoc=\empty
 -_-_-

The following might be solved with protect(?).

\let\Link|=\no:lnk is a problem for \Configure{ref}.

8.6 Links

<..html divs..>+
 \def\html:sectoc#1{\csname if:toc\endcsname{%
    \xdef\CurSecHaddr{<.section html addr.>}%
    \edef\:attr{\noexpand\scp:Link{%
      \ifTag{<.HTag tag.><.toc-section html addr.>}%
             {<.toc-section html addr.>}%
             {<.section html addr.>}%
      }}%
    \:attr{<.section html addr.>}}%
    \ifx \EndTitle:Link\:gobble \if:toc{\scp:EndLink}\fi
    <.typeset the html sec title.>\EndTitle:Link{\if:toc{\scp:EndLink}}}
 \def\html:tocsec#1{\string\csname\space a:TocLink\string\endcsname
    {\FileNumber
    }{<.section html addr.>}{<.toc-section html addr.>}{#1}}
 \let\CurSecHaddr=\empty
 -_-_-

If option sections+ is active, the full title is an anchor. Might be a problem, in particular when the title contains a footnote. If the option is not active, the anchor for access from the tocs is empty.

The command \uppercase is put outside the command \:toc to convert the lower case character tokens to uppercase characters before they are inserted into the file. Within \:toc the command \uppercase is written as is into the auxiliary file, and takes effect only when the auxiliary file is imported.

\Get:SecAnchor should provide an anchor in \:SecAnchor for the cross references. If none is provided, tex4ht will offer one. tex4ht doesn’t really need the address; the idea is to save on duplicated anchors.

<..section html addr..>
 \ifx \:SecAnchor\:UnDef
    <.toc tag.>1-\file:id-\TitleCount
 \else \:SecAnchor \fi  -_-_-

<..toc-section html addr..>
 <.toc tag.>2-\file:id-\TitleCount -_-_-

<..toc tag..>
 Q-_-_-

<..hook for ref/label..>
 \Get:SecAnchor{#1}{#2}{#3}%
 -_-_-

<..elements for divs..>+
 \def\Get:SecAnchor#1#2#3{}
 -_-_-

8.7 Control Links on Section Heads

Option for univerally no links from titles of sections.

<..html divs..>+
 \:CheckOption{sections+}\if:Option
      \def\Title:Link{\Link}
      \def\EndTitle:Link#1{#1}
 \else
      \def\Title:Link#1{\Link{}}
      \let\EndTitle:Link=\:gobble
    \Log:Note{for back links to toc,
        use the command line option ‘sections+’}%
 \fi
 -_-_-

<..shared config..>+
 \NewConfigure{toTocLink}[2]{\def\scp:Link{#1}\def\scp:EndLink{#2}}
 \Configure{toTocLink}{\Title:Link}{\EndLink}
 -_-_-

The above gives global control. The following local one. E.g., \NoLink{section} asks that sections of type ‘section’ will not act as hot buttons.

<..html divs..>+
 \def\NoLink#1{\expandafter
   \gdef\csname #1:Href-\endcsname{\let\EndTitle:Link=\:gobble}}%
 -_-_-

<..href on sec head?..>
 \csname #1:Href-\endcsname
 -_-_-

8.8 Cut-Offs

The following makes a call to, e.g., \cut:at{section}{title}-

<..button for cut at sect..>
 <.set TitleMark.>%
 \expandafter\ifx  \csname Cut:#1\endcsname\relax
   <.boundaries of non-cut sections.>%
 \else
    <.boundaries of cut sections.>%
    <.TITLE for Sec.>%
    \csname Cut:#1\endcsname{#3}%
 \fi
 \global\let\sec:lvl=\HPageDepth
 <.record sections hierarchy.>%
 -_-_-

The \let\sec:lvl|=\HPageDepth is used to determine whether we have prev-next links with next HPage. As we out from hypertext pages, the value of \HPageDepth decreases, and the values of \sec:lvl are kept one value behind. If just before entering a hypertext page we have \sec:lvl>\HPageDepth, it means that the last HPage and the next one are at the same depth. Hence, we allow for prev-next links. We want the \global because section titles can be within groups as is the case, for instance, for tables of contents of tables or figures in LaTeX. Without the global, will need to fix locally the values of \sec:lvl for titles that are nested in groups.

<..TITLE for Sec..>
 \expandafter\ifx \csname a:\sec:typ TITLE\endcsname\relax\else
    \expandafter\let\expandafter\a:CutAtTITLE
              \csname a:\sec:typ TITLE\endcsname\fi
 -_-_-

<..TITLE for SecNO..>
 \expandafter\ifx \csname a:\sec:typ TITLE\endcsname\relax
    \expandafter\HCode \else
 \expandafter\expandafter\csname a:\sec:typ TITLE\endcsname\fi
 -_-_-

<..c:TITLE: for Sec..>
 \expandafter\def\csname c:#1TITLE+:\endcsname{%
    \expandafter\def\csname a:#1TITLE\endcsname####1}%
 -_-_-

<..html divs..>+
 \HAssign\sec:lvl=0
 -_-_-

8.9 Hooks

BeforEvery and Every are single-parameter macros.

<..def /:Every..>
 \def\:Every#1{%
    \expandafter\edef\csname Every#1\endcsname{%
       \def\expandafter\noexpand \csname :Every#1\endcsname####1}%
    \expandafter\edef\csname BeforeEvery#1\endcsname{%
       \def\expandafter\noexpand\csname :BeforeEvery#1\endcsname####1}%
 }
 -_-_-

\Every... and not \AfterEvery..., because we are not yet after the section, we are only after the title.

Default hooks are set to tables of contents.

<..initiate BeforeEvery/Every div..>
 \:Every{#1}%
 \csname Every#1\endcsname{%
    \expandafter\ifx\csname Toc:#1\endcsname \relax\else
        \a:TocAt  \csname Toc:#1\endcsname \b:TocAt
    \fi
    \ignorespaces}%
 -_-_-

<..delayed TocAt..>
 \a:dTocAt  \csname TocAt*\endcsname   \b:dTocAt
 \expand:after{\global\let}\csname TocAt*\endcsname=\empty
 -_-_-

<..html config util..>+
 \NewConfigure{TocAt*}[2]{%
     \c:def\a:dTocAt{#1}\c:def\b:dTocAt{#2}}
 \NewConfigure{TocAt}[2]{%
     \c:def\a:TocAt{#1}\c:def\b:TocAt{#2}}
 \Configure{TocAt*}{}{}
 \Configure{TocAt}{}{}
 -_-_-

The following occurs for sectioning commands without subdivisions.

<..BeforeEvery hook..>
 \expandafter\ifx \csname :BeforeEvery#1\endcsname\relax \else
    \csname :BeforeEvery#1\endcsname{#3}%
 \fi
 -_-_-

<..Every hook..>
 \expandafter\ifx \csname :Every#1\endcsname\relax \else
    \csname :Every#1\endcsname{#3}%
 \fi
 -_-_-

8.10 Utilities

Normally, the leading paragraphs in chapters and sections start with no indentation, whereas the other paragraphs start with indentations. To achieve this effect, we can allow a contribution of an indentation to all the paragraphs, with provisions for removing the indentations from selected paragraphs.

Without the \immediate we can get problems on boundary between pages.

8.11 Configurations for CutAt

The \par\ShowPar is to ensure that buttons at end of a page will not get into the last entry of the table in case of a cut-off situation.