# Sorting index entries with accented words

Friends, I'm struggling for some time with this disturbance in the TeX force:

I have a set of words in Portuguese which are accented. When sorting these words, we treat accented letters the same way as their accentless counterparts. So, a list with these words:

abacate
ábaco
alavanca
árvore
arte
ácaro
aba


is sorted as

aba
abacate
ábaco
ácaro
alavanca
arte
árvore


When using these words as index entries, the accented letters are sorted via makeindex as symbols:

\begin{filecontents*}{mystyle.ist}
delim_0 " \\dotfill "
delim_1 " \\dotfill "
delim_2 " \\dotfill "
\end{filecontents*}

\documentclass{memoir}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{imakeidx}[2012/05/09]

\def\pfill{\unskip~\dotfill\penalty500
\strut\nobreak\dotfil~\ignorespaces}

\def\efill{\hfill\nopagebreak}

\makeindex[name=words,columns=1,options=-s mystyle]
\begin{document}

Hello world.

\index[words]{abacate}
\index[words]{ábaco}
\index[words]{alavanca}
\index[words]{árvore}
\index[words]{arte}
\index[words]{ácaro}
\index[words]{aba}

\printindex[words]
\end{document}


Marco Daniel brilliantly suggested me in the chat to try xindy instead of makeindex. So

xindy -M texindy -C utf8 -L portuguese filename.idx


produces the "correct" sorting (in Portuguese of course, I'm aware that other languages have different rules).

Unfortunately, I use some custom styles for my indices (we can see one of them above). For my despair, xindy works quite differently than makeindex, and that .ist style of mine is not supported AFAIK.

It would be fine for me to move to xindy if I could also port my .ist styles as well.

The workaround I'm using right now is to provide an accentless word before the "correct" one:

\index[words]{abacate}
\index[words]{abaco@ábaco}
\index[words]{alavanca}
\index[words]{arvore@árvore}
\index[words]{arte}
\index[words]{acaro@ácaro}
\index[words]{aba}


This one works. :)

Is it possible to provide a sorting rule to makeindex, or maybe providing similar .ist styles to xindy? I'm fine with the current workaround, but it's quite painful to remove every single accent from my index entries. I'd prefer to stick with makeindex, if possible. :)

• It is hopeless to stay with makeindex, what special things does your .ist do? Note that texindy adds a lot of things people have to add manually with makeindex – daleif May 31 '12 at 13:29
• @daleif: I've never used texindy before, this is actually my first try. :) My .ist's are not complex, they are very similar to the one from my question, I usually have some TikZ in the header parts. I'd be glad to try other approaches. :) – Paulo Cereda May 31 '12 at 13:36
• Did you have a look into the default output (the .ind) file that texindy provide? It make use of two macros to typeset the header parts, \lettergroupDefault (the non-alfabetical one) and \lettergroup, both are defined in the .ind file if not already defined by the user. The \dotfill part should not be that hard to add using a custom style. – daleif May 31 '12 at 13:49
• If you are able to program in TeX, you may adapt my esindex to Portuguese (it's intended for Spanish). It uses makeindex and there are options for setting how accented letters (or italics) are sorted, particles to be removed from the key sort, letter-by-letter vs. word-by-word, and more. But as I've said, it's intended for Spanish, so I presume vowels with tilde doesn't work as you could expect. – Javier Bezos May 31 '12 at 14:19
• You could simply try \index{abaco@ábaco} as introduced in the MakeIndex manual. But probably the proposed solutions with Xindy are more reliable for future projects. – Thorsten Donig May 31 '12 at 16:54

Here's the simple solution. Well, not so simple, after all. :)

One small problem, that I'll solve in a next release of imakeidx: for some reason (that I don't remember now) we decided that program=xindy called texindy anyway. But unfortunately, it seems that the calls

xindy -M texindy -M mystyle -C utf8 -L portuguese words.idx


and

texindy -M mystyle -C utf8 -L portuguese words.idx


are not equivalent, as the latter throws up an incomprehensible error (probably a bug in the texindy script).

Thus the following document will require to run manually xindy (but you have Arara, so it's not a problem), until the small problems are corrected.

Notice that xindy provides two commands for the letter groups, which should be redefined in the preamble to do what's wanted.

\begin{filecontents*}{mystyle.xdy}
(markup-locclass-list :open "\dotfill " :sep "\dotfill ")
\end{filecontents*}

\documentclass{memoir}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{imakeidx}[2012/05/09]
\newcommand*{\lettergroupDefault}[1]{}
\newcommand*\lettergroup[1]{%
\par\textit{#1}\par
\nopagebreak
}

\def\pfill{\unskip~\dotfill\penalty500
\strut\nobreak\dotfil~\ignorespaces}

\def\efill{\hfill\nopagebreak}

\makeindex[name=words,columns=1,program=xindy,options=-M texindy -M mystyle -C utf8 -L portuguese]
\begin{document}

Hello world.

\index[words]{abacate}
\index[words]{ábaco}
\index[words]{alavanca}
\index[words]{árvore}
\index[words]{arte}
\index[words]{ácaro}
\index[words]{aba}

\printindex[words]
\end{document}

• Joachim mentioned that at some point. Rather anoying. – daleif May 31 '12 at 14:03
• @daleif There's a tex/inputenc/ hardcoded in texindy that should be removed, I guess. – egreg May 31 '12 at 14:12
• Yes, I just wonder why there hasn't been any updates to xindy.... – daleif May 31 '12 at 14:34
• Thanks for the full explanation, egreg! :) – Paulo Cereda Jun 1 '12 at 1:21

I need a little more space, but something like this:

\newcommand\lettergroup[1]{%
\par\textit{#1}\par
\nopagebreak}
\newcommand\lettergroupDefault[1]{\lettergroup{#1}}


and a new module (mystyle.xdy):

(markup-locclass-list :open "\dotfil ")


Then invoke texindy via

texindy -M mystyle.xdy ....


that seems to do the same as your MWE, just with texindy instead

• How nice! The "style" is written in Lisp! :) I'll take a look on the examples in the xindy folder. Thanks! (BTW sorry for the delay on upvoting and commenting your answer, I was out of votes) – Paulo Cereda Jun 1 '12 at 0:59
• the xindy internals is written in Lisp (AFAIR) – daleif Jun 1 '12 at 10:18

Here a solution using only a style file.

The style consists only of two line:

(markup-locclass-list  :open " \dotfill\ "   )



Here a complete MWE which needs shell-escape.

\RequirePackage{filecontents}
\begin{filecontents*}{mystyle.xdy}
;;; xindy style file

;;;dotted line between name and page number
(markup-locclass-list  :open " \dotfill\ "   )

\end{filecontents*}

\documentclass{memoir}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{imakeidx}[2012/05/09]

\def\pfill{\unskip~\dotfill\penalty500
\strut\nobreak\dotfil~\ignorespaces}

\def\efill{\hfill\nopagebreak}

\makeindex[program=texindy,options=-M mystyle.xdy,name=words,columns=1]

\begin{document}

Hello world.

\index[words]{abacate}
\index[words]{ábaco}
\index[words]{alavanca}
\index[words]{árvore}
\index[words]{arte}
\index[words]{ácaro}
\index[words]{aba}

\printindex[words]
\end{document}