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.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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,
    link,
    % 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,
    link,
    % linkname={#2},% see option `dest' of \bookmark
  ]{#2}%
}

I have put the file name in \detokenize to avoid trouble with _.

share|improve this answer
    
You are a genius! How about bookmarks according to figure file names? –  Laura Apr 13 '13 at 21:28
    
@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
    
And even more complicated, nested bookmarks for figure labels and then figure file names? :) –  Laura Apr 13 '13 at 21:30
    
Above code beautifully produces PDF with bookmarks for labels of the figures included, and not their file names. Let me try your comment suggestion, while you can think about nested case, if you be so kind. –  Laura Apr 13 '13 at 21:33
    
@Laura Also the nesting request is not clear to me. Perhaps you can update the question to give an example. –  Heiko Oberdiek Apr 13 '13 at 21:34

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.