[pdftex] Adding an index to the bookmark
Andreas Matthias
amat at kabsi.at
Sun Jun 1 17:13:37 CEST 2003
Joe Riel <joe.riel at incep.com> wrote:
> Yes, I'm using hyperref.
>
> I didn't clearly explain what I am trying to do.
> It's not that I want to add an entry for the index
> in the bookmarks window (in AcroReader)
> [the tocbibind package from Peter Wilson worked great,
> thanks for that], but rather that I want to add
> the whole index to the bookmarks window [what is it really called?]
In PDF Jargon it is called `outline'.
> so that I can click on a hyperlinked index entry in the
> bookmarks window and jump to the proper place in the document.
Maybe the macros \bmprintindex does what you want. At least
it works for this small example. Don`t know about bigger
documents.
Here are some remarks:
* \bmprintindex has one argument indicating the bookmark level,
below which the bookmarks are closed. The argument is a number.
* The bookmarks of the index will allways appear after all other
bookmark created by hyperref.
* The bookmarks link only to the first appeareance of a world.
* Don't do foolish things like \index{hog@\textbf{hog}}. It
won't work.
Ciao
Andreas
\documentclass[a4paper]{book}
\usepackage{makeidx,hyperref}
\hypersetup{bookmarksopen, bookmarksopenlevel=3}
\makeatletter
\newcommand*{\bookmark}[3][0]{%
\pdfoutline user {<< /S /GoTo /D (#3) >>} count #1 {#2}}
\newcommand*{\bmprintindex}[1]{% #1:bookmarkopenlevel for index
\begingroup
% Determin number of direct subentries in the outline
\gdef\topbmitems{0}%
\def\bmitem##1,##2\hyperpage##3{%
\@tempcnta\topbmitems\relax
\advance\@tempcnta 1\relax
\xdef\topbmitems{\the\@tempcnta}%
\gdef\currbmitem{bm.##1}%
\global\@namedef{bm.##1}{0}%
}%
\def\bmsubitem##1,##2\hyperpage##3{%
\gdef\currbmsubitem{\currbmitem.##1}%
\global\@namedef{\currbmitem.##1}{0}%
\@tempcnta\@nameuse{\currbmitem}\relax
\advance\@tempcnta 1\relax
\expandafter\xdef\csname\currbmitem\endcsname{\the\@tempcnta}%
}%
\def\bmsubsubitem##1,##2\hyperpage##3{%
\gdef\currbmsubsubitem{\currbmsubitem.##1}%
\global\@namedef{\currbmsubitem.##1}{0}%
\@tempcnta\@nameuse{\currbmsubitem}\relax
\advance\@tempcnta 1\relax
\expandafter\xdef\csname\currbmsubitem\endcsname{\the\@tempcnta}%
}%
\let\item\bmitem
\let\subitem\bmsubitem
\let\subsubitem\bmsubsubitem
\let\theindex\empty
\let\endindex\empty
\InputIfFileExists{\jobname.ind}{}{}%
% Set bookmarks
\@ifundefined{chapter}{\def\toplevel{1}}{\def\toplevel{0}}%
%
\def\firstpage##1{\@firstpage##1----\\}
\def\@firstpage##1--##2--##3\\{%
\ifx\\##2\\\@commafirstpage{##1}%
\else##1\fi}
\def\@commafirstpage##1{\@@commafirstpage##1, ,\\}
\def\@@commafirstpage##1, ##2,##3\\{##1}
%
\def\bmitem##1,##2\hyperpage##3{%
\@tempcnta\toplevel\relax \advance\@tempcnta 1\relax
\gdef\currbmitem{bm.##1}%
\bookmark[\@bookmarkopenstatus{\@tempcnta}\@nameuse{\currbmitem}]
{##1}{page.\firstpage{##3}}%
}%
\def\bmsubitem##1,##2\hyperpage##3{%
\@tempcnta\toplevel\relax \advance\@tempcnta 2\relax
\gdef\currbmsubitem{\currbmitem.##1}%
\bookmark[\@bookmarkopenstatus{\@tempcnta}\@nameuse{\currbmsubitem}]
{##1}{page.\firstpage{##3}}%
}%
\def\bmsubsubitem##1,##2\hyperpage##3{%
\@tempcnta\toplevel\relax \advance\@tempcnta 3\relax
\gdef\currbmsubsubitem{\currbmsubitem.##1}%
\bookmark[\@bookmarkopenstatus{\@tempcnta}\@nameuse{\currbmsubsubitem}]
{##1}{page.\firstpage{##3}}%
}%
\let\item\bmitem
\let\subitem\bmsubitem
\let\subsubitem\bmsubsubitem
\def\@bookmarksopenlevel{#1}%
\bookmark[\@bookmarkopenstatus{\toplevel}\topbmitems]{\indexname}{}%
\InputIfFileExists{\jobname.ind}{}{}%
\endgroup
}% bmprintindex
\makeatother
\makeindex
\begin{document}
\setcounter{tocdepth}{3}
\chapter{chapter}
\section{section}
\subsection{subsection}
\subsubsection{subsubsection}
\let\ORIGindex\index
\def\index#1{#1\ORIGindex{#1}}
\Huge
\index{testing index}
\newpage
\index{test}, \index{hello}, \index{hello!hello}
\newpage
\index{test}, \index{hello}, \index{hello!test}, \index{hello!hello!hy}
\newpage
\index{test}, \index{hello!hell at helloj}
\bmprintindex{1}
\printindex
\end{document}
More information about the pdftex
mailing list