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?

  • 1
    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
  • 1
    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

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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