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

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"
share|improve this question
\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
up vote 21 down vote accepted

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
share|improve this answer
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
@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}
share|improve this answer
You were able to calculate the runtime... and it was less than 1%? Really? – Werner Dec 9 '11 at 5:37

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.