# Problem setting lengths in an environment (spilling outside of the environment)

I am having with spacing between paragraphs in my document, and I think I have been able to trace back to a custom environment I have defined.

\makeatletter
\def\remarkname{Remark}
\newcounter{counter@myremarks}
\newenvironment{remark}{\par\vspace{0.2cm}\par\noindent\begingroup\small%
\textbf{\remarkname~\arabic{counter@myremarks}.}~~\ignorespacesandallpars}{%
\newenvironment{remark*}{\par\vspace{0.2cm}\par\noindent\begingroup\small%
\textbf{\remarkname.}~~\ignorespacesandallpars}{%
\makeatother

The \ignorespacesandallpars command is by Martin Scharrer and comes from a previous StackExchange question.

(I know that there are many other ways - packages, or the definitions in amsmath - to get this sort of environment, but I have not yet found something that I'm completely happy with, and it is easier at the moment to use a custom definition.)

After I use this definition, I think I notice spacing being a bit wacky, and requiring additional \smallskip or \medskip commands. I wonder what I am doing wrong.

Is my problem somewhere else, or am I doing something wrong here?

UPDATE: The following snippet illustrates one of the problems (the spacing before the second itemize list is not the same than the first):

\documentclass{article}

\makeatletter
\def\ignorespacesandallpars{%
\begingroup
\catcode13=10
\@ifnextchar\par
{\endgroup\expandafter\ignorespacesandallpars\@gobble}%
{\endgroup}%
}
\def\remarkname{Remark}
\newenvironment{remark*}{\par\vspace{0.2cm}\par\noindent\begingroup\small%
\textbf{\remarkname.}~~\ignorespacesandallpars}{%
\makeatother

\begin{document}

Following is an item list
\begin{itemize}
\item One
\item ...
\end{itemize}

\begin{remark*}
Now a remark.
\end{remark*}

And another item list
\begin{itemize}
\item One
\item ...
\end{itemize}

\end{document}
-
Thanks for the code. Why are you using \@afterindentfalse\@afterheading? – Gonzalo Medina Aug 21 '12 at 19:45
@GonzaloMedina: if I recall correctly, what I wanted is to prevent the following paragraph from having indent, and to make it so no amount of spacing would change this (the fact that what follows not be indented). – Jérémie Aug 21 '12 at 21:37

Well \@afterheading is one of the reasons sectioning commands should never be used in groups ;-)

It gobally sets \@nobreaktrue and then locally sets \everypar to undo it. So after the end of your environment (undoing the \everypar setting) you have \@nobreaktrue sitting there waiting for the next list to catch it...

And \@nobreak makes a list not insert \topsep...

To avoid this mess, you must make sure \@afterheading is called outside your environment.