I am looking for something that is the equivalent of \providecoordinate in TikZ/PGFplots. This would be easy if I knew how to test if a coordinate is already defined.

There are similar questions about how to implement something which effectively implements providetikzstyle and how to implement provideenvironment.

1 Answer 1


A coordinate in TikZ is a special form of node. The coordinate x/y etc. values of a node is stored in a macro named \pgf@sh@np@<name> which existence you can test. The following code should do it and support most variations of the \coordinate syntax. Supporting the \path coordinate syntax, i.e. allow for \path providecoordinate is not possible without extensively hacking into the path parsing code.



    \ifcsname pgf@sh@np@#3\endcsname\else


   \providecoordinate [] (A) at (0,0);
   \coordinate (B) at (0,0);

   \providecoordinate (B) at (1,0);

   % Small test: Both at the same location? YES!
   \draw [red]   (A) circle (1pt);
   \draw [green] (B) circle (2pt);


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .