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?

Mico
  • 506,678
raphink
  • 31,894
  • 3
    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. – raphink 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. – raphink Jun 10 '13 at 21:35
  • If you want to stick with makeindex, are yiu using pdflatex/inputenc or xe/lua-latex, the accented letter handling is completely different in those cases – David Carlisle Jun 10 '13 at 22:06
  • @DavidCarlisle: I'm using LuaLaTeX. – raphink Jun 11 '13 at 05:30
  • Ah so you won't be accepting my answer then:-) still it may be useful to someone... – David Carlisle Jun 11 '13 at 07:26
  • in luatex it must be possible to do something similar to mine but instead of active inputenc characters just process the string with a lua regexp string replace to replace accented characters by the base – David Carlisle Jun 11 '13 at 07:29

2 Answers2

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

egreg
  • 1,121,712
  • 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. – raphink Jun 11 '13 at 05:31
  • @egreg: That's pretty cool. I generate two indexes for that book, but only one has this requirement, and the other one has quite complex settings. Is there a way to keep using makeindex for one index and use xindy for the other? – raphink Jun 11 '13 at 05:34
  • @ℝaphink --- I just realized that I certainly have to go through the following post: http://tex.stackexchange.com/questions/71167/how-to-use-xindy-with-miktex – pluton Jun 11 '13 at 06:37
  • 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 Jun 11 '13 at 08: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

David Carlisle
  • 757,742