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.

After adding support for tooltips today in pdfcomment (\pdftooltip) I wanted to make a TikZ example with tooltip annotations. Within \pdftooltip the annotated element is set into a box to measure the size, which does not work for parts of a TikZ graphic. There are workarounds (manual box or \textbullet) in the following example:

\documentclass{article}
\usepackage{tikz}
\usepackage{pdfcomment}[2011/05/19]
% http://svn.berlios.de/viewvc/pdfcomment/trunk/dev/tex/latex/pdfcomment/pdfcomment.sty?revision=11
\begin{document}
\begin{tikzpicture}[scale=1.5]
    % Draw axes
    \draw [<->,thick] (0,2) node (yaxis) [above] {$y$}
        |- (3,0) node (xaxis) [right] {$x$};
    % Draw two intersecting lines
    \draw (0,0) coordinate (a_1) -- (2,1.8) coordinate (a_2);
    \draw (0,1.5) coordinate (b_1) -- (2.5,0) coordinate (b_2);
    % Calculate the intersection of the lines a_1 -- a_2 and b_1 -- b_2
    % and store the coordinate in c.
    \coordinate (c) at (intersection of a_1--a_2 and b_1--b_2);
    % Draw lines indicating intersection with y and x axis. Here we use
    % the perpendicular coordinate system
    \draw[dashed] (yaxis |- c) node[left] {$y'$}
        -| (xaxis -| c) node[below] {$x'$};
    % Draw a dot to indicate intersection point
    %% 1 - add a box manually %%
    \fill[red] (c) circle (2pt);
    \draw (c) node {\pdftooltip{\rule{0pt}{5pt}\rule{5pt}{0pt}}{This is the intersection point\textCR of the two lines!}};
    %% 2 - use \textbullet, which produxes a size in a box %%
    %\draw[red] (c) node {\pdftooltip{\textbullet}{This is the intersection point\textCR of the two lines!}};
    %% 3 - produces an error %%
    % "\fill[red] (c) circle (2pt);" can not be put in a box to measure the size
    %\pdftooltip{\fill[red] (c) circle (2pt);}{This is the intersection point\textCR of the two lines!}}    
\end{tikzpicture}
\end{document}

graphic with tooltip annotation

Is there a way that part of a TikZ graphic does produce a size when set into a box?

share|improve this question
    
The required pdfcomment version seems to not be on CTAN yet. Could you provide an alternative download link in the meantime? –  Martin Scharrer May 19 '11 at 17:37
    
@ Martin Scharrer It's in the example ;-) svn.berlios.de/viewvc/pdfcomment/trunk/dev/tex/latex/pdfcomment/… –  Josef May 19 '11 at 17:42
    
Aaaah, you mean this hard to read gray-on-gray text? ;-) –  Martin Scharrer May 19 '11 at 17:43
    
@Martin Scharrer Exactly! ;-) –  Josef May 19 '11 at 17:45

1 Answer 1

up vote 3 down vote accepted

I would make the tooltip part of the path. Then you can access the paths bounding box using current path bounding box and measure its dimensions.

\fill[red] (c) circle (2pt)
    let
        \p1 = (current path bounding box.south west),
        \p2 = (current path bounding box.north east)
    in
  node at (current path bounding box) {% should be in the center of the current path
    \pdftooltip{\rule{\dimexpr\x2-\x1\relax}{0pt}\rule{0pt}{\dimexpr\y2-\y1\relax}}%
    {This is the intersection point\textCR of the two lines!}%
};

However, for circles this seems to generate a rectangle which fits into the circle not around it.

For multiple paths you can use a scope and track the bounding box of it using local bounding box. Then use the same measurement technique as above.

share|improve this answer
    
Thanks, your solutions works after adding \usetikzlibrary{calc} (TikZ creates a useful error message! Hurrah! ;-)). As i'm not a regular user of TikZ i will have to look up the scope thing tomorrow. –  Josef May 19 '11 at 19:13
    
@Josef: Ups, yeah I forgot to mention the calc library. It should be also possible to use some path option to execute the code after the path. –  Martin Scharrer May 19 '11 at 19:15

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.