# Can I put pdf bookmarks of the alphabetic “sections” of the index?

Is there any way to (automagically) create pdf bookmarks for each "section" of the index? A "section" in the index is for each letter of the alphabet. Make sense?

Is there a way to do this?

Minimal Working Example:

\documentclass{article}
\usepackage{imakeidx}

\makeindex

\title{An Example of an Article with an Index}

\begin{document}
\maketitle

Alligator\index{Alligator}
Bat\index{Bat}
Crocodile\index{Crocodile}
Dingo\index{Dingo}
Elephant\index{Elephant}
Frog\index{Frog}
Giraffe\index{Giraffe}
Horse\index{Horse}
Iguana\index{Iguana}
Jaguar\index{Jaguar}
Kangaroo\index{Kangaroo}
Lemur\index{Lemur}
Mongoose\index{Mongoose}
Newt\index{Newt}
Octopus\index{Octopus}
Penguin\index{Penguin}
Quail\index{Quail}
Rabbit\index{Rabbit}
Snake\index{Snake}
Turtle\index{Turtle}
Unicorn\index{Unicorn}
Velociraptor\index{Velociraptor}
Wildabeest\index{Wildabeest}
Xantus\index{Xantus}
Yak\index{Yak}
Zebra\index{Zebra}

\printindex

\end{document}

-
Would you be able to create a minimal working example (MWE) that shows a document with some index entries? – Werner Nov 30 '11 at 4:15
Added minimal working example. I know there is a way for stackexchange to automatically compile my LaTeX and create a PDF inline. Can you show me how to do it? – jlconlin Nov 30 '11 at 4:33
– Werner Nov 30 '11 at 4:40

You need an index style file (.ist) for this. But using imakeidx it's easy to configure this file:

\begin{filecontents*}{\jobname.ist}
\end{filecontents*}

\documentclass{article}
\usepackage{imakeidx}

\bigskip\noindent{\large\bfseries\pdfbookmark[1]{#1}{index.#1}#1\par}\nobreak
}
\makeindex[options={-s \jobname.ist}]

\title{An Example of an Article with an Index}

\begin{document}
\maketitle

Alligator\index{Alligator}
Bat\index{Bat}
Crocodile\index{Crocodile}
Dingo\index{Dingo}
Elephant\index{Elephant}
Frog\index{Frog}
Giraffe\index{Giraffe}
Horse\index{Horse}
Iguana\index{Iguana}
Jaguar\index{Jaguar}
Kangaroo\index{Kangaroo}
Lemur\index{Lemur}
Mongoose\index{Mongoose}
Newt\index{Newt}
Octopus\index{Octopus}
Penguin\index{Penguin}
Quail\index{Quail}
Rabbit\index{Rabbit}
Snake\index{Snake}
Turtle\index{Turtle}
Unicorn\index{Unicorn}
Velociraptor\index{Velociraptor}
Wildabeest\index{Wildabeest}
Xantus\index{Xantus}
Yak\index{Yak}
Zebra\index{Zebra}

\clearpage
\pdfbookmark[0]{\indexname}{\indexname}
\printindex

\end{document}


If you don't want the big fat letters at the index itself but only bookmarks, you may replace definition of \indexhead at the example above by:

\newcommand*{\indexheading}[1]{%
\pdfbookmark[1]{#1}{index.#1}%
}


Note: filecontents environment writes the file only if it doesn't exist already. If you want to filecontents environment to overwrite an existing file, you should load package filecontents before.

-
Fantastic! Exactly what I needed. Thanks! – jlconlin Nov 30 '11 at 14:23
Only a small remark: One can use (and I do use) filecontents for a style file without imakeidx, but it saves the separate call of makeindex or xindy. – Speravir Nov 30 '11 at 20:15
@Speravir: Right, but without imakeidx you cannot make a one file MWE, but have to describe how to configure which editor to use the makeindex style file. – Schweinebacke Nov 30 '11 at 21:22