In the following MWE, I declare a new shape myshape. In several instances, I plan to use a dimension that is calculated from different pgf keys (\my@width). One of these instances includes the declaration of the saved anchor \base. At the moment, I have to duplicate the code that calculated this dimension, as I cannot simply use \my@width inside the \savedanchor declaration (it doesn't seem to be available or default to 0/empty). So I am wondering if there is a way to achieve this or if I am simply putting the cart before the horse, i.e. should I ditch the dimension altogether (I'm assuming I can't use the saved anchor inside the \saveddimen declaration either) and rely only on the saved anchor definition?
\documentclass[a4paper]{article}
\usepackage{tikz}
\makeatletter
\pgfdeclareshape{myshape}
{
%
% Saved dimensions
%
\saveddimen{\my@width}{%
\pgfmathsetlength{\pgf@xa}{\pgfkeysvalueof{/pgf/minimum width}}
\pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/inner xsep}}
\pgfmathsetlength{\pgf@xc}{\pgfkeysvalueof{/pgf/outer xsep}}
\pgf@x=.5\pgf@xa
\advance\pgf@x by .5\pgf@xb
\advance\pgf@x by .5\pgf@xc
}
\saveddimen{\my@height}{%
\pgf@x=\pgfkeysvalueof{/pgf/minimum height}%
}
%
% Saved anchors
%
\savedanchor\base{%
% Duplicated code, can't use \my@width here
\pgfmathsetlength{\pgf@xa}{\pgfkeysvalueof{/pgf/minimum width}}
\pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/inner xsep}}
\pgfmathsetlength{\pgf@xc}{\pgfkeysvalueof{/pgf/outer xsep}}
\pgf@x=.5\pgf@xa
\advance\pgf@x by .5\pgf@xb
\advance\pgf@x by .5\pgf@xc
\pgf@y=0pt
}
%
% Anchors
%
\anchor{center}{%
\base
\pgfutil@tempdima=\my@height
\advance\pgf@y by .5\pgfutil@tempdima
}
\anchor{south}{\base}
%
% Background path
%
\backgroundpath{%
\pgfutil@tempdima=\my@width
\pgfutil@tempdimb=\my@height
\pgf@xa=.5\pgfutil@tempdima
\pgf@ya=0pt
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\advance\pgf@ya by \pgfutil@tempdimb
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\advance\pgf@xa by -.5\pgfutil@tempdima
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\advance\pgf@xa by \pgfutil@tempdima
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}}
}
}
\tikzset{
every myshape node/.style={
draw=black, thick, minimum width=1cm, minimum height=2.5cm,
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node[myshape] at (0,0) {};
\node[myshape, inner sep=10pt] at (3,0) {};
\end{tikzpicture}
\end{document}




pgfin a nutshell so is "inside\saved..., declare everything from first principles (i.e. existingpgfcommands) and only reuse any\saved...inside\anchoror\backgroundpathdeclarations? – ThomasH Mar 28 '13 at 21:49