\section{Test A}
\section{Test B}
\subsection{Test Ba}
\subsection{Test Bb}
\section{Test C}
\subsection{Test Ca}


In the epub file produced by tex4ebook, the numbering of the ToC (that is, the ToC as the bookmarks, not the printed ToC) is weird, which looks like:

2 Contents
13 Test A
24 Test B
  2.14 Test Ba
  2.24 Test Bb
35 Test C
  3.15 Test Ca

The printed ToC is however normal. I wonder the reason for that, and a workaround to fix it.

1 Answer 1


Edit: I fixed this issue in tex4ebook sources, the new version is already on CTAN and in TeX Live. So this bug shouldn't happen in the future.

Original answer:

Try this configuration file:

% get filename for the section label
% sometimes, TeX4ht returns list of file numbers for label. we must use just
% the first number. we use the LaTeX 3 sequence list to get it.
    % cw:)Q#1 is csname of tag from the xref file. we convert it to sequence
  % get first item and put it to a token list
    \seq_get_left:NN \l_tmpa_seq \l_tmpa_tl
      % \RefFileNumber returns file name for the given file number
      % \ncx:hfilename contains the filename for later use
      \tl_set:Nx \ncx:hfilename {\RefFileNumber{\l_tmpa_tl}}
      \tl_set:Nn \ncx:hfilename {nic}

It fixes a bug in tex4ebook.4ht, which uses the \cs_if_exist_use:cTF command. This wrong command prints result of the tested macro to the output. This results in spurious numbers in the NCX file.

Without the fix, a typical TOC entry in the NCX file looks like this:

<text><navmark type="section">  3</navmark>5     Test C </text> 

Number 5 is spurious, it shouldn't be there. With the fix:

<text><navmark type="section">  3</navmark>      Test C </text>

You must log in to answer this question.

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