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:


\caption{drawing of \tex}

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


This appears to be a problem with scoping. If you move the \def to be before the tikzpicture things should work. Alternatively using a gdef (which makes the definition global) instead of \def, should also work.

  • worked indeed, thanks ! dunno why but I thought \def was something defined in tikz environment. – ben paillard Aug 4 '11 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.