1

MSE:

\documentclass{amsart}

\begin{document}
\title{Test}
\author{Anonymous}
\date{}
\maketitle

\setcounter{tocdepth}{1}
\tableofcontents

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

\end{document}

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

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:

\Preamble{xhtml}
\ExplSyntaxOn
% 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.
\def\ncx:newhfile#1{
  \cs_if_exist:cTF{cw:)Q#1}{%
    % cw:)Q#1 is csname of tag from the xref file. we convert it to sequence
    \seq_set_from_clist:Nc\l_tmpa_seq{cw:)Q#1}
  % 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}
  }
}
\ExplSyntaxOff
\begin{document}
\EndPreamble

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 .