1

I use tex4ebooks the first time. I thought today that I managed to get indexing with it, but then at the final step an encoding problem arose, which I already solved with the help of the forum.

But now an undefined control sequence come with the minimal example as following:

The config for tex4ebook shows this:

\Preamble{xhtml,no-cut,3,info}
\usepackage{indexing4ht}
\usepackage{gettitlestring}
\makeatletter
\Configure{@author}{\let\footnote\@gobble}
\Configure{@title}{\let\footnote\@gobble}
\makeatother
\GetTitleStringDisableCommands{%
\renewcommand\textbf[1]{#1}%
\renewcommand\LaTeX{LaTeX}
}
\begin{document}
\Configure{DocumentLanguage}{de}
% You can also add more authors to your ebook metadata:
\Configure{OpfMetadata}{\HCode{<dc:creator>An author</dc:creator>}}
\Configure{OpfMetadata}{\HCode{<dc:title>A title</dc:title>}}
\Configure{OpfMetadata}{\HCode{<dc:publisher>A publisher</dc:publisher>}}
\Configure{OpfMetadata}{\HCode{<dc:contributor>Somethin</dc:contributor>}}
\Configure{OpfMetadata}{\HCode{<dc:date opf:event='Originalausgabe'>2023</dc:date>}}
\EndPreamble

The indexing4ht.sty is as follows:

\ProvidesPackage{indexing4ht}
\RequirePackage{etoolbox}
\RequirePackage{gettitlestring}
% Befehl zum Abrufen der vollständigen Abschnittsnummer für den aktuellen Abschnittsbefehl
\newcommand\getCurrentSectionNumber{%
  \ifnum\c@section=0 %
  \thechapter
  \else
  \ifnum\c@subsection=0 %
  \thesection
  \else
  \ifnum\c@subsubsection=0 %
  \thesubsection
  \else
  \thesubsubsection
  \fi
  \fi
  \fi
}

\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-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")
\end{filecontents*}
\endinput

An the indexing4ht.4ht shows:

\@ifpackageloaded{imakeidx}{%
    \makeatletter
    \newcommand\:wrindex[3]{%
      \edef\th@idx@entry{\detokenize{#2}}
        \imki@wrindexentry{#1}{\th@idx@entry}{#3}
    }
    \makeatother
}{%ToDo: Provide configuration for index writing without imakeidx
    \newcommand\:wrindex[3]{}
}

% because imakeidx has support for multiple indices, we need to select a
% right one
\NewConfigure{indexname}{1}
% default index name is \jobname

% configure variable which is saved on every index call
% section mark is used by default, other possible values may be paragraphs, or
% links to individual index entries
\NewConfigure{indexvalue}{1}
\Configure{indexvalue}{\getCurrentSectionNumber}
\NewConfigure{indexidentifier}{1}
\Configure{indexidentifier}{\CurSecHaddr}

% we need to suppress adding of multiple identical identifiers
\edef\curseccnt{}
\renewcommand\index[2][]{%
  \ifx|#1|%
     \Configure{indexname}{\jobname}%
   \else\Configure{indexname}{#1}%
     \fi%
  \:wrindex{\a:indexname}{#2}{\a:indexvalue}
    % save identifier only if it haven't been used yet
  \expandafter\ifcsname usedsec\a:indexvalue\endcsname
    \else%
    \Tag{sec\a:indexvalue}{\a:indexidentifier}
  \fi%
  \expandafter\gdef\csname usedsec\a:indexvalue\endcsname{yes}
  \let\curseccnt\newseccnt
}

% print index locators. make links to destinations in document
\newcommand\idxlocator[1]{%
\ifTag{sec#1}{\a:locatorlink{\Ref{sec#1}}{}#1\b:locatorlink}{#1}%
%\ifTag{sec#1}{\Link{\Ref{sec#1}}{}#1\EndLink}{#1}%
\typeout{\LikeRef{sec#1}}}

\NewConfigure{locatorlink}{2}
\Configure{locatorlink}{\Link}{\EndLink}

% to support crossreferencess, we save index keyword with unique identifier

\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}

  
\renewcommand\see[1]{%
  \GetTitleString{#1}%
  \a:see\ \ifTag{idxkw#1}{\a:seeLink{\Ref{idxkw\GetTitleStringResult}}{}#1\b:seeLink}{#1}
}  

% make link configurable, in order to enable user to add custom parameters
\NewConfigure{seeLink}{2}
\Configure{seeLink}{\Link}{\EndLink}

\NewConfigure{see}{1}
\Configure{see}{\textit{siehe}}

\renewcommand\seealso[1]{%
  \GetTitleString{#1}%
  \a:seealso\ \ifTag{idxkw#1}{\a:seeAlsoLink{\Ref{idxkw\GetTitleStringResult}}{}#1\b:seeAlsoLink}{#1}
}

\NewConfigure{seeAlsoLink}{2}
\Configure{seeAlsoLink}{\Link}{\EndLink}

\NewConfigure{seealso}{1}
\Configure{seealso}{\textit{siehe auch}}

And finally the makefile mymakef.mk4 is this:

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

Then I run first

tex4ebook -a debug -c myconfig.cfg -m index -e mymakef.mk4 Sourcename.tex

And then call xindy manually to get the .ind file

call xindy -L german -C duden-utf8 -I latex -M Sourcename.xdy Sourcename.idx

And then I run tex4ebook again an get the undefined controll sequence error:

Undefined control sequence.
l.9   \item \idxkeyword
                       {Ende}, \idxlocator{4}

The tex-file finallly is this as minimal example:

\documentclass[11pt,a4paper]{report}
\usepackage[cmintegrals,cmbraces]{newtxmath}
\usepackage{ebgaramond-maths}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{tex4ebook}
\usepackage[xindy,noautomatic]{imakeidx}
\makeindex[intoc=false,columns=1,noautomatic,title=Alphabetisches Verzeichnis]
\usepackage[hyperindex=true,
pdfauthor={Autor},
pdftitle={Titel},
pdfkeywords={Philosophy}]{hyperref}

\begin{document}
\tableofcontents    
    \section{Übungen}
    Praxis und Übungen\index{Uebungen@Übungen}
    
    \section{Abschnitt Eins}
    
    Zwei Welten\index{Welten} und Ähren im Feld.
    
    \section{Abschnitt Zwei}    
    
    Beginn und Ende\index{Ende}
    
    \printindex
\end{document}

Maybe someone knows the clue to the door. Thank you.

Thomkrates

1 Answer 1

0

Indexing is now supported out of the box in TeX4ht, so you don't really need the indexing4ht package. You can remove it from your .cfg file. I also had to remove Make:biber {} from your build file, because you don't use BibLaTeX in the example, and it resulted in an error.

For German-Duden, try this build file:

if mode=="draft" then
  Make:htlatex {}
else
  Make:htlatex {}
  Make:xindy {language="german-duden"}
  Make:htlatex {}
  Make:htlatex {}
end

The up-to-date information about indexing is available in this how to.

This is how your index looks in Calibre:

enter image description here

23
  • Thank you, how did you do that? I removed indexinght.sty and Make:biber {}. And started from scratch, with 1. tex4ebook like above mentioned 2. xindy like above mentioned and 3. again tex4ebook. But I get the same error message. Do I have the newest tex4ebook version? --> Version 0.3h. Is this new enought?
    – Thomkrates
    Mar 12 at 19:54
  • xindy shows the info lines: "Encountered unexpected char '\' on line 1 Encountered unexpected char 'b' on line 1 Encountered unexpected char 'e' on line 1 Encountered unexpected char 'f' on line 1 ..." Is this again an encoding problem?
    – Thomkrates
    Mar 12 at 20:10
  • @Thomkrates you don't need to run Xindy manually, it is called automatically from the build file, with necessary post-processing steps.
    – michal.h21
    Mar 12 at 20:34
  • Thank you. Unfortunately I do not got your result. The index in the epub is without hyperref. And additionally with the minimal example, I got two table of contents in the epub und doubled. - Is this intentious? - The latest version of tex4ebook is 0.3i. I copied the files in appropriate folder.
    – Thomkrates
    Mar 12 at 21:03
  • @Thomkrates yes, the double TOC is intentional, this fixes a bug with split chapters, where the TOC was in a separate page and there was no way how to go from the main HTML file to subpages. So now the main TOC is printed in the main page, but you will get an extra TOC when you use \tableofcontents. You can disable the second TOC using \ifdefined\HCode\else\tableofcontents\fi.
    – michal.h21
    Mar 12 at 21:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .