Newsgroups: comp.text.tex
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uupsi!rice!tone.rice.edu!dorai
From: dorai@tone.rice.edu (Dorai Sitaram)
Subject: \obeyindentedlines
Message-ID: <1991Apr22.205010.17846@rice.edu>
Sender: news@rice.edu (News)
Organization: Rice University, Houston
Date: Mon, 22 Apr 91 20:50:10 GMT

I've been trying for quite some time to get a certain form of
\obeylines to work but keep getting baulked.  The control sequence
that I want is called \obeyindentedlines and is similar to \obeylines
except that it also respects any leading spaces (and tabs), but not
those spaces that may occur inside the ensuing line.

Thus

\documentstyle[obeyindentedlines]{article}
\begin{document}

{\obeyindentedlines
The woods are lovely, dark and deep,
  But I have       promises to         keep,
And miles     to go     before        I sleep,
  And miles to go           before         I        sleep.
}

\end{document}

should come out as

The woods are lovely, dark and deep,
  But I have promises to keep,
And miles to go before I sleep,
  And miles to go before I sleep.

My most recent attempt looks like:

% ***** obeyindentedlines.sty *****

\def\makeactive#1{\catcode`#1\active}

\def\singlespace{\ }
\def\tabspace{\ \ \ \ \ \ \ \ }

{\makeactive\^^M%
\makeactive\ %
\makeactive\^^I%
\gdef\obeyindentedlines{%
\makeactive\^^M%
%
\def^^M{\par\mbox{}%
\begingroup%
\makeactive\ %
\makeactive\^^I%
\let \singlespace%
\let^^I\tabspace%
\keepindents}%
%
\def\keepindents{\futurelet\next\keepindentsII}%
%
\def\keepindentsII{\ifx\next  \noexpand\keepindents%
\else\ifx\next^^I^^I\noexpand\keepindents%
\else\noexpand\endgroup\fi\fi}%
}}

% ***** end of file *****

I tried permuting the \noexpands around, but to no avail.  I either
get error messages, or get all the spaces, not just the leading ones,
treated as true spaces.  What am I doing wrong?

--d
