# [texhax] question about \if

Uwe Lueck uwe.lueck at web.de
Fri Nov 12 13:30:55 CET 2010

"Vafa Khalighi" <vafakhlgh at gmail.com>, 12.11.2010 12:30:17:
HO>> And what do you want to test?
HO>> * argument starts with t',
HO>> * after expansion the first token is t',
HO>> * the argument contains t',
HO>> * ...
HO>> The context is important, are assigments allowed or is the
HO>> test restricted to expandable contexts?
HO>> ...
>
> actually I want to have a group of tokens instead a single token.
>
> To be more specific, this is what I have in mind:
>
> \newcommand{\setmaindir}[1]{\if#1RTL\pagedir TRT\else \if#1LTR\pagedir TLT\fi\fi}
>
> so that
>
> \setmaindir{RTL} gives  \pagedir TRT and
> \setmaindir{LTR} gives \pagedir TLT

Aha.

1. The TeXbook starts explaining conditional definitions on page 207.

You seem to want to test if two token lists are the same. Usually, one uses \def and \ifx for this (not the full story).

I realize that if somone learns other programming languages before learning about TeX, it may be a surprise to learn that TeX's \if is a very special thing, it plays a very minor role as an analogue to "if" in other programming languages.

2. For a programmer, reading some documentation of the programming language may be helpful.

A TeX macro programmer should IMHO read the TeXbook -- or something similar, I cannot properly compare ... but it is the only book I really can recommend for this purpose!

So I am somehow reviving that RTFM idea that has played some role in the past of this list ...

3. For a programmer, adopting some logical thinking may be helpful. It may be good to think of a somewhat formal specification, at least for a restricted set of input situations.

I know examples typically are the starting point, but one should then try at (partial) generalizations.

Cheers,

Uwe.
`