I've been using a command to automatically place a number specially (on the baseline) if at the beginning of a new paragraph, and normally (as a superscript) otherwise. See \fooauto in the listing below. It uses ifvmode to test for the start of a paragraph. The code was aided by the Q&A here: how-can-a-macro-detect-if-its-at-a-paragraph-beginning.
Unfortunately, ifvmode isn't an adequate test for the case where text follows a {verse} environment. The ifvmode test returns true in that case whether or not the text starts a new paragraph.
How can I make the start-of-paragraph test better such that it handles this case?
(Note that the modifications to the {verse} environment are not necessary to show this problem, but illustrate the no-gap look used by Oxford Press that I'm trying to imitate.)
\documentclass{article}
\makeatletter
% Copied from article.cls: \topsep and \partopsep added:
\renewenvironment{verse}
{\let\\\@centercr
\list{}{\itemsep \z@
\topsep \z@% new
\partopsep 0.5\baselineskip% new
\itemindent -1.5em%
\listparindent\itemindent
\rightmargin \leftmargin
\advance\leftmargin 1.5em}%
\item\relax}
{\endlist}
\newcommand\footxt[1]{\textsuperscript{#1}} % used if not at start of paragraph
\newcommand\foopar[1]{#1\enspace} % used if atstart of paragraph
% See https://tex.stackexchange.com/questions/86143/
\newcommand*\fooauto[1]{%
\ifvmode% Current test for beginning of paragraph, fails after {verse} env
\foopar{#1}%
\expandafter@gobble%
\else%
\expandafter@firstofone
\fi%
{\footxt{#1}}}
\makeatother
\begin{document}
\fooauto{1}The fooauto{} command works correctly here at the
beginning of a new paragraph.
\fooauto{2}The fooauto{} command works correctly here when not at the
beginning of a new paragraph.
\begin{verse}
Start of verse\
End of verse.
\end{verse}
\fooauto{3}Start of new paragraph, ifvmode test works correctly.
\begin{verse}
Start of verse\
End of verse.
\end{verse}
\fooauto{4}Not the start of a new paragraph, ifvmode test in fooauto{} failed.
(But Latex somehow knew not to indent, so it knows that we're not
at the beginning of a paragraph.)
\end{document}


@endpepart of your package, or built into Latex? – dedded Nov 12 '22 at 12:17@endpeis in theLaTeXkernel. You could use a similar test in your own macro probably\if@endpe ...\else ... \fiLet me see if I can have a go for you. – David Purton Nov 12 '22 at 13:11