[Tex/LaTex] Checking if two conditionals are met

conditionalsetoolbox

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"

Best Answer

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

\ifboolexpr{%
    test {\ifnumless{a}{b}} 
    and
    test{\ifnumgreater{x}{100}}
   }{YES}{NO}

For more details see the documentation (section 3.6.5).


I want to show an example.

\documentclass{article}
\usepackage{etoolbox}
\newcounter{a}\newcounter{b}\newcounter{x}
\newrobustcmd*\setabx[3]{%
  \setcounter{a}{#1}\setcounter{b}{#2}\setcounter{x}{#3}%
}

\newrobustcmd*\iftwocont{%
  \ifboolexpr{%
    test {\ifnumless{\value{a}}{\value{b}}} 
    and
    test{\ifnumgreater{\value{x}}{100}}%
  }%
}
\begin{document}
\setabx{1}{1}{1}
\iftwocont{$a<b$ and $x>100$}{The logical combination is false}

\setabx{5}{10}{300}
\iftwocont{$a<b$ and $x>100$}{The logical combination is false}
\end{document}

Result:

The logical combination is false
a < b and x > 100
Related Question