I'm using htlatex to create an ebook.

For some customization reasons, I need to use imakeidx instead of makeidx. Additionally, some of my index entries are using \textit{}, e.g. \index{\textit{example}}.

This works fine with standard latex. But with htlatex, it's a problem. Specifically, for the index I need to run:

tex '\def\filename{{doc}{idx}{4dx}{ind}} \input idxmake.4ht'

and it's getting tripped up by the \textit{} in the index entry. The error message is:

! Undefined control sequence.
l.1 \indexentry{\textit

Here is an MWE:




An \textit{example}\index{\textit{example}}.


The commands I'm using to process this are:

htlatex doc "xhtml,charset=utf-8" " -cunihtf -utf8"
tex '\def\filename{{doc}{idx}{4dx}{ind}} \input idxmake.4ht'
makeindex -o doc.ind doc.4dx
htlatex doc "xhtml,charset=utf-8" " -cunihtf -utf8"

If I change imakeidx to makeidx, it works. But, I need to use imakeidx.

1 Answer 1


It seems that the issue is that the \textit command is executed somewhere in the index processing. Because the indexing is done by plain TeX, it doesn't know LaTeX commands, as \textit is. The easiest solution is to define dummy \textit macro:

tex '\def\textit#1{#1}\def\filename{{sample}{idx}{4dx}{ind}} \input idxmake.4ht' 

This version compiles without issues and the output seems correct:

enter image description here

Note that there is also another solution for indexing, using Xindy (1, 2), which uses section numbers instead of page numbers for locators. This may be more useful than page numbers which are used by default.

  • This does solve my problem with \textit{} not being defined. But, there appear to be larger issues with idxmake.4ht not being compatible with imakeidx; in the above solution doc.ind is coming from htlatex itself. I ended up using the Xindy approach you @michal.h21 mentioned, via your helpers4ht package.
    – cryptoplex
    Jan 2, 2018 at 5:29

You must log in to answer this question.

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