# 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 three variants:

%draggable tip, AR-only

%starred variant for non-draggable tip text, AR-only

%doubly-starred variant also works in Evince, on-click, not draggable

In contrast to the un-starred \tooltip command, the doubly-starred

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 un-starred (draggable tip text) and single-starred (not draggable) variant.

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

Evince:

\documentclass[a6paper,12pt]{scrbook}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   non-draggable version:
%
% for Evince (visible on click, not draggable)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{media9}[2015/11/02]
\usepackage{xcolor}
\usepackage{calc}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}

\ExplSyntaxOn
\let\tpPdfAnnot\pbs_pdfannot:nnnn\def\tpPdfLastAnn{\g_pbs_pdflastann_tl}
\let\tpPdfXform\pbs_pdfxform:n\def\tpPdfLastXform{\g_pbs_pdflastxform_tl}
\ExplSyntaxOff

\makeatletter
\NewDocumentCommand{\tooltip}{ssO{blue}mO{yellow!20}m}{{%
\leavevmode%
\IfBooleanT{#1}{%
\ocgbase@new@ocg{tipOCG.\thetcnt}{%
/Print<</PrintState/OFF>>/Export<</ExportState/OFF>>%
}{false}%
\xdef\tpTipOcg{\ocgbase@last@ocg}%
}%
\IfBooleanTF{#2}{%
/Subtype/Link/Border [0 0 0]/A <</S/SetOCGState/State [/Toggle \tpTipOcg]>>
}{%
/Subtype/Screen%
\IfBooleanTF{#1}{%
/AA<<%
/E<</S/SetOCGState/State [/ON \tpTipOcg]>>%
/X<</S/SetOCGState/State [/OFF \tpTipOcg]>>%
>>%
}{
/AA<<%
/E<</S/JavaScript/JS(%
var fd=this.getField('tip.\thetcnt');%
\IfBooleanF{#1}{%
if(typeof(click\thetcnt)=='undefined'){%
var click\thetcnt=false;%
var fdor\thetcnt=fd.rect;var dragging\thetcnt=false;%
}%
}%
if(fd.display==display.hidden){%
fd.delay=true;fd.display=display.visible;fd.delay=false;%
}%
this.dirty=false;%
)>>%
/X<</S/JavaScript/JS(%
if(!click\thetcnt&&!dragging\thetcnt){fd.display=display.hidden;}%
if(!dragging\thetcnt){click\thetcnt=false;}%
this.dirty=false;%
)>>%
/U<</S/JavaScript/JS(click\thetcnt=true;this.dirty=false;)>>%
/PC<</S/JavaScript/JS (%
var fd=this.getField('tip.\thetcnt');%
try{fd.rect=fdor\thetcnt;}catch(e){}%
fd.display=display.hidden;this.dirty=false;%
)>>%
/PO<</S/JavaScript/JS(this.dirty=false;)>>%
>>%
}
}%
}{{\color{#3}#4}}%
\sbox\tiptext{\fcolorbox{black}{#5}{#6}}%
\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{#4}+\tdp}[0pt][0pt]{\makebox[0pt][l]{\hspace{\tipshift}%
\tpPdfAnnot{\twd}{\tht}{\tdp}{%
/Subtype/Widget/FT/Btn/T (tip.\thetcnt)%
/AP<</N \tpPdfLastXform>>%
/MK<</TP 1/I \tpPdfLastXform/IF<</S/A/FB true/A [0.0 0.0]>>>>%
\IfBooleanTF{#1}{%
/Ff 65537/OC \tpTipOcg%
}{%
/Ff 65536/F 3%
/AA <<%
/U <<%
/S/JavaScript/JS(%
var fd=event.target;%
var mX=this.mouseX;var mY=this.mouseY;%
var drag=function(){%
var nX=this.mouseX;var nY=this.mouseY;%
var dX=nX-mX;var dY=nY-mY;%
var fdr=fd.rect;%
fdr[0]+=dX;fdr[1]+=dY;fdr[2]+=dX;fdr[3]+=dY;%
fd.rect=fdr;mX=nX;mY=nY;%
};%
if(!dragging\thetcnt){%
dragging\thetcnt=true;Int=app.setInterval("drag()",1);%
}%
else{app.clearInterval(Int);dragging\thetcnt=false;}%
this.dirty=false;%
)%
>>%
>>%
}%
}%
\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 draggable and shown on mouse-over.
\end{document}
-
What package/class provides \ocgbase@new@ocg? – 1010011010 Nov 23 '15 at 12:11
@1010011010 ocgbase.sty (part of package ocgx2) loaded by media9.sty. – AlexG Nov 23 '15 at 12:46

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.