Suppress indentation after environment in LaTeX

glts picture glts · Apr 29, 2010 · Viewed 10.7k times · Source

I'm trying to create a new environment in my LaTeX document where indentation in the next paragraph following the environment is suppressed.

I have been told (TeXbook and LaTeX source) that by setting \everypar to {\setbox0\lastbox}, the TeX typesetter will execute this at the beginning of the next paragraph and thus remove the indentation:

\everypar{\setbox0\lastbox}

So this is what I do, but to no effect (following paragraph is still indented):

\newenvironment{example}
  {\begin{list}
     {}
     {\setlength\leftmargin{2em}}}
  {\end{list}\everypar{\setbox0\lastbox}}

I have studied LaTeX's internals as well as I could manage. It seems that the \end routine says \endgroup and \par at some point, which may be the reason LaTeX ignores my \everypar setting. \global doesn't help either. I know about \noindent but want to do this automatically.

Example document fragment:

This is paragraph text. This is paragraph text, too.

\begin{example}
  \item This is the first item in the list.
  \item This is the second item in the list.
\end{example}

This is more paragraph text. I don't want this indented, please.

Internal routines and switches of interest seem to be \@endpetrue, \@endparenv and others. Thanks for your help.

Answer

Ivan Andrus picture Ivan Andrus · Apr 30, 2010

I couldn't get anything to work without redefining \end, but I'm certainly no expert.

The following is quite hacky, but worked in my limited testing. Of course this will interfere with nested environments (you should be able to redefine \begin to restore the old \end if you have problems).

\newenvironment{example}{%
  \bgroup
  \let\oldend=\end
  \def\end##1{\oldend{##1}\csname @afterindentfalse\endcsname
                          \csname @afterheading\endcsname}
  \begin{list}{}
    {\setlength\leftmargin{2em}}
  }{%
  \end{list}
  \egroup
}