# Tooltip that works with all pdf readers

Is it possible to get tooltips into a LaTeX pdf?

I am working on my CV. I would like to show some more information on my electronic version once you swipe over that field with the mouse. i.e. when swiping with the mouse over education I want to show my subjects taken in undergrad through a tooltip.

Is this possible and if yes would if work for all kind of pdf readers?

-
Is it possible? Yes. Would it work for all kinds of PDF readers? Maybe not. –  Werner Jan 23 '14 at 5:37
How PDF viewers show 'hover text' is down the them, not the source (LaTeX or otherwise). Thus the best you can hope is to check with a set of viewers. –  Joseph Wright Jan 23 '14 at 6:58
You have alreay tagged with an according package name, cf. also Mouseover events in beamer: hovering on \eqref and a comment containing the original equation popping up. There is at least the package pdfcomments, as well. For the PDF readers: As example SumatraPDF does not at all execute such tooltips. –  Speravir Jan 23 '14 at 19:04
Also interesting: Showing the bibliographic entry in a popup when you hover over the citation key. Quite probably there are more of this. –  Speravir Feb 16 '14 at 23:45

Finally I came up with a \tooltip command that works across a small number of PDF viewers, among which is an Open-Source one. The tooltip command allows for TeX-formatted tip texts.

It comes in to variants: \tooltip and \tooltip*.

In contrast to the un-starred \tooltip command presented in

the command

\tooltip[<link colour>]{<link text>}[<tip box colour>]{<tip text>}


has the following restrictions:

1. The tip text box is not draggable.
2. The Link must be clicked once for the tip to show up and clicked once again to go away. Mouse-over and mouse-out are not enough.

These were necessary to meet the different PDF viewer capabilities.

Tooltips that become visible on mouse-over work only in Adobe Reader and can be inserted using the starred variant

\tooltip*[<link colour>]{<link text>}[<tip box colour>]{<tip text>}


The result was successfully tested in Evince (open-source!), Adobe Reader and PDF-XChange Viewer. The \tooltip requires package media9, version 0.49 (2015/01/21).

Evince:

\documentclass[a6paper,12pt]{scrbook}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% for Evince (visible on click)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{media9}[2015/01/21]
\usepackage{xcolor}
\usepackage{calc}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}

\ExplSyntaxOn
\let\tpPdfAnnot\mix_pdfannot:nnnn\def\tpPdfLastAnn{\g_mix_pdflastann_tl}
\let\tpPdfXform\mix_pdfxform:n\def\tpPdfLastXform{\g_mix_pdflastxform_tl}
\let\tpPdfObj\mix_pdfobj:nnn\def\tpPdfLastObj{\g_mix_pdflastobj_tl}
\ExplSyntaxOff

\makeatletter
\NewDocumentCommand{\tooltip}{sO{blue}mO{yellow!20}m}{{%
\leavevmode%
\tpPdfObj{}{dict}{/Type/OCG/Name (tipOCG.\thetcnt)%
/Usage<</Print<</PrintState/OFF>>/Export<</ExportState/OFF>>>>%
}%
\xdef\@ocgbase@ocgs{\@ocgbase@ocgs\space\tpPdfLastObj}%
\xdef\@ocgbase@offocgs{\@ocgbase@offocgs\space\tpPdfLastObj}%
\edef\tpTipOcg{\tpPdfLastObj}%
\IfBooleanTF{#1}{%
/Subtype/Screen%
/AA<<%
/E<</S/SetOCGState/State [/ON \tpTipOcg]>>%
/X<</S/SetOCGState/State [/OFF \tpTipOcg]>>%
>>%
}{%
/Subtype/Link/Border [0 0 0]/A <</S/SetOCGState/State [/Toggle \tpTipOcg]>>
}%
}{{\color{#2}#3}}%
\sbox\tiptext{\fcolorbox{black}{#4}{#5}}%
\edef\twd{\the\wd\tiptext}%
\edef\tht{\the\ht\tiptext}%
\edef\tdp{\the\dp\tiptext}%
\measureremainder{\whatsleft}\tipshift=0pt%
\ifdim\whatsleft<\twd\setlength\tipshift{\whatsleft-\twd}\fi%
\tpPdfXform{\tiptext}%
\raisebox{\heightof{#3}+\tdp}[0pt][0pt]{\makebox[0pt][l]{\hspace{\tipshift}%
\tpPdfAnnot{\twd}{\tht}{\tdp}{%
/Subtype/Widget/FT/Btn/Ff 65537/T (tip:\thetcnt)%
/AP<</N \tpPdfLastXform>>%
/MK<</TP 1/I \tpPdfLastXform/IF<</S/A/FB true/A [0.0 0.0]>>>>%
/OC \tpTipOcg
}%
\xdef\@anim@fields{\@anim@fields\space\tpPdfLastAnn}%
}}%
\stepcounter{tcnt}%
}}
\makeatother
\newsavebox\tiptext\newcounter{tcnt}
\newlength{\whatsleft}\newlength{\tipshift}
\newcommand{\measureremainder}[1]{%
\begin{tikzpicture}[overlay,remember picture]
\path let \p0 = (0,0), \p1 = (current page.east) in
[/utils/exec={\pgfmathsetlength#1{\x1-\x0}\global#1=#1}];
\end{tikzpicture}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}\Huge
Einstein's \tooltip{formula}{$E=m c^2$} is well known.
Another famous formula is due to \tooltip{Pythagoras}{$a^2+b^2=c^2$}.
This \tooltip*{tip}{is visible only in AR} is shown on mouse-over, but only in AR.
\end{document}

-

Tooltips in PDF documents are generally possible. I do know two packages; one of them you tagged yourself for your question, the other one I added, click on these tags to see, which questions were already asked in TeX.SX: & . But as Joseph Wright in a comment wrote:

How PDF viewers show 'hover text' is down the them, not the source (LaTeX or otherwise). Thus the best you can hope is to check with a set of viewers.

I can tell you, that SumatraPDF, a popular viewer for Windows, does not show any tooltip at all with “tooltip” in a strict meaning, but does show comments, when you hover with the mouse over one of them. What is supported, what not, can be seen when reading the documentation of package pdfcomment. There is a type \pdfmarkupcomment that actually almost acts like a tooltip.