2

When I create an MWE below, the sort order in the index is perfectly alphabetical. However when I work with a very large document which uses babel in the exact same manner, the order in the index is broken. I observe groups of alphabetically correctly ordered entries, but they are sprinkled with entries out of order. I cannot post the entire document as it is megabytes in size and have no idea how to troubleshoot, as it uses dozens of packages.

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

\index{жзи}

\clearpage
\lipsum[2]

\index{где}

\clearpage
\lipsum[3]

\index{абв}

\printindex
\end{document}

Edit (taken from the answer below):

I just reproduced the problem by adding more entries. The 2nd entry is in the wrong place:

\documentclass{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1,T2A]{fontenc}
\usepackage[main=russian]{babel}
\usepackage{lipsum}
\usepackage{makeidx}
\makeindex
\begin{document} 
\lipsum[1]
\index{жзи}
\clearpage
\lipsum[2]
\index{где}
\clearpage
\lipsum[3]
\index{абв}
\clearpage
\lipsum[4]
\index{эюя}
\clearpage
\lipsum[5]
\index{шщы}
\clearpage
\lipsum[6]
\index{клм}
\printindex
\end{document}

1 Answer 1

1

There are a couple of problems to solve.

  1. MakeIndex doesn't know about Russian and Cyrillic.

  2. There are expansion issues with Cyrillic characters in pdflatex.

The first problem is solved using xindy. The second is solved by defining an ad hoc command for Cyrillic words to index.

\documentclass{article}
\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} 
\lipsum[1]
\rindex{жзи}
\clearpage
\lipsum[2]
\rindex{где}
\clearpage
\lipsum[3]
\rindex{абв}
\clearpage
\lipsum[4]
\rindex{эюя}
\clearpage
\lipsum[5]
\rindex{шщы}
\clearpage
\lipsum[6]
\rindex{клм}
\printindex
\end{document}

After running LaTeX, run

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

and run LaTeX again (substitute <filename> with the actual file name).

enter image description here

3
  • For whatever reason this works in the MWE but not in a real document. When I compile the MWE then it produces an .ind file with the same index items as in the MWE: \item абв, 3. But if I compile another real document, then the entries are \item \T2A\CYRD \T2A\cyro \T2A\cyrz , \hyperpage{224} and there is an error on the 2nd pass: Undefined control sequence. \item \T
    – SuperAl
    Commented Dec 20, 2019 at 18:24
  • It sounds like the issue begins in the .idx file as it also contains \T2A\CYRD Something is encoding every cyrillic letter in my "big" document but not in the MWE. What could it be?
    – SuperAl
    Commented Dec 20, 2019 at 19:30
  • I narrowed it down to the memoir class. It causes the .idx to be generated with encoded Cyrillic characters. I shall ask another question with this info.
    – SuperAl
    Commented Dec 20, 2019 at 19:42

You must log in to answer this question.

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