2

Let's have a look at the example:

Some text.
\iffalse
Nothing to print.
\fi
Further text.

I would expect that this is handled like

Some text.

Further text.

because the system simply removes the part between \iffalseand \fi. But when you test it, in the resulting pdf you read Some text. Further text. in the same line. So this suggests that the text is handled like

Some text.
Further text.

Can somebody explain why we lose one linebreak?

1 Answers1

6

Whitespaces (but not empty lines, because they are \par) after macros, primitives etc. are always ignored (they delimit the macro name). A end of line is just a whitespace. So you not just have to remove everything from \iffalse until the end of \fi, but also the whitespaces (end-of-line) after \fi and you'll get:

Some text.
Further text.

In in other words: Because end-of-line is just a whitespace, your original code is the same like

Some text. \iffalse Nothing to print. \fi Further text.

and this expands to:

Some text. Further text.

Note: The space after “text.” is not the space from behind \fi, it is the space from before \iffalse.

Note: In previous versions of the answer I wrote “is the same like” instead of “expands to”, but this is not really correct, because TeX really scans and parses the \iffalse, so a line with \iffalse is never an empty line in sense of TeX. Additionally the special handling of \if… happens: TeX reads the following without expanding until either \else or \fi is found. And if while this reading another TeX \if… (e.g., \iftrue, \iffalse, \ifcase, \ifx, \ifcsname, \if etc.) is found, it is also read until the corresponding \fi.

cabohah
  • 11,455
  • How many whitespaces after a \fi are ignored? If I add a further newline after \fi one sees a linebreak in the pdf document. However, if I put a space after \fi and then a newline I don't see a newline in the pdf document. In both cases it are two whitespaces. I don't understand the logic. – principal-ideal-domain Apr 25 '23 at 12:01
  • 1
    @principal-ideal-domain Empty lines are \par and therefore not ignored. This is nothing special for \if…\fi but the same for other commands like \relax. – cabohah Apr 25 '23 at 12:05
  • Depends on your exact definition of "whitespace". "Characters with whitespace catcode before tokenization" are ignored, but "whitespace token" certainly is not. In that sense the first sentence is a bit confusing because the "whitespace" part refers to the characters but the part in the parentheses refer to the tokens. – user202729 Apr 25 '23 at 12:28