# htlatex: incorrect minitoc when using custom list of <things>

This question is a follow-up to tex4ht: custom list of … (part 2 of 2)

I'm using htlatex to produce html on a one-subsection-per-page basis. I'm also using the technique described in the post linked above to produce a custom list of <things>. The two methods are, it appears, interfering with one another, as demonstrated in the following minimum working example.

## mwe.tex

\documentclass{article}

\usepackage{figuredescriptions}
\begin{document}

\section{First section}

\subsection{subsection}
\figuredescription{Figure description needed: 9}

\figuredescription{Figure description needed: 10}

\subsection{another subsection}

\section{Second section}

section text

\subsection{a subsection}

subsection text

\listofdesc

\end{document}


## ht-mwe.cfg

\Preamble{xhtml,3}
\begin{document}
\EndPreamble


## figuredescriptions.sty

\ProvidesPackage{figuredescriptions}
\newcommand\printdescentry[1]{#1}
\newcommand{\listofdesc}{\section{List of figure descriptions}\@starttoc{desc}}
\endinput


The file figuredescriptions.4ht is not necessary to demonstrate the problem.

Upon running the command

 htlatex mwe.tex "ht-mwe.cfg"


then I receive the following output:

Notice that the 'minitoc' for section 2 is not correct.

I can get round this by not having a minitoc by using \Preamble{xhtml,3,nominitoc} but perhaps in the future I'd actually quite like a (correct!) minitoc on a per-section basis.

## the question

How can I amend the code above so that minitocs on a per-section basis are correct in the html output?

• This is indeed strange issue, I've not found the solution yet, I will investigate it more tomorrow. – michal.h21 Apr 5 '18 at 19:05

It seems that this issue is caused by manual \addtocontentsline used in \figuredescription command. Some counters needs to be updated in this case. I've found the following note in tex4ht sources:

Tex4ht relies on two counters '\TitleCount' and '\TocCount' to decide which entries of the global TOC should go to the local TOC. The first counter is increased when sectioning commands are encountered. The second counter is increased when the global TOC is traversed.

A discrepancy will occur when the contributions of the sectioning commands to the global TOC are not synchronized with the increments of the first counter. That will normally be the case when sectioning commands are introduced without tex4h being informed about their designation as sectioning commands.

As I understand it, it is necessary to update the \TitleCount counter manually. For example by appending the following code to figuredescription.4ht:

\pend:defI\figuredescription{\gHAdvance\TitleCount  1\relax}


The \pend:defI command will insert code at the beginning of command with one argument. I've found the code \gHAdvance\TitleCount 1 in the various places in tex4ht source code.

The TOC seems to be correct now:

Note that I've added \TocAt{section,subsection} to the .cfg file to request the TOC before the section text.

• Many thanks indeed for this, it's wonderful. I've found your answers and knowledge of tex4ht to be invaluable. I've also still failed to find a comprehensive source of documentation (other than grepping the source) -- I would be interested in collaborating in constructing a 'readthedocs' for htlatex, perhaps via GitHub, is this something you'd be interested in? (Obviously I don't have anywhere near as much knowledge in htlatex as you, but I do have experience in writing documentation) – cmhughes Apr 6 '18 at 14:04
• @cmhughes thanks for your kind words. Regarding the documentation, I've set up basic outline for a new documentation here. As you can see, I update it only sparingly, I would definitely welcome some help. I can move it to Github if it would enable easier collaboration, I understand that SVN and our current source repository are not as user friendly. – michal.h21 Apr 6 '18 at 17:53
• I'd be very happy to try to contribute as much as I can, although I freely admit to not being an expert in tex4ht -- perhaps that might be an advantage, for the kinds of examples I would contribute. The format is up to you, but I'd certainly express a preference for Github. Have you seen Sphinx, which can be directly plugged in to readthedocs? MathJax uses it, and I've used it for latexindent as well; it seems to work well – cmhughes Apr 6 '18 at 18:32
• @cmhughes I think tex4ht expertise is not that important, some feedback is always welcome, for example regarding writing style, if everything is understandable, providing LaTeX examples, etc. I will set up Github repo then. I want to keep the documentation in LaTeX, main reason is to provide an example of complex document produced by tex4ht with lot of custom configurations and macros. – michal.h21 Apr 6 '18 at 19:39
• @cmhughes I've created a Github repo for the documentation: github.com/michal-h21/tex4ht-doc – michal.h21 Apr 8 '18 at 16:48