# Use a tikz variable outside tikz environment… or something that could do that whatsoever?

I want to use a variable that could be used in TikZ code to get an external data file, and outside this code to define a legend associated. TikZ won't let me use \caption inside its environment, and the label solution doesn't work...

For example with various external drawing I want to be able to use the name of the drawing in a caption pretty much like that:

\documentclass{article}
\usepackage{tikz,graphicx}
\begin{document}

\begin{tikzpicture}
\def\tex{texsx}
\includegraphics[width=2cm]{\tex};
\end{tikzpicture}
\caption{drawing of \tex}
\end{document}

It sounds trivial to me but I couldn't find anything.

-
What kind of variable is it? You should be able to use a \caption inside a \node. Please consider adding a minimal working example (MWE) that illustrates your problem. – Martin Scharrer Aug 4 '11 at 17:48
MWE is now done ! – ben paillard Aug 4 '11 at 18:01