# htlatex, imakeidx, and textit in an index entry

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
{example}}{1}


Here is an MWE:

\documentclass{book}

\usepackage{imakeidx}
\makeindex

\begin{document}

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

\printindex
\end{document}


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.

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'