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.

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}
share|improve this question
    
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? –  Jeremy Nov 30 '11 at 4:33
1  
See How do you crop an attached pdf? –  Werner Nov 30 '11 at 4:40

1 Answer 1

up vote 8 down vote accepted

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.

share|improve this answer
    
Fantastic! Exactly what I needed. Thanks! –  Jeremy 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

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.