6

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}
\usepackage[colorlinks]{hyperref}

\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}
3
  • Would you be able to create a minimal working example (MWE) that shows a document with some index entries?
    – Werner
    Commented Nov 30, 2011 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
    Commented Nov 30, 2011 at 4:33
  • 1
    See How do you crop an attached pdf?
    – Werner
    Commented Nov 30, 2011 at 4:40

1 Answer 1

8

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

\begin{filecontents*}{\jobname.ist}
  headings_flag 1
  heading_prefix "\\indexheading{"
  heading_suffix "}"
\end{filecontents*}

\documentclass{article}
\usepackage{imakeidx}
\usepackage[colorlinks,bookmarks]{hyperref}

\newcommand*{\indexheading}[1]{%
  \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.

2
  • 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
    Commented Nov 30, 2011 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. Commented Nov 30, 2011 at 21:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .