[comp.text.tex] easy macro for novice

davis@pacific.mps.ohio-state.edu ("John E. Davis") (12/05/90)

Hi,

   I wrote the following macro:

   \def\dolines#1{\medskip\obeylines#1\medskip}

Then, when I do:

\dolines{
            This is line 1.
	    This is line 2.
	    This is line 3.
}

I get:

This is line 1. This is line 2. This is line 3.

This is not what I want.  Aparantly TeX is converting the 'newlines' to spaces
before substitution into the macro.  If this is the correct diagnosis,  how do
I supress this within the macro definition?

I looked at the FAQ sheet and tried the TeXbook and found no answers.


--
John

  bitnet: davis@ohstpy
internet: davis@pacific.mps.ohio-state.edu

jg@prg.ox.ac.uk (Jeremy Gibbons) (12/08/90)

davis@pacific.mps.ohio-state.edu ("John E. Davis") writes

> I wrote the following macro:
> \def\dolines#1{\medskip\obeylines#1\medskip}
[...]
> This is not what I want.  Aparantly TeX is converting the 'newlines' to 
> spaces before substitution into the macro.  If this is the correct 
> diagnosis, how do I supress this within the macro definition?

Your diagnosis is nearly correct. \obeylines `changes the category codes' of
newlines, to make them `active' (ie TeX commands); newline is then defined to
do a \par. Unfortunately, the category codes of arguments to macros are fixed
when the argument is matched, not when it is executed, so the newlines in your
argument aren't active ones.

The easiest fix is not to pass the text as an argument:

   \def\dolines{\medskip\obeylines}
   \def\enddolines{\medskip}
   
   \begin{dolines}
      Line 1.
      Line 2.
      Line 3.
   \end{dolines}

(At a guess.)

*-----------------------------------------------------------------------*
|  Jeremy Gibbons (jg@uk.ac.oxford.prg)   Funky Monkey Multimedia Corp  |
*-----------------------------------------------------------------------*