3

Update:

As I mentioned in the comment below, the Table of contents should be the same regardless of the splitting done. So the solution should produce the same toc in HTML from the following commands

 htlatex foo.tex
 htlatex foo.tex "htm,2"

Original question below

When setting \setcounter{tocdepth}{0} in report class, then the PDF file shows only the chapters as expected in toc, but the HTML shows both chapter and sections in toc.

When setting \setcounter{tocdepth}{1} in artice class, then the PDF file shows only the sections as expected in toc, and now the HTML shows only the sections in toc as expected as well.

So, the question is: Why tex4ht agrees with pdf toc for article and not for report?

The following diagram illustrates this. I am not using any options or configuration files other than standard commands to build these. MWE and commands used is below.

enter image description here

Article

\documentclass{article}%
\setcounter{tocdepth}{1}
\begin{document}
\tableofcontents
\clearpage

\section{This is section 1}
some text in section 1
\subsection{1}
some text in section, subsection

\section{This is section 2}
some text in section 2
\subsection{1}
some text in section, subsection

\section{This is section 3}
some text in section 3
\subsection{1}
some text in section, subsection

\end{document}

commands used

pdflatex foo.tex
htlatex foo.tex

Report

\documentclass{report}%
\setcounter{tocdepth}{0}
\begin{document}
\tableofcontents
\clearpage

\chapter{This is chapter 1}
some text in chapter 1
\section{1}
some text in chapter, section

\chapter{This is chapter 2}
some text in chapter 2
\section{1}
some text in chapter, section


\chapter{This is chapter 3}
some text in chapter 3
\section{1}
some text in chapter, section

\end{document}

Appendix

I know of a work around for the report case. But the question is really not to find a workaround, but why it happens in first place. Here is the work around for those interested.

\documentclass{report}%
\setcounter{tocdepth}{0}
\begin{document}

\ifdefined\HCode
  \Configure{tableofcontents*}{chapter}  %force htlatex to only show chapters
\else
\tableofcontents
\fi
\clearpage

\chapter{This is chapter 1}
some text in chapter 1
\section{1}
some text in chapter, section

\chapter{This is chapter 2}
some text in chapter 2
\section{1}
some text in chapter, section    

\chapter{This is chapter 3}
some text in chapter 3
\section{1}
some text in chapter, section

\end{document}

HTML result now is as expected

Mathematica graphics

Here is the full output of the htlatex output for the report case. It is not too large, but posting it since the comment below said this can't be produced on a different machine. I am using texlive 2014 as can be seen from the log:

>htlatex foo.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(./foo.tex (/usr/local/texlive/2014/texmf-dist/tex/latex/base/report.cls
Document Class: report 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.sty)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.4ht
::::::::::::::::::::::::::::::::::::::::::
 TeX4ht info is available in the log file 
::::::::::::::::::::::::::::::::::::::::::
) (/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.sty
--- needs --- tex4ht foo ---
(./foo.tmp) (./foo.xref)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/latex.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/fontmath.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/report.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(./foo.aux) [1] (./foo.4ct) [2] [3]
Chapter 1.
[4]
Chapter 2.
[5]
Chapter 3.
[6] (./foo.aux) )
Output written on foo.dvi (6 pages, 12504 bytes).
Transcript written on foo.log.
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(./foo.tex (/usr/local/texlive/2014/texmf-dist/tex/latex/base/report.cls
Document Class: report 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.sty)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.4ht
::::::::::::::::::::::::::::::::::::::::::
 TeX4ht info is available in the log file 
::::::::::::::::::::::::::::::::::::::::::
) (/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.sty
--- needs --- tex4ht foo ---
(./foo.tmp) (./foo.xref)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/latex.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/fontmath.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/report.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(./foo.aux) [1] (./foo.4ct) [2] [3]
Chapter 1.
[4]
Chapter 2.
[5]
Chapter 3.
[6] (./foo.aux) )
Output written on foo.dvi (6 pages, 12504 bytes).
Transcript written on foo.log.
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(./foo.tex (/usr/local/texlive/2014/texmf-dist/tex/latex/base/report.cls
Document Class: report 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.sty)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.4ht
::::::::::::::::::::::::::::::::::::::::::
 TeX4ht info is available in the log file 
::::::::::::::::::::::::::::::::::::::::::
) (/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/tex4ht.sty
--- needs --- tex4ht foo ---
(./foo.tmp) (./foo.xref)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/latex.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/fontmath.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/report.4ht
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(./foo.aux) [1] (./foo.4ct) [2] [3]
Chapter 1.
[4]
Chapter 2.
[5]
Chapter 3.
[6] (./foo.aux) )
Output written on foo.dvi (6 pages, 12504 bytes).
Transcript written on foo.log.
----------------------------
tex4ht.c (2012-07-25-19:36 kpathsea)
tex4ht -f/foo.tex 
  -i~/tex4ht.dir/texmf/tex4ht/ht-fonts/ 
(/usr/local/texlive/2014/texmf-dist/tex4ht/base/unix/tex4ht.env)
(/usr/local/texlive/2014/texmf-dist/tex4ht/ht-fonts/iso8859/1/charset/unicode.4hf)
(/usr/local/texlive/2014/texmf-dist/fonts/tfm/public/cm/cmr10.tfm)
(/usr/local/texlive/2014/texmf-dist/tex4ht/ht-fonts/alias/lm/lm-rep-cmrm/cmr.htf)
Searching `lm-rep-cmrm.htf' for `cmr10.htf'
(/usr/local/texlive/2014/texmf-dist/tex4ht/ht-fonts/unicode/lm/lm-rep-cmrm.htf)
[1 file foo.html
 file foo.css
 file foo.tmp
] [2] [3] [4] [5] [6]
Execute script `foo.lg'
----------------------------
t4ht.c (2012-07-25-19:28 kpathsea)
t4ht -f/foo.tex 
(/usr/local/texlive/2014/texmf-dist/tex4ht/base/unix/tex4ht.env)
Entering foo.lg
Entering foo.css
Entering foo.tmp
>

Here is the actual HTML produces as well. (not too large also)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
  "http://www.w3.org/TR/html4/loose.dtd">  
<html > 
<head><title></title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)"> 
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)"> 
<!-- html --> 
<meta name="src" content="foo.tex"> 
<meta name="date" content="2014-08-09 11:55:00"> 
<link rel="stylesheet" type="text/css" href="foo.css"> 
</head><body 
>

   <h2 class="likechapterHead"><a 
 id="x1-1000"></a>Contents</h2> <div class="tableofcontents">
   <span class="chapterToc" >1 <a 
href="#x1-20001" id="QQ2-1-2">This is chapter 1</a></span>
<br />   &#x00A0;<span class="sectionToc" >1.1 <a 
href="#x1-30001.1" id="QQ2-1-3">1</a></span>
<br />   <span class="chapterToc" >2 <a 
href="#x1-40002" id="QQ2-1-4">This is chapter 2</a></span>
<br />   &#x00A0;<span class="sectionToc" >2.1 <a 
href="#x1-50002.1" id="QQ2-1-5">1</a></span>
<br />   <span class="chapterToc" >3 <a 
href="#x1-60003" id="QQ2-1-6">This is chapter 3</a></span>
<br />   &#x00A0;<span class="sectionToc" >3.1 <a 
href="#x1-70003.1" id="QQ2-1-7">1</a></span>
   </div>


   <h2 class="chapterHead"><span class="titlemark">Chapter&#x00A0;1</span><br /><a 
 id="x1-20001"></a>This is chapter 1</h2>
<!--l. 10--><p class="noindent" >some text in chapter 1
   <h3 class="sectionHead"><span class="titlemark">1.1   </span> <a 
 id="x1-30001.1"></a>1</h3>
<!--l. 12--><p class="noindent" >some text in chapter, section

   <h2 class="chapterHead"><span class="titlemark">Chapter&#x00A0;2</span><br /><a 
 id="x1-40002"></a>This is chapter 2</h2>
<!--l. 15--><p class="noindent" >some text in chapter 2
   <h3 class="sectionHead"><span class="titlemark">2.1   </span> <a 
 id="x1-50002.1"></a>1</h3>
<!--l. 17--><p class="noindent" >some text in chapter, section

   <h2 class="chapterHead"><span class="titlemark">Chapter&#x00A0;3</span><br /><a 
 id="x1-60003"></a>This is chapter 3</h2>
<!--l. 21--><p class="noindent" >some text in chapter 3
   <h3 class="sectionHead"><span class="titlemark">3.1   </span> <a 
 id="x1-70003.1"></a>1</h3>
<!--l. 23--><p class="noindent" >some text in chapter, section

</body></html> 
4
  • I've got correct results for report on my machine, only chapters, not sections
    – michal.h21
    Aug 9, 2014 at 16:49
  • @michal.h21 are you using texlive 2014?
    – Nasser
    Aug 9, 2014 at 16:54
  • no, texlive 2013, but there should be no difference in how tex4ht handles tocdepth, afaik
    – michal.h21
    Aug 9, 2014 at 17:10
  • @michal.h21 I see. Agree with you, should not be difference, but it looks like something changed somewhere then.
    – Nasser
    Aug 9, 2014 at 17:13

1 Answer 1

3

There is macro \:TOC in support .4ht file for each documentclass:

\edef\:TOC{
   \noexpand\ifx [\noexpand\:temp
      \noexpand\expandafter\noexpand\:TableOfContents
   \noexpand\else
      \noexpand\Auto:ent{\ifnum \c@tocdepth >-2 part,\fi
\expandafter\ifx \csname @chapter\endcsname\relax
   \ifnum \c@tocdepth >\z@  section,\fi
\else
   \ifnum \c@tocdepth >\m@ne chapter,appendix,\fi
   \ifnum \z@>\c@tocdepth\else section,\fi
   \ifnum 1>\c@tocdepth \else subsection,\fi
\fi
\ifnum 2>\c@tocdepth \else subsection,\fi
\ifnum 3>\c@tocdepth \else subsubsection,\fi
\ifnum 4>\c@tocdepth \else paragraph,\fi
\ifnum 5>\c@tocdepth \else subparagraph,\fi
UnDFexyz}%

list with values section commands which will form toc is created by this macro.

see these lines:

\expandafter\ifx \csname @chapter\endcsname\relax
   \ifnum \c@tocdepth >\z@  section,\fi
\else
   \ifnum \c@tocdepth >\m@ne chapter,appendix,\fi
   \ifnum \z@>\c@tocdepth\else section,\fi

to explain that, for documentclasses without \chapter command, this declaration is used:

   \ifnum \c@tocdepth >\z@  section,\fi

otherwise, this:

   \ifnum \c@tocdepth >\m@ne chapter,appendix,\fi
   \ifnum \z@>\c@tocdepth\else section,\fi

first declaration is used in article class, second in chapter or book. I have no idea, why declaration for section has such complicated form:

   \ifnum \z@>\c@tocdepth\else section,\fi

if I am not mistaken, this means that section is included in the list if \c@tocdepth is greater than or equal zero, which is incorrect. You may make local copy of report.4ht and put corrected version of \:TOC here:

\edef\:TOC{%
\noexpand\ifx [\noexpand\:temp
      \noexpand\expandafter\noexpand\:TableOfContents
\noexpand\else
      \noexpand\Auto:ent{\ifnum \c@tocdepth >-2 part,\fi
\expandafter\ifx \csname @chapter\endcsname\relax
   \ifnum \c@tocdepth >\z@ section,\fi
\else
   \ifnum \c@tocdepth >\m@ne chapter,appendix,\fi
   \ifnum \c@tocdepth>0 section,\fi
   \ifnum \c@tocdepth>1 subsection,\fi
\fi
\ifnum \c@tocdepth>2 subsection,\fi
\ifnum \c@tocdepth>3 subsubsection,\fi
\ifnum \c@tocdepth>4 paragraph,\fi
\ifnum \c@tocdepth>5 subparagraph,\fi
UnDFexyz}%
   \noexpand\fi}

if you make bug report for this on tex4ht bug tracker, we may make patch for literate sources and put corrected version to texlive

5
  • Thanks. Good job finding the bug. I applied your patch to the file /usr/local/texlive/2014/texmf-dist/tex/generic/tex4ht/report.4ht and rebuild the MWE and now the HTML generated with correct table of content. Entered a bug in tex4ht now. Added bug is puszcza.gnu.org.ua/bugs/index.php?228
    – Nasser
    Aug 9, 2014 at 19:42
  • @Nasser I am happy it works, for some reason my toc include only chapters no matter of \tocdepth value
    – michal.h21
    Aug 9, 2014 at 19:42
  • I am afraid I have bad news. This bug still shows up when splitting the document! I did a test now on the same document, but used the following command: htlatex foo.tex "htm,2" and now when looking at the HTML I see that the toc is showing the section again! So there is more subtle interactions and other logic somewhere else that needs to be sorted out. Splitting the document should have no effect on the table of contents. i.e. same toc should result from htlatex foo.tex and htlatex foo.tex "htm,2". I am using texlive 2014
    – Nasser
    Aug 10, 2014 at 16:57
  • @Nasser I guess that in the case of splitting document into parts, tocdepth is not taken into account and you have to use native tex4ht solutions like \TocAt and \Configure{tableofcontents}
    – michal.h21
    Aug 10, 2014 at 17:52
  • Yes, this is what I do now. As I showed in my workaround above in the question, in the appendix. Since I use splitting for almost all my pages, I guess I still have to use this workaround. So we can consider this bug still open until a solution is found that also works for splitting case as well. Thank you.
    – Nasser
    Aug 10, 2014 at 17:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .