# Ignore spaces and \par's after an environment

In defining an environment, I could use \ignorespacesafterend to ignore all spaces after the environment. But how could I also ignore all \pars and empty lines after the environment?

In other word, how could I modify the following latex source

\documentclass{article}

\newenvironment{abc}{\ignorespaces}{\ignorespacesafterend}

\begin{document}

\begin{abc}
One
\end{abc}
\par
\begin{abc}
Two
\end{abc}

\begin{abc}
Three
\end{abc}

\end{document}


to get the following result?

OneTwoThree

-
take a look at tex.stackexchange.com/questions/23100/… –  dcmst May 19 '14 at 7:55
@dcmst I tried to put \ignorespacesandallpars from that answer into my \newenvironment, but it failed to remove \pars. –  Z.H. May 19 '14 at 8:00

You need to drop the command in at the right place (which is why latex has \ifgnorespacesafterend not just \ignorespaces. Also your sample result indicated that you wanted to not only ignore space after \end{} but also remove the space already added before that, hence the \ifhmode\unskip\fi line. The definition is not quite as in the linked question (I removed the catcode setting)

\documentclass{article}

\newenvironment{abc}{\ignorespaces}{%
\ifhmode\unskip\fi
\aftergroup\useignorespacesandallpars}

\def\useignorespacesandallpars#1\ignorespaces\fi{%
#1\fi\ignorespacesandallpars}

\makeatletter
\def\ignorespacesandallpars{%
\@ifnextchar\par
{\expandafter\ignorespacesandallpars\@gobble}%
{}%
}
\makeatother

\begin{document}

\begin{abc}
One
\end{abc}
\par
\begin{abc}
Two
\end{abc}

\begin{abc}
Three
\end{abc}

\end{document}

-
I try to understand the above code. It seems that \def\useignorespacesandallpars#1\ignorespaces\fi{#1\fi\ignorespacesandallpars} is dependent on the definition of the \end macro. –  Z.H. May 19 '14 at 10:52
Also, the result is still correct when I remove \aftergroup. Why we need \aftergroup here? –  Z.H. May 19 '14 at 10:56
@Z.H. actually you don't need \afergroup: originally I was going to use \aftergroup\ignorespacesandallpars but that wasn't quite the right place either so I added the \use... macro (which does as you note depend on the definition of \end to explicitly insert it, which means the aftergroup isn't needed (but doesn't do any harm) –  David Carlisle May 19 '14 at 11:31