3

Indeed, with this key, visibility does not work properly.

I quote the manual:

/tikz/switch ocg with mark on={<ocg reference»}{<OCGs list> } These styles transform the current path or the current node in a link acting as if it is produced by the macro \switchocg (the visibility status of referenced OCGs in the list is reversed).

A mark (currently a simple cross) is drawn over the current path or node in an OCG whose reference is ocg reference . The visibility status of this OCG will be reversed as those of the entire list.

Thus, the following two examples should work in the same way. However, only the second one with the switchocg key with the status=invisible leaves the rectangle invisible from the beginning.

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage[tikz]{ocgx2} 
\usetikzlibrary{positioning}

\tikzset{%
  button on/.style={%
    draw,minimum size=5mm,
    line width=1pt,
    fill=blue!50,rounded corners,
    switch ocg with mark on={#1}{},
  },
}
\begin{document}


\begin{tikzpicture}
\begin{scope}[ocg={name=rect1,ref=rect1,status=invisible}]
\draw[fill=green!50](0,0)rectangle(2,1);
\end{scope}
\node[button on=rect1]at (-1.5,.5)(but){};
    \node[right=0 of but]{rect1};
\end{tikzpicture}

\begin{tikzpicture}
\begin{scope}[ocg={name=rect2,ref=rect2,status=invisible}]
\draw[fill=green!50](0,0)rectangle(2,1);
\end{scope}
\node[draw,rounded corners,switch ocg=rect2] at (-1,.5) {rectangle};
\end{tikzpicture}

\end{document}

screenshot

4

The switch ocg with mark on Tikz style implicitly sets the PDF layer, whose ID is passed to it as its argument, to the visibility state ON.

In the document code listed in the question, the button is inserted after the rectangle shape which belongs to the same PDF layer as the button's cross-mark. With ocgx2, the layer visibility setting that comes last wins over previous settings. You can easily check this by swapping rectangle and the button:

Original code:

\begin{scope}[ocg={name=rect1,ref=rect1,status=invisible}] % layer `rect1' set to OFF,
\draw[fill=green!50](0,0)rectangle(2,1);
\end{scope}
\node[button on=rect1]at (-1.5,.5)(but){}; % but ON wins, as it comes last

For testing:

\node[button on=rect1] at (-1.5,.5)(but){}; % layer `rect1' set to ON,
\begin{scope}[ocg={name=rect1,ref=rect1,status=invisible}] % OFF wins, as desired
\draw[fill=green!50](0,0)rectangle(2,1);
\end{scope}
2

The English and French manuals of the ocgx package do not indicate the same keys.

The French manual indicates the key

/tikz/switch OCG with mark={< basename >}{< OCG list > }

This key is not indicated in the English manual which indicates two keys:

/tikz/switch ocg with mark on={< ocg reference > }{< OCGs list > }

/tikz/switch ocg with mark off={< ocg reference >}{< OCGs list > }

To ensure that the rectangle is not displayed by default at the beginning, we must use the switch ocg with mark off key.

screenshot

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage[tikz]{ocgx2} 
\usetikzlibrary{positioning}

\tikzset{%
  button on/.style={%
    draw,minimum size=5mm,
    line width=1pt,
    fill=blue!50,rounded corners,
    switch ocg with mark off={#1}{},
  },
}
\begin{document}


\begin{tikzpicture}
\begin{scope}[ocg={name=rect1,ref=rect1}]
\draw[fill=green!50](0,0)rectangle(2,1);
\end{scope}
\node[button on=rect1]at (-1.5,.5)(but){};
    \node[right=0 of but]{rect1};
\end{tikzpicture}

\begin{tikzpicture}
\begin{scope}[ocg={name=rect2,ref=rect2,status=invisible}]
\draw[fill=green!50](0,0)rectangle(2,1);
\end{scope}
\node[draw,rounded corners,switch ocg=rect2] at (-1,.5) {rectangle};
\end{tikzpicture}

\end{document}

If AlexG (ocgx2 maintainer) and Paul Gaborit (ocgx maintainer) are kind enough to clarify this, I will gladly accept their answer.

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.