Hello Jurgen,

> I am new to this list and can at best be described as "casual LaTeX user" - I 
> use it every year or two for some minor writing project, and then put it 
> aside again (promptly forgetting many of the technical details in the 
> process). For my current writing project, I need to create an epub version of 
> the ebook I am writing. tex4ebook has generally served my needs very well, 
> but now I also want to add an index - or rather, at least two. Some quick 
> research indicated that the imakeidx package was the best tool for this, but 
> now I have hit a snag:
>
> When I compile the LaTeX files with TeXworks (using the pdfLaTeX + MakeIndex 
> + BibTeX option) I get proper hyperlinked indices like I want. However, if I 
> compile them afterwards with tex4ebook (using cygwin) I do get an epub 
> file... but the index is _not_ hyperlinked, unlike the other components of 
> the epub file (such as the table of contents, footnotes, or other 
> crossreferences using hyperref).
>

tex4ht has a build in support for makeindex, but it is not really user
friendly. I've create a support for imakeidx package with Xindy as an
index processor. You can find it in the Helpers4ht bundle:

https://github.com/michal-h21/helpers4ht

It is not on CTAN, so you need to install it manually, I hope the
instructions in the Install section will work for you. Detailed
description of the usage can be found here:

https://tex.stackexchange.com/a/430819/2891

I've tried to adapt this process to your test file and here is my
solution. I've modified your test file slightly:

-------------
\documentclass[oneside]{book}

\ifdefined\HCode
  \usepackage[xindy,noautomatic]{imakeidx}
\else
  \usepackage[]{imakeidx}
\fi
\usepackage{tex4ebook}
\usepackage{xcolor}
\usepackage[hyperindex=true]{hyperref}

\makeindex[intoc=true,name=index1,title=Index]
\makeindex[intoc=true,name=index2,title=NochEinIndex]

\begin{document}

\tableofcontents

\chapter{Test}

This is a test.\index[index2]{Test 1}

This is another test.\index[index1]{Test 2}

\printindex[index1]
\printindex[index2]

\end{document}
------------------

The change here is that no automatic index generation is done with tex4ht.

The indexing support must be enabled in the configuration file, like
myconfig.cfg:

-----------
\usepackage{indexing4ht}
\Preamble{xhtml}
\begin{document}
\EndPreamble
-------------

The Xindy then must be called manually. To ease this task, it is
possible to use a build file. Like this, mybuild.mk4:

-----
Make:add("xindy", function(par)
  par.idxfile = par.idxfile or par.input .. ".idx"
  local modules = par.modules or {par.input}
  local t = {}
  for k,v in ipairs(modules) do
    t[#t+1] = "-M ".. v
  end
  par.moduleopt = table.concat(t, " ")
  local xindy_call = "xindy -L ${language} -C ${encoding} ${moduleopt}
${idxfile}" % par
  print(xindy_call)
  return os.execute(xindy_call)
end, { language = "english", encoding = "utf8"})


if mode=="index" then
  Make:htlatex {}
  Make:xindy { idxfile="index1.idx"}
  Make:xindy { idxfile="index2.idx"}
  Make:htlatex {}
  Make:htlatex {}
elseif mode=="draft" then
  Make:htlatex {}
else
  Make:htlatex {}
  Make:htlatex {}
  Make:htlatex {}
end
------


The index generation can be then requested using:

     tex4ebook -m index -c myconfig.cfg -e mybuild.mk4 Test.tex

This should generate the index. As epub file doesn't contain pages,
section numbers are used as pointers instead.

Best regards,
Michal

Reply via email to