Trailing space in parameter delimited with \par
It is that way just because that's the way it is. Essentially the first end of line turns into a space as usual, the second newline turns into \par
. The normal \par
behaviour does an \unskip
to remove a final glue node (usually from this space) before breaking the lines..
A couple of possibilities below.
\def\test #1\par{\def\param{#1}}
\test test
\hbox{\vrule\param\vrule} % prints "|test |"
\def\testB #1 \par{\def\param{#1}}
\testB test
\hbox{\vrule\param\vrule} % prints "|test|"
\def\testC #1\par{\def\param{#1\unskip}}
\testC test
\hbox{\vrule\param\vrule} % prints "|test|"
\bye
Note that if you use an actual explicit \par
in the use as in
\test test\par
then the additional space is not there, so your original would not have an extra space. \testB
would have an error as it would be looking for a \par
preceded by a space.
There is another possibility. To create a macro, which reads its parameter to the end of line. This solution is inspired from OPmac trick 0121. Macro programmer can use
\eoldef\macro#1{here is a parameter "#1"}
and then \macro text<end of line>
causes that "#1" is text
. The \eoldef
macro can be defined by:
\gdef\eoldef#1{\def#1{\begingroup \catcode`\^^M=12 \eoldefA#1}%
\expandafter\def\csname\string#1:G\endcsname}
{\catcode`\^^M=12 %
\gdef\eoldefA#1#2^^M{\endgroup\csname\string#1:G\endcsname{#2}}}