I need to make a conditional like this:
IF #1 > \variable OR #1 = 0
THEN
PRINT "True"
ELSE
PRINT "False"
If #1
is greater than \variable
or is equal to 0
, then it it true. The value only contains integers of 0 or greater. There are never any decimals.
I have this conditional in plain TeX, which checks if #1
is greater than \variable
, but I do not know how to add the #1 = 0
part.
\ifnum0#1>\variable
True
\else
False
\fi
How can I create a conditional that checks if at least one of these conditionals is true?
Best Answer
\if
expands tokens until two non-expandable tokens remain. If one of the conditions is true, then the expansion isT
, otherwiseF
. This is compared with the lastT
in the line.Advantage:
TRUE
is not duplicated as inAdvantage: All number parsings are stopped by well defined tokens. Example: The token
T
stops the scanning of the number\variable
. If theTRUE
part starts with a number123abc
and\variable
is defined as5
Then
#1
must be greater than5123
!Depending on the definition of
\variable
the evaluation of\variable
as number might skip a first space of theTRUE
part.Advantage: The conditionals are well matched, thus this construct can also be used inside other conditionals. If TeX skips a conditional branch it only checks the command tokens for real
\if...
primitives,\else
,\fi
, and\or
(for\ifcase
).For example with a macro
\ifOR
the following is not well matched:\ifOR
does not count as macro, but there are two\ifnum
, but only one\fi
.Disadvantage: The
\if
condition is not easy to read.