7

These two produce the same result:

abc
%\null
def
\bye
abc
\null
def
\bye

These two are different:

abc

%\null
def
\bye
abc

\null
def
\bye

Does anybody know where this behavior is documented in The TeXbook?

2
  • @cfr "so a paragraph break is inserted" - precision: it's inserted after hbox. But where exactly is this behavior described? Aug 7 '15 at 3:12
  • Actually, I have no idea.
    – cfr
    Aug 7 '15 at 3:27
11

From the TeX Book (Chapter 13 Modes, p 86):

Exercise 13.1:

If you say \hbox{...} in horizontal mode, TeX will construct the specified box and it will contribute the result to the current paragraph. Similarly, if you say \hbox{...} in vertical mode, TeX will construct a box and contribute it to the current page. What can you do if you want to begin a paragraph with an \hbox?

Answer (Appendix A: Answers to All Exercises, p 313):

Simply saying \hbox{...} won't work, since that box will just continue the previous vertical list without switching modes. You need to start the paragraph explicitly, and the straightforward way to do that is to say \indent\hbox{...}. But suppose you want to define a macro that expands to an hbox, where this macro is to be used in the midst of a paragraph as well as at the beginning; then you don't want to force users to type \indent before calling your macro at the beginning of a paragraph, nor do you want to say \indent in the macro itself (since that might insert unwanted indentations). One solution to this more general problem is to say \ \unskip\hbox{...}, since \ makes the mode horizontal while \unskip removes the unwanted space. Plain TeX provides a \leavevmode macro, which solves this problem in what is probably the most efficient way: \leavevmode is an abbreviation for \unhbox\voidbox, where \voidbox is a permanently empty box register.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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