# Automatic prefix in index for words with accented characters

When generating an index with French words, I need to add a prefix to accentuated words so they they get listed in alphabetical order:

\index{saintete@sainteté}
\index{ame@âme}


Is there a way to have this done automatically?

-
Not with MakeIndex that's irremediably old-fashioned and deals only with Latin unaccented characters. With Xindy it should be possible. –  egreg Jun 10 '13 at 21:11
\newcommand\saintete{sainteté\index{saintete@sainteté}}..? –  jon Jun 10 '13 at 21:12
@jon: I'd have to do that for hundreds of keywords then. –  ℝaphink Jun 10 '13 at 21:15
I figured; but this is another reason why technical/special terminology should always be encoded in macros (easy to say that at the wrong time, I know). The advantage, however, is that you can do things like: \newcommand{\saintete}[1][]{sainteté\index{saintete@sainteté!#1}} and then have in your text, main and sub-entries like \saintete and \saintete[typologie de] very easily. –  jon Jun 10 '13 at 21:27
Well I don't really do my indexes this way actually (not for this book at least). Quite a few words I use as index do not actually occur in the text. –  ℝaphink Jun 10 '13 at 21:35

With Xindy instead of MakeIndex the sorting seems to be correct.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[texindy]{imakeidx}
\makeindex[options=-L french]
\begin{document}
ame\index{ame}
âme\index{âme}
année\index{année}
cote\index{cote}
côte\index{côte}
coté\index{coté}
côté\index{côté}

\printindex
\end{document}


Recall that imakeidx with Xindy requires -shell-escape (or running texindy manually).

-
What are your exact command lines for compiling this example with Xindy? Thanks –  pluton Jun 10 '13 at 22:52
@pluton Just pdflatex -shell-escape <filename> –  egreg Jun 10 '13 at 22:54
That is strange. I've been trying that several times and it does not work. On windows, I got a "'texindy' is not recognized as an internal or external command, operable program or batch file" error message. I have to investigate. –  pluton Jun 10 '13 at 23:02
@pluton: I'm guessing you need to install xindy. –  ℝaphink Jun 11 '13 at 5:31
@ℝaphink Don't give the texindy option to the package, but use \makeindex[program=texindy,options=-L french,...] for defining the index which you want to use Xindy for. –  egreg Jun 11 '13 at 8:30

Sticking with makeindex and pdftex you can do something like this

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{makeidx}
\makeindex
\let\oldindex\index
\makeatletter

\def\index#1{%
{\let\IeC\@firstofone   \let\^\@empty
\let\'\@empty
\let\\@empty
\let\'\@empty
\let\@tabacckludge\@gobble
\protected@xdef\tmp{#1\unexpanded{@#1}}}%
\oldindex{\tmp}}
\makeatother
\begin{document}

ame\index{ame}
âme\index{âme}
année\index{année}
cote\index{cote}
côte\index{côte}
coté\index{coté}
côté\index{côté}

\printindex
\end{document}


which produces an idx file

\indexentry{ame@ame}{1}
\indexentry{ame@\IeC {\^a}me}{1}
\indexentry{annee@ann\IeC {\'e}e}{1}
\indexentry{cote@cote}{1}
\indexentry{cote@c\IeC {\^o}te}{1}
\indexentry{cote@cot\IeC {\'e}}{1}
\indexentry{cote@c\IeC {\^o}t\IeC {\'e}}{1}
`

and output

-
That looks like a very interesting alternative. –  ℝaphink Jun 11 '13 at 5:35