12

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?

7

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
  • 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
  • Hmmm. OK. Your solution is the closest then. But is there anyway to make the icons smaller? – Alec Jacobson Aug 7 '13 at 13:13
  • 1
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.