4

To get a handout, I drew polygons on A4 paper arranged in landscape mode. In order to create an interactive slide show with beamer associated with these documents, I had to reduce the dimensions with scale=.25 so that all the figures appear on the slide. To simplify the demonstration, the polygons have been replaced by rectangles.

Handout code:

\documentclass[10pt,landscape,a4paper]{article}

\usepackage{tikz}   
\begin{document}
\begin{tikzpicture}[scale=.5]
\draw[thick](0,4)rectangle(21,10);
\draw[thick](24,-10)rectangle(39,-3);
\draw[thick](24,0)rectangle(34,10);% carré
\end{tikzpicture}

\end{document}

The beamer code

\documentclass[aspectratio=1610,10pt]{beamer} % Présentation générale et mise en page
\usepackage[tikz]{ocgx2}            

\begin{document}
\begin{frame}{test ocgx2}
\begin{tikzpicture}[scale=.25]
\draw[switch ocg=Un,thick](0,4)rectangle(21,10);
\begin{scope}[ocg={name=Un,ref=Un,status=invisible},every path/.style={blue,line width=.8pt}]
\draw[fill=green!30](0,4)rectangle(21,10);
\end{scope}

\draw[switch ocg=Deux,thick](24,-10)rectangle(39,-3);
\begin{scope}[ocg={name=Deux,ref=Deux,status=invisible},every path/.style={blue,line width=.8pt}]
\draw[fill=green!30](24,-10)rectangle(39,-3);
\end{scope}

\draw[thick,switch ocg=Trois](24,0)rectangle(34,10);% squarre
\begin{scope}[ocg={name=Trois,ref=Trois,status=invisible},every path/.style={blue,line width=.5pt}]
\draw[fill=green!30](24,0)rectangle(34,10);% carré
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}

Edit: Each rectangle is interactive. By clicking on it, it is colored alternately green or white (action \switchocg). When scaled, the interactive area overlaps with the other rectangles and becomes inactive. For example, by clicking on the lower rectangle, the upper rectangle link is activated.

Is it possible to use ocgx or ocgx2 with scaling?

Translated with www.DeepL.com/Translator

ocgx2 test

  • 1
    I apologize in advance if that's nonsense, I really do not know what ocgx does. But I think I got a different (or better behavior) by using \begin{tikzpicture}[x={(0.25,0)},y={(0,0.25)}] instead of \begin{tikzpicture}[scale=.25]. Could you perhaps check? – user121799 Jun 24 '18 at 22:01
  • @marmot Thank you so much, it works great, can you make it a solution? – AndréC Jun 25 '18 at 4:44
  • 2
    Fixed in ocgx2 as of v. 0.35. See below. – AlexG Jun 26 '18 at 13:49
  • Version 0.36 is available on MikTeX today. – AndréC Jun 28 '18 at 3:19
6

This is a bug in the current versions of the ocgx and ocgx2 packages.

A new ocgx2 version (0.35 2018/06/26) is on the way to CTAN. In the meantime, the fixed file ocgx2.sty can be downloaded ↗here.


Background:

TikZ paths are turned into clickable PDF-Layer switching links by overlaying the link-making command (\switchocg...) onto the bounding box of the current path as a TikZ-postaction. Command \switchocg... needs a text-box of appropriate size as its 2nd argument in order to create the mouse sensitive rectangle. Originally, a \rule placed in a \phantom was used whose width and height were calculated from the bounding box lower-left and upper-right corner coordinates. The result was saved in \p3 (see diff below). However, \p3 does not seem to be subject to scaling if used in the node object of path picture. Instead, we create coordinates (p1) and (p2) from \p1 and \p2 and use them directly in the nested tikzpicture:

\tikz \useasboundingbox (p1) rectangle (p2);

Excerpt from the diff between the fixed and the old ocgx2.sty version:

   switch ocg/.style={
     postaction={
       path picture={
         \path let
         \p1 = (path picture bounding box.south west),
-        \p2 = (path picture bounding box.north east),
-        \p3 = (\x2-\x1,\y2-\y1)
+        \p2 = (path picture bounding box.north east)
         in
-        (path picture bounding box.center)
-        node[inner sep=0pt,anchor=center,outer sep=0pt]
-        {\switchocg*{#1}{\phantom{\rule{\x3}{\y3}}}};
+        coordinate (p1) at (\p1) coordinate (p2) at (\p2)
+        node[inner sep=0pt,anchor=south west,outer sep=0pt] at (p1)
+        {\switchocg*{#1}{\tikz \useasboundingbox (p1) rectangle (p2);}};
       }
     }
   },
  • 2
    Cool. +1. That's a really quick fix! – user121799 Jun 26 '18 at 14:08
  • Thanks for this quick fix, so I accept your solution and thank @marmot for its solution. – AndréC Jun 26 '18 at 14:46
  • 1
    Hope it won't make @marmot angry. Thank you for reporting the issue! (And +1 for marmot, in order to appease him/her.) – AlexG Jun 26 '18 at 14:47
  • 2
    @marmot Explanation added. – AlexG Jun 27 '18 at 8:30
  • 1
    2nd update since yesterday :-) Just simplified the code a bit. – AlexG Jun 27 '18 at 17:03
5

I have to admit that I a have not even heard about the ocgx(2) packages before looking at this question. So I cannot really explain why, but it seems that replacing \begin{tikzpicture}[scale=.25] by \begin{tikzpicture}[x={(0.25,0)},y={(0,0.25)}] does the trick. (Of course I understand how these options differ, that's why I tried that out, but again I do not know the details of the ocgx(2) packages to tell what goes wrong if one uses scale.)

The complete MWE thus becomes:

\documentclass[aspectratio=1610,10pt]{beamer} % Présentation générale et mise en page
\usepackage[tikz]{ocgx2}            

\begin{document}
\begin{frame}{test ocgx2}
\begin{tikzpicture}[x={(0.25,0)},y={(0,0.25)}]
\draw[switch ocg=Un,thick](0,4)rectangle(21,10);
\begin{scope}[ocg={name=Un,ref=Un,status=invisible},every path/.style={blue,line width=.8pt}]
\draw[fill=green!30](0,4)rectangle(21,10);
\end{scope}

\draw[switch ocg=Deux,thick](24,-10)rectangle(39,-3);
\begin{scope}[ocg={name=Deux,ref=Deux,status=invisible},every path/.style={blue,line width=.8pt}]
\draw[fill=green!30](24,-10)rectangle(39,-3);
\end{scope}

\draw[thick,switch ocg=Trois](24,0)rectangle(34,10);% squarre
\begin{scope}[ocg={name=Trois,ref=Trois,status=invisible},every path/.style={blue,line width=.5pt}]
\draw[fill=green!30](24,0)rectangle(34,10);% carré
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}
  • The ocgx2 package is the continuity of the ocgx package and integrates the ocg, ocg-p packages. It allows you to create interactive PDF files. See a demonstration here: mirrors.ctan.org/macros/latex/contrib/ocgx/demo-ocgx.pdf – AndréC Jun 25 '18 at 5:15
  • @AndréC Thanks! (This I also figured in the meantime.) I guess that the problem is that there is somewhere some distance is hard coded, to see what I mean compare \tikz[scale=0.25]{\draw(0,0)--(1cm,0);} to \tikz[x={(0.25,0)}]{\draw(0,0)--(1cm,0);}. But I am far from being sure about that. – user121799 Jun 25 '18 at 5:21
  • Each rectangle is interactive. By clicking on each, it is coloured green or white. With scale, the interactive zone is that of the path coded in hard and thus exceeds the rectangle since the latter is scaled. With the other solution, the interactive zone is that of the rectangle and nothing but this zone. – AndréC Jun 25 '18 at 11:10
  • 2
    The workaround is not necessary anymore, with ocgx2 v. 0.35. – AlexG Jun 26 '18 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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