[Tex/LaTex] Override default cite tooltip

bibtexcitingmacpdfcomment

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

\documentclass{article}
\usepackage[colorlinks=true]{hyperref}
\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).

Animated gif of what's going on

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?

Best Answer

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!

How about using PDF text annotations instead?

PDF text annotations (1)

PDF text annotations (2)

\documentclass{article}
\usepackage[colorlinks=true]{hyperref}
\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:

PDF Markup Highlight annotation

\documentclass{article}
\usepackage[rgb]{xcolor}
\usepackage[colorlinks=true]{hyperref}
\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

Highlight annotation with question mark

EDIT3:

Or the same again with a tooltip:

tooltip annotation with question mark

\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
Related Question