An advanced TeX question
Also posted to tex-latex (page can be found here)
Try typing in the following code:
x y % two spaces between x and y % The argument of \eatandx is ignored. % Note the space after the x. \newcommand{\eatandx}[1]{x } \eatandx{z} y
The second paragraph outputted has an extra space between the x and the y. I’m pretty sure this is caused by the fact that \eatandx
takes an argument. Ideally, I’d like both paragraphs to look the same in the PDF (like “x-space-y”). Is there any way for the space at the end of the result of \eatandx
and the space just after it to be combined into a single space (so it looks like the two spaces from the first paragraph that turned into a single space in the output)? I don’t think \unskip has the right behavior, because \eatandx{z}y
should also become “x-space-y” due to the space after the x.
I suspect that this behavior happens because TeX parses the spaces in the first paragraph with its “eyes” (to use Knuth’s term), while macro expansion occurs later (possibly in either the “mouth” or the “bowels” of TeX, I think?). This would cause the first line to become the token list “x-space-y” while the second becomes “x-space-space-y” instead. However, I have no idea how to correct this and get the behavior I want (or even if that’s possible).
Any insight would be most welcome. Thanks very much!