# Showing the bibliographic entry in a popup when you hover over the citation key

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?

• \fullcite is a \protected command. It cannot be expanded, because it contains something that isn't expandable, namely macro definitions.
– TH.
Apr 10, 2011 at 1:28
• You can probably duplicate \blx@citei@fullcite except save the text produced rather than typeset it and then use \pdfmarkupcomment. I don't have time to try it right now, myself. Maybe someone else can give it a go.
– TH.
Apr 10, 2011 at 1:34
• If you want to see it done right, try one of these open access articles.
– Emre
Aug 16, 2011 at 21:57
• @Emre The journal you linked i snot open-access, it seems. Mar 19, 2012 at 8:43
• @matth Thanks for the notice. Try this PDF or search Google for recent articles.
– Emre
Mar 20, 2012 at 4:20

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",

}

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


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.

• Good solution. But could you say how to use it in XeLaTex? Apr 10, 2011 at 9:05
• @filokalos: there's some incompatibility with fancytooltips and XeLaTeX (some driver option). If I have the time I will look into it. Apr 11, 2011 at 20:28
• @filokalos: fancytooltips might depend on some support for directly outputting PDF code. Maybe the difference is that the pdftex engine goes directly to PDF while xetex routes through DVI? Perhaps lualatex would work? Apr 11, 2011 at 20:46
• @Gonzalo Medina: Would it be possible to deposit somewhere a compiled version of your example, please? Aug 20, 2011 at 18:14
• @Stephen: I could compile my example and upload it somewhere, but I don't know if the tooltips will then be visible. Aug 20, 2011 at 22:59

Both Gonzalo Medina and Audrey posted an excellent solution. But the things are simpler now. See the fancy-preview webpage - based on the new version of fancytooltips (May 2012), preview.sty and some bash scripts you get tooltips for bibliographic entries, theorems, definitions, displayed equations etc. automatically.

Edit: Small example and screenshots are attached.

\documentclass{article}
\usepackage{amsmath,amsthm}
\newtheorem{lemma}{Lemma}
\usepackage{hyperref} % Important!
\begin{document}

\begin{lemma}[Lemma from \cite{M}]\label{lemma}
If $k<0$, then
$$\label{eq:1} x^2+k<x^2$$
for every real number $x$.
\end{lemma}

Inequality \eqref{eq:1} in Lema \ref{lemma} can be proved easily. Is
more general than \cite[Theorem 3.4]{K}.

\begin{thebibliography}{9}
\bibitem[M]{M} Me: My book related to the problem (2006), 145 p.
% The new line is important!

\bibitem{K} Karl: Karl's paper published in some minor proceedings,
a local conferrence organized by his university (2005), 23--25.
% The new line is important!

\end{thebibliography}
\end{document}


Ref M

Ref 1

Equation (1)

Lemma 1.

• +1. Thank you for developing this. Is it possible to have it work with Xetex/Luatex and using a package, rather than a bash script?
– Emre
May 7, 2012 at 20:03
• Your answer would benefit if you made it more self contained by including a description of how to use that script and screenshots of its results.
– N.N.
May 7, 2012 at 20:11
• I copied and pasted your example document into TeXMaker on my Windows 7 PC. When I compile I get the normal output, but the 'previews' don't work for me (in Adobe Reader) :( Is there something that I am missing? Oct 14, 2012 at 11:11
• How exactly do you compile the document and how exactly do the output messages look like? Nov 26, 2012 at 7:39
• I'm having the same problem as @User17670 when I read it in Adobe Acrobat on Mac OS. May 2, 2013 at 1:48

After giving Gonzalo's nice answer a whirl, I put together some tweaks. Here's a summary.

• Tooltip creation. A tooltip for every entry in the given bib file(s) can easily be created using \nocite{*}, \AtDataInput and list processing commands from etoolbox.

• Tooltip location. By default tooltips appear at the top of the page in the presentation document, no matter where the active areas are located. We can move each tooltip closer to its active area by resizing the pages in the tooltips document and using the movetips option setting.

• Citation commands. Instead of issuing the \tooltip command directly, tooltips can be incorporated into existing citation commands via the bibhyperref format. The starred variant of \tooltip allows us to separate the active areas for citation links and tooltips.

Here's an example of how all these ideas can be implemented.

% --- tooltips document
\begin{filecontents*}{bibtooltips.tex}
\documentclass{article}
\usepackage{xcolor}
\usepackage[createtips]{fancytooltips}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[maxnames=2]{biblatex}
\usepackage{geometry}

% Size page a little larger than the longest tooltip
\pagestyle{empty}
\parindent=0pt

\DeclareCiteCommand{\keytipcite}
{}
{\null\vfill% Move tooltip to bottom of page
\begin{center}
\keytip{\thefield{entrykey}}%
\fcolorbox{brown!50}{yellow!10}
{\footnotesize\parbox{0.95\textwidth}
{\usedriver
{\clearfield{extrayear}% Omit extraneous fields here
\clearfield{subtitle}%
\clearfield{booksubtitle}%
\clearfield{mainsubtitle}%
\clearfield{issuesubtitle}%
\clearfield{journalsubtitle}}
{\thefield{entrytype}}}}%
\end{center}
\medskip% Leave space below tooltip to avoid obscuring text
\newpage}
{}
{}

\def\allkeys{}

\begin{document}
%\nocite{*}
\nocite{companion,cicero,baez/article,bertram,kant:kpv,kant:ku}
\nocite{aristotle:poetics,aristotle:rhetoric,aristotle:anima}
\forlistloop{\keytipcite}{\allkeys}
\end{document}
\end{filecontents*}
% --- end of tooltips document

% --- presentation document
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage[filename=bibtooltips,mouseover,movetips]{fancytooltips}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[style=numeric-comp]{biblatex}
\usepackage{hyperref}
\definecolor{tooltipcolor}{named}{Green}

% Display nothing in "extratext" area following the tooltip (by default this
% area displays a speech bubble/balloon)
\let\TooltipExtratext\relax

% Apply tooltip to "extratext" area just after inline citation links
\DeclareFieldFormat{bibhyperref}{%
\tooltip*{\bibhyperref{#1}}{\thefield{entrykey}}}

% Define new citation commands that replace citation links with tooltips
\DeclareFieldFormat{bibtooltip}{\tooltip{#1}{\thefield{entrykey}}}
\newrobustcmd*{\tooltiphook}{%
\AtNextCite{\DeclareFieldAlias{bibhyperref}{bibtooltip}}}
\newrobustcmd*{\tooltipcite}{\tooltiphook\cite}
\newrobustcmd*{\tooltipcites}{\tooltiphook\cites}

% Apply tooltip to instance where numeric-comp uses \bibhyperref instead
% of bibhyperref format
\makeatletter
\newbibmacro*{cite:dump:tooltip}{%
\ifnumgreater{\value{cbx@tempcnta}}{0}
{\ifnumgreater{\value{cbx@tempcnta}}{1}
{\bibrangedash}
{\multicitedelim}%
\tooltip*
{\bibhyperref[\cbx@lastkey]{%
\ifdef\cbx@lastprefix
{\printtext[prefixnumber]{\cbx@lastprefix}}
{}%
\printtext[labelnumber]{\cbx@lastnumber}}}
{\cbx@lastkey}}
{}%
\setcounter{cbx@tempcnta}{0}%
\global\undef\cbx@lastprefix}
\ifcsundef{abx@macro@\detokenize{cite:dump}}
{}{\renewbibmacro*{cite:dump}{\usebibmacro{cite:dump:tooltip}}}
\makeatother

\begin{document}
\null\vfill
\subsection*{Inline citations}
\textcite[10--15]{companion} showed that...
\textcites[10]{companion}[1-10]{cicero}{}{kant:kpv,kant:ku}.
Filler text \parencites(e.g.)()[10]{companion}{cicero}{baez/article}.
Filler text.\supercite{bertram}
\subsection*{Footnote citations}
Filler text.\footcites{cicero}{companion}
Filler text.\footnote{See \smartcite{cicero}.}
\subsection*{More inline citations}
\textcites[10--15]{companion}[10]{cicero} show that...
Filler text \parencites(e.g.)()[10]{companion}{cicero}{baez/article}.
Filler text \tooltipcites(e.g.)()[10]{companion}{cicero}{baez/article}.
Filler text \parencite[e.g.][]{baez/article,bertram,cicero,kant:ku,companion}.
Filler text
\cite{cicero,companion,aristotle:poetics,aristotle:rhetoric,aristotle:anima,bertram}.
\printbibliography
\end{document}


Note the following:

• I've used filecontents to just to keep all the code together.

• The above formats can apply tooltips to any standard citation label, but \tooltip*/\tooltip needs to be applied directly whenever \bibhyperref is used instead of the format. The numeric-comp style's cite:dump macro is an example of this.

• The load order of the fancytooltips and biblatex packages is intentional. If biblatex is loaded first in the presentation document, it will generate persistent "rerun LaTeX" messages.

• Documents are best viewed at their full width. Otherwise you should consider making the tooltips half the \textwidth of the presentation document.

• When you published your answer I thought about writing a note like this, but then I forgot. Better late than never: nice answer! May 19, 2012 at 0:55
• @Audrey: \supercite{bertram} in Inline citations actually adds extra vertical space between the current and the upper line. Might it be possible to change that? Oct 24, 2012 at 16:07
• @maetra Odd. I didn't notice that back then. This can't get fixed without adjustments to how fancytooltips sets the "extratext" area - something that I won't have time to look into for awhile. If you're willing to part with the bibliography links, you could use \DeclareFieldAlias{bibhyperref}{bibtooltip}. Otherwise you could try contacting Robert with a stripped-down MWE (i.e. without biblatex). Oct 25, 2012 at 3:42
• @Audrey I tried to analyze this a bit more and found that the line spacing is correct in the article class if you use \tooltip instead of \tooltip* in \DeclareFieldFormat{bibhyperref}, but this doesn't work in beamer, so I posted a question here: tex.stackexchange.com/questions/79168/… Oct 26, 2012 at 13:11
• @maetra Yes, the new bibtooltip format I defined does the same thing. I don't think the culprit here is beamer, but \tooltip*. Unlike its unstarred variant, it sets an "extratext" area following the tooltip text. Oct 26, 2012 at 14:44

Unfortunately, JavaScript or OCG-based solutions work only in certain PDF viewers. I found that the most cross-viewer solution at present is to use PDF Underline annotations, which work not only in Adobe software, but even in most major browsers (at least in modern Firefox, Chrome, Edge, and other Chromium-based browsers). This can be useful if you are going to post your document online (e.g. on arXiv).

Not being much of a TeX savvy, I wrote this horribly buggy, but relatively simple code:

\begin{filecontents}{popupcite.sty}
\usepackage{pdfcomment}
\hypersetup{unicode}
% suppress annoying hyperref warnings
\let\HyPsd@RemoveSpaceWarning\@gobble

%Fixes a bug in soulpos package (used by pdfcomment). Without this fix, pdfmarkupcomments don't play well with \clearpage. Copypasted from StackExchange.
\AtEndDocument{\clearpage\immediate\write\@auxout{\string\ulp@afterend}}

%read bbl file and parse it to grab full citations
\providecommand{\grabfullcitations}[1]{%
\begingroup
%we don't need to typeset the reference section
\def\thebibliography{\begingroup\@gobble}%
\def\endthebibliography{\endgroup}%
%The bibliography environment contains a list of bibitems delimited by empty lines. Let's redefine \bibitem to store the bibliographic entry in \fullcitation@<key>
\def\bibitem[##1]##2 ##3\par{%
\expandafter\gdef\csname fullcitation@##2\endcsname{##3}%
}%
%Now we can read the bbl file, and LaTeX will put the bibliographic entries in \fullcitation@<key>
\input{#1}%
%Syntactic sugar to access \fullcitation@<key> by typing \fullcitation{<key>}
\gdef\fullcitation##1{\csname fullcitation@##1\endcsname}%
\endgroup%
}

%We need to attach a popup to each citation label. \cite function takes citation keys and outputs all the labels altogether, so we have to interfere somewhere in its internals. Since hyperref already works with each label separately, let's patch its \hyper@natlinkstart function. The most cross-viewer kind of popups are PDF Underline annotations, which are provided by the pdfcomment package. So we wrap each label in a \pdfmarkupcomment before creating a hyperlink. \pdfmarkupcomment parameters are chosen so as to make the underlining and annotation author/date/etc. invisible.
\pdfmarkupcomment[markup=Underline,color={1 1 1},opacity=0,subject={},author={},date={{ }}]{{#2}}{\fullcitation{#1}}%
}%
\end{filecontents}

%generated by BibTeX using plainnat style
\begin{filecontents}{main.bbl}
\begin{thebibliography}{3}
\providecommand{\natexlab}[1]{#1}
\providecommand{\url}[1]{\texttt{#1}}
\expandafter\ifx\csname urlstyle\endcsname\relax
\providecommand{\doi}[1]{doi: #1}\else
\providecommand{\doi}{doi: \begingroup \urlstyle{rm}\Url}\fi

\bibitem[Fardin(2014)]{three}
MA~Fardin.
\newblock On the rheology of cats.
\newblock \emph{Rheology Bulletin}, 83\penalty0 (2):\penalty0 16--17, 2014.

\bibitem[Lisi(2007)]{two}
A~Garrett Lisi.
\newblock An exceptionally simple theory of everything.
\newblock arXiv preprint arXiv:0711.0770, 2007.

\bibitem[Nikoli{\'c}(2008)]{one}
Hrvoje Nikoli{\'c}.
\newblock {Would Bohr be born if Bohm were born before Born?}
\newblock \emph{American Journal of Physics}, 76\penalty0 (2):\penalty0
143--146, 2008.

\end{thebibliography}
\end{filecontents}

\documentclass{article}
\usepackage[super,comma,sort&compress]{natbib}
\usepackage{popupcite}

\grabfullcitations{main.bbl}

\begin{document}
Pop-up~\cite{one,two,three} citations! O\textunderscore o
\input{main.bbl}
\end{document}


• Firefox

• Chrome