LaTeX equivalent of ConTeXt buffers

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.


The following code shows three possible solutions to the updated question.

\documentclass{minimal}
\usepackage{tikz}

\def\NODESa
  {\matrix
    {
    \node (a) {$a$} ; & \node (b) {$b$} ; \\
    } ;
  }

\def\NODESb
  {\matrix[ampersand replacement=\&]
    {
    \node (a) {$a$} ; \& \node (b) {$b$} ; \\
    } ;
  }

\begingroup
\catcode`\&=\active
\def\x#1{#1}%
\x{%
\endgroup
\def\NODESc
  {\matrix
    {
    \node (a) {$a$} ; & \node (b) {$b$} ; \\
    } ;
  }
}

\begin{document}
\begin{tikzpicture}
  \scantokens\expandafter{\NODESa}
\end{tikzpicture}
\begin{tikzpicture}
  \NODESb
\end{tikzpicture}
\begin{tikzpicture}
  \NODESc
\end{tikzpicture}
\end{document}

Based on Joel's comment above, I'd just write

\def\buffernodes{
  % tikz code for drawing nodes
}
\def\bufferedges{
  % tikz code for drawing edges
}
\def\bufferhighlight{
  % tikz code for highlight a part
}

\buffernodes
\newpage
\buffernodes\bufferedges
\newpage
\buffernodes\bufferedges\bufferhighlight

You could write a wrapper to implement a more ConTeXt-like buffer interface, but for this simple example I think it's fine as-is.