# Expand (for PDF ToC) biblatex's citation commands

For a research report I want to embed some of the cited papers as PDFs (with \includepdf). As all related metadata is available in the bibtex database and also the PDF filenames can be computed out of the bibtex key. So I would like to have an \IncludePaper{<bibtex key>} command that (a) creates an entry with the paper's title in the ToC and (b) includes the PDF:

\documentclass{book}

\usepackage{filecontents}
\usepackage[defernums=true, hyperref, backref, refsegment=chapter]{biblatex}
\usepackage{hyperref}

\begin{filecontents}{\jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {The Alpha Paper},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {The Bravo Paper},
}
@misc{C03,
author = {Cuthor, C.},
year = {2003},
title = {The Charlie Paper},
}
\end{filecontents}

% The bibtex database to use (\bibliography{bibliotest} in your case)
\bibliography{\jobname}

\newcommand{\IncludePaper}[1]{%
\phantomsection{}
\addcontentsline{toc}{section}{\citeyear{#1}: \citetitle{#1}}
% \includepdf[pages=-,pagecommand={}]{#1.pdf}
}

\begin{document}

\tableofcontents

\nocite{*}
\printbibliography

\chapter{Papers}
\IncludePaper{A01}
\IncludePaper{B02}
\end{document}


This works relatively well, including nice entries in the ToC. In the PDF ToC (the tree view on the lefthand side of the PDF viewer), however, only the citation keys appear.

I guess this is caused by the fact that \citeyear and \citetitle are protected commands that are not expanded when the PDF ToC is created.

Is there any way to get just the plain text result of these commands and pass it to \addcontentsline in a way, so that the PDF ToC contains the paper's year and title?

## 2 Answers

Instead of using \newcommand to define \IncludePaper it is possible to use biblatex facilities to create a new citation command where one has access to all biblatex features, for example:

\DeclareCiteCommand{\IncludePaper}{}{
\phantomsection{}
\addcontentsline{toc}{section}{\thefield{year}\addcolon\addspace\thefield{title}}
}{}{}

• I really like this one. Understanding embedding of the PDF as a special citation command is beautiful from the conceptual point of view! – Daniel Jul 5 '13 at 13:26
• A remaining problem: Using the citation command results in an additional page before the included PDF. Even with the most simplistic \DeclareCiteCommand{\IncludePaper}{\includepdf[pages=-]{filename.pdf}}{}{} any use of \Includepaper{<some key>} will insert an extra page before the PDF. Any idea how to solve that? – Daniel Jul 5 '13 at 13:30

The usebib package can do it:

\documentclass{book}

\usepackage{filecontents}
\usepackage[defernums=true, hyperref, backref, refsegment=chapter]{biblatex}
\usepackage{hyperref}
\usepackage{usebib}

\begin{filecontents}{\jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {The Alpha Paper},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {The Bravo Paper},
}
@misc{C03,
author = {Cuthor, C.},
year = {2003},
title = {The Charlie Paper},
}
\end{filecontents}

% The bibtex database to use (\bibliography{bibliotest} in your case)
\bibliography{\jobname}
\bibinput{\jobname}

\newcommand{\IncludePaper}[1]{%
\phantomsection{}
\addcontentsline{toc}{section}{\usebibentry{#1}{year}: \usebibentry{#1}{title}}
% \includepdf[pages=-,pagecommand={}]{#1.pdf}
}

\begin{document}

\tableofcontents

\nocite{*}
\printbibliography

\chapter{Papers}
\IncludePaper{A01}
\IncludePaper{B02}
\end{document}


• Your usebib is is a nice little package for lightweight bibtex handling! – Daniel Jul 5 '13 at 13:34
• @Daniel I wrote it with such applications in mind; of course biblatex can do better. – egreg Jul 5 '13 at 13:36