Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The result of \pgfmathparse is automatically stored in \pgfmathresult. Is it possible to store it in an other variable, too?

share|improve this question
add comment

2 Answers

up vote 15 down vote accepted

Use \pgfmathsetmacro\mymacro{...} instead of \pgfmathparse{...}.

From the v2.10 pgfmanual, section 62.1 Commands for Parsing Expressions, page 527:

\pgfmathsetmacro{<macro>}{<expression>}
Defines <macro> as the value of <expression>. The result is a decimal without units.

\pgfmathsetlengthmacro{<macro>}{<expression>}
Defines <macro> as the value of <expression> LaTeX in points.

\pgfmathtruncatemacro{<macro>}{<expression>}
Defines <macro> as the truncated value of <expression>.

In theory you could also say \let\mymacro\pgfmathresult, but I recommend the above macros.

share|improve this answer
add comment

I guess with

\edef\myvar{\pgfmathresult}

when the value from \pgfmathparse has been computed. Or \xdef instead of \edef if you need it globally, i.e., outside the TiKZ environment in which the computation is performed.

share|improve this answer
    
Note that \pgfmathresult is already fully expand, so I would prefer \let\myvar\pgfmathresult, with \global as prefix if required. –  Martin Scharrer May 21 '11 at 22:45
    
@Martin: Is it possible to define one of the macros in your answer globally? –  egreg May 21 '11 at 22:54
    
No. Adding \global in front of them shouldn't work. –  Martin Scharrer May 21 '11 at 23:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.