At the end of a custom pseudo-list environment, I re-define \@doendpe to prevent indents in the paragraphs immediately following the environment, regardless on whether there is a blank line after the \end{env} (1st case) or not (2nd case). This works fine for most use cases (1st through 3rd cases).
However, if there is a non-empty pair of curly brackets at the beginning of the paragraph immediately following the environment, the no-indent spreads to the next paragraph as well (4th case). If the group is empty, it works as expected (5th case):
\documentclass{article}
\parindent8mm
\author{}
\title{}
\makeatletter
\let\orig@doendpe@doendpe
\newenvironment{mylist}
{\list{}{%
\leftmargin0pt
\parindent0pt
\bfseries\sffamily
}\item\relax}
{\endlist
\gdef@doendpe{%
@endpetrue
\everypar{{\setbox\z@\lastbox}\everypar{}@endpefalse}%
\global\let@doendpe\orig@doendpe}%
}
\makeatother
\begin{document}
\begin{mylist}
1st case
\end{mylist}
test test test
test test test
test test test
\begin{mylist}
2nd case
\end{mylist}
test test test
test test test
test test test
\begin{mylist}
3rd case
\end{mylist}
[test test test]
test test test
test test test
\begin{mylist}
4th case
\end{mylist}
{[}test test test{]}
test test test
test test test
\begin{mylist}
5th case
\end{mylist}
{}test test test
test test test
test test test
\end{document}
Output:
I'd like to know (1), why this solution breaks when there is a non-empty pair of brackets immediately after the \end (and why it doesn't break when the brackets are empty) and (2), what would I need to change in the definition of the environment to make it work with all five use cases.


\globalto\everyparat both places and it fixes the issue... but I can't answer the question because I've no idea how\@doendpeworks. – user202729 Jan 11 '23 at 08:36\everypar, did i get that about right? – Lupino Jan 11 '23 at 09:01