# Specify which picture variant to show

Inside a frame I am including a .tex file containing a TikZ picture with several overlay specifications such that they result in 9 variants of the same picture, that is, that frame has 9 slides.

Later, if I want one of those picture variants in another frame how can I get it? Is there something like this \getoverlay{1}{\input{mytikzpicture}} ?

-
I'm guessing you'll get notified of my new answer. I hope I understood the question right this time! – Loop Space Jan 31 '12 at 18:53

The following code works on my simple test, but I don't know if it will work with more complicated code. If it doesn't, please post some example code of the sort that you want to work with.

Here's the code:

\documentclass{beamer}
\usepackage{tikz}

\makeatletter
\newenvironment{inframe}[2][1]{%
\edef\inframe@current{\the\value{beamerpauses}}%
\setcounter{beamerpauses}{#1}%
\beamer@slideinframe=#2\relax
\let\beamer@anotherslidetrue=\@empty
\let\beamer@localanotherslidetrue=\@empty
}{%
\setcounter{beamerpauses}{\inframe@current}%
}
\makeatother

\begin{document}
\begin{frame}
Some stuff which \pause extends over \pause several slides \pause
\begin{inframe}{3}
\begin{tikzpicture}
\draw[use as bounding box] (0,0) rectangle (3,3);
\draw<1-> (0,0) -- (3,3);
\draw<.(1)> (3,0) -- (0,3);
\draw<3> (0,1) -- (3,1);
\draw<4> (1,0) -- (1,3);
\end{tikzpicture}
\end{inframe}
Some stuff which \pause extends over \pause several slides
\end{frame}
\end{document}


Now for the explanation. We define a new environment, inframe, which takes one mandatory argument, a number (and an optional argument, also a number - see below). What happens is that in the environment, the slide number is set to that number (the mandatory one) which means that in the environment, overlay specifications are processed as if the slide number was the given one, not the real one.

This does, however, cause a few problems because if beamer thinks that it is on slide 2 and it encounters an overlay specification for, say, slide 4 then it says to itself "I have to do another frame". Since on every slide, we confuse it into thinking it is on, say, slide 2 then every time around it thinks "I'm going to have to do another run, here". So to avoid an endless loop, we temporarily disable the "Do I do another frame?" check. That's the anotherslide bits. The other problem that this causes (that I know of - there may be more) is that specifications such as + do funny things to a counter called beamerpauses. Within the environment, we want these to work as they should, but then we want to forget these changes when we go back to the normal frame. So we save the value of beamerpauses at the start and reset it at the end. The optional argument allows us to specify a "start point" for beamerpauses which allows us to imagine that things like + start at something other than 1.

Warning: When testing, be ready to kill the TeX process as it is easy to get into infinite loops.

-
I tested your code on a new .tex file, with only this changes \begin{inframe}{3} \begin{tikzpicture} %\draw[use as bounding box] (0,0) rectangle (3,3); \draw<1-> (0,0) -- (3,3); \draw<2> (3,0) -- (0,3); \draw<3> (0,1) -- (3,1); \draw<4> (1,0) -- (1,3); \end{tikzpicture} \end{inframe} but it always draws the same picture dispite the overlay you choose (I am using pdflatex, don't know if this is relevant though). – Mário Jan 31 '12 at 20:10
I think another approach is to avoid overlay specifications alltogether and have some new macros based on \ifnum\iframe = #1 ... \fi that will choose among the image variants according to the value of \iframe. But I've not tested this yet. – Mário Jan 31 '12 at 20:17
@Mário That's odd. When I vary the argument to the inframe environment then I get different pictures with your code. (I'm also using pdflatex; more relevant might be the versions of PGF and of Beamer. I'm using PGF2.10 and Beamer 3.12.) – Loop Space Jan 31 '12 at 20:43
I am using the same versions of PGF and Beamer, with MiKTeX 2.8 and SumatraPDF 1.9 to watch the results. Your solution makes perfect sense, but for some reason when I vary the argument to the inframe environment then I get always the same result: it only draws the first line corresponding to \draw<1-> ... – Mário Feb 1 '12 at 8:32
There was a small but significant cut-and-paste error which I have now corrected. Try it again. (Many thanks to @wh1t3 for spotting it in chat.) – Loop Space Feb 1 '12 at 10:37

More of a hack than a proper solution, you can restrict a frame to a single overlay with

\begin{frame}<overlay>


If you can get it into a file (I guess that's what mytikzpicture has, after all), and then just input again in another frame, you can use this to get overlay 9.

-
The problem with this solution is that in the other frame where I want to put my picture variant I have other overlay specifications, so these won't work if I do what you suggest – Mário Jan 30 '12 at 20:27