13

I'm trying to define an environment/command, with the following property: The immediate paragraph after the environment must not be indented. The following shows my attempt at defining such environment/command:

\makeatletter    
\newenvironment{NoIndEnv}{}{\par\@afterindentfalse\@afterheading}    
\newcommand{\NoIndCmd}[1]{#1 \par\@afterindentfalse\@afterheading}    
\makeatother

Now compare the following two:

\begin{NoIndEnv}
   Text ...
\end{NoIndEnv}

Some text ...

and

\NoIndCmd{Text ...}

Some text ...

For some reason, the environment definition works only if it is placed after a \section command; i.e.:

\section{}

\begin{NoIndEnv}
   Text ...
\end{NoIndEnv}

Some text ...

Could you please help me figure out what's wrong?

3
  • 1
    Simply ending it with \par\noindent doesn't work? Commented Jul 17, 2011 at 11:09
  • @Martin: Peculiarly, it does not work either! Commented Jul 17, 2011 at 11:25
  • Even for commands,\par\noindent can only work if there's no empty line (that means \par) afterward. Commented Sep 21, 2017 at 19:36

1 Answer 1

13

The problem is that \@afterindentfalse\@afterheading are done inside a group, in the environment case. Solution: do them after the group has ended.

\newenvironment{NoIndEnv}
  {}
  {\par\aftergroup\@afterindentfalse\aftergroup\@afterheading}
1
  • 1
    Thank you both for the question, and the answer: it is very useful and not that easy to find!
    – Jérémie
    Commented May 1, 2012 at 21:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .