I have a question about \saveddimen
usage inside of a \pgfdeclareshape
command. My code is as follows:
\documentclass{article}
\usepackage{tikz}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\makeatletter
\pgfdeclareshape{myshape}{
\savedanchor{\centerpoint}{\pgf@x=0pt\pgf@y=0pt}
\saveddimen{\mydima}{%
\pgf@x=20pt
}
\saveddimen{\mydimb}{%
\pgf@x=20pt %% =\mydima
\pgf@x=-\pgf@x
}
%
\anchor{center}{\centerpoint}
\backgroundpath{%
\pgf@xa=\mydima \pgf@ya=\mydima
\pgf@xb=\mydimb \pgf@yb=\mydimb
\pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
\pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
\pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw[help lines] (0,0) grid (4,4);
\node[myshape,draw] at (2,2) {test};
\end{tikzpicture}
\end{document}
This produces a node, with top and bottom horizontal lines.
In my real world example, I want to have a dimension \dimenb
which is a function of \dimena
. If I uncomment the %%
in the
\saveddimen{\dimenb}
command the setting \pgf@x=\dimmena
I get an error message.
Question: Is it legal to use a saved dimension in the definition of another saved dimension, and if yes, how?
\saveddimen{\mydima}{\pgf@x=20pt}\saveddimen{\mydimb}{\pgf@x=-\pgf@x}
would be enough. Since\pgf@x
is overwritten by\mydima
previously.\mydima
the register\pgf@x
still holds the dimension, and I can use it in the definition of\mydimb
. That is easily breakable code. Add additional code bewtween the statements to break it \saveddimen{\mydima}{ --set \pgf@x here} \some-code-manipulating \pgf@x \saveddimen{\mydimb}{ --\pgf@x here is no longer set to \mydima} I still wonder why I cannot use the\mydima
macro in another\saveddimen
command, as it works in the\backgroundpath
?@
character and the nickname just as I did in this comment. There is even an autocomplete feature if you type a few characters and press TAB key. I will try to address your question as soon as possible.