TOC in tex4ht still confuses me to this day. Does one still need to use
\Configure{tableofcontents*}{section,subsection,etc...}
or can tex4ht use the standard latex setting used for PDF, which is
\setcounter{tocdepth}{5} % for main TOC (change number as needed)
\setcounter{secnumdepth}{5}
\tableofcontents
I am asking because below it shows one must use the \Configure
command. Here is MWE
\documentclass[12pt]{article}
\begin{document}
%
\title{Notes on something important}
\author{me}
\date{\today}
\maketitle
\setcounter{tocdepth}{5} % for main TOC to go all way to \paragraph
\setcounter{secnumdepth}{5}
\tableofcontents
%
\section{Very important section}
\subsection{Very important subsection}
\subsubsection{Very important subsubsection}
Hence we see that
\paragraph{some results}
Therefore we see it is proven.
\end{document}
Compile to pdf using lualatex
gives
So TOC shows the \paragraph
, but using same code, compiled to html using
make4ht -ulm default -a debug main.tex 'mathjax,htm'
gives
It does not show \paragraph
. If I modify the latex part for toc to do this
\ifdefined\HCode
\Configure{tableofcontents*}{section,subsection,subsubsection,paragraph}
\else
\setcounter{tocdepth}{5} % for main TOC
\setcounter{secnumdepth}{5}
\tableofcontents
\fi
Now HTML gives
So now paragraph
shows in TOC but with no number. But finally If I change the latex to
\setcounter{tocdepth}{5} % for main TOC
\setcounter{secnumdepth}{5}
\ifdefined\HCode
\Configure{tableofcontents*}{section,subsection,subsubsection,paragraph}
\else
\tableofcontents
\fi
Now the HTML is correct
So my question is: It is possible to have the above output directly just using
\setcounter{tocdepth}{5} % for main TOC
\setcounter{secnumdepth}{5}
\tableofcontents
Without having to add
\ifdefined\HCode
\Configure{tableofcontents*}{section,subsection,subsubsection,paragraph}
\else...\fi
Since it seems to me the information for tex4ht is already there, so why does one have to add the \Configure
command. It will simplify the Latex.
What is the correct way to set the TOC in tex4ht to be the same as the PDF? Does one need to always have the \Configure
there?
TL 2023
Update July 27, 2023
Unfortunately the solution given does not work when asking to split the document, which is 90% of the cases I have. i.e. moving the commands \setcounter{tocdepth}
and \setcounter{secnumdepth}
works in tex4ht only if one does not ask to split the document. Otherwise the whole TOC no longer shows up! Here is a MWE
\documentclass[12pt]{book}
\setcounter{tocdepth}{1} % for main TOC, show part and chapter
\setcounter{secnumdepth}{1}
\begin{document}
\title{my book}
\author{me}
\date{\today}
\maketitle
\tableofcontents
\part{first part}
\chapter{first chapter in part 1}
things here
\part{second part}
\chapter{first chapter in part 2}
more things here
\end{document}
And now compiling using
make4ht -ulm default -a warning main.tex 'mathjax,htm,2'
And looking at the HTML, there is no TOC at all showing. Nothing. Just blank space. But compiling using
make4ht -ulm default -a warning main.tex 'mathjax,htm'
The correct TOC now shows in the HTML.
The workaround is to go back to using \Configure
for text4ht, like this
\documentclass[12pt]{book}
\begin{document}
\title{my book}
\author{me}
\date{\today}
\maketitle
\ifdefined\HCode
\Configure{tableofcontents*}{part,chapter}
\else
\setcounter{tocdepth}{1} % for main TOC
\setcounter{secnumdepth}{1}
\tableofcontents
\fi
\part{first part}
\chapter{first chapter in part 1}
things here
\part{second part}
\chapter{first chapter in part 2}
more things here
\end{document}
And now compiling using same command, with any level of splitting, the TOC shows on the main page OK and never goes away.