I have seen answers to this question floating around but none of them appeared to solve the problem.
I want to be able to throw a code block into an already defined tikzpicture. So I attempted to make a command that replaces \node{}; and ran into a known problem with verbatim-like environments inside commands.
I have a complete example here.
It does not build with pdflatex.
Notice blue \node works, but \rednode fails.
\documentclass{beamer}
\usepackage{tikz}
\usepackage{listings}
\newcommand{\rednode}[1]{
\node[draw=red]{#1};
}
\begin{document}
\begin{frame}[fragile]
\begin{tikzpicture}
\node[draw=blue]{
\begin{lstlisting}
int main()
{
printf("Hello World\n");
}
\end{lstlisting}
};
\rednode{
\begin{lstlisting}
int main()
{
printf("Hello World\n");
}
\end{lstlisting}
}
\end{tikzpicture}
\end{frame}
\end{document}
Solutions explored involve the cprotect package, tabular environments, and minipage environments.

\verb-specific options there does not work here. – user202729 Jul 27 '22 at 06:55