# Beamer: Uncover magnification using tikz spy library

Using the spy library, I would like to first highlight (in this case with an rectangle) the area which gets magnified and the show the magnification on the next slide. I am doing this manually in the MWE below, but prefer an automatic solution.

\documentclass[10pt,aspectratio=169]{beamer}

\usepackage{tikz}
\usetikzlibrary{spy}

\begin{document}
\begin{frame}
\begin{tikzpicture}[%
spy using outlines={rectangle, magnification=4, size=2cm, connect spies},
]
\fill [blue!20] (0,0) rectangle (2,3);
% I want to avoid to manually draw this rectangle:
\draw (-2.5mm,-2.5mm) rectangle (2.5mm, 2.5mm);
\pause
\spy on (0,0) in node at (-2,1);

\end{tikzpicture}
\end{frame}
\end{document}


The result should look like this:

Big thanks to @samcarter for explaining the question to me! Using some tricks from the aobs package.

\documentclass[10pt,aspectratio=169]{beamer}

\usepackage{tikz}
\usetikzlibrary{spy}
\tikzset{
invisible/.style={opacity=0,text opacity=0},
visible on/.style={alt={#1{}{invisible}}},
connect on/.style={alt={#1{connect spies}{}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}
},
}

\begin{document}
\begin{frame}
\begin{tikzpicture}[%
spy using outlines={rectangle, magnification=4, size=2cm},
]
\fill [blue!20] (0,0) rectangle (2,3);
\spy[connect on=<2->] on (0,0) in node[visible on=<2->] at (-2,1);

\end{tikzpicture}
\end{frame}
\end{document}


• Thx, but the result should look like the animation in my question. Jun 28 '18 at 11:30
• @marmot At first I did not understand the question at all, but after a while I think the key of the question is hidden in the comment % I want to avoid to manually draw this rectangle: Jun 28 '18 at 14:57
• Glad the library is somehow useful for inspiration ;) Jun 29 '18 at 6:41
• @ClaudioFiandrino The library is great!! Sadly, some excerpts from it are scattered over the places without mentioning the source. (So I tried to do better, e.g. here. ;-)
– user121799
Jun 29 '18 at 14:01
• @ClaudioFiandrino The library is fantastic! Thanks a lot for it! The only problem is that I can never remember the order of the letters in aobs:) Jun 29 '18 at 14:45