One of the more frustrating features of TeX's macro-expansion based language is that the control code and the code it controls can interact unexpectedly. This means that if you want a conditional block \ifwhatever...\fi
to control some macro \macro
that affects stuff after the block, you need to leapfrog \macro
to finish the conditional first:
\ifwhatever
\expandafter\macro
\fi
<stuff taken as an argument by \macro>
You see, the \expandafter
eats the \fi
before \macro
can. Using this trick, you can write some code that conditionally executes some following code. Say you have a conditional \ifwhatever
, and you want to execute <code>
if it is true, but not if it is false. Then you can write (here I am assuming \makeatletter
is active):
\ifwhatever
\expandafter\@firstofone
\else
\expandafter\@gobble
\fi
{<code>}
This can be generalized if you want to select among two different pieces of code, which by the way is how the LaTeX-style conditionals \ifwhatever{<true code>}{<false code>}
work:
\ifwhatever
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{<code 1>}
{<code 2>}
I wouldn't advise doing this with more than one conditional, though: if you want to execute <code>
when \ifwhatever
or \ifnot
is true, you have to write:
\ifwhatever
\expandafter\@gobble
\else
\ifnot
\expandafter\expandafter\expandafter\@firstoftwo
\else
\expandafter\expandafter\expandafter\@gobble
\fi
\fi
{<code>}
This profusion of \expandafter
s is to skip \@firstoftwo
or \@gobble
and expand first one token, then another after it, before going back to expand the macro you actually want once there is nothing in its way.
Of course, the technique of using multiple \expandafter
s to skip ahead is itself an idiom. For example, you can expand the first token in a group once:
\expandafter{\macro}
or twice:
\expandafter\expandafter
\expandafter{\macro}
or three times:
\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter
\expandafter{\macro}
and you see the pattern. I may as well explain why this works. When the first \expandafter
goes off, it expands in turn the third, then the first in the next row, then the first in the following row, and finally, \macro
. The intervening tokens are not expanded in this "run", but just stuck back in order. The effect is that every other column of \expandafter
s vanishes, \macro
is expanded once, and then TeX starts expanding again with what is now the first \expandater
, which was the second. The configuration has become the one for expanding \macro
twice, and so we end up expanding it three times.
The \lccode
of a character is used in hyphenation when \uchyph
is set to zero:
\documentclass{article}
\begin{document}
\uchyph=0 %
\begingroup
\lccode`\C=`\C
Some filler text.
Some filler text.
Some filler text.
Some filler text.
Capitalised word.
\par
\endgroup
\begingroup
\lccode`\C=`\c
Some filler text.
Some filler text.
Some filler text.
Some filler text.
Capitalised word.
\par
\endgroup
\begingroup
\uccode`\C=`\C
Some filler text.
Some filler text.
Some filler text.
Some filler text.
Capitalised word.
\par
\endgroup
\begingroup
\uccode`\C=`\c
Some filler text.
Some filler text.
Some filler text.
Some filler text.
Capitalised word.
\par
\endgroup
\end{document}
Notice that \uchyph
is therefore misleadingly-named, as what is tested is whether the word starts with a lower case letter (one with \lccode
equal to itself).
Best Answer
There are exactly 7 places in the TeX program where TeX executes the paragraph builder internally, i.e. turning a horizontal list (if there is one under construction) into a paragraph. This happens not by inserting a
\par
token into the input stream but by executing the procedure end_graf implemented in module §1096 in the TeX program.This procedure does nothing if TeX is not in horizontal mode, more or less nothing if in horizontal mode but with an empty list (null paragraphs are ignored by TeX), and executes the procedure line_break otherwise (and that one does all the magic about adding parfillskip penalties, etc.).
The seven places are
\vbox
but also\noalign
or\vcenter
or an alignment cell\par
)In none of these cases there is a
\par
token inserted (that might be subject to redefinitions); instead, the end_graf procedure is executed!\par
tokens are only inserted when in horizontal mode and primitives incompatible with horizontal mode (like\vskip
,\hrule
, ... the full list in is §1094 in the TeX code) are encountered. And of course in the tokenization process when TeX replaces two endline chars by\par
(i.e., making empty lines equivalent to\par
).