I am using the etoolbox package to check some variables. I can use \ifnumless{a}{b}{True}{False} to check if "a" is less than "b" and output "True" if true and "False" if false". How can I check if two conditionals are met though? E.g.:

IF a < b AND x > 100
DO "True"
ELSE "False"
  • 3
    \ifnumless{a}{b}{\ifnumgreater{x}{100}{True}{False}}{} – Werner Dec 6 '11 at 23:32
  • Does this mean I end up with two "False"'s? – Village Dec 6 '11 at 23:34
  • @Werner needs another False in his code (between the final {}). But you will end up with only 1 "False". Since the evaluation can always only end up in one branch. I think that it's a perfectly acceptable answer otherwise and Werner should add it. – Roelof Spijker Dec 7 '11 at 10:21

You can use the logical combination and and or in the test \ifboolexpr

    test {\ifnumless{a}{b}} 

For more details see the documentation (section 3.6.5).

I want to show an example.


    test {\ifnumless{\value{a}}{\value{b}}} 
\iftwocont{$a<b$ and $x>100$}{The logical combination is false}

\iftwocont{$a<b$ and $x>100$}{The logical combination is false}


The logical combination is false
a < b and x > 100
  • Have you ever looked in the trace log of \ifboolexpr? :) It's plentiful even for simple tests. If the conditions aren't more than two, I will suggest a direct test instead. – Ahmed Musa Dec 7 '11 at 2:15
  • 2
    @AhmedMusa: ifboolexpr allows the logical combination required by the OP. – Marco Daniel Dec 7 '11 at 8:54

The following takes less than 1% of the runtime used by \ifboolexpr and it does arithmetic. It can be changed to also do real numbers.


\numtest 1+2<3+2 and 4+3>2+3{true}{false}
\numtest 1+2<3+2 and 2+3>2+3{true}{false}
\numtest 1+2+4>3+2 and 2+3+4=2+3+5+3{true}{false}
  • 7
    You were able to calculate the runtime... and it was less than 1%? Really? – Werner Dec 9 '11 at 5:37

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.