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

In section 63.1 Operators of the pgf manual pgfmanual.pdf I see the claim that

x != y returns 1 if x ≠ y, 0 otherwise.

Unfortunately, I can't get that to work:


gives me a Missing \begin{document} error, but replacing != by <= works.

Is this a bug in pgfmath, or a misunderstanding on my part? (This may be related to the factorial operator being ! too.)

share|improve this question
\pgfmathnotequal{3}{4} or \pgfmathparse{notequal(20,25)} maybe? MATLAB took over the CPU so I can't test :) – percusse Jan 10 '12 at 3:08
This is "because" your command actually writes 34 to the input, as can be seen by putting it after \begin{document}. Also, it sets \pgfmathresult = 4. This seems like it does not agree with the specification, so I would call it a bug, but as I cannot understand how pgfmathparse works, I don't want to glorify that judgment by phrasing it as an answer. – Ryan Reich Jan 10 '12 at 3:23
up vote 9 down vote accepted

There seems to be an error in pgfmathparser.code.tex. Line 712 of the latest version (1.47) reads

\pgfmathdeclareoperator{!=}{notequalto}{2}{infix} {250}

but it should be

\pgfmathdeclareoperator{!=}{notequal}{2}{infix} {250}

since the function is called notequal (not notequalto). Changing this line fixes the problem. I'll file a bug report.

share|improve this answer
Oh, that makes sense. Somewhere in the code is written something like \csname pgf@operator@!=@name\endcsname which is no doubt applied to the arguments {3}{4}. Since the former expands to \notequalto, which does not exist, it turns into \relax and the arguments are dumped to the input. Meanwhile \pgfmathresult has been set internally and was not properly reset, so ends up as 4 somehow. – Ryan Reich Jan 10 '12 at 3:46
Fixed in the cvs repository. Thanks for the report and the fix. An updated version of pgf-cvs should become available in the tlcontrib repository in a few days. – cjorssen Jan 10 '12 at 8:42
@cjorssen: Wow, that was quick! And so convenient, without even going through the bug tracker! Thanks! – Jake Jan 10 '12 at 9:10

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.