<div dir="ltr"><div>basically Phil you are doomed (unless you are tempted to try luatex which has more possibilities)</div><div><br></div><div>you mention paragraphs ending with \par, \endgraf, a blank line or \vskip.</div><div><br></div><div>blank lines and vskip are Ok really as they cause the \par token to be inserted, so if you have hooked some code into \par that will run.</div><div><br></div><div>\endgraf or other commands let to the primitive are Ok if you give yourself access to the format early enough that you know that no one has taken  control.</div><div><br></div><div>But there are two cases that you really can't easily  trap.</div><div><br></div><div>In classic tex you can end a paragraph by ending a vbox, that does not insert a \par token: it just directly ends the paragraph with no macro-layer hook at all.</div><div><br></div><div>In pdftex (and xetex) a paragraph can be ended with \primitive\par which is again pretty tricky to catch without breaking other uses of \primitive.</div><div><br></div><div>partial paragraphs ended with $$ also make things interesting.<br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 2 Oct 2019 at 08:10, Taylor, P <<a href="mailto:P.Taylor@rhul.ac.uk">P.Taylor@rhul.ac.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



<div bgcolor="#FFFFFF">
While working on the most recent iteration of my code for floating image insertion, I encountered a situation in which I was unable to determine the correct value of \prevgraf.  It transpired that this was because the previous paragraph had been terminated
 (via a macro) by \endgraf rather than with a blank line, explicit \par or \vskip.  Although Knuth provides \everypar, which can be reliably used to trap
<i>entry </i>to a paragraph, there does not appear (to me, at least) to be any 100% reliable method of trapping exit therefrom, and of course once the next paragraph has been entered, the previous (and desired) value of \prevgraf has been lost.  I wonder if
 anyone has successfully addressed this problem, and found a reliable way of trapping paragraph exits, or equivalently, returns to vertical mode.  Re-defining \endgraf solves the trivial case, but of course one can never know what other synonyms for the primitive
 \par might have been created before one's own code is entered.<br>
<br>
<i>Philip Taylor</i><br>
--------<br>
\count 0 = 0
<p style="margin:0px;text-indent:0px">
\everypar = {\advance \count 0 by 1 }</p>
<p style="margin:0px;text-indent:0px">
\def \par {\primitive \par \message {para.\string ~\the \count 0: \string \prevgraf = \the \prevgraf;}}</p>
<p style="margin:0px;text-indent:0px">
\leavevmode \par</p>
<p style="margin:0px;text-indent:0px">
\leavevmode \vskip 0 pt</p>
<p style="margin:0px;text-indent:0px">
\leavevmode \endgraf</p>
<p style="margin:0px;text-indent:0px">
\leavevmode % only this line is followed by a blank line<br>
<br>
</p>
<p style="margin:0px;text-indent:0px">
\end<br>
</p>
<p style="margin:0px;text-indent:0px">
<br>
-> <br>
</p>
<br>
<p style="margin:0px;text-indent:0px">
( para.~1: \prevgraf= 1; para.~2: \prevgraf= 1; para.~4: \prevgraf= 1; [4] )</p>
<br>
<p style="margin:0px;text-indent:0px">
i.e., no \prevgraf report for para.~3, the paragraph terminated by \endgraf.<br>
</p>
</div>

</blockquote></div>