6

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?

9
  • 3
    Not with MakeIndex that's irremediably old-fashioned and deals only with Latin unaccented characters. With Xindy it should be possible.
    – egreg
    Commented Jun 10, 2013 at 21:11
  • \newcommand\saintete{sainteté\index{saintete@sainteté}}..?
    – jon
    Commented Jun 10, 2013 at 21:12
  • @jon: I'd have to do that for hundreds of keywords then.
    – raphink
    Commented Jun 10, 2013 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
    Commented Jun 10, 2013 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.
    – raphink
    Commented Jun 10, 2013 at 21:35

2 Answers 2

7

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).

enter image description here

7
  • What are your exact command lines for compiling this example with Xindy? Thanks
    – pluton
    Commented Jun 10, 2013 at 22:52
  • @pluton Just pdflatex -shell-escape <filename>
    – egreg
    Commented Jun 10, 2013 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
    Commented Jun 10, 2013 at 23:02
  • @pluton: I'm guessing you need to install xindy.
    – raphink
    Commented Jun 11, 2013 at 5:31
  • 1
    @ℝ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
    Commented Jun 11, 2013 at 8:30
6

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

enter image description here

1
  • That looks like a very interesting alternative.
    – raphink
    Commented Jun 11, 2013 at 5:35

You must log in to answer this question.

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