3

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:

Rendered output of above code

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.

Lupino
  • 2,772
  • 1
    Through some debugging (print out the value of everypar token list variable every time the code is executed, and every time it's set) I observe that after "everypar is set to nothing" the next time "value of everypar" is still nonempty, so I prefix \global to \everypar at both places and it fixes the issue... but I can't answer the question because I've no idea how \@doendpe works. – user202729 Jan 11 '23 at 08:36
  • 2
    your braces mean that the begin of the paragraph where everypar is executed is inside a group and so the doendpe-everypar can't do its magic to reset itself. – Ulrike Fischer Jan 11 '23 at 08:43
  • @UlrikeFischer "begin of the paragraph" meaning that there must be horizontal material? That's why empty braces have no effect since they don't cause a switch to h-mode and therefore don't "expand"(?) the \everypar, did i get that about right? – Lupino Jan 11 '23 at 09:01
  • 2
    yes. You could read ltpara-doc.pdf. It explains quite nicely what is going on at the begin of the paragraph. – Ulrike Fischer Jan 11 '23 at 09:03

1 Answers1

5

Your braces in case 4 with the text in it mean that the paragraph is started in a group. In this group \everypar is executed and it does reset itself but only locally, and so after the group the "doendpe-everypar" magic to reset itself is lost again.

You could use a para hook instead:

\documentclass{article}
\parindent8mm
\author{}
\title{}

\newenvironment{mylist} {\list{}{% \leftmargin0pt \parindent0pt \bfseries\sffamily }\item\relax} {\endlist\AddToHookNext{para/begin}{\OmitIndent}}

\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}

enter image description here

Ulrike Fischer
  • 327,261
  • It should be noted that this requires a rather recent verison of LaTeX. In TL2019, this doesn't work (Undefined control sequence \AddToHookNext). – Lupino Jan 11 '23 at 09:06
  • yes, the hook management in general and especially the para hooks are a recent addition and one of the reasons why it can pay off to invest some time and effort to update (and keep up-to-date) your tex system. See also https://tex.stackexchange.com/q/670578/2388 – Ulrike Fischer Jan 11 '23 at 09:12
  • Although I now understand what the issue is from your and user202729's comments under the OP, would you mind to add a few lines on what exactly went wrong (question (1)) so I can flag your answer as "accepted"? – Lupino Jan 12 '23 at 08:42