[Tex/LaTex] How to show tikz node names in the output (e.g. in a label)

tikz-pgf

When editing figures with many nodes in TikZ (e.g. using tikzedt — http://www.tikzedt.org/), it gets cumbersome to keep track of the names of nodes. Therefore, I would like to display their names in labels, when generating preliminary output.

after reading through the documentation and searching the internet, this was the closest I got, based on this post:
How to extract the value from a pgfkeys style element

But I do not know how to refer to the name of the current node..

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[
% does work:
    mystyle/.style={label={right:\pgfkeysvalueof{/pgf/minimum width}}}
% does not work:
%    mystyle/.style={label={right:\pgfkeysvalueof{/pgf/name}}}
  ]

  \node [mystyle, draw] (n1) {1};
\end{tikzpicture}

\end{document}

The generated output is shown below on the left, the desired output is shown on the right:

output

I would like the label to be defined in a style and not in the code of the every separate node, so that I do not need to edit the code for every node separately.

Thanks a lot in advance!

Best Answer

Do you want something like this?

Courtesy of Alenanno ...

\documentclass[border=10pt,multi,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[
    mystyle/.style={%
      label={right:\pgfkeysvalueof{/pgf/minimum width}},
    },
   my style/.style={%
     append after command={% courtesy of Alenanno ref: https://tex.stackexchange.com/questions/287967/drawing-thin-line-around-a-multipart-tikz-shape#comment696552_287972
       \pgfextra{\node [right] at (\tikzlastnode.mid east) {\tikzlastnode};}
     },
   },
  ]
  \node (n1) [mystyle, draw] {1};
  \node (n2) [my style, draw] at (0,1) {2};
\end{tikzpicture}
\end{document}

name to right

EDIT

Following up on percusse's comment, you can see that

  \draw (0,0) -- (1,1) node (n2) [my style, draw] {2} -- (2,2) node (n3) [my style, draw]{2};

does what is wanted in terms of locating the nodes ...

what I would expect location-wise, but not otherwise

but not what you might hope otherwise ....