# Why does memoir class encode the contents of .idx file and how can it still be used to produce a properly sorted Russian index?

When using the answer I faced the following error message on the 2nd pass (with pdflatex):

Undefined control sequence. \item \T

It originates from the entry in the .ind file:

\item \T2A\CYRD \T2A\cyro \T2A\cyrz , \hyperpage{224}

In turn it is generated by the following entry in the .idx file:

\indexentry{\T2A\CYRD \T2A\cyro \T2A\cyrz |hyperpage}{224}

If I switch memoir to article or book then the index contains the entries defined in the document verbatim, without them being encoded.

The following MWE can be used to validate:

\documentclass{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1,T2A]{fontenc}
\usepackage[main=russian]{babel}
\usepackage{lipsum}
\usepackage{makeidx}
\makeindex

\newcommand{\rindex}[1]{\expandafter\index\expandafter{\detokenize{#1}}}

\begin{document}
жзи\rindex{жзи}
\clearpage
где\rindex{где}
\clearpage
абв\rindex{абв}
\clearpage
эюя\rindex{эюя}
\clearpage
шщы\rindex{шщы}
\clearpage
клм\rindex{клм}

\printindex
\end{document}

It passes the 1st pass, then command texindy -L russian -C utf8 "document.idx" generates the .ind file, and the 2nd pass fails.

• You may want to consider updating your TeX system. I have a fully updated system with LaTeX2e <2019-10-01> patch level 3 and get \indexentry{жзи}{1} etc. in the .idx file. I think I remember that LaTeX 2019-10-01 brought great improvements for Unicode handling in pdfLateX in some areas. Alternatively it might be a good idea to switch to a Unicode engine like XeLaTeX or LuaLaTeX. Dec 20, 2019 at 20:01
• Thank you. I am on TL 2018 and am staying on it due to hardware and software constraints out of scope of this question. Dec 20, 2019 at 20:04
• I think that for this to work the following package has to be used: \usepackage[xindy]{imakeidx} Dec 20, 2019 at 20:04