I would like to detect if a macro is executed inside a tikzpicture or more specific inside a node of a picture. In my MWE I used \ifpgfpicture which does not do the job because it considers the node content as 'outside' the picture. I would like to see 'INSIDE' as node text.
I am not looking for any additions to the tikzpicture environment like some every picture tricks to remember that we are inside the environment. Is there any already existing state macro/variable of pgf/tikz which can be questioned for this purpose?
\documentclass{article}
\usepackage{tikz}
\newcommand{\testinpic}{%
\ifpgfpicture INSIDE \else OUTSIDE\fi%
}
\begin{document}
\testinpic
\begin{tikzpicture}
\fill[blue!10!white] (-4,-1) rectangle (4,1);
\node {\testinpic};
\end{tikzpicture}
\end{document}


hboxorminipageenvironment before placed in the node shape. So you need to patch the node placement code to insert a hook. Otherwise it will never be inside since everything is expanded before the placement. – percusse Jun 27 '13 at 08:58nodeis pretty similar to what happens in ordinary text. So I think I would go for a new conditional and add it to every tikzpicture via theexecute at begin picturestyle. I think that would be more reliable than trying to hook into something in thenodestructure. – Andrew Stacey Jun 27 '13 at 09:11