TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm reading TeX by Topic, but in little chunks (rather than from first page to last) and just read the stuff on conditionals. I want to be sure that I understand what's going on when TeX starts skipping stuff. What I've gleaned so far is that in, say, \iffalse ... \fi then:

  1. TeX doesn't do expansions.

  2. TeX keeps track of \if...s to ensure that the \fi really matches the \iffalse.

It's that last bit that I'm wanting to make sure that I get straight in my head. To make it a precise question:

What exactly is an \if...?

One reason for my worry is that I have some pseudo-ifs in my code, where a command starts \if... but isn't actually an \if. On the other hand, what if I had a command that didn't start with the three characters \if but happened to be \let to an \if? So, for example, which of the following count as an \if when the macro (not the definition of it) is used between \iffalse ... \fi:

  1. \let\ifabc=\ifx (so, to be clear, what happens in \iffalse ... \ifabc ... \fi, does the \ifabc count as an \if?
  2. \def\ifabc{\ifx}
  3. \edef\ifabc{\ifx}
  4. \let\ifabc=\SomePreviouslyDefinedCommandThatIsntAnIf
  5. \let\abc=\ifx
share|improve this question
up vote 21 down vote accepted

When TeX is skipping tokens in a false path of a conditional it looks at every token without expanding it and modifies an if-counter very similar to the brace counter. If the token is a primitive \if... token (e.g. \let to any of TeX's original conditionals like \if, \ifx, \ifnum, ...) the counter is increased and if it's identical to \fi (i.e. \fi or any macro let to it) the counter is decreased. The name of the macro is not important. Conditionals inside other macros are never seen.

To answer your questions in detail:

  1. \let\ifabc=\ifx (so, to be clear, what happens in \iffalse ... \ifabc ... \fi, does the \ifabc count as an \if?

    A: Yes, \ifabc counts as an if.

  2. \def\ifabc{\ifx}

    A: No, \ifabc isn't a if. It will work in the true path, because it is expanded there, but not in the false path.

  3. \edef\ifabc{\ifx}

    A: This wont work, because \ifx is expanded and therefore awaits its two input tokens and the final \fi. Even so, primitives can't be expanded to their underlying meaning, otherwise they wouldn't be primitives.

  4. \let\ifabc=\SomePreviouslyDefinedCommandThatIsntAnIf

    A: As I've said above , the name doesn't matter; this is not an if.

  5. \let\abc=\ifx

    A: The name doesn't matter; this is an if.

For further information about the if-switches see The TeXBook in "Chapter 20: Definitions (also called Macros)", page 207 ff.

share|improve this answer
@Andrew: I am not sure I understand your question, but let me point out that TeX primitives and the control sequences usually denoting them are two different things. Try \let\somethingelse\if \let\if\relax \show\somethingelse for example: It says \somethingelse means \if even though \if doesn't mean \if anymore. The tests done when skipping text is against the TeX primitives – the names of commands is irrelevant. Uh, maybe that means the answer to your question is “yes”. – Harald Hanche-Olsen Feb 25 '11 at 9:47
As a general point, when TeX shows you the meaning of a primitive (\show = \show, etc.), the second '\show' is an internal token and not a 'normal' control sequence. That's why something like \let\mymacro\relax \def\relax{} \show\mymacro gives \mymacro=\relax: you are seeing the internal token (essentially the memory location containing the definition of, in this case, the \relax primitive). – Joseph Wright Feb 25 '11 at 10:10
@Hendrik: With a recent engine, there is always \(pdf)primitive to get at the original definition. – Joseph Wright Feb 25 '11 at 10:33
@Hendrik: Then it doesn't work (there are no immutable names in TeX) – Joseph Wright Feb 25 '11 at 10:48
To clarify things a bit: when we say "the \if primitive" we mean a control sequence token whose meaning is the original (IniTeX) meaning of \if. TeX usually tests not for a specific control sequence, but for specific meanings. (An important exception is \par.) As a corollary to Martin's explanations, you cannot easily define a macro that can be used with the same syntax as the conditional primitives (a popular way is \let\then\iffalse \def\ifsomething\then{}). – Philipp Feb 25 '11 at 17:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.