Is it possible to use beamer's overlay specifications in other documentclasses?

I'm writing an article that involves a lot of diagrammatic calculus, that is, there is a big TikZ picture with nodes and lines and that picture gets modified slightly in each step of the calculation. Say, the label of a line changes or a line becomes dotted or vanishes.

Now I find myself thinking that this would be so easy if I were writing a beamer presentation. Then I would just write the whole picture with all modifications in it and modify it by using overlays. For example, I could use \visible<...>{...} to make a line vanish in a later part of the calculation. See an example I made "by hand" here:

But I have article as document class and I don't want to change that. Is there a way to use beamer's overlay specifications in a tikzpicture and then have, say, an align environment where each line is one overlay of the picture?

EDIT: Thanks for the inventive idea of actually creating a separate beamer file and including its output. But I really don't want to go to the trouble of creating external files and adjusting margins manually. This looks like far too much work and trouble for a result that doesn't look appropriate for my purposes. I personally would rather stick to TikZ styles and PGF keys to hack my way around it.

EDIT 2: Finding Liam's question here asking something similar, I'd like to rephrase my question: Given my picture drawn with beamer overlay specifications, is there a way to extract the picture how it would have looked like on frame $n$?

• Just to clarify, you want the pictures next to each other, no animation? – Johannes_B Nov 28 '14 at 18:05
• That's right. Or below each other, for that matter. I want to be able to print it at the end with all the steps of the calculations in it. – Turion Nov 28 '14 at 18:07
• Though it’s said to be out of date, I still sometimes use texpower with document classes like pdfscreen; texpower may do what you want. – Thérèse Nov 28 '14 at 19:53
• beamer is quite different from other classes. In particular, it parses stuff differently and redefines many commands in order to make stuff work with overlay specifications. I doubt there is a general solution which does not involve essentially reproducing that functionality. And that would depend, among other things, on your document class. And you'd have to be careful not to load other packages which tried to redefine the same commands. If you wanted something which would work for some specific form of overlay specification or with something similar to an overlay specification.... – cfr Feb 23 '15 at 23:06

You can use standalone class with beamer option which allows to use all beamer overlay constructs. This will create a pdf with as much as pages as overlays. Each of these pages can be cropped with pdfcrop and you'll get a new pdf file with one adjusted overlay in each page. Finally you can include all of them in your article with page= includegraphics option or with recent tcolorbox rater library.

As an example I've adapted the code from my answer to drawing(uncover) a curve bit-by-bit using tikzpcture and beamer and \onslide just eliminating frame titles:

\documentclass[beamer]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usetikzlibrary{decorations}

% A simple empty decoration, that is used to ignore the last bit of the path
\pgfdeclaredecoration{ignore}{final}
{
\state{final}{}
}

% Declare the actual decoration.
\state{initial}[
width={0pt},
next state=middle
]
{\decoration{moveto}}

\state{middle}[
next state=final
]
{\decoration{curveto}}

\state{final}
{\decoration{ignore}}
}

\tikzset{middle segment/.style={decoration={middle},decorate, segment length=#1}}

\newcommand{\mypath}{(10,0)(9,-0.1)(8,-0.3)(7,-0.8)(6,-2)(5,-4.5)(4,-5)(3,-3)(2,0)(1.5,1.5)(1.4,1.75)(1.35,2)}

\begin{document}
\begin{frame}{} %<- no title for better cropping
\begin{tikzpicture}
\onslide<5->{\draw[green!20, pattern color =green!20, thin,pattern=north west lines] (0,-5) rectangle (2,2)  node[rotate=90,midway,above] {\tiny{\textcolor{green!30!black}{repulsive forces dominant}}};}% drawn first so appear as underlay
\onslide<5->{\draw[red!0, pattern color =red!20, thin,pattern=north west lines] (2,-5) rectangle (10,2)  node[midway,above] {\tiny{\textcolor{red!30!black}{attractive forces dominant}}};}

\onslide<1->{\draw[thick,->] (0,0) --(10,0) node[above left=0.2] {\tiny{Separation}};}
\onslide<1->{\draw[thick,->] (0,-5) --(0,2) node[rotate=90, near end,above] {\tiny{Potential Energy}};}

\onslide<2>{\draw[middle segment=0.3,color=blue, thick,-] plot[smooth] coordinates{\mypath};}
\onslide<3>{\draw[middle segment=0.6,color=blue, thick,-] plot[smooth] coordinates{\mypath};}
\onslide<4>{\draw[middle segment=0.8,color=blue, thick,-] plot[smooth] coordinates{\mypath};}
\onslide<5>{\draw[color=blue, thick,-] plot[smooth] coordinates{\mypath};}

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


The result has been pdfcrop-ed and included in an article file like this:

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}

\begin{document}
\lipsum[1]
\begin{tcbraster}[raster columns=2, raster equal height]
\tcbincludegraphics[graphics options={page=1}]{214474-crop}
\tcbincludegraphics[graphics options={page=2}]{214474-crop}
\tcbincludegraphics[graphics options={page=3}]{214474-crop}
\tcbincludegraphics[graphics options={page=4}]{214474-crop}
\tcbincludegraphics[graphics options={page=5}]{214474-crop}
\end{tcbraster}
\end{document}


2nd version

It could be easier. Command \tcbincludepdf{pdffile.pdf} inside a tcbraster environment includes one page after page from dffile.pdf. Therefore, same results as previous code could be obtaned with just:

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}

\begin{document}
\lipsum[1]
\begin{tcbraster}[raster columns=2, raster equal height]
\tcbincludepdf{214474-crop.pdf}
\end{tcbraster}
\end{document}


Here's a possibility, which I also posted at this related question. It's a little parser to interpret the Beamer-style overlay specifications of the forms \only<->, \only<a->, \only<-b>, \only<a-b>, and \only<a> and test them against a macro \slide.

\documentclass[12pt]{article}
\usepackage{tikz}

\makeatletter
\newcounter{only@begin}%
\newcounter{only@end}%
\def\@only@hyphen{-}%
\def\only<#1>#2{%
\bgroup
\def\only@test{#1}%
\ifx\only@test\@only@hyphen
\c@only@begin=-100\relax
\c@only@end=100\relax
\else
\parseonlybegin\only@relax#1-\endparseonly
\parseonlyend\only@relax#1-\endparseonly
\fi
\ifnum\c@only@begin<\slide\relax
\ifnum\c@only@end>\slide\relax
#2\relax
\fi
\fi
\egroup
}

\def\@only@relax{\only@relax}%
\def\only@striponetoken#1{}%
\def\only@gobblehyphen#1-{#1}
\def\parseonlybegin#1-#2\endparseonly{%
\def\only@test{#1}%
\ifx\only@test\@only@relax
\setcounter{only@begin}{-100}%
\else
\expandafter\c@only@begin\only@striponetoken#1\relax%
\fi
}
\def\parseonlyend#1-#2\endparseonly{%
\def\only@test{#2}%
\ifx\only@test\@empty
% No hyphen in original.
\c@only@end=\c@only@begin%
\else
\ifx\only@test\@only@hyphen
% \only<a->
\setcounter{only@end}{100}%
\else
% \only<a-b> or \only<-b>; #2 contains 'b-'
\expandafter\c@only@end\only@gobblehyphen#2\relax%
\fi
\fi
}

\makeatother
\begin{document}

\def\mypic#1{%
\def\slide{#1}%
\begin{tikzpicture}[every node/.style={anchor=base,circle, draw}]
\draw (0,0) rectangle (6,2);
\node at (1,1) {a};
\only<2->{ \node at (2,1) {b}; }
\only<2-3>{ \node at (3,1) {c}; }
\only<3>{ \node at (4,1) {d}; }
\only<-4>{ \node at (5,1) {e}; }
\end{tikzpicture}%
\par
}

\mypic{1}%
\mypic{2}%
\mypic{3}%
\mypic{4}%
\mypic{5}%

\end{document}


This compiles to

• Wow! Make a package out of it! – Turion Oct 20 '15 at 6:02

Haven't tried this with a tikzpicture, but since you say it'd be easy if it were in beamer, I'll use beamer pages as included graphics:

Main tex file:

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}

\begin{document}
\begin{align}
x &= \fbox{\begin{minipage}[c]{2.5in}{\vspace{0pt}\includegraphics[page=1]{\jobname-beamer.pdf}}\end{minipage}} \\
% Ref: http://texblog.net/latex-archive/graphics/includegraphics-top-align/
&= \fbox{\begin{minipage}[c]{2.5in}{\vspace{0pt}\includegraphics[page=2]{\jobname-beamer.pdf}}\end{minipage}}
\end{align}
\end{document}


with an associated beamer file of:

\documentclass{beamer}
\geometry{width=2in, height=2in, paperwidth=2in, paperheight=2in}

\begin{document}

\begin{frame}
\visible<1->{One}

\visible<2->{Two}
\end{frame}

\end{document}

• That's a nice idea, but doesn't look good in terms of fonts and margins. I added some graphics in the question. – Turion Nov 28 '14 at 19:46
• Do you have a minimal tikzpicture you can show? Should be easy enough to modify margins or other sizes in beamer. – Mike Renfro Nov 28 '14 at 19:55
• I really don't want to go to the trouble of creating external files and adjusting margins manually. – Turion Dec 1 '14 at 11:45