# TikZ spy and Beamer uncover

I'm trying to uncover a magnifying glass using the \spy functionality of TikZ, however, as you can see in the minimal working example below, the glass is there from frame 1. Does someone know how to fix this issue ?

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\begin{document}

\begin{frame}
Space
\begin{center}
\begin{tikzpicture}[spy scope={magnification=1.5, size=2cm},every spy in node/.style={remember picture,overlay,magnifying glass,circular drop shadow,fill=white,draw,ultra thick, cap=round}]
\node[rectangle, draw, minimum width=1cm, minimum height=1cm] (N) {};
\uncover<2->{\spy on (N) in node;}
% \only<2>{\spy on (N) in node;}
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}

-
What's wrong with the only command you have commented out? –  Geoff Reedy Dec 26 '12 at 20:56
It's moving the text Space in the frame. –  BigDawg Dec 26 '12 at 21:08

Why \uncover<2-> and \visible<2-> do not work I don’t know, but here are two work-arounds:

## Work-Around 1: \alt + \pgfkeysalso

There are two /.styles and one /.code, to help with beamer:

• invisible/.style={opacity=0,text opacity=0}
This style is not very beamer special because it sets only every opacity (draw, fill, text) to zero, which means: It is there, but you cannot see it. It occupies the same space, much like \phantom.
• alt/.code args={<#1>#2#3}{\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}}
This code handler uses two things:

1. The \alt<overlay>{arg1}{arg2} macro provided by beamer that executes arg1 when on overlay, otherwise arg2; and
2. \pgfkeysalso which adds TikZ keys to a path without changing it otherwise. This is similar to adding [some keys=values] to a path.
• visible on/.style={alt={#1{}{invisible}}}
This style is rather a shortcut to alt. It does nothing to a path on <#1> but hides in otherwise.

If you want to use overlay specification with a ,, e.g. <2,4>, you have to enclose it in { }: visible on={<2,4>}. (For that same reason are the alt arguments enclosed in braces.)

### Code

\documentclass{beamer}
\usepackage{tikz}
\tikzset{
invisible/.style={opacity=0,text opacity=0},
visible on/.style={alt={#1{}{invisible}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}
},
}
\begin{document}

\begin{frame}
Space
\begin{center}
\begin{tikzpicture}[spy scope={magnification=1.5, size=2cm},every spy in node/.style={remember picture,overlay,magnifying glass,circular drop shadow,fill=white,draw,ultra thick, cap=round}]
\node[rectangle, draw, minimum width=1cm, minimum height=1cm] (N) {};
\spy[visible on=<2->] on (N) in node;
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}


## Work-Around 2: overlay

The TikZ key overlay prevents the update of the bounding box. The content is simply overlayed on the page with no respect for everything.

This does work in this case …

### Code

\documentclass{beamer}
\usepackage{tikz}
\begin{document}

\begin{frame}
Space
\begin{center}
\begin{tikzpicture}[spy scope={magnification=1.5, size=2cm},every spy in node/.style={remember picture,overlay,magnifying glass,circular drop shadow,fill=white,draw,ultra thick, cap=round}]
\node[rectangle, draw, minimum width=1cm, minimum height=1cm] (N) {};
\only<2->{\spy[overlay] on (N) in node;}
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}

-
Thank you ! I tried the [overlay] option but with uncover, not only, of course I had the same issue, should have tried that in the first place instead of bothering you. Anyway your code for visible on might help me for some other things, so thanks again ! –  BigDawg Dec 27 '12 at 9:43