4

Here is my LaTeX code.

\documentclass{article}
\newcommand{\macro}[1]{A: #1}
\begin{document}

A: B0

A:  B1

\macro{B2}

\macro{ B3 }

\end{document}

Here is the output.

Image of rendered LaTeX code

I want to know why there is an additional space before B3 in the output above. As far as I know multiple consecutive spaces should collapse to a single space.

But from the above output seems when one of the multiple spaces come from the macro definition and the other from the macro argument, they collapse to two spaces. Why?

1
  • 2
    For the same reason \space\space doesn't collapse in a single space: because it produces two space tokens. Spaces are “collapsed” only during the tokenization phase. When tokens have been formed, they are used one by one.
    – egreg
    Commented Aug 29, 2016 at 15:59

1 Answer 1

6

Two or more space characters in the file are collapsed, producing a single space token, but two consecutive space tokens make a double sized space. Here you have one space token in the macro replacement text, before #1, and the supplied argument starts and ends with a space token, so you get a double space.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .