TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to use logical functions in pgfmath and getting unexpected errors. It seems to be related to the use of \pgfmathsetmacro, which according to my understanding should be equivalent to \pgfmathparse{whatever}\let\macro=\pgfmathresult. However, the following example from the manual works with \pgfmathparse and gives the error

! Missing number, treated as zero.
<to be read again> 
l.52 ...etmacro\macro{ifthenelse(5==4,"yes","no")}

when used with \pgfmathsetmacro:

\pgfmathparse         {ifthenelse(5==4,"yes","no")}% Works
\pgfmathsetmacro\macro{ifthenelse(5==4,"yes","no")}% Fails

Shouldn't I be able to do this?

share|improve this question
After looking at the \tracingall output for not very long, I think it might be a bug: pgf is trying to set a \dimen register to "no", which is not going to work. – Bruno Le Floch Feb 2 '12 at 19:44
Note that this turns out to not being related to the ifthenelse operator (so the title can be misleading). \pgfmathsetmacro\macro{"no"} won't work either. – cjorssen Feb 2 '12 at 21:07
up vote 7 down vote accepted

Here is the definition of \pgfmathsetmacro in file pgfmathcalc.code.tex.


The use of \pgfmathsetlength prevents from using something else than numbers as a result of the evaluation of #2 by \pgfmathparse (which is the case in your sample code). As Bruno Le Floch pointed out in comment, this leads to assign nopt to the dimension \pgfmath@x which does not work.

I must admit it's not the behavior I would expect looking at the documentation. So at least, it should be specified in the doc or the macro should be modified to deal with such string cases.

share|improve this answer

Your Answer


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.