# Override default cite tooltip

I'm trying to add a tooltip to each inline citation. So far I've almost got it working using pdfcomment:

\documentclass{article}
\usepackage{pdfcomment}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{Bli74,
author = {Blinder, Alan S.},
year = {1974},
title = {The economics of brushing teeth},
}
\end{filecontents}

\usepackage{usebib}
\bibinput{\jobname}

\makeatletter
\let\@internalcite\cite
\renewcommand{\cite}[1]{%
\pdftooltip{\@internalcite{#1}}{\usebibentry{#1}{title}}}
\makeatother

\begin{document}
This is a citation: \cite{Bli74}.

\bibliographystyle{apalike}
\bibliography{\jobname}
\end{document}


But there seems to be a default tooltip because of the link in the citation "Go to page 1" in my mac's Preview.app. I see that my custom tooltip is working but only on the thin boundary of the citation (including the little brackets).

Is there a way to redefine the cite command to avoid this tooltip and use just my custom tip for the entire citation?

Meanwhile, I would also like to handle multiple citations: \cite{thing1,thing2}. How can I extract (split on comma) and add tooltips to both thing1 and thing2?

The problem is that you are having two so called PDF annotations defined at almost the same place. One for the tooltip and another one for the hyperlink, which is technically also a PDF annotation.

You can switch off the hyperlink with:

\usepackage[colorlinks=true,draft]{hyperref}


So in this case, you can only have the one without the other!

\documentclass{article}
\usepackage{pdfcomment}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{Bli74,
author={Blinder, Alan S.},
year={1974},
title={The economics of brushing teeth},
}
\end{filecontents}
\usepackage{usebib}
\newbibfield{author}
\bibinput{\jobname}
\makeatletter
\let\@internalcite\cite
\renewcommand{\cite}[1]{%
\@internalcite{#1}\pdfcomment[icon=Help,author=Reference:]{\usebibentry{#1}{author} (\usebibentry{#1}{year})\textCR\usebibentry{#1}{title}}}
\makeatother
\begin{document}
This is a citation: \cite{Bli74}.
\bibliographystyle{apalike}
\bibliography{\jobname}
\end{document}


EDIT:

For a more subtle appearance, you can use empty and invisible PDF Markup Highlight annotations:

\documentclass{article}
\usepackage[rgb]{xcolor}
\usepackage{pdfcomment}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{Bli74,
author={Blinder, Alan S.},
year={1974},
title={The economics of brushing teeth},
}
\end{filecontents}
\usepackage{usebib}
\newbibfield{author}
\bibinput{\jobname}
\makeatletter
\let\@internalcite\cite
\renewcommand{\cite}[1]{%
\mbox{%
\@internalcite{#1}%
\hbox to 0pt{%
\raisebox{1ex}{%
\pdfmarkupcomment[color=yellow,opacity=0,author=Reference:]%
{}%
{\usebibentry{#1}{author} (\usebibentry{#1}{year})\textCR%
\usebibentry{#1}{title}}}}}%
}%
\makeatother
\begin{document}
This is a citation: \cite{Bli74}.
\bibliographystyle{apalike}
\bibliography{\jobname}
\end{document}


EDIT2:

For viewers without additional marker, you can use your own marker like a tiny question mark. You should also increase opacity.

\let\@internalcite\cite
\renewcommand{\cite}[1]{%
\mbox{\textcolor{blue}{%
\@internalcite{#1}%
\ifpc@gopt@final\else%
\hbox to 0pt{%
\raisebox{1ex}{\tiny%
\pdfmarkupcomment[color=yellow,opacity=0.5,author=Reference:]%
{?}%
{\usebibentry{#1}{author} (\usebibentry{#1}{year})\textCR%
\usebibentry{#1}{title}}}}%
\fi%
}%
}%
}%
\makeatother


EDIT3:

Or the same again with a tooltip:

\makeatletter
\let\@internalcite\cite
\renewcommand{\cite}[1]{%
\mbox{\textcolor{blue}{%
\@internalcite{#1}%
\ifpc@gopt@final\else%
\hbox to 0pt{%
\raisebox{1ex}{\tiny%
\pdftooltip[color=yellow,opacity=0.5,author=Reference:]%
{\fboxsep1pt\fcolorbox{blue}{yellow}{?}}%
{\usebibentry{#1}{author} (\usebibentry{#1}{year})\textCR%
\usebibentry{#1}{title}}}}%
\fi%
}%
}%
}%
\makeatother

• Is there any way to switch off just the PDF annotations for the link? Instead of completely turning it off? – Alec Jacobson Aug 6 '13 at 15:42
• Well, i'm not sure what you mean. But the link is the PDF annotation. The annotation defines a clickable area, which 'overlays' the page. These annoations have different 'actions', like 'jump to' (hyperlink) or to show a tooltip. If you have two annotations at the same place, one is necessarily on top of the other. In theory, it should be possible to redefine the internals of hyperref to add a tooltip. Then you would need a very smart interface for the autogenerated hyperlinks. Maybe it's possible by redefing quite big parts of hyperref. – Josef Aug 6 '13 at 16:07
• BTW, in AR I don't see a tooltip at all with your original example. The 'Go to page 1' seems to be an addition of Preview. For now hyperref does not add tooltips to hyperlink annotations. – Josef Aug 6 '13 at 16:13
• The appearance and size of the icons depends on the viewer. Different viewers have different sets of icons. – Josef Aug 7 '13 at 15:12
• You can use your own marker like a tiny question mark. This should at least work with a double click to open the text box. See my edit. – Josef Aug 9 '13 at 12:36