Before starting, here are rules of thumb to remember. Most of these rules will cover most of the common uses.
\TocAt{chapter,section} %show sections only in chapters TOC
\TocAt{section,subsection} %show subsections only in sections TOC
The general outlines of the themes below are needed if one wants to do something more complicated than the above rules of thumb.
These themes were done using the command
htlatex foo.tex "htm,3"
And then adding the control of where to split pages to separate HTML pages or not, and controlling where table of contents show up right inside the latex file. This is needed since there is no other way to control which sections or chapters to split or not to split using global method, and so the logic has to be embedded inside the latex file.
All logic for both pdf and htlatex is inside the same file and is controlled using
\ifdefined\HCode to tell if one is running in pdf or htlatex, since only generation to
HTML and PDF is done here.
report class, main TOC shows only chapters. Chapter 2 has TOC and all its sections in one web page, but chapter 1 has TOC but its sections are each on separate web pagebreak
This is compiled using
htlatex foo.tex "htm,3"
\documentclass{report} \setcounter{tocdepth}{0} \setcounter{secnumdepth}{4} \usepackage{lipsum} \usepackage{titletoc} \begin{document} \title{my web site} \author{me} \date{\small\today} \maketitle %tell tex4ht to make main toc show only chapters %thanks to Radhakrishnan CV for this solution \ifdefined\HCode \Configure{tableofcontents*}{chapter} \fi \tableofcontents \ifdefined\HCode \TocAt{chapter,section} %show section only in chapters TOC \TocAt{section,subsection} %show subsection only in sections TOC \fi %--------------------- \chapter{chapter 1} \ifdefined\HCode \else { \startcontents[chapter] \printcontents[chapter]{}{1}{\setcounter{tocdepth}{1}} } \fi \lipsum[10] \section{section 1 in chapter 1} \lipsum[1-2] \section{section 2 in chapter 1} \lipsum[1-2] \subsection{subsection 1 in section 2 in chapter 1} \lipsum[1-2] \section{section 3 in chapter 1} \lipsum[1-2] %--------------------- \ifdefined\HCode \PauseCutAt{section} \fi \ifdefined\HCode \else { \stopcontents[chapter] } \fi \chapter{chapter 2} \lipsum[10] \section{section 1 in chapter 2} \lipsum[1-2] \section{section 2 in chapter 2} \lipsum[1-2] \subsection{subsection 1 in section 2 in chapter 2} \lipsum[1-2] \section{section 3 in chapter 2} \lipsum[1-2] \end{document}
There seems to be an issue somewhere, I need to resolve. This is getting complicated.
\documentclass{report} \setcounter{tocdepth}{0} \setcounter{secnumdepth}{4} \usepackage{lipsum} \usepackage{titletoc} \begin{document} \title{my course A} \author{me} \date{\small\today} \maketitle \ifdefined\HCode \Configure{tableofcontents*}{chapter} \fi \tableofcontents \ifdefined\HCode \TocAt{chapter} %turn off TOC \fi %--------------------- \chapter{chapter 1 my HWs} \begin{tabular}{|l|l|} \hline HW & grade \\\hline HW1 \ ref{sec:HW1} & 100\% \\\hline HW2 \ ref{sec:HW2} & 100\% \\\hline \end{tabular} \ifdefined\HCode \TocAt{section,subsection} %turn on TOC \fi \section{HW 1} \ifdefined\HCode \else { %turn on local TOC \startcontents[section] \printcontents[section]{}{1}{\setcounter{tocdepth}{1}} } \fi \label{sec:HW1} \subsection{problem 1} \lipsum[10] \subsection{problem 2} \lipsum[10] \subsection{problem 3} \lipsum[10] \section{HW 2} \label{sec:HW2} \subsection{problem 1} \lipsum[10] \subsection{problem 2} \lipsum[10] \subsection{problem 3} \lipsum[10] \ifdefined\HCode \TocAt{chapter,section} %turn on TOC \PauseCutAt{section} % do not SPLIT this section \fi %------------------------------ \chapter{project} \ifdefined\HCode \else { %turn on local TOC \startcontents[chapter] \printcontents[chapter]{}{1}{\setcounter{tocdepth}{1}} } \fi \section{introduction} \lipsum[10] \section{design} \lipsum[10] \section{appendix} \lipsum[10] \end{document}