[Tex/LaTex] Making and sorting index for Russian

xindy

Trying to make index with Russian words, MWE:

\documentclass{book}
\usepackage[T1, T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english, russian]{babel}
\usepackage[xindy]{imakeidx}
\makeindex

\begin{document}

\chapter{Первая}

\index{notepad}
\index{apple}
\index{часть}
\index{дерево}
\index{электрон}

\printindex

\end{document}

I use MiKTeX (full and updated), run: latexmk.exe -pdf file.tex

This gives me file.pdf with russian words in Index, but they are sorted in wrong way. file.idx is:

\indexentry{notepad}{1}
\indexentry{apple}{1}
\indexentry{\IeC {\cyrch }\IeC {\cyra }\IeC {\cyrs }\IeC {\cyrt }\IeC {\cyrsftsn }}{1}
\indexentry{\IeC {\cyrd }\IeC {\cyre }\IeC {\cyrr }\IeC {\cyre }\IeC {\cyrv }\IeC {\cyro }}{1}
\indexentry{\IeC {\cyrerev }\IeC {\cyrl }\IeC {\cyre }\IeC {\cyrk }\IeC {\cyrt }\IeC {\cyrr }\IeC {\cyro }\IeC {\cyrn }}{1}

And I see the problem is that LaTeX makes index according to these {\cyrch}, {\cyre} etc. I thought using utf8 encoding and xindy could solve all the problems with languages. How to make russian index with correct sorting: дерево, часть, электрон in my case?

Best Answer

Due to some constraints, the \index command doesn't work very well with UTF-8 characters (something which could only be solved with a brand new version, I'm afraid.)

You can overcome the issue by doing

\documentclass{book}
\usepackage[T1, T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english, russian]{babel}
\usepackage[xindy]{imakeidx}
\makeindex

\makeatletter
\newcommand{\rindex}[2][\imki@jobname]{%
  \index[#1]{\detokenize{#2}}%
}
\makeatother

\begin{document}

\chapter{Первая}

\rindex{notepad}
\rindex{apple}
\rindex{часть}
\rindex{дерево}
\rindex{электрон}

\printindex

\end{document}

Calling

texindy -L russian -C utf8 <filename>.idx

produces the index as expected:

enter image description here

Related Question