[texhax] read argument until EOL

Heiko Oberdiek heiko.oberdiek at googlemail.com
Thu Jan 6 16:24:23 CET 2011

On Thu, Jan 06, 2011 at 11:24:22AM +0000, Philip Taylor (Webmaster, Ret'd) wrote:

> Arno Trautmann wrote:
> >Hi all,
> >
> >a question I posted on the LaTeX3-list and Uwe Lueck asked me to re-post
> >here:
> >
> >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.
> >
> >Here, "My Title" should be accesible in the \eolsection as #1.
> >For my case, the solution does not have to be robust or cover any
> >strange case with catcodes, verbatim or anything else, just plain text
> >will appear.
> 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
> 	}
> Where I have "\message {##1}", you should insert whatever
> you want to do with My Title and analogous parameters.

"1" might have the wrong uccode different than 0 or `1.
(But I would consider it as quite small risk.)

Here is a different design (using some of the code above).
Macro \eolgrab executes it first argument with the
rest of the line as argument.

%%% test.tex %%% begin %%%
% preamble loads package ltxcmds for compatibility to plain TeX
% and sets the catcode of "@" to letter
\expandafter\ifx\csname RequirePackage\endcsname\relax
  \input ltxcmds.sty\relax
\catcode64=11 %

% define macro \eolgrab
  \catcode`\^^M=\ltx at active
  \catcode`\^^M=\ltx at active%
\ltx at firstofone{\endgroup%

% postamble: restore previous catcode of "@"

% example: simple LaTeX document
\eolgrab\documentclass article
\eolgrab\begin document
\eolgrab\section Hello World
\eolgrab\end document
%%% test.tex %%% end %%%

Example for plain TeX:

\eolgrab\message Some text
\eolgrab{\immediate\write16}Hello World

Also the definitions of \eol... macros are simplified:

% or in LaTeX

Yours sincerely
  Heiko Oberdiek

More information about the texhax mailing list