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.
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.
The toc in the pdf file is correct and the links work- see below.
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:
Thank you.
\index{Muller@Müller}
?