17

In source2e.pdf, the definition of \verb is

\def\verb{\relax\ifmmode\hbox\else\leavevmode\null\fi
  \bgroup
    \verb@eol@error \let\do\@makeother \dospecials
    \verbatim@font\@noligs
    \@ifstar\@sverb\@verb}

There is a \null in non-mathematical model. \null is just \hbox{}. What is the purpose of using it here?

9

There is a case, where \null makes a difference:

At the start of a line TeX removes glue and penalties. If \verb starts with an invisible space, then it would be removed:

\documentclass{article}
\begin{document}
  \noindent x\\
  \begingroup
    % \let\null\relax
    \verb| |y
  \endgroup
\end{document}

\null as \hbox{} prevents that the space is gobbled at the start of a new line:

result without \null

If \null is disabled, then the space is removed:

result with \null

Thus \null helps that characters inside the argument of \verb do not vanish unexpectedly.

Disclaimer: I do not know the real reason, which the author of \verb had in mind.

| improve this answer | |
  • Nice catch! You always surprise me. – sos.frank Apr 8 '14 at 21:36
  • 1
    This is the real reason. I kind of remember that this got added precisely for this way back – Frank Mittelbach May 13 '14 at 11:33

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.