This is a follow-up of my previous question here.

It uses the files provided by @Michal.h21. I have modified the input file as below:


title={Polymer Chemistry}









\tableofcontents \newpage




\lipsum \newpage

Here comes a quotation \cite{Hiemenz}.


\lipsum \newpage


\printbibliography \newpage



The configuration and build files are the same as the previous question and again provided by @Michal.h21.

The main issues are:

  1. The \indexprologue command is correctly handled in the pdf:

pdf output

However, it is ignored in the tex4ebook run.

tex4ebook output

  1. I think there is inconsistent behavior in the intoc option and the \addcontentsline{toc}{chapter}{Index} option. The intoc option is ignored in the tex4ebook run.

  2. The index link in the TOC points to a blank page rather than to where the index header is.

tex4ebook output

It is correct in the pdf file.

pdf output

  1. The use of an automatic option in the makeindex command doesn't produce hyperlinks:

tex4ebook output

Using the noautomatic option works. This is not a big issue, but it is different to how a normal latex run behaves and it seems strange.

Have others experienced these issues, and are there any suggested fixes or ways to get consistent results?

I suspect this will fall on @Michal.h21 and so I will thank him in advance.


The previous version of configuration for imakeidx package didn't take into account some features of this package, it used the default tex4ht configuration to handle the \printindex command. We can use the modified version of imakeidx definition to get support for some of these features.

This is the new version of imakeidx.4ht file:


% \patchcmd{\index}{\@index}{\@Index}{}{}
% \patchcmd{\xIndex}{\@index}{\@Index}{}{}
% \let\protected@iwrite\protected@write
% \let\@index\@Index
% \patchcmd{\protected@iwrite}{\write}{\immediate\write}{}{}


  \global\advance\idxkwdcnt by 1\relax%
  % use tags only one time



  % \imki@indexlevel{\indexname}\imki@indexheaders
      \parskip\z@ \@plus .3\p@\relax


\ConfigureEnv{theindex}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="theindex">}}{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}{}{}

(define-attributes (("default" "definition" "textbf")))
( define-location-class "sec-num" :var
             :sep "." "arabic-numbers"
             :sep "." "arabic-numbers"
             :sep "." "arabic-numbers"
             :sep "." "arabic-numbers"
(require "texindy.xdy")
(markup-keyword :open "\idxkeyword{" :close "}" )
(markup-locref :open "\idxlocator{" :close "}")
(markup-locref :open "\textbf{\idxlocator{" :close "}}"  :attr "textbf")
(markup-locref :open "\textbf{\idxlocator{" :close "}}"  :attr "definition")

The important change is this:

  % \imki@indexlevel{\indexname}\imki@indexheaders
      \parskip\z@ \@plus .3\p@\relax


\ConfigureEnv{theindex}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="theindex">}}{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}{}{}

The \reneenwironment{theindex} will take into account the \indexprologue and TOC support, \ConfigureEnv{theindex} will add <div class="theindex"> element around the index contents.

With this change, you don't need to use \addcontentsline{toc}{chapter}{Index} in your document anymore, the link from TOC links correctly to the index.

Regarding your last question, the automatic option of imakeidx doesn't work because you need to use different options when you compile with pdflatex and with tex4ht. This is why xindy is called from the build file. The other reason is that LaTeX is called multiple times in each tex4ebook run and it doesn't make sense to compile the index in each of these calls.

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.