Why is there a \null in \verb?

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?

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:

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

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.

• Nice catch! You always surprise me. – sos.frank Apr 8 '14 at 21:36
• 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