# How to add parameters to shape which internally use 'append after command'

Edit: It seems that this question (one of mine first here) is not so clear as I imagined, when ask them. So I -- stimulated by recently received comments on it -- rephrase it with hope, that now hopefully will be more clear, what bother me at that time. Here we go:

In one of my text books I had a great number of images made by TikZ package, which have only slightly different common elements. The definitions for this elements I store in \tikzset something like this:

   \tikzset{TCP/.style = {
tcpBOX/.style 2 args = {shape=rectangle,
draw=##1, % border color
fill=##2, % fill collor
thick, inner sep= 2mm, outer sep=0mm, minimum height=11mm,
% etc
},
% other common elements
}}
and used in TikZ pictures as
\begin{tikzpicture}[TCP]
\node (n1) [tcpBOX={black}{none}] at (0,0) {some text};
% ...
\end{tikzpicures}


In some cases I need labels inside tcpBOX node. For this I use the solution which Mark Wibrow provided me years ago on this comp.text.tex thread:

\documentclass[tikz,border=5mm]{standalone}
%%% code from ctt, December 1999
\makeatletter
\def\tikzsavelastnodename#1{\let#1=\tikz@last@fig@name}
\makeatother
\tikzset{
BOX/.style = {rectangle,
minimum width=33mm,
minimum height=22mm,
draw,
thick,
text=red,
append after command={\pgfextra{\tikzsavelastnodename\tikzsavednodename}},#1%
},
add text/.style args = {#1:#2}{append after command={%
node[anchor=#1]  at (\tikzsavednodename.#1) {#2}}
},
}
%%% example of use
\begin{document}
\begin{tikzpicture}
\node[BOX,
]   (a)             {box};
\end{tikzpicture}
\end{document}


Its work fine, how to merge code for tcpBOX and BOX in a way, that the tcpBOX can be used for example as:

\node[box=<desired parameter>, ...
add text=south:lorum] (<node name>) at (<coordinate>) {text in box};


In time of asked this question I haven't clue how to merge both style definition, because they have own arguments to be set in their use (tcpBOX for "draw" and "fill" and BOX for append command).

-
I'm not sure I quite understand the question. If you want to change the fill, why don't you just add e.g. fill=blue (or whatever) to the parameters you pass? Why do you want to be able to write e.g. BOX={fill=blue} or something? (If that's the idea - I'm not really sure how you envisage this working.) Your parameters will override the defaults e.g. you can also add text=green to get "box" appearing in green rather than red. Maybe you should post what you tried. That might give a clearer sense of what you are trying to achieve. – cfr Dec 22 '13 at 4:06
Of course i can define each shapes as you suggest. Actually, up to now i ding so. The idea behind of my questions is the following: for illustration my text book (few hundredths images) i prepare standard shapes which has i thair use small variations (width, fill color) which I wrote as parameters to shape. Some times hapens, that i like to add some text in this shapes in sense of given example. in such a cases I need to 'revrite' existing shapes as you suggest. I just like to escape this and if it is possible, to use 'standardized' form of predefined shapes collected in tikzset. – Zarko Dec 22 '13 at 8:22
But why do you want to add the parameter to box=<> rather than just adding it? I could understand if you wanted to create a few standard options e.g. BOX, BOF, BOG etc. but I understood that you wanted to use the parameters when calling BOX i.e. for each instance. And I don't get why that would be more convenient that just adding the parameters directly. I still think showing what you tried might make this clearer. Failing that, maybe just give a concrete example of what you have in mind. Or have I misunderstood the point at which you want to specify the additional parameters? – cfr Dec 22 '13 at 13:25
Meanwhile I rethinking my problem and your questions and find solution which fulfill my expectations. I define "append after command" as separate style and as such added to style for BOX. Now the definition for BOX style can have own parameters. Thank you very much for your attention, it helps me a lot. – Zarko Dec 24 '13 at 23:37
Perhaps you could post your solution here so that other users can see exactly what you did and benefit from it? – cfr Dec 28 '13 at 19:54

Now the questions seems to be quite trivial and solution so obvious ... Any way, solution which I use now solve my problem on the following way:

• for append after command={\pgfextra{\tikzsavelastnodename\tikzsavednodename}},##1 I define as new style named saveLNN (as acronym for save-Last-Node-Name)
• to my definition of tcpBOX add this saveLNN

Complete code is:

\documentclass[tikz,border=5mm]{standalone}

\makeatletter
\def\tikzsavelastnodename#1{\let#1=\tikz@last@fig@name}
\makeatother

\tikzset{TCP/.style = {%
saveLNN/.style = {append after command={%
\pgfextra{\tikzsavelastnodename\tikzsavednodename}},##1},
append after command={node[ATnode,anchor=##1]
at (\tikzsavednodename.##1) {##2}}
},
ATnode/.style = {inner sep=0.5mm,
font=\tiny\bfseries\sffamily},
tcpBOX/.style 2 args = {shape=rectangle,
draw=##1, % border color
fill=##2, % fill collor
thick, inner sep= 2mm, outer sep=0mm, minimum height=11mm,
saveLNN},
}
}% end of tikzset


which gives:

I'm still open for better solution(s).

-