TransWikia.com

Caption package breaks tex4ht automatic sectioning pagination

TeX - LaTeX Asked on June 9, 2021

The caption package seems to break automatic sectioning pagination in tex4ht. The document test.tex

documentclass{article}
usepackage{graphicx, caption, blindtext}

begin{document}
    part{Part One}
        section{Section One}
        blindtext
        section{Section Two}
        blindtext
        begin{figure}
            includegraphics[width=0.5textwidth]{example-image-a}
            caption{label{fig:mwe}Some Caption}
        end{figure}
    part{Part Two}
        section{Section Three}
        blindtext
        section{Section Four}
        blindtext
end{document}

when compiled using

make4ht test.tex "xhtml,mathjax,3"

Generates testpa1.html correctly as expected

<body>
   <!-- l. 5 --><div class='crosslinks'><p class='noindent'>[<a href='Test1pa2.html'>next</a>] [<a href='#tailTest1pa1.html'>tail</a>] [<a href='Test1.html#Test1pa1.html'>up</a>] </p></div>
   <h1 class='partHead'><span class='titlemark'>Part I<br /></span><a id='x2-1000I'></a>Part One</h1>
   <div class='sectionTOCS'>
   <span class='sectionToc'>1 <a href='Test1se1.html#x3-20001'>Section One</a></span>
<br />   <span class='sectionToc'>2 <a href='Test1se2.html#x4-30002'>Section Two</a></span>
   </div>


   <!-- l. 14 --><div class='crosslinks'><p class='noindent'>[<a href='Test1pa2.html'>next</a>] [<a href='Test1pa1.html'>front</a>] [<a href='Test1.html#Test1pa1.html'>up</a>] </p></div>
<!-- l. 14 --><p class='indent'>   <a id='tailTest1pa1.html'></a> </p> 
</body>

but the file testpa2.html is missing the links to Sections Three and Four:

<body>
   <!-- l. 14 --><div class='crosslinks'><p class='noindent'>[<a href='Test1pa1.html'>prev</a>] [<a href='Test1pa1.html#tailTest1pa1.html'>prev-tail</a>] [<a href='#tailTest1pa2.html'>tail</a>] [<a href='Test1.html#Test1pa2.html'>up</a>] </p></div>
   <h1 class='partHead'><span class='titlemark'>Part II<br /></span><a id='x5-4000II'></a>Part Two</h1>
   <div class='sectionTOCS'>
   </div>


   <!-- l. 19 --><div class='crosslinks'><p class='noindent'>[<a href='Test1pa1.html'>prev</a>] [<a href='Test1pa1.html#tailTest1pa1.html'>prev-tail</a>] [<a href='Test1pa2.html'>front</a>] [<a href='Test1.html#Test1pa2.html'>up</a>] </p></div>
<!-- l. 19 --><p class='indent'>   <a id='tailTest1pa2.html'></a> </p> 
</body> 

In a larger document with lots of parts and sections, things start going bad at the first instance of the caption command and get worse from there.

If I remove either the caption command or the caption package from the MWE, everything works as expected.

I have seen this answer, but the modification suggested in that answer seems to already be in caption-hooks.4ht in TL2021.

One Answer

Try this .cfg file:

Preamble{xhtml}
makeatletter
 renewcommand*caption@@@addcontentsline[4]{%
   deftemp{#1}deftempa{toc}ifx temptempaelse%
   gHAdvanceTitleCount  1 %
   fi%
   addcontentsline{#1}{#2}{protectnumberline{#3}{detokenize{#4}}}%
 }
makeatother
begin{document}
EndPreamble

The caption command as defined by captionpackage adds figure caption to the table of figures. For some reason, this prevents printing of subsequent tables of contents after that point. It needs to step the TitleCount counter to get it working.

It seems to work with this change:

enter image description here

Correct answer by michal.h21 on June 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP