I would like to perform a calculation using \pgfmathparse and then store \pgfmathresult as the value of a pgfkey.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\pgfkeys{/junk/.initial=0}
\pgfmathparse{5+10}
\pgfkeys{/junk=\pgfmathresult}
junk = \pgfkeysvalueof{/junk}\par
\pgfmathparse{8*5}
% This second use of \pgfmathparse will change the contents of \pgfmathresult.
% The key value will now be changed to the new contents of \pgfmathresult.
junk is now = \pbfkeysvalueof{/junk}/par
\end{document}
The output of the code is:
junk = 15.0
junk is now = 40.0
So it looks like the value of the key points to the contents of the macro. If the contents of the macro change, then the value of the key changes.
This is not what I want. I want the value of the key to be the value of the macro. If the value of the macro changes, then the value of the key should remain unchanged.
I tried to use
\pgfmathsetmacro{\tempmacro}{5+30}
\pgfkeys{/junk=\tempmacro}
but if I use \tempmacro later on for something else
\pgfmathsetmacro{\tempmacro}{8*5}
then once again the value of the key is changed to the new value of the macro.
I don't want to have to define a macro for every key value that is stored. That seems to me to defeat the purpose of using pgfkeys. I could just use the macros, but I would really like to use the keys.
I also tried the suggestions in the post Store \pgfmathresult in a variable, but the result is the same.
/.expand onceis explained in Section 55.4.6 "Expanded and Multiple Values". I thought I had read thepgfkeyschapter thoroughly, but obviously I missed that. Thanks! – Nicholas Hill Mar 16 '13 at 22:15