[Tex/LaTex] Is it possible to use beamer’s overlay specifications in other documentclasses

beameroverlaystikz-pgf

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:

enter image description 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$?

Best Answer

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.
\pgfdeclaremetadecoration{middle}{initial}{
    \state{initial}[
        width={0pt},
        next state=middle
    ]
    {\decoration{moveto}}

    \state{middle}[
        width={\pgfdecorationsegmentlength*\pgfmetadecoratedpathlength},
        next state=final
    ]
    {\decoration{curveto}}

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

% Create a key for easy access to the decoration
\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}

enter image description here

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}
Related Question