Using end-of-line delimiter in plain Tex macro
The end-of-line character is not available to be used in the main input stream, under the standard setting which is
\endlinechar=`\^^M
\catcode`\^^M=5
(see The ^^ notation in various engines for information about the ^^
notation).
When TeX sees a character with category code 5, it immediately converts it either to a space or to a \par
token if another follows (possibly after the “skipping blanks” phase). When it sees the (operating system defined) end-of-record, it throws it away together with anything that can be on the line past it, removes all trailing blank spaces and inserts the \endlinechar
.
Usually the \endlinechar
has category code 5, but this is not mandatory and different effects can be obtained by changing the category code. For instance, \obeylines
makes \^^M
into an active character and assign it the same meaning as \par
.
For your application you can look at section 11.9.4 of TeX by Topic; basically you do
\def\mymacro{\begingroup\catcode`\^^M=12 \xmymacro}
{\catcode`\^^M=12 %
\gdef\xmymacro#1^^M{Content: #1\endgroup}%
}
Changing the category code of ^^M
must be done in a group or otherwise you end up painting yourself into a corner.
However, I can't recommend doing this: editors might have different ideas about you with respect to when lines should end and hitting a key by mistake can spoil your work. Moreover, using \mymacro
inside an argument to another macro will definitely not work.
Important note
The end-of-line character mentioned above is not the system dependent record terminator. When TeX (any engine implementing it) reads a line, is informed by the operating system what the record terminator is; upon finding it, it throws it away together with everything after it on the same line; then it removes trailing blank spaces (character code 32) and tabs (character code 9); finally it inserts the character having the code equal to the current value of \endlinechar
.
So it's immaterial whether the record terminator is CR (ASCII 13), LF (ASCII 10) or CR+LF, or nothing at all (like for legacy IBM mainframes).
The TeX Live implementation allows any of the combinations above (CR, LF or CR+LF): it examines the first lines of the file and decides upon the line terminator to inform TeX of.
OPmac defines:
\def\eoldef#1{\def#1{\begingroup \catcode`\^^M=12 \eoldefA#1}%
\expandafter\def\csname\string#1:M\endcsname}
{\catcode`\^^M=12\gdef\eoldefA#1#2^^M{\endgroup\csname\string#1:M\endcsname{#2}}}
Then you can define your macro:
\eoldef\foo#1{\message{param: "#1"}}
And you can use it:
\foo this is parameter
and this is next text.