Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Background

Looking to indent an arbitrary n-level hierarchy within an index and have hyperlinks for the final item, using the memoir class and pdfTeX 3.1415926-2.4-1.40.13 (TeX Live 2012).

For example:

\index[classification]{Anthropoidea!Hominoidea!Hominidae!Homo!sapiens}

Should produce:

mockup

Where the 2 in "sapiens, 2" is hyperlinked back in the document (PDF).

Problem

First, makeindex can only nest 3-levels deep. Second, xindy is incompatible with hyperref; from the man page:

In particular, this means that by default the LaTeX package "hyperref" will create raw index files that cannot be processed with xindy. This is not a bug, this is the unfortunate result of an intented [sic] incompatibility. It is currently not possible to get both hyperref's index links and use xindy.

Question

How would you create hyperlinked indexes that nest to an arbitrary depth?

Example Document

A minimal document might resemble:

\documentclass{memoir}
\usepackage{filecontents}

\begin{filecontents*}{style1.xdy}
(markup-index :open  "~n\begin{theindex}~n"
              :close "~n\end{theindex}~n"
              :tree)
(markup-indexentry :open "~n            \sssssubitem "  :depth 5)
\end{filecontents*}

\long\def\lettergroup#1\item{\item\textbf}
\let\lettergroupDefault\lettergroup

\usepackage{makeidx}
\makeindex

\begin{document}
Start

\index{Anthropoidea!Hominoidea!Hominidae!Homo!sapiens}

End
\printindex
\end{document} 

However, this does not produce the correct results, when run with:

pdflatex file.tex; texindy file.idx; pdflatex file.tex

Related Links

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted
\documentclass{memoir}
\usepackage{filecontents}

\begin{filecontents*}{style1.xdy}
(markup-locref :open "\hyperpage{" :close "}")

(markup-index :open  "~n\begin{theindex}~n"
              :close "~n\end{theindex}~n"
          :tree
              )
(markup-indexentry :open "~n       \sssubitem " :depth 3) 
(markup-indexentry :open "~n            \sssssubitem "  :depth 4)
(markup-indexentry :open "~n            \sssssssubitem "  :depth 5)
\end{filecontents*}

\long\def\lettergroup#1\item{\item\textbf}
\let\lettergroupDefault\lettergroup
\makeatletter
\newcommand\sssubitem{\@idxitem \hspace*{40\p@}}
\newcommand\sssssubitem{\@idxitem \hspace*{50\p@}}
\newcommand\sssssssubitem{\@idxitem \hspace*{60\p@}}

\makeatother
\usepackage{makeidx}
\makeindex
\usepackage{hyperref}
\begin{document}
Start

\index{Anthropoidea!Hominoidea!Hominidae!Homo!sapiens}


End
\printindex
\end{document} 

You can use hyperref macro \hyperpage to link to the indexed page. With

(markup-locref :open "\hyperpage{" :close "}")

you tell xindy to enclose page numbers with this macro.

For more hierarchical levels, you can use

(markup-indexentry :open "~n       \sssubitem " :depth 3) 
(markup-indexentry :open "~n            \sssssubitem "  :depth 4)
(markup-indexentry :open "~n            \sssssssubitem "  :depth 5)

and define macros like \sssubitem:

\newcommand\sssubitem{\@idxitem \hspace*{40\p@}}

Compile with

pdflatex filename
texindy -M style1 filename.idx
pdflatex filename

You must tell texindy to use the module with -M option.

The result:

hiearchical index

share|improve this answer
    
Děkuji, michal.h21. –  Dave Jarvis Feb 20 '13 at 17:21
    
@DaveJarvis není zač :) –  michal.h21 Feb 20 '13 at 19:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.