[Tex/LaTex] Xindy: Encapsulations for Index

hyperrefindexingxindy

Well, I struggled to improve my index generated by Xindy. I tried to add several entries with bold page numbers by using \index{...|textbf} as classified in latex-loc-fmts.xdy, without any success.

When running Xindy (no matter which way, tex2xindy/texindy/xindy) together with texindy.xdy, the following errors are reported (Yes, they are errors because affected entries won't be passed to the generated .ind – IOW not displayed):

line X: multiple |'s
...
WARNING: unknown attribute `textbfhyperpage'! (ignored)

I've no idea how to handle this behavior and would be pleased, if somebody would share his experiences. BTW: I'm using Xindy-2.4 (TL2012)…

UPDATE:

\documentclass{article}
\usepackage{hyperref} % conflict!
\usepackage{makeidx}
\makeindex
\begin{document}
start
Nunc ligula faucibus \index{vel|textbf}. Nullarutrum porttitor...
\index{a}\index{b}\index{ä}\index{z}
end
\printindex
\end{document}

…compiled with:

latex <file> && xindy -M texindy <file> && latex <file>

…results:

It works without hyperref, but when it's been crawled it doesn't. Since hyperref is more or less a standard, it's necessary for me to get Xindy working together with hyperref. Any ideas?

Best Answer

You must use a separate style file for xindy. The following example results in:

enter image description here

As always I used imakeidx to simplify the process. However you have to compile with shell-escape.

The trick is to allow hyperref to provide a every feature for the index but the writing to the idx-file must be done without any influence by hyperref. This can be achieved by loading imakeidx after hyperref. The formating rules like textbf must be defined in the style file of xindy.

\documentclass{article}
\usepackage[utf8]{inputenc}


\usepackage[hyperindex=true]{hyperref}
\usepackage{imakeidx}
\makeindex[program=texindy,options=-M mystyle.xdy]

\usepackage{filecontents}
\begin{filecontents*}{mystyle.xdy}
;;; xindy style file
(markup-locclass-list :open "\dotfill" :sep "")

(define-attributes (( "textbf" "default" )) )
(markup-locref   :attr  "textbf"     :open "\textbf{\hyperpage{" :close "}}")
(markup-locref   :attr  "textit"     :open "\textit{\hyperpage{" :close "}}")
(markup-locref   :attr  "textttt"     :open "\textttt{\hyperpage{" :close "}}")
(markup-locref   :attr  "texttsc"     :open "\texttsc{\hyperpage{" :close "}}")
(markup-locref   :attr  "default"     :open "\hyperpage{" :close "}")



\end{filecontents*}

\begin{document}
start
Nunc ligula faucibus \index{vel|textbf}. Nullarutrum porttitor...
\index{a}\index{b}\index{ä}\index{z}
end
\printindex
\end{document}

Updated version with see and see also and inside the style file the modul makeindex is loaded.

\documentclass{article}
\usepackage[utf8]{inputenc}


\usepackage[hyperindex=true]{hyperref}
\usepackage{imakeidx}
\makeindex[program=texindy,options=-M mystyle.xdy]

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

;;; Load a predefined style:
(require "makeindex.xdy")


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

(define-attributes (( "textbf" "default" )) )
(markup-locref   :attr  "textbf"     :open "\textbf{\hyperpage{" :close "}}")
(markup-locref   :attr  "textit"     :open "\textit{\hyperpage{" :close "}}")
(markup-locref   :attr  "textttt"     :open "\textttt{\hyperpage{" :close "}}")
(markup-locref   :attr  "texttsc"     :open "\texttsc{\hyperpage{" :close "}}")
(markup-locref   :attr  "default"     :open "\hyperpage{" :close "}")



\end{filecontents*}

\begin{document}
start
Nunc ligula faucibus \index{vel|textbf}. Nullarutrum porttitor...
\index{a}\index{b}\index{ä}\index{z}
\index{Peter}
\index{Jenny}
\index{Pet|see{Peter}}
\index{Jen|seealso{Jenny}}

end
\printindex
\end{document}
Related Question