3

This is a follow-up of my previous question here. I'm using texlive 2020 and using the files provided by @Michal.h21.

I have modified the input file sample.tex.

\documentclass[ebook,12pt,oneside,openany]{memoir}

\usepackage{lipsum}

\usepackage[backend=biber,hyperref=auto,backref=true]{biblatex}
\bibliography{test}

\usepackage{imakeidx}
\makeindex[intoc=true,columns=1,noautomatic]

\usepackage[hyperindex=true]{hyperref}

\title{Book}
\author{Author}
\date{}

\begin{document}

\maketitle

\frontmatter

\tableofcontents \newpage

\mainmatter

\chapter{C1}

aword\index{aword}

\lipsum \newpage

\chapter{C2}

bword\index{bword}

\index{Muller@M\"{u}ller}

\lipsum \newpage

zword\index{zword}

\backmatter

\printindex

\end{document}

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

ebook.cfg:

% save the clearpage before it is redefined by tex4ht
\let\oldclrearpage\clearpage
% define macro for newpage insertion
\def\mypagebreak{\Configure{newpage}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="newpage"></div>}}}
%
\Preamble{xhtml}
\CutAt{section}
%
% enforce newpage
%
% define it for \newpage
%
\mypagebreak
\Css{.newpage{page-break-before:always;}}
% modify \Configure{BODY} so our confiurations work on all extracted pages
\Configure{@BODY}{\def\clearpage{\bgroup\mypagebreak\oldclrearpage\egroup}}
\Configure{@/BODY}{\global\let\clearpage\oldclrearpage\Configure{newpage}{}}
\begin{document}
\EndPreamble

build.mk4

Make:add("biber","biber ${input}")
Make:add("xindy", function(par)
  -- par.encoding  = par.encoding or "utf8"
  -- par.language = par.language or "english"
  par.idxfile = par.idxfile or par.input .. ".idx"
  local modules = par.modules or {}
  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 -L ${language} -C ${encoding} ${moduleopt} ${idxfile}" % par)
end, {modules = {"texindy"}, language = "english", encoding = "utf8"})

if mode=="draft" then
  Make:htlatex {}
else
 Make:htlatex {}
 Make:biber {}
 -- xindymodule = Make.params["input"]
 Make:xindy {modules = {"sample"}}
 Make:htlatex {}
 Make:htlatex {}
 Make:htlatex {}
end

imakeidx.4ht

\RequirePackage[]{etoolbox}
\RequirePackage{gettitlestring}
\newcounter{indexcnt}
\let\@Index\@index
\patchcmd{\@Index}{\@wrindex}{\@Wrindex}{}{}
\let\@Wrindex\@wrindex
\patchcmd{\@Wrindex}{\thepage}{\theindexcnt}{}{}
\let\xIndex\index
\patchcmd{\xIndex}{\@index}{\@Index}{}{}
\patchcmd{\xIndex}{\@index}{\@Index}{}{}

\pretocmd{\xIndex}{\@stepindexcnt\@indexanchor}
% \patchcmd{\index}{\@index}{\@Index}{}{}
% \patchcmd{\xIndex}{\@index}{\@Index}{}{}
% \let\protected@iwrite\protected@write
% \let\@index\@Index
% \patchcmd{\protected@iwrite}{\write}{\immediate\write}{}{}
\patchcmd{\@Wrindex}{\protected@write}{\protected@iwrite}{}{}
\let\Index\xIndex
\let\index\xIndex
%\show\Index
\newcommand\@indexanchor{%
  \edef\idx@anch{idx-anch\theindexcnt}%
  \Link[]{}{\idx@anch}\EndLink%
  %\Ref{(idx-link-\idx@anch)}{\FileName/\idx@anch}
}
\newcommand\@stepindexcnt{\stepcounter{indexcnt}}
\newcommand\hello[1]{\@hello#1}
\def\@hello#1/{%
  \Link{idx-anch#1}{}#1\EndLink%
}


\GetTitleStringSetup{expand}
\GetTitleStringDisableCommands{%
  \renewcommand\LaTeX{LaTeX}
}

\newcount\idxkwdcnt
\LinkCommand\IdxKWLink{span,href,id}
\newcommand\idxkeyword[1]{%
  \global\advance\idxkwdcnt by 1\relax%
  % use tags only one time
  \GetTitleString{#1}
  \ifcsdef{idxkw\GetTitleStringResult}{}%
  %{\Tag{idxkw#1}{idxkw\the\idxkwdcnt}}%
  {\expandafter\Tag\expandafter{idxkw\GetTitleStringResult}{idxkw\the\idxkwdcnt}}%
  \csgdef{idxkw\GetTitleStringResult}{x}
  \a:IdxKW{}{idxkw\the\idxkwdcnt}#1\b:IdxKW
}


\NewConfigure{IdxKW}{2}
\Configure{IdxKW}{\IdxKWLink}{\EndIdxKWLink}


\newcommand\idxlocator[1]{\Link{idx-anch#1}{}#1\EndLink}%

\renewenvironment{theindex}%
{\imki@maybeaddtotoc
  % \imki@indexlevel{\indexname}\imki@indexheaders
      \imki@idxprologue
      \global\let\imki@idxprologue\relax
      \parindent\z@
      \parskip\z@ \@plus .3\p@\relax
      \raggedright
      \let\item\@idxitem
    \imki@othercode}
{%
}


\let\indexspace\relax

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


\begin{filecontents*}{\jobname.xdy}
(define-attributes (("default" "definition" "textbf")))
( define-location-class "sec-num" :var
                        ("arabic-numbers"
             :sep "." "arabic-numbers"
             :sep "." "arabic-numbers"
             :sep "." "arabic-numbers"
             :sep "." "arabic-numbers"
))
(require "texindy.xdy")
;;(markup-trace :on)
;; ignore group headers
;;markup-letter-group :open "% ")
;;
(markup-index :open  "\begin{theindex}~n
 \providecommand*\lettergroupDefault[1]{}
 \providecommand*\lettergroup[1]{%
 \par}"
          :close "~n~n\end{theindex}~n"
          :tree)
;;
(markup-keyword :open "\idxkeyword{" :close "}" )
(markup-locref :open "\idxlocator{" :close "}")
(markup-locref :open "\textrm{\idxlocator{" :close "}}"  :attr "textrm")
(markup-locref :open "\textrm{\idxlocator{" :close "}}"  :attr "definition")
;;
;; change style of index entries
;;(markup-locclass-list :open "\dotfill " :sep ", ")
(markup-locclass-list :open "\ \ \ ")
(markup-locref-list :sep ", ")
\end{filecontents*}

The index item for Muller is not generated correctly - see picture below.

Index from tex4ebook

The tex4ebook run gives errors.

This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/W32TeX) (preloaded format=latex)
 \write18 enabled.
entering extended mode
[ERROR]   htlatex: Compilation errors in the htlatex run
[ERROR]   htlatex: Filename Line    Message
[ERROR]   htlatex: ./ebook.cfg  40   Missing \endcsname inserted.
[ERROR]   htlatex: ./ebook.cfg  40   LaTeX Error: Missing \begin{document} in `ebook.cfg'.
[ERROR]   htlatex: ./ebook.cfg  40   Extra \endcsname.
[ERROR]   htlatex: ./ebook.cfg  40   Missing \endcsname inserted.
[ERROR]   htlatex: ./ebook.cfg  40   Missing \endcsname inserted.
[ERROR]   htlatex: ./ebook.cfg  40   Extra \endcsname.
[ERROR]   htlatex: ./sample.ind [15 17   Missing \endcsname inserted.
[ERROR]   htlatex: ./sample.ind [15 17   Missing \endcsname inserted.
[ERROR]   htlatex: ./sample.ind [15 17   Extra \endcsname.
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/W32TeX) (preloaded format=latex)
 \write18 enabled.
entering extended mode
[ERROR]   htlatex: Compilation errors in the htlatex run
[ERROR]   htlatex: Filename Line    Message
[ERROR]   htlatex: ./ebook.cfg  43   Missing \endcsname inserted.
[ERROR]   htlatex: ./ebook.cfg  43   LaTeX Error: Missing \begin{document} in `ebook.cfg'.
[ERROR]   htlatex: ./ebook.cfg  43   Extra \endcsname.
[ERROR]   htlatex: ./ebook.cfg  43   Missing \endcsname inserted.
[ERROR]   htlatex: ./ebook.cfg  43   Missing \endcsname inserted.
[ERROR]   htlatex: ./ebook.cfg  43   Extra \endcsname.
[ERROR]   htlatex: ./sample.ind [15 17   Missing \endcsname inserted.
[ERROR]   htlatex: ./sample.ind [15 17   Missing \endcsname inserted.
[ERROR]   htlatex: ./sample.ind [15 17   Extra \endcsname.
--- warning --- Ignoring \special{t4ht.html}

The index from a pdflatex run is correct.

The tex4ebook run used to work correctly a few years ago but it doesn't now.

Is there a way to fix this thank you?

Update using build.mk4 from @Michal.h21.

I get index errors and no index is generated.

Errors in tex4ebook run:

This is LuaTeX, Version 1.12.0 (TeX Live 2020/W32TeX)
 restricted system commands enabled.
[ERROR]   htlatex: Compilation errors in the htlatex run
[ERROR]   htlatex: Filename Line    Message
[ERROR]   htlatex: ./sample.ind [15 5    Extra }, or forgotten $.
[ERROR]   htlatex: ./sample.ind [15 9    Missing $ inserted.
[ERROR]   htlatex: ./sample.ind [15 13   Missing } inserted.

sample.idx

\beforeentry{samplech1.html}{dx3-2001}{}
\indexentry{aword}{3}
\beforeentry{samplech2.html}{dx4-3001}{}
\indexentry{bword}{9}
\beforeentry{samplech2.html}{dx4-3002}{}
\indexentry{Muller@M\"{u}ller}{9}
\beforeentry{samplech2.html}{dx4-3003}{}
\indexentry{zword}{13}

sample.ind

\begin{theindex}
\indexspace
\textbf{A}\label{L-xindex-A}
\nopagebreak[4]
  \item aword, {\Link[]{dx3-2001}{}1\EndLink{}}
\indexspace
\textbf{B}\label{L-xindex-B}
\nopagebreak[4]
  \item bword, {\Link[]{dx4-3001}{}2\EndLink{}}
\indexspace
\textbf{M}\label{L-xindex-M}
\nopagebreak[4]
  \item M\({u}ller, {\Link[]{dx4-3002}{}3\EndLink{}}
\indexspace
\textbf{Z}\label{L-xindex-Z}
\nopagebreak[4]
  \item zword, {\Link[]{dx4-3003}{}4\EndLink{}}
\end{theindex}

Update 2:

There are two issues still for the ebook.

The index doesn't show on the table of contents and the links in the index don't go anywhere - see below.

ebook

The toc in the pdf file is correct and the links work- see below.

pdf

Is there any way to fix this thank you.

Update 3:

The index now shows in the toc using the new imakeidx.4ht.

I added an extra line to the build file to get the links to work. It's now

if mode=="draft" then
 Make:htlatex {}
else
  Make:htlatex {}
  Make:xindy {modules={"utf8-lang"}}
  Make:biber {}
  Make:htlatex {}
  Make:xindy {modules={"utf8-lang"}}
  Make:htlatex {}
end

Is this the best or most efficient way?

I also changed the xindy module to utf8-lang as above and added a new line

S\'{e}an\index{Sean@S\'{e}an}

in the input file and it worked as well. Is this the best way to deal with character accents from

https://en.wikibooks.org/wiki/LaTeX/Special_Characters#Escaped_codes

and not just german ones?

There is still one minor issue with the index. There is a missing space between "aword" and the "B" header:

new index

Thank you.

2
  • 1
    Does it work with \index{Muller@Müller}? May 12, 2020 at 8:09
  • No using the accented character gives a UseRawInputEncoding error.
    – user41974
    May 12, 2020 at 8:45

1 Answer 1

1

I've changed the indexing support in make4ht and tex4ebook, so you don't need to use imakeindex.4ht anymore. You can delete it. Instead, built-in TeX4ht indexing support can be used.

The build.mk4 file can look like this:

if mode=="draft" then
  Make:htlatex {}
else
  Make:htlatex {}
  Make:xindy {modules={"duden-utf8"}}
  Make:biber {}
  Make:htlatex {}
  Make:htlatex {}
end

The Make:xindy command is built-in make4ht command. There are also Make:xindex and Make:makeindex commands. See the make4ht documentation for more details.

This is the resulting index in the Epub file, compiled using

tex4ebook -l -c epub.cfg -e build.mk4 filename.tex

enter image description here

Every term has now distinct number, so index contains all used terms. This is a difference to the previous version, where terms were sorted under section numbers.

Edit:

For the intoc option imakeidx support, try the following version of imakeidx.4ht:

% imakeidx.4ht (2020-05-18-14:06), generated from tex4ht-4ht.tex
% Copyright 2019 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\immediate\write-1{version 2020-05-18-14:06}


\def\:temp#1#2#3{\html:addr%
\hbox{\Link-{}{dx\last:haddr
}\EndLink}%
\expandafter\protected@write\csname#1@idxfile\endcsname{}%
{\string\beforeentry{\RefFileNumber\FileNumber}{dx\last:haddr
}{\a:makeindex}}%
\o:imki@wrindexentrysplit:{#1}{#2}{#3}%
}
\HLet\imki@wrindexentrysplit\:temp

\ifx \a:makeindex\:UnDef
\NewConfigure{makeindex}{}\Configure{makeindex}{}
\fi
\Configure{@begin}{theindex}{\ind:defs\imki@maybeaddtotoc}



\Hinput{imakeidx}
\endinput

I've updated TeX4ht sources, so it should work everywhere soon.

18
  • 1
    @user41974 ah, binhex.tex should be part of your installation. it is in texmf-dist/tex/generic/kastrup/binhex.tex in my install. it is needed for accented characters with LuaTeX or XeTeX.
    – michal.h21
    May 13, 2020 at 12:05
  • 1
    @user41974 ah, I've replaced \index{Muller@M\"{u}ller} with \index{Müller} and it worked. This seems like a bug in Xindex, as it introduces wrong characters in the generated .ind file: \item M\({u}ller, {7}. It works correctly with Xindy. But I would use accented characters anyway and then Xindex works well.
    – michal.h21
    May 14, 2020 at 8:38
  • 1
    @user41974 and do you use LuaTeX (with make4ht -l option)? Accented version should definitely work. If accent doesn't work, you can use the ASCII version with Xindy
    – michal.h21
    May 14, 2020 at 11:55
  • 1
    @user41974 sure, please see the edit
    – michal.h21
    May 14, 2020 at 12:49
  • 1
    @user41974 sorry that was syntax error in the build file. It should be fixed now, it works with tex4ebook and make4ht as well.
    – michal.h21
    May 14, 2020 at 15:27

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.