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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I tried using the fancytooltips package and like it a lot. One thing that I could imagine would be nice is to have the entry showing up as a movable box instead of just a tooltip. (Sometimes the tooltip obscures other text.) Is this possible at all to implement? I mean it could take a lot of work, but if it's possible at all I'd like to look into it.

The examples and screenshots of fancytooltips can be found in this post. To quote from that post:

Both Gonzalo Medina and Audrey posted an excellent solution. But the things are simpler now. See the fancy-preview webpage - based on the new version of fancytooltips (May 2012), preview.sty and some bash scripts you get tooltips for bibliographic entries, theorems, definitions, displayed equations etc. automatically.

Small example and screenshots are attached.

\usepackage{hyperref} % Important!

\begin{lemma}[Lemma from \cite{M}]\label{lemma}
  If $k<0$, then
  for every real number $x$.

Inequality \eqref{eq:1} in Lema \ref{lemma} can be proved easily. Is
more general than \cite[Theorem 3.4]{K}.

\bibitem[M]{M} Me: My book related to the problem (2006), 145 p.
  % The new line is important!

\bibitem{K} Karl: Karl's paper published in some minor proceedings, 
    a local conferrence organized by his university (2005), 23--25.
  % The new line is important!


The file in Adobe Reader

enter image description here

Ref M

enter image description here

Ref 1

enter image description here

Equation (1)

enter image description here

Lemma 1.

enter image description here

share|improve this question
Just because many users (like me) might not be familiar with fancytooltips, could you add a MWE, perhaps even demonstrating the problematic overlap, and a picture of the output? – doncherry Apr 6 '13 at 17:00
@doncherry Good point, I've just edited to add that! – Mika H. Apr 6 '13 at 17:10
Thanks! Perhaps you could even include (reproduce) it in this question? We kind of like to have everything in one place. – doncherry Apr 6 '13 at 17:20
@doncherry Done! – Mika H. Apr 6 '13 at 21:35
up vote 26 down vote accepted

This would require hacking the fancytooltips package.

Since fancytooltips depends on packages which are not in TeXLive, I tried something on my own.


In addition, the tool-tip command defined below supports all common output drivers (LaTeX workflows):

  • latex->dvips->ps2pdf (dvips must not be called with option -Ppdf!)
  • latex->dvipdfmx
  • xelatex, lualatex, pdflatex

The command

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

creates a tooltip that can be dragged around.

The colour arguments are optional and default to blue and yellow!20. Predefined colour names and colour expressions according to the colour-model of the xcolor package can be used.

<link text> is breakable across line endings, except for the latex->dvips->ps2pdf workflow.

Multi-line <tip text> should be put into a \parbox or minipage.

  %dvipdfmx     %uncomment this for latex->dvipdfmx

% tooltips with LaTeX
% optimized for Adobe Reader (visible on mouse-over)
%     usage: \tooltip[<link colour>]{<link text>}[<tip box colour>]{<tip text>}
%   non-draggable version:
%     usage: \tooltip*[<link colour>]{<link text>}[<tip box colour>]{<tip text>}
% for Evince (visible on click, not draggable)
%   usage: \tooltip**[<link colour>]{<link text>}[<tip box colour>]{<tip text>}


      /Subtype/Link/Border [0 0 0]/A <</S/SetOCGState/State [/Toggle \tpTipOcg]>>
          /E<</S/SetOCGState/State [/ON \tpTipOcg]>>%
          /X<</S/SetOCGState/State [/OFF \tpTipOcg]>>%
            var fd=this.getField('tip.\thetcnt');%
                var click\thetcnt=false;%
                var fdor\thetcnt=fd.rect;var dragging\thetcnt=false;%
          /PC<</S/JavaScript/JS (%
            var fd=this.getField('tip.\thetcnt');%
      /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]>>>>%
        /Ff 65537/OC \tpTipOcg%
        /Ff 65536/F 3%
        /AA <<%
          /U <<%
              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;%
  \begin{tikzpicture}[overlay,remember picture]
    \path let \p0 = (0,0), \p1 = (current page.east) in

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$}.

enter image description here

How it works:

Two PDF-Annotations (mouse-sensitive regions) are created: (1) A link around the blue link text, which is breakable across line endings. (2) An interactive (/Ff 65536) button (/FT/Btn) widget (/Subtype/Widget) for the tip text.

Visibility of the tip box is controlled via a JavaScript action that is bound to the mouse-enter event of the link. In order to show/hide the tip it is sufficient to repeatedly hover the mouse pointer over the link text.

The tip text may not be directly embedded into the page content; it couldn't be moved around otherwise. Rather, it is typeset into a box (\sbox) and subsequently distilled into a so-called Form-XObject, which is a self-contained PDF entity with graphical and/or textual content. This Form-XObject is bound to the button widget appearance via the /MK entry.

The dragging is implemented as a JavaScript action, which is triggered by the mouse-up event of the tip-text button. The mouse movement is tracked by the function drag() which is repeatedly executed using a JavaScript timer (app.setInterval). The deltas of the mouse position thus determined are continuously added to the coordinates (rect property) of the JavaScript Field object that represents the tip-text button.

share|improve this answer
That looks great, AlexG! Could you please add some comment on what each part of your code is doing, so that I (and others) can understand it more easily? Thanks! – Mika H. Apr 16 '13 at 15:33
Currently I am a bit short of time. Will do that later. – AlexG Apr 17 '13 at 6:33
@MikaH: ...Done. Plus some code fixes. – AlexG Apr 19 '13 at 11:57
@AlexG Mother of God! img.mu.cdn.li/Ao/xqefEH.jpg Excellent work! Questions: Could it be made so that (in your MWE) "formula" could be replaced by \eqref{}, if you know what I mean? Also, does the end-user require anything other than a PDF viewer? – User 17670 Apr 19 '13 at 14:52
@User17670: First, we would need to redefine the equation environment such that it puts the equation in an \sbox in addition to typesetting it onto the page. Then, \eqref cannot be used as it only inserts the equation number (we do not really want to change this!). Instead, we need a new macro, say, \eqrepeat{...}, to be used as <tip text>, which inserts the previously typeset equation using \usebox. As for requirements, pdflatex is used for typesetting; the end-user only needs AdobeReader. I could extend this code to different drivers (dvips->ps2pdf, XeLaTeX, ...), if needed. – AlexG Apr 19 '13 at 15:14

Your Answer


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.