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.
\pdfoutput=1
\documentclass[12pt]{amsart}
\usepackage{boolexpr}

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

\begin{document}
\switch[\p=]
\case{\q}abc
\endswitch
def
\end{document}

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

\switch[1=]

it will be OK. But only change the line to

\case{1}abc

yields the same error.

Any idea why this happens? Thank you in advance.

share|improve this question
2  
@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

2 Answers 2

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:

\switch[\numexpr\p\relax=]
\case{\q} abc
\endswitch

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

\switch[\number\p=]

works.

share|improve this answer

use counters instead of macros:

\documentclass{amsart}
\usepackage{boolexpr}
\newcounter{p}\setcounter{p}{1}
\newcounter{q}\setcounter{q}{1}

\begin{document}
\switch[\value{p}=]
\case{\value{q}} abc
\endswitch
def
\end{document}
share|improve this answer
1  
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
1  
@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

 
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.