[Tex/LaTex] LaTeX equivalent of ConTeXt buffers


While creating a series of graphics (using TikZ) in ConTeXt, I frequently use ConTeXt's buffer to "copy-paste" code. Is there a LaTeX package that implements this feature?

Since most LaTeX users may not know what buffers do, let me explain that. Suppose I want to draw a graph in steps: in the first step, only draw the nodes, in the second step draw the edges, in the third step highlight a part of the graph.

In ConTeXt, I would do this as follows:

% tikz code for drawing nodes

% tikz code for drawing edges

% tikz code for highlight a part

\startTEXpage \getbuffer[nodes] \stopTEXpage
\startTEXpage \getbuffer[nodes,edges] \stopTEXpage
\startTEXpage \getbuffer[nodes,edges,highlight] \stopTEXpage

This will give me a pdf file with three pages, that build up the graph in steps. How do I do the same in LaTeX?

I can use the preview package to extract TikZ pictures on individual pages, but don't know how to build the graph in steps. One option is to use beamer overlays to create the graph in steps, but creating a presentation for each figure appears to be an overkill. I can just copy paste code, but that is difficult to maintain in the long run. Any suggestions?


The proposed solution of storing the contents in a macro does not always work. For example


    \node (a) {$a$} ; & \node (b) {$b$} ; \\
    } ;


! Package pgfbasematrix Error: Single ampersand used with wrong catcode.

Any other suggestions?

Best Answer

Not really a proper answer, but perhaps it is useful as hint:

Based on what buffers do, the filecontents environment combined with \input (for \getbuffer) and \verbatiminput (for \typebuffer) comes closest, I think.

Related Question