[comp.text.tex] \obeyindentedlines

dorai@tone.rice.edu (Dorai Sitaram) (04/23/91)

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

dorai@tone.rice.edu (Dorai Sitaram) (04/23/91)

In article <1991Apr22.205010.17846@rice.edu> dorai@tone.rice.edu (Dorai Sitaram) writes:
>% ***** 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}%
>}}


Ah, that's obviously wrong since it doesn't progress (or _eat_) any
spaces.  Yes, I've tried

{
...
\def\keepindents{\futurelet\next\keepindentsII}%
%
\def\keepindentsII{\ifx\next  \noexpand\keepindentsIII%
\else\ifx\next^^I^^I\noexpand\keepindentsIII%
\else\noexpand\endgroup\fi\fi}%
%
\def\keepindentsIII##1{\keepindents}
...
}

but that doesn't help either.  This is getting to be uncomfortably
tantalizing!

--d