5.4 tex4ht themes

Before starting, here are rules of thumb to remember. Most of these rules will cover most of the common uses.

  1. If using the report class and if splitting is set to 2, then each chapter (and anything in it, such as sections and subsections) all go to separate one web page).
  2. If using the report class and if splitting is set to 3, then each section (and anything in it, such as subsections) all go to separate one web page).
  3. If using report class, to Force a table of content to show under each chapter add this \TocAt{chapter,section} %show sections only in chapters TOC
  4. To Force a table of content to show under each section add this \TocAt{section,subsection} %show subsections only in sections TOC
  5. If using article class, then using split 2 then each section is put on its own page (including all its subsections).
  6. If using article class, then using split 3 will put each section on its page, and each subsection (and everything inside subsections) on its own page.

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.

5.4.1 theme 1

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"
 

  1. HTML output of this theme is HTML
  2. PDF output of this theme is PDF
\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}
 

5.4.2 theme 2

There seems to be an issue somewhere, I need to resolve. This is getting complicated.

  1. HTML output of this theme is HTML
  2. PDF output of this theme is PDF
\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}