[Tex/LaTex] Are there any “if” commands like “\ifnum” in LaTeX

conditionals

Are there any commands containing "if", similar to \ifnum, preferably in LaTeX (rathar than TeX)?
For example, is there anything like \ifstring? (I am not after \ifstring only, I want to know which options are available, if any).

Best Answer

The \if... commands are mostly TeX primitives (with \newif it's possible to define other conditionals).

There is something like \ifstring, but it uses \ifnum; the command \pdfstrcmp takes two strings as argument and compares it, returning -1 if the first precedes the second (in the lexicographic order based on ASCII codes), 0 if the strings are equal and 1 otherwise. The usual ways to exploit it are

\ifnum\pdfstrcmp{string1}{string2}=0
   <code if the strings are equal>
\else
   <code if the strings are different>
\fi

or

\ifcase\pdfstrcmp{string1}{string2}%
   <code if the strings are equal>
\or
   <code if string2 comes after string1>
\else
   <code if string1 comes before string2>
\fi

In XeTeX there's \strcmp that does the same; loading pdftexcmds one can use \pdf@strcmp with pdftex, xetex and luatex.

In the pseudocodes above "string1" and "string2" can be also macros, which will be expanded similarly to what happens with \edef and at the end (when no more expansions can be performed) the tokens are "detokenized" for the comparison (so \relax becomes a six character string followed by a space; for example \pdfstrcmp{\relax}{\string\relax\space} returns 0).