1

How to make and sort index on cyrilic alphabet?

Trying to make index with Serbian words:

\documentclass{book}
\usepackage[OT1, OT2]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english, serbian]{babel}
\usepackage{imakeidx}

\makeindex[name=person,title={Indeks imena},options=-s index_style.ist]

\makeindex[program=makeindex,columns=2,intoc=true,options=-s index_style.ist]

\begin{document}

\chapter{Pitagora}

\index[person]{Pitagora|text}

\index[person]{Riman|text}

\index[person]{Vijet|text}

\index[person]{Gaus|text}

\printindex[person]

\end{document}
5
  • You're using Cyrillic by default, so that's how the names are interpreted.
    – egreg
    Apr 2 '20 at 19:53
  • Yes, names are interpreted, but not sorted. For example: Vijet, Gaus, Pitagora and Riman.
    – BranislavM
    Apr 2 '20 at 19:57
  • What's in index_style.ist?
    – egreg
    Apr 2 '20 at 20:00
  • 1
    Anyway, MakeIndex only sorts using ASCII.
    – egreg
    Apr 2 '20 at 20:03
  • index_style.ist is file: headings_flag 1 heading_prefix "{\\large\\bfseries " heading_suffix "}\\nopagebreak\n" delim_0 " \\dotfill " delim_1 " \\dotfill " delim_2 " \\dotfill "
    – BranislavM
    Apr 2 '20 at 20:05
2

This works for me:

\documentclass{book}
\usepackage[OT1, OT2]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english, serbian]{babel}
\usepackage[xindy]{imakeidx}

\makeindex[program=truexindy,name=person,title={Indeks imena},options=-M mystyle.xdy]

\usepackage{filecontents}
\begin{filecontents*}{mystyle.xdy}
(require "lang/serbian/utf8-lang.xdy")
(require "texindy.xdy")
(define-letter-groups
    ("A" "B" "V" "G" "D" "DJ" "E" "ZH" "Z" "I" "J" "K" "L" "LJ" "M"
     "N" "NJ" "O" "P" "R" "S" "T" "C1" "U" "F" "H" "C" "CH" "D2" "SH"))
(sort-rule "a" "A")
(sort-rule "b" "B")
(sort-rule "v" "V")
(sort-rule "g" "G")
(sort-rule "d" "D")
(sort-rule "Dj" "DJ")
(sort-rule "dj" "DJ")
(sort-rule "e" "E")
(sort-rule "Zh" "ZH")
(sort-rule "zh" "ZH")
(sort-rule "z" "Z")
(sort-rule "i" "I")
(sort-rule "j" "J")
(sort-rule "k" "K")
(sort-rule "l" "L")
(sort-rule "Lj" "LJ")
(sort-rule "lj" "LJ")
(sort-rule "m" "M")
(sort-rule "n" "N")
(sort-rule "Nj" "NJ")
(sort-rule "nj" "NJ")
(sort-rule "o" "O")
(sort-rule "p" "P")
(sort-rule "r" "R")
(sort-rule "s" "S")
(sort-rule "t" "T")
(sort-rule "c1" "C1")
(sort-rule "u" "U")
(sort-rule "f" "F")
(sort-rule "h" "H")
(sort-rule "c" "C")
(sort-rule "Ch" "CH")
(sort-rule "ch" "CH")
(sort-rule "d2" "D2")
(sort-rule "Sh" "SH")
(sort-rule "sh" "SH")
\end{filecontents*}

\begin{document}

\chapter{Pitagora}

\index[person]{Pitagora}

\index[person]{Riman}

\index[person]{Vijet}

\index[person]{Gaus}

\printindex[person]

\end{document}

Then you compile like this:

pdflatex yourFile.tex
xindy -M mystyle.xdy -L serbian person.idx
pdflatex yourFile.tex

But be careful! Letters you get as a combination with number, such as c1 or d2 will be sorted wrong. Always is better to use utf8 input and T2A encoding rather than OT2 with ASCII input.

P.S. For Serbian I always recommend to use package cmsrb. In new version I created experimental encodings where you can use dx cy for џ ћ so the results with sorting will be better.

EDIT:

After some playing with xindy, I've found another solution where the problems with a letters that are created like a ligature with number for OT2 encoding, such as c1 for ћ, can be solved. Also, for Serbian language the letter group is already defined, therefore there is no need to write it again, we will just map Latin letter or ligature to the corresponding Cyrillic UTF-8 letter.

\documentclass{book}
\usepackage[OT1, OT2]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english, serbian]{babel}
\usepackage[xindy]{imakeidx}

\makeindex[program=xindy,name=person,title={Indeks imena},columns=1]

\usepackage{filecontents}
\begin{filecontents*}{mystyle.xdy}
(require "texindy.xdy")
(merge-rule "DJ" "Ђ" :again)
(merge-rule "Dj" "Ђ" :again)
(merge-rule "dj" "Ђ" :again)
(merge-rule "ZH" "Ж" :again)
(merge-rule "Zh" "Ж" :again)
(merge-rule "zh" "Ж" :again)
(merge-rule "LJ" "Љ" :again)
(merge-rule "Lj" "Љ" :again)
(merge-rule "lj" "Љ" :again)
(merge-rule "NJ" "Њ" :again)
(merge-rule "Nj" "Њ" :again)
(merge-rule "nj" "Њ" :again)
(merge-rule "C1" "Ћ" :again)
(merge-rule "c1" "Ћ" :again)
(merge-rule "CH" "Ч" :again)
(merge-rule "Ch" "Ч" :again)
(merge-rule "ch" "Ч" :again)
(merge-rule "D2" "Џ" :again)
(merge-rule "d2" "Џ" :again)
(merge-rule "SH" "Ш" :again)
(merge-rule "Sh" "Ш" :again)
(merge-rule "sh" "Ш" :again)
(merge-rule "A" "А" :again)
(merge-rule "a" "А" :again)
(merge-rule "B" "Б" :again)
(merge-rule "b" "Б" :again)
(merge-rule "V" "В" :again)
(merge-rule "v" "В" :again)
(merge-rule "G" "Г" :again)
(merge-rule "g" "Г" :again)
(merge-rule "D" "Д" :again)
(merge-rule "d" "Д" :again)
(merge-rule "E" "Е" :again)
(merge-rule "e" "Е" :again)
(merge-rule "Z" "З" :again)
(merge-rule "z" "З" :again)
(merge-rule "I" "И" :again)
(merge-rule "i" "И" :again)
(merge-rule "J" "Ј" :again)
(merge-rule "j" "Ј" :again)
(merge-rule "K" "К" :again)
(merge-rule "k" "К" :again)
(merge-rule "L" "Л" :again)
(merge-rule "l" "Л" :again)
(merge-rule "M" "М" :again)
(merge-rule "m" "М" :again)
(merge-rule "N" "Н" :again)
(merge-rule "n" "Н" :again)
(merge-rule "O" "О" :again)
(merge-rule "o" "О" :again)
(merge-rule "P" "П" :again)
(merge-rule "p" "П" :again)
(merge-rule "R" "Р" :again)
(merge-rule "r" "Р" :again)
(merge-rule "S" "С" :again)
(merge-rule "s" "С" :again)
(merge-rule "T" "Т" :again)
(merge-rule "t" "Т" :again)
(merge-rule "U" "У" :again)
(merge-rule "u" "У" :again)
(merge-rule "F" "Ф" :again)
(merge-rule "f" "Ф" :again)
(merge-rule "H" "Х" :again)
(merge-rule "h" "Х" :again)
(merge-rule "C" "Ц" :again)
(merge-rule "c" "Ц" :again)
\end{filecontents*}

\begin{document}

\chapter{Pitagora}

\index[person]{Pitagora}

\index[person]{Riman}

\index[person]{Vijet}

\index[person]{Gaus}

\printindex[person]

\end{document}

After that, compile your code with:

pdflatex yourFile.tex
xindy -M mystyle.xdy -C utf8 -L serbian person.idx
pdflatex yourFile.tex

Of course, if you want to use some other ligatures, like d1 for ђ, you will have to add line (merge-rule "d1" "Ђ" :again).

xindy Serbian OT2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.