You can try something like that but there are several possibilities but what do you want to do ?
\documentclass{article}
\usepackage{tikz}
\newcommand{\mathresult}[1]{%
\pgfmathparse{#1}\pgfmathsetmacro\mymathresult{\pgfmathresult}}
\newcommand{\doublemathresult}[1]{%
\mathresult{#1}%
\pgfmathparse{2 * \mymathresult}%
\pgfmathsetmacro\mymathresult{\pgfmathresult}}
\begin{document}
\mathresult{2}\mymathresult
\doublemathresult{2}\mymathresult
\end{document}
I don't really get the question so I hope this is what you wanted. If you include a full document (such that we copy paste and see the problem on our systems) things are much more easier.
Here, you can change the default setting within a scope but your block
style had a node distance
which was resetting every time it is issued. I've made it 2mm such that we can see the difference easier.
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,shapes.geometric,positioning}
\begin{document}
\begin{tikzpicture}[decision/.style={diamond, draw, text width=4.5em, text badly centered, node distance=3.5cm, inner sep=0pt},
block/.style ={rectangle, draw, text width=6em, text centered, rounded corners, minimum height=4em, minimum height=2em},
cloud/.style ={draw, ellipse, minimum height=2em},
line/.style ={draw,-latex'},
node distance = 1cm,
auto]
\node [block] (1st) {1st};
\node [block, right= of 1st] (2nd1) {2nd1};
\begin{scope}[node distance=2mm and 10mm]%Here we change it for everything inside this scope
\node [block, above= of 2nd1] (2nd2) {2nd2};
\node [block, below= of 2nd1] (2nd3) {2nd3};
\node [block, right= of 2nd1] (3rd1) {3rd1};
\node [block, above= of 3rd1] (3rd2) {3rd2};
\node [block, above= of 3rd2] (3rd3) {3rd3};
\end{scope}
\node [block, below= of 3rd1] (3rd4) {3rd4};
\node [block, below= of 3rd4] (3rd5) {3rd5};
\path [line] (1st) -- (2nd1);
\path [line] (2nd1) -- (2nd2);
\path [line] (2nd1) -- (2nd3);
\path [line] (2nd2) -- (3rd3);
\path [line] (2nd1) -- (3rd1);
\path [line] (1st) -- (2nd1);
\end{tikzpicture}
\end{document}
Best Answer
The problem in pgfmath expansion - call a command from within a pgfmath environment is the same as here: a
\pgfmathparse
command, which is not expandable, is being used somewhere where it wants to be expanded. In that case it is within another\pgfmathparse
. In this case, the real problem is in the node name itself. The solution avoids the expansion issue by first processing the macro outside an "expansion context" (not sure if that's the right term! I mean that it is in the normal run of TeX and not in an\edef
.) and then using the result of that in the expansion place. Thus:fails but the solution is to do:
That solution would work here as well, but its implementation would be:
The point here is that we have to avoid putting anything unexpandable in the brackets. So all the
\pgfmathparse
routines have to be executed before we get to that point. No matter how you dress it up,\node (\mymacro{2}{3})
executes\mymacro
in the\edef
that sets the node name and so all the workings of\mymacro
are evaluated at that point.To do it all in one step would require an expandable version of
\pgfmathparse
. For particular circumstances, such as that in the original question, one can use the integer routines from LaTeX3 (texdoc source3
).