# 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 '11 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 '11 at 1:34
If you want to see it done right, try one of these open access articles. –  Emre Aug 16 '11 at 21:57
@Emre The journal you linked i snot open-access, it seems. –  matth Mar 19 '12 at 8:43
@matth Thanks for the notice. Try this PDF or search Google for recent articles. –  Emre Mar 20 '12 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? –  filokalos Apr 10 '11 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. –  Gonzalo Medina Apr 11 '11 at 20:28
Ok.:) Thank you. –  filokalos Apr 11 '11 at 20:36
@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? –  Sharpie Apr 11 '11 at 20:46
@Gonzalo Medina: Would it be possible to deposit somewhere a compiled version of your example, please? –  Stephen Aug 20 '11 at 18:14

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! –  Gonzalo Medina May 19 '12 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? –  maetra Oct 24 '12 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). –  Audrey Oct 25 '12 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/… –  maetra Oct 26 '12 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. –  Audrey Oct 26 '12 at 14:44

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 '12 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 '12 at 20:11
+1 biblatex doesn't print bibliography items via \bibitem, but this looks like a great solution for biblatex alternatives. Thanks for this (and the fancytooltips package). –  Audrey May 7 '12 at 20:37
Emre: I have no experience with Xetex, but the answer is probably no, since it does not generate PDF directly. I have minor experience with luatex, but guess, it will work. –  robert.marik.cz May 8 '12 at 15:10
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? –  User 17670 Oct 14 '12 at 11:11