[Tex/LaTex] The different meanings of LaTeX’s \stop command

meaningparsing

we know that

\stop

will cause LaTeX to stop parsing and output what it has processed up to this command.

But then I discovered another way to use it, as demonstrated in this minimum working example:

\documentclass{article}
  \def\demo#1-#2\stop{#2}
\begin{document}
  \def\sample{foo-bar}
  \expandafter\demo\sample\stop
  There's the Word 'bar' above this text and
  this made it into the output despite a stopping command.
\end{document}

How is \stop used here and why didn't it actually interrupt the LaTeX?

Best Answer

The meaning of \stop is never actually read in the above. It is just used as a delimiter token. In this situation, absolutely anything will do:

\documentclass{article}
  \def\demo#1-#2\StopInTheNameOfTeX{#2}
\begin{document}
  \def\sample{foo-bar}
  \expandafter\demo\sample\StopInTheNameOfTeX
  There's the Word 'bar' above this text and
  this made it into the output despite a stopping command.
\end{document}

A simple \show\StopInTheNameOfTeX shows that this has no meaning, but in this context that meaningless is itself meaningless.

Related Question