[tex4ht] How to make table of contents use correct settings of \setcounter{tocdepth} for \tableofcontents ?

Nasser M. Abbasi nma at 12000.org
Sun Aug 11 10:15:11 CEST 2013


On 8/11/2013 1:36 AM, Radhakrishnan CV wrote:

>
> I think, the following might help you:

Thanks you very much. Yes, that worked very well.

For completion, I  have a MWE below which generates a local TOC
for one chapter which is larger than the second local TOC for
the second chapter, both for pdflatex and htlatex.  The main
page TOC only shows the chapters in its TOC.

ps. If you would have any hints or insight for the splitting problem
http://tug.org/pipermail/tex4ht/2013q3/000860.html
that would be great. That is the main stumbling block for me and
if any one can solve it, it would be you :)

This MWE uses etoc for local TOC for the pdf version.
(for some reason it makes a page break in each chapater, but I
am sure this is an etoc setting and I have not had time to look at it)

-------------------------------------------------
\documentclass{report}%
\usepackage{etoc}
\setcounter{tocdepth}{0}
\setcounter{secnumdepth}{4}

\makeatletter
\@ifpackageloaded{tex4ht}
   {\let\iftexforht\@firstoftwo}
   {\let\iftexforht\@secondoftwo}
\makeatother

\begin{document}

\title{test TOC with tex4ht 2}
\author{me}
\date{\today}
\maketitle

\ifdefined\HCode %thanks to Radhakrishnan CV for this solution
\Configure{tableofcontents*}{chapter}
\fi

\tableofcontents  % MAIN TOC

\ifdefined\HCode  %reset for local TOC for tex4ht
\TocAt{chapter,section,subsection,subsubsection}
\fi
%------ F I R S T    C H A P T E R -----
\chapter{Heading chapter 1}
\ifdefined\HCode
\else
{
\setcounter{tocdepth}{4}  %reset for local TOC for pdf
\localtableofcontents
}
\fi

some text
\section{Heading section 1 under chapter 1}
text
\subsection{Heading subsection 1 under section 1 under chapter 1}
text
\subsubsection{Heading subsubsection 1}
text

%------ S E C O N D     C H A P T E R -----

\ifdefined\HCode
\TocAt{chapter,section} %reset for local TOC for tex4ht
\fi

\chapter{Heading chapter 2}
\ifdefined\HCode\
\else
{
\setcounter{tocdepth}{2}  %reset for local TOC for pdf
\localtableofcontents
}
\fi

some text
\section{Heading section 1 under chapter 2}
some text
\subsection{Heading subsection 1 under section 1 under chapter 2}
text
\subsubsection{Heading subsubsection 1 under subsection 1 under section 1 under chapter 2}
text

\end{document}

--Nasser



More information about the tex4ht mailing list