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

\def \p{1}
\def \q{1}


Compiling the above I get the following error

! Missing number, treated as zero.
<to be read again> 
                   \bex@=0 truepart 
l.12 \endswitch

But if we change the definition to

\def \q{2}

or change the line to


it will be OK. But only change the line to


yields the same error.

Any idea why this happens? Thank you in advance.

share|improve this question
@Herbert has given a good answer, which solves the issue, but I'd say this might be regarded as a bug in boolexpr. I suggest you report it to the package author. – Joseph Wright Dec 29 '11 at 9:46
up vote 5 down vote accepted

It seems not to be well documented, but the examples show that a counter value is expected. You can fool the package by using \numexpr:

\case{\q} abc

The problem is that one has to "announce" boolexpr the type of test to be performed in some way; also



share|improve this answer

use counters instead of macros:


\case{\value{q}} abc
share|improve this answer
Only p must be declared as a counter ;-) – Marco Daniel Dec 29 '11 at 9:59
Yes, that's quite strange. It seems that the expression before the equality sign must not be a macro. Using \value is a bit cumbersome, and I cannot even define a \v to replace it because that will yield the same error. Anyway, the answer doesn't give insight why this happens. – Junyan Xu Dec 29 '11 at 10:07
I now find \pdfstrcmp more suitable for my purpose. I originally want to encode strings into numbers so that I can compare them, but it's no longer necessary. Still want an explanation to the curious behavior of boolexpr. Won't TeX expand out the macros before compilation? What's different between macros and numbers? – Junyan Xu Dec 29 '11 at 10:23
@Marco: true, but it doesn't hurt :-) – Herbert Dec 29 '11 at 10:44
@JunyanXu: What's different between macros and numbers? I think this is a new interesting question. – Marco Daniel Dec 29 '11 at 10:48

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.