[texhax] question about newlines

Philip G. Ratcliffe philipratcliffe at tiscali.it
Sat Oct 23 18:55:31 CEST 2004


>  >>I don't have much experience writing advanced macros, but
>  >>I always wanted to write a macro that has a newline as delimiter.
>  >>So I could say something like
>  >>
>  >>----
>  >>\mymacro argument
>  >>
>  >>rest of the document
>  >>---
>  >>
>  >>Do you know any way of doing this?
>  >
>  >
>  > Try this
>  >
>  > \def\mymacro#1\par{blah blah #1 blah blah}
>
> But a newline isn't a par; it's much closer to
> a space than anything else.  If Carlos is really
> going to succeed in taking #1 to be everything
> up to (but not including) end of line, he'll
> need some catcode trickery along the lines of :
>
> 	\def \activeeol {\catcode `\^^M = \active}
> 	\def \passiveeol {\catcode `\^^M = 5 }
>
> 	\def \mymacro
> 		{\activeeol
> 		 \Mymacro
> 		}
>
> 	\begingroup
> 	\activeeol %
> 	\gdef \Mymacro #1
> 		{\passiveeol %
> 		 <do something with #1>%
> 		}%
> 	\endgroup

Sorry, I interpreted "newline" as "empty line" (that is how the example
appeared).  If the poster really wants the end of line character to be the
delimiter, then Philip's trickery is required.

On the other hand, if \par is a useful delimiter and if the additional space
at the end of the line is the problem, then this is enough:

\def\mymacro#1 \par{blah blah #1 blah blah}

The space before \par will caise the implicit trailing space to be eaten.

Cordialmente,  Philip G. Ratcliffe
-----------------------------------------
Professor of Nuclear & Subnuclear Physics
Dipartimento di Fisica e Matematica
Universita degli Studi dell'Insubria
via Valleggio 11
22100 Como (CO)
Italy

Tel. +39 (039) 238.6231
Fax  +39 (039) 238.6119
Cell +39 (340) 2346580
Web  http://www.unico.it/~pgr
-----------------------------------------



More information about the texhax mailing list