Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
Is it possible? Yes. Would it work for all kinds of PDF readers? Maybe not. –  Werner Jan 23 at 5:37
2  
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 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 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 at 23:45

2 Answers 2

up vote 6 down vote accepted

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

In contrast to the \tooltip command presented in

Are mouse over definitions of acronyms possible?.

the command given below 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.

The result was successfully tested in Evince (open-source!), Adobe Reader and PDF-XChange Viewer. The \tooltip requires package media9, version 0.41 (2014/03/06).


Evince:

enter image description here

\documentclass[a6paper,12pt]{scrbook}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% usage: \tooltip[<link colour>]{<link text>}[<tip box colour>]{<tip text>}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{media9}[2014/03/25]
\usepackage{xcolor}
\usepackage{calc}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}

\ExplSyntaxOn
\let\tpPdfLink\mix_pdflink:nn
\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\@anim@ocgs{\@anim@ocgs\space\tpPdfLastObj}%
  \xdef\@anim@offocgs{\@anim@offocgs\space\tpPdfLastObj}%
  \edef\tpTipOcg{\tpPdfLastObj}%
  \tpPdfLink{%
    /Subtype/Link/Border [0 0 0]/A <</S/SetOCGState/State [/Toggle \tpTipOcg]>>
    %/Subtype/Screen%
    %/AA<<%
    %  /E<</S/SetOCGState/State [/ON \tpTipOcg]>>%
    %  /X<</S/SetOCGState/State [/OFF \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}}[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$}.
\end{document}
share|improve this answer

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.

See also this fixed bug in SumatraPDF Bug tracker: PDF Comments Don't Work.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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