This question can be solved in several parts:
In what extend can pdf comments be part of TikZ pictures?
As long as the comment is put inside a node{}
, there is nothing impossible. In fact, you can put almost everything inside a node{}
. For example:
\tikz[remember picture,id=right triangle]{
\draw(0,0)node[below]{\pdfmarkupcomment[color=yellow]{$A$}{This is (0, 0)}}
--(6,0)node[right]{\pdfmarkupcomment[color=yellow]{$B$}{This is (6, 0)}}
--(0,3)node[above]{\pdfmarkupcomment[color=yellow]{$C$}{This is (0, 3)}};
--cycle
}

How to make a comment associated to a line/polyline/polygon?
The pdfcomment provide \pdflinecomment
so that you can, according to the manual, typeset a comment in form of a line, polyline or polygon
at the wished spot of the page.
For example:
\pdflinecomment[type=polyline,opacity=1,color=green,line={
200 500 260 500 200 530
}]{This is a triangle comment!}

How to position this comment
From the previous example we see that a line comment is defined by x- and y- coordinates, in bp
, relative to the lower left corner of this page. But how do we generate these numbers automatically so that the comment coincides with the triangle in TikZ pucture?
A possibility is that TikZ has an option called remember picture
and it will store the position of the TikZ picture. By using this imformation we have a chance to calculate the coordinates we need.
But instead of doing boring maths, we can fire \pgfsys@markposition
multiple times so that every position we need are stored. And again, there is nothing impossible if you put them in node{}
's:
\def\markposition#1{
\pgfsys@markposition{#1}
}
\tikz{
\draw(0,0)node{\markposition{point A}}
--(6,0)node{\markposition{point B}}
--(0,3)node{\markposition{point C}}
--cycle;
}
And then we can retrieve those coordinate by \pgfsys@getposition
:
\def\getposition#1#2#3{
\pgfsys@getposition{#1}\pointposition\pointposition
\pgf@sys@bp@correct\pgf@x\xdef#2{\pgf@sys@tonumber\pgf@x}
\pgf@sys@bp@correct\pgf@y\xdef#3{\pgf@sys@tonumber\pgf@y}
}
\getposition{point A}\Ax\Ay
\getposition{point B}\Bx\By
\getposition{point C}\Cx\Cy
Now \Ax
is the x-coordinate of A, and so on. So afterwards we can these coordinates in \pdflinecomment
as follows:
\let~\space
\pdflinecomment[type=polyline,opacity=1,color=blue,line={
\Ax~\Ay~\Bx~\By~\Cx~\Cy
}]{This is a triangle comment!}

Can I get rid of the ugly blue drawing?
Change the opacity
:

Full code
\documentclass{article}
\usepackage{tikz,pdfcomment,lipsum}
\begin{document}
\lipsum[1]
\tikz[remember picture,id=right triangle]{
\draw(0,0)node[below]{\pdfmarkupcomment[color=yellow]{$A$}{This is (0, 0)}}
--(6,0)node[right]{\pdfmarkupcomment[color=yellow]{$B$}{This is (6, 0)}}
--(0,3)node[above]{\pdfmarkupcomment[color=yellow]{$C$}{This is (0, 3)}}
--cycle;
}
\lipsum[2]
\clearpage
\lipsum[3]
\pdflinecomment[type=polyline,opacity=1,color=green,line={
200 500 260 500 200 530
}]{This is a triangle comment!}
\lipsum[4]
\clearpage
\lipsum[5]
\makeatletter
\def\markposition#1{
\pgfsys@markposition{#1}
}
\tikz{
\draw(0,0)node{\markposition{point A}}
--(6,0)node{\markposition{point B}}
--(0,3)node{\markposition{point C}}
--cycle;
}
\def\getposition#1#2#3{
\pgfsys@getposition{#1}\pointposition\pointposition
\pgf@sys@bp@correct\pgf@x\xdef#2{\pgf@sys@tonumber\pgf@x}
\pgf@sys@bp@correct\pgf@y\xdef#3{\pgf@sys@tonumber\pgf@y}
}
\getposition{point A}\Ax\Ay
\getposition{point B}\Bx\By
\getposition{point C}\Cx\Cy
\let~\space
\pdflinecomment[type=polyline,opacity=.5,color=blue,line={
\Ax~\Ay~\Bx~\By~\Cx~\Cy
}]{This is a triangle comment!}
\lipsum[6]
\end{document}
ocgx
package; on this site have a look to Explanatory bubbles in beamer the Interactive word explanation part, Interactive PDF, Latex and Article of the Future and tex.stackexchange.com/questions/65096/…Acrotex
: see as reference Mouseover events in beamer: hovering on \eqref and a comment containing the original equation popping upocg
is probably the most general, I am trying to avoid external scrips and Acrotex dependency.fancytooltips
package.