[texhax] read argument until EOL

Uwe Lueck uwe.lueck at web.de
Thu Jan 6 14:07:18 CET 2011


"Philip Taylor (Webmaster, Ret'd)" <P.Taylor at rhul.ac.uk>, 06.01.2011 12:24:22:
>Arno Trautmann wrote:
>> How to code a macro that reads an argument until the end of the line?
>> e.g. to get rid of braces in \section:
>>
>>    \eolsection My Title
>>    normal text.
>
> I am going to take my life in my hands and type in an extempore
> solution without testing : /caveat emptor/ !
>
> \def \eolsection
>	{
>		\begingroup
>		\catcode `\^^M = \active
>		\uccode `\~ = `\^^M
>		\uppercase {\def \innereolsection ##1~}{\endgroup \message {##1}}\relax
>         	\innereolsection
>	}

Great! Two little pieces of envy/efficiency: 
1.) at least one space token in the macro definition can be avoided; 
2.) \innereolsection needn't be defined anew at each call of \eolsection, cf.:

\def\toeol{% save space token
  \begingroup\catcode`\^^M\active\dotoeol}
{\uccode`\~=`\^^M
 \uppercase{\gdef\dotoeol#1~}{\endgroup\message{^^J#1^^J}}}

[TESTED with a single occurrence and line]

Cf. Wikipedia: "Envy, jealousy and schadenfreude"!

-- I realize: my version can be fooled by redefining \dotoeol, Phil's is more robust in this respect.

Cheers, 

    Uwe.


More information about the texhax mailing list