1

From what I read I had thought that the package noindentafter would reliably get rid of any indent after an environment no matter if followed or not by an empty line, as suggested here. But consider this:

\documentclass{report}
\usepackage{lipsum}

\newenvironment{newenv}{}{%
%\ignorespacesafterend\noindent% << OPTION 2
} 
\usepackage{noindentafter}\NoIndentAfterEnv{newenv} % OPTION 1

\begin{document}

\begin{newenv} % First Sequence

\lipsum[6]

\end{newenv}

\lipsum[7-8]

\begin{newenv} % Second Sequence
\lipsum[6]
\end{newenv}
\lipsum[7-8]
\end{document}

Using noindentafter works for the first sequence, but not for the second where I have left no line after \end{newenv}. Now I've tried to not use the package and do it manually with what I've labeled option 2 above (outcommenting option 1). This works for the second scenario but not for the first. I have further tried to use both together (leaving both options uncommented), which gives the weird result that while in the second scenario it's fine, in the first scenario I now get the first and second paragraphs after the environment with no indent.

From the package documentation and this question and the ones referred to in there I couldn't figure out what could be wrong here. (Other than me leaving or not an empty line, but I am trying to find a stable solution since the particular environment I'm working on gets \input from other files where I can never be sure if they end or do not end with an empty line.)

jan
  • 2,236
  • Blank lines have a semantic value. Trying to modify it is bound to give you any sort of problem. – egreg Oct 23 '16 at 13:08
  • @egreg Hmm, but is there a way to make it behave differently whether or not there is an empty line after that particular enviroment? – jan Oct 23 '16 at 13:22
  • The code of noindentafter checks whether it is followed by a paragraph, which means it doesn't do anything if there is no empty line after the environment. You will have to patch \NoIndentAfterEnv to insert some \par if you want to change this. – Ulrike Fischer Oct 23 '16 at 13:29
  • @UlrikeFischer OK, I see, but if it checks whether it is followed by a paragraph, why do I get noindent in the second paragraph if I use both of the above options together? – jan Oct 23 '16 at 13:34
  • noindentafter redefines temporarly \par and restore it later, but as it doesn't insert a \par and so actually suppress one \par in the process and so the \noindent is used for the second paragraph. See also https://tex.stackexchange.com/questions/268532/why-does-noindentafter-package-cause-this-behavior/268537#268537 – Ulrike Fischer Oct 23 '16 at 13:55
  • @UlrikeFischer Hmm, I still don't seem to get it. The solution in the question you refer to still doesn't solve the second scenario. I've also tried putting a \par after the environment but to no avail. – jan Oct 23 '16 at 14:12
  • Note: the noindentafter package is broken with the latest latex version (may 2021), seems it has been broken since nov 2019. See this github issue and this SE TeX question for details and potential solutions. – Carl May 11 '21 at 18:19

1 Answers1

3

Assuming that you want always to start a new paragraph after your environment you could do this:

\documentclass{report}
\usepackage{lipsum}
\usepackage{noindentafter}

\newenvironment{newenv}{}{\par} %\par!
\NoIndentAfterEnv{newenv} 
\makeatletter
\appto\@noindent@newenv@hook{\par}{}{}
\makeatother
\begin{document}
normal indent

\begin{newenv} 

in env

\end{newenv}

after env \par after env

\begin{newenv} 
in env
\end{newenv}
after env \par after env
\end{document}

enter image description here

Ulrike Fischer
  • 327,261