# PDF bookmarks according to figure titles or labels

I have dozens of figures that I am going to include in one PDF file using the following code combination:

% allpdfs.tex
\documentclass{article}
\usepackage{pdfpages}
\newcommand{\myimagelist}[2]{\includepdf[fitpaper=true]{#2}}

\begin{document}
\input{filelist}
\end{document}


where my filelist contains pdf figures and their locations:

% filelist.tex
\myimagelist{some label}{some path/pdffile1}
\myimagelist{some other label}{some path/pdffile2}
% ....


my question is, how do I modify first code to include bookmarks in PDF according to the titles or labels of the figures I am including in it?

-

Option link of \includepdf adds a link <file name>.<page number> for each included page. This can be used to specify the destination for a bookmark link:

\documentclass{article}
\usepackage{pdfpages}
\usepackage{hyperref}
\usepackage{bookmark}

\bookmarksetup{
numbered,
open,
}

\newcommand*{\myimagelist}[2]{%
\bookmark[
dest={#2.1},% see option linkname' of \includepdf
keeplevel,
rellevel=1,
]{#1 (\detokenize{#2})}%
\includepdf[
fitpaper,
% linkname={#2},% see option dest' of \bookmark
]{#2}%
}

\begin{document}

\section{Images}

\myimagelist{some label}{some path/pdffile1}
\myimagelist{some other label}{some path/pdffile2}

\end{document}


In the example above, the bookmark contains both the label and the file name is appended in parentheses. Also it is possible to put the file name in another bookmark:

\newcommand*{\myimagelist}[2]{%
\bookmark[
dest={#2.1},% see option linkname' of \includepdf
keeplevel,
rellevel=1,
]{#1}%
\bookmark[
dest={#2.1},% see option linkname' of \includepdf
keeplevel,
rellevel=2,
]{\detokenize{#2}}%
\includepdf[
fitpaper,
% linkname={#2},% see option dest' of \bookmark

I have put the file name in \detokenize to avoid trouble with _.
@Laura What do you mean, the bookmark text is the same as the file name (some path/pdffile1) instead of some label? Then just use #2 instead of #1 for the mandatory argument of \bookmark`. – Heiko Oberdiek Apr 13 '13 at 21:30