Reliably trapping end of paragraph / return to vertical mode

Taylor, P P.Taylor at rhul.ac.uk
Wed Oct 2 09:08:28 CEST 2019


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 entry 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.

Philip Taylor
--------
\count 0 = 0

\everypar = {\advance \count 0 by 1 }

\def \par {\primitive \par \message {para.\string ~\the \count 0: \string \prevgraf = \the \prevgraf;}}

\leavevmode \par

\leavevmode \vskip 0 pt

\leavevmode \endgraf

\leavevmode % only this line is followed by a blank line


\end

->


( para.~1: \prevgraf= 1; para.~2: \prevgraf= 1; para.~4: \prevgraf= 1; [4] )


i.e., no \prevgraf report for para.~3, the paragraph terminated by \endgraf.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/texhax/attachments/20191002/df9674b4/attachment.html>


More information about the texhax mailing list