TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I think I've seen this question before, but I can't find it. The problem is simple; before I assign a name to a node I would like to know if the name is already used.

I think when a node is created \node (name) {label}; some macros are defined from name.

share|improve this question
Upped and starred. This has bothered me for a while. – qubyte Dec 9 '11 at 13:43
Related Question: Checking whether or not a node has been previously defined. – Peter Grill Dec 4 '12 at 19:58
up vote 24 down vote accepted

A PGF/TikZ node with the name <name> defines the macro \pgf@sh@ns@<name> (e.g. \csname pgf@sh@ns@#1\endcsname where #1 is the name). This macro defines the node shape (ns), e.g. rectangle. Other defined macros are \pgf@sh@np@<name> (Node Point), \pgf@sh@nt@<name> (Node Transformation matrix) and \pgf@sh@pi@<name> (node Picture Id).

You can use e.g. \@ifundefined{pgf@sh@ns@#1}{<node does not exists>}{<node exists>} to test if a node with this name got already define in the document (node are declared globally).

If you want to test if the node was already used in the current picture, you better test (also) the picture id if it matches the current picture id (\pgfpictureid, e.g. pgfid1, i.e. use \ifx for comparision).

Here some possible implementations of such macros (not tested yet):

% or

   \expandafter\ifx\csname pgf@sh@pi@#1\endcsname\pgfpictureid
share|improve this answer
Thanks I forgot the part of the name pgf@ns@... thanks also for the abbreviations ns, np, etc. very useful. Do you know what is the signification of sh ? Now with your help, I look at the sources and I remark : \pgfutil@ifundefined{pgf@sh@ns@#1} . – Alain Matthes Dec 9 '11 at 15:15
@Altermundus: I would say sh stands for 'shape'. Nodes are defined mostly over their shape. – Martin Scharrer Dec 9 '11 at 15:21
To place a node with the anchor of a given named node, the sources give : \def\pgfpointanchor#1#2{% % Ok, check whether #1 is known! \pgfutil@ifundefined{pgf@sh@ns@#1} {\pgfutil@ifundefined{pgf@sh@ns@not yet positionedPGFINTERNAL#1}{%... – Alain Matthes Dec 9 '11 at 15:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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