I want to define a conditional command that I can easily use with \ifnum
, hence such a command should expand to a number. However, I sometimes need to define temporary commands which breaks such usage, as the following MWE illustrates.
\documentclass{article}
\def\isEqualTFO#1#2#3#4{%
% return #2 if \entry is defined and equals #1
% return #3 if \entry is defined and is not equal to #1
% otherwise returns #4
\ifdefined\exclusiveEntry
\def\tmp{#1}
\ifx\exclusiveEntry\tmp
#2
\else
#3
\fi
\else
#4
\fi}
\begin{document}
Test
\def\exclusiveEntry{Hello}
\isEqualTFO{Hello}{1}{2}{3}
\isEqualTFO{World}{1}{2}{3}
% This returns an error "Missing number, treated as zero."
% \ifnum\isEqualTFO{Hello}{1}{2}{3}=2
% First\else Second\fi
\end{document}
My command \isEqualTFO
returns one of three inputs depending on the value of \entry
. However, because I am having to \def\tmp
to be able to compare \entry
with the input using \ifx
, this break the usage of my command in \ifnum
since it does not expand to a simple number.
How do I correctly use isEqualTFO
with ifnum
? by either modifying the command definiton or changing the way I call it? For example, I thought calling
\expandafter\ifnum\isEqualTFO{Hello}{1}{2}{3}
would do the trick, but it still gives the same error.
\pdfstrcmp
(called\strcmp
in some engines or lua expl3 provides a version that works in all engines