[Tex/LaTex] Showing the bibliographic entry in a popup when you hover over the citation key

biblatexcitingexpansionpdf

I thought it would be useful to have bibliographic entries displayed as a tooltip so readers are not interrupted by following hyperlinks or trying to find the Bibliography, so I created the following command:

\newcommand\annocite[1]{\pdfmarkupcomment[markup=Underline,subject=Citation]
   {\parencite{#1}}{\fullcite{#1}}}

Unfortunately this does not work. Instead of showing the bibliographic entry in the popup, it merely displays the citation key; i.e., the \fullcite command seems to have no effect. I believe the problem is related to argument expansion. Here is a MWE:

\documentclass{article}
\usepackage{biblatex,pdfcomment,filecontents}
\bibliography{\jobname}

\newcommand\annocite[1]{\pdfmarkupcomment[markup=Underline,subject=Citation]
    {\parencite{#1}}{\fullcite{#1}}}

\begin{filecontents}{\jobname.bib}
@article{Bli74,
  author = {Blinder, Alan S.},
  year = {1974},
  title = {The economics of brushing teeth},
  journaltitle = {Journal of Political Economy},
  volume = {82},
  number = {4},
  pages = {887--891},
}
\end{filecontents}

\begin{document}
Hover over this citation: \annocite{Bli74}

The tooltip should contain the following text: \fullcite{Bli74}

\end{document}

Can anyone think of a solution, or better, a way to redefine biblatex' citation commands (e.g., \parencite, \cite) to do this automatically?

Best Answer

The idea is to use the fancytooltips package. I will show schematically the process: to make my example compilable for everyone, I'll use the following bibliographical database (called biblio.bib):

@book{goossens93,
    author = "Michel Goossens and Frank Mittlebach and Alexander Samarin",
    title = "The Latex Companion A",
    year = "1993",
    publisher = "Addison-Wesley",
    address = "Reading, Massachusetts"

}

@book{knuth79,
    author = "Donald E. Knuth",
    title = "Tex and Metafont, New Directions in Typesetting",
    year = {1979{(}1950{)}},
    publisher = "American Mathematical Society and Digital Press",
    address = "Stanford"
}

First you need to create a .pdf file containing the \keytips commands and the text for the tooltips that will be used by the fancytooltips package. To create this .pdf document you can use LaTeX: in this example I used a file (called bibtips.tex) having the following aspect:

\documentclass{article}
\usepackage{xcolor}
\usepackage{biblatex}
\usepackage[createtips]{fancytooltips}

\newcommand\MyTip[1]{%
  \keytip{#1}
  \fcolorbox{green!50!black}{yellow!20}{\parbox{\textwidth}{\fullcite{#1}}}\newpage%
}

\bibliography{biblio}

\begin{document}

\MyTip{goossens93}
\MyTip{knuth79}

\end{document}

You need to use the \MyTip command for every bibliographical entry that will have a tooltip in your final document.

Compile this file in the standard way: pdflatex+bibtex+pdflatex+pdflatex to generate the references, one on each page, nicely framed, and with the corresponding \keytip command. The resulting .pdf file has to be in the same directory containing your main .tex file.

Now, your main document has to be something like the following (note that the value for the filename key is exactly the name of the .pdf file obtained in the previous step):

\documentclass{article}
\usepackage{xcolor}
\usepackage{biblatex}
\usepackage[filename=bibtips,mouseover]{fancytooltips}

\bibliography{biblio}

\begin{document}

\tooltip{\cite{goossens93}}{goossens93}

\tooltip{\cite{knuth79}}{knuth79}

\end{document}

Compile this file in the standard way: pdflatex+bibtex+pdflatex+pdflatex and you'll see your citations with a blue balloon; if you move the mouse pointer to the active area, a tooltip will open displaying the complete bibliographical information corresponding to the citation.

Some remarks:

  1. Of course, you can obtain fancyer tooltips by changing the aspect of the references in the file bibtips.pdf.

  2. This approach doesn't work in all PDF viewers, since it requires cooperation with JavaScripts; you have to use Adobe Reader or Adobe Acrobat to see the tooltips.