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.

So I'm trying to set a variable using the value of another variable. Basically something like below:

\pgfmathsetmacro{\newVar}{\pgfmathifthenelse{\oldVar==0}{(\x/2)}{\x}}

But no matter what I do I can't seem to get the syntax right. I'm assuming it has something to do with expanding stuff, but can't figure out what is and isn't needing to be expanded. I can't find anything on this that makes sense. All the ones I've seen use the if/then to actually output things rather than set them as variables. Any thoughts?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

\pgfmathifthenelse is the standalone version that writes the result to \pgfmathresult, setting macro needs the inline math function evaluated such as

 \pgfmathsetmacro{\newVar}{ifthenelse(\oldVar==0,(\x/2),\x)}

or shorter

 \pgfmathsetmacro{\newVar}{(\oldVar==0?(\x/2):\x)}.
share|improve this answer

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.