Consider follwong MWE. I have defined a style mynodestyle to style selected nodes in mypic. I want to customize the styling when placing some mypics.
\documentclass{standalone}
\usepackage{tikz,relsize}
\tikzset{
mynodestyle/.style={text=red,font=\relsize{1}},
%
% Would following alternative definition of 'mynodestyle' with the given default value be sensible?
mynodestyle2/.style={#1},
mynodestyle2/.default={text=red,font=\relsize{1}},
%
pics/mypic/.style={code={%
\node[mynodestyle] at (0,0) {Hello}; % How can I 'style' these nodes with text from outside of the pic code?
\node[mynodestyle] at (2,0) {World};
\node at (2,-1) {I should not be in style.}; % non styled node
}}
}
\begin{document}
\begin{tikzpicture}
\path (0,0) pic {mypic};
\path (0,-3) pic [mynodestyle={text=orange,font=\relsize{2}}] {mypic};
\path (0,-6) pic [mynodestyle/.append style={text=blue,font=\relsize{4}}] {mypic}; % If I have to use it this way, does a default make sense?
\path (0,-9) pic {mypic};
\end{tikzpicture}
\end{document}
Can someone explain to me what happens in the case of the second placement of mypic? What does [mynodestyle={text=orange,font=\relsize{2}}] here do (no effect) and why becomes the node text without mynodestyle red?
And in general I have the impression that I do not know how to do this properly.
The notation /.style n args is too rigid because all arguments become mandatory. However, I would like to have my defaults for the selected nodes which I can overwrite individually and extend when needed.
Related question:


.append styleto keep defaults which are not changed for a specific instance ofmypic. Can you explain what your solution offers as an advantage in contrast to using.style=...or.append style=...? – Hotschke Jun 04 '20 at 15:51my node style/.code={\tikzset{mynodestyle/.append style={#1}}}. Note that this is not my suggestion, but this way of dealing with styles gets used all over, as e.g. innodes={draw}, which is basically a short cut forevery node/.append style={draw}. – Jun 04 '20 at 15:57