18

According to Xindy revisited: Multi-lingual index creation for the UTF-8 age (TUGboat), “if one has a raw index file that was produced by [XeTeX], one can use xindy; it will ‘just work’.”

Unfortunately I can't get it to “just work”. How can I use Xindy together with XeLaTeX or LuaLaTeX?


An example LaTeX file:

\documentclass{article}
\makeindex

\begin{document}
start
\index{a}\index{b}\index{ä}\index{ü}
end
\end{document}

The LaTeX Companion (2ed) then tells me to run

texindy -L german-duden test.idx

However when I do this all umlauts are sorted under O.

Caramdir
  • 89,023
  • 26
  • 255
  • 291

3 Answers3

17

Based on Ulrike's answer, here is one way to invoke xindy to get it to sort .idx files created by Xe/LuaLaTeX. The trick is to use xindy directly (instead of texindy) and pass the -C utf8 flag.

Minimal Example

\documentclass{article}
\usepackage{luatextra}
\usepackage{makeidx}
\makeindex
\begin{document}
üäö

start 
\index{a}\index{b}\index{ä}\index{ü}
end

\printindex
\end{document}

Compilation

lualatex filename.tex
xindy -M texindy -C utf8 -L german-duden filename.idx 
lualatex filename.tex

In (pdf)latex you can use UTF-8 encoding and xindy in the following way:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{makeidx}
\makeindex

\begin{document}
start
\index{a}\index{b}\index{ä}\index{ü}
end
\printindex
\end{document}

And then simply run texindy -L ⟨language⟩ ⟨filename⟩.idx.

In LuaTeX you can also use the luainputenc package to use legacy encodings.

\documentclass{article}
\usepackage{fontspec}
\usepackage[utf8]{luainputenc}
\usepackage{makeidx}
\makeindex

\begin{document}
start 
\index{a}\index{b}\index{ä}\index{ü}
end
\printindex
\end{document}

Again, run texindy -L ⟨language⟩ ⟨filename⟩.idx.

Here the result for both examples:

result

Caramdir
  • 89,023
  • 26
  • 255
  • 291
Marco Daniel
  • 95,681
  • 1
    As I said, I want to compile with XeTeX or LuaTeX. Both of those provide UTF-8 by default and don't use any inputenc/fontenc ”hacks” to support the encoding. So this won't work. – Caramdir Aug 15 '11 at 16:55
  • The problem here is, that the .idx file created by pdflatex isn't actual unicode, but contains LaTeX-encoded umlauts (etc.). In comparison the modern engines create fully unicode-encoded .idx files. xindy is supposed to support this, I just don't know how. – Caramdir Aug 15 '11 at 16:58
  • 1
    I does work with the luainputenc hack. Still I'd prefer a solution that uses Unicode throughout. While the solution works in this case, something like \index{α} would still cause trouble. – Caramdir Aug 15 '11 at 17:11
  • @Caramdir: I saw it. I tried also fontspec but it doesn't work. – Marco Daniel Aug 15 '11 at 17:12
  • Surprisingly fontspec and luainputenc seem to work together for me . – Caramdir Aug 15 '11 at 17:14
  • @Caramdir: I changed my example according to your comment. – Marco Daniel Aug 15 '11 at 18:04
  • 2
    @Caramdir: It is not surprising that fontspec + luainputenc works: fontspec loads xunicode which gives most of the standard commands (" etc) senseful definitions. But having to use luainputenc should not be necessary. After all one point of xindy is to get real utf8 support. – Ulrike Fischer Aug 15 '11 at 19:19
  • That last example finally does what I want. Thank you and @Ulrike. Before posting this question I even tried texindy -C utf8, but this gives an error. Apparently it does work when using xindy directly. Could you please edit your answer to make it clearer that the first way is the correct one and the other options should only be used in legacy documents (or when working with (pdf)latex). – Caramdir Aug 15 '11 at 19:52
  • 1
    I changed your answer a bit, so that it is more helpful for people coming here from google who didn't follow how the answer came to be (this question is currently the top result for a search for lualatex xindy). – Caramdir Aug 17 '11 at 17:15
  • @Caramdir: No problem ;-) – Marco Daniel Aug 17 '11 at 17:38
  • @Caramdir @Marco: Hi, I tried your solution (i.e. running xindy -M texindy -C utf8 am.idx) but it doesn’t work. I get this error: *** - PROGN: variable TEXINDY.XDY has no value. Can someone tell whats wrong. – Tobi Jun 16 '14 at 20:04
  • @Tobi: You should probably ask a new question. – Caramdir Jun 16 '14 at 23:51
  • @Caramdir: Wasn’t sure about that, but while preparing that question I found the solution. I’ll posted it as a self-anwser: Using windy with texindy.xdy. – Tobi Jun 17 '14 at 09:27
6

here is an example with an own style file for xindy. Run it with

lualatex <file>
xindy -C utf8 -I latex -M myModuleE <file>.idx
lualatex <file>

then I get the attached output

\documentclass[]{article}
\usepackage{fontspec}
\usepackage[ngerman]{babel}
\usepackage{filecontents,multicol}
\begin{filecontents*}{myModuleE.xdy}
(define-attributes ("default"))
(define-location-class "page-numbers" ("arabic-numbers"))
(markup-index :open  "~n\begin{theindex}~n"
              :close "~n\end{theindex}~n"
              :tree)
(markup-locclass-list :open "\quad{}")
(markup-locref-list   :sep ", ")
(markup-indexentry :open "~n  \item "           :depth 0)
( define-letter-group "A--D" :prefixes ("A" "B" "C" "D") )
( define-letter-group "E--G" :after "A--D" :prefixes ("E" "F" "G") )
( define-letter-group "H--K" :after "E--G" :prefixes ("H" "I" "J" "K") )
( define-letter-group "L--N" :after "H--K" :prefixes ("L" "M" "N" ) )
( define-letter-group "O--R" :after "L--N" :prefixes ("O" "P" "Q" "R") )
( define-letter-group "S--V" :after "O--R" :prefixes ("S" "T" "U" "V") )
( define-letter-group "W--Z" :after "S--V" :prefixes ("W" "X" "Y" "Z") )
(sort-rule "a" "A")
(sort-rule "b" "B")
(sort-rule "c" "C")
(sort-rule "d" "D")
(sort-rule "e" "E")
(sort-rule "f" "F")
(sort-rule "g" "G")
(sort-rule "h" "H")
(sort-rule "i" "I")
(sort-rule "j" "J")
(sort-rule "k" "K")
(sort-rule "l" "L")
(sort-rule "m" "M")
(sort-rule "n" "N")
(sort-rule "o" "O")
(sort-rule "p" "P")
(sort-rule "q" "Q")
(sort-rule "r" "R")
(sort-rule "s" "S")
(sort-rule "t" "T")
(sort-rule "u" "U")
(sort-rule "v" "V")
(sort-rule "w" "W")
(sort-rule "x" "X")
(sort-rule "y" "Y")
(sort-rule "z" "Z")
(markup-letter-group-list :sep "~n\indexspace")
(sort-rule "Ä" "A")
(sort-rule "ä" "A")
(sort-rule "Ö" "O")
(sort-rule "ö" "O")
(sort-rule "Ü" "U")
(sort-rule "ü" "U")
(merge-rule "\\[a-zA-Z@]+ *" "" :eregexp)
(merge-rule "\\[^a-zA-Z@]" "" :eregexp)
(merge-rule "^[{}$]" "" :eregexp)
\end{filecontents*}
\makeatletter
\renewenvironment{theindex}
  {\raggedright\small\let\item\@idxitem \parskip .0pt\@plus .3\p@\relax
   \begin{multicols}{2}}{\end{multicols}}
\makeatother
\usepackage{makeidx}\makeindex
% xindy -C utf8 -I latex -M myModuleE datei.idx
\begin{document}
\printindex     \newpage  foo \index{ä}\index{ü}
\index{Aal}   \index{Berg}\index{Cäsar}
\index{Donau} \index{Emil}\index{Flora}
\index{Garten}\index{Ober}\index{Zucker}
\index{Österreich}\index{klein}\index{groß}
\end{document}

enter image description here

5

I don't have a working xindy. But according to this message http://sourceforge.net/mailarchive/message.php?msg_id=26841124 I think you need at least the option -C utf8 and perhaps also a new xindy style.

Ulrike Fischer
  • 327,261