2

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}

output

dedded
  • 2,236

1 Answers1

1

Update using supplied MWE

This uses the same logic as below, but just modifies your fooauto macro:

\newif\ifusefoopar
\newcommand*\fooauto[1]{%
  \if@endpe
    \usefooparfalse
  \else
    \usefoopartrue
  \fi
  \ifvmode
  \else
    \usefooparfalse
  \fi
  \ifusefoopar
    \foopar{#1}%
    \expandafter\@gobble%
  \else%
    \expandafter\@firstofone
  \fi%
  {\footxt{#1}}}

Old answer

Although not explicit, it looks a bit like you are trying to typeset a section of the Bible as some Bibles print verses in this way.

I plan to include this kind of feature into my scripture package, but haven't done so yet.

However, it may be possible to sufficiently hack it in now depending on the complexity of your requirements.

In the following solution, I have not attempted to make the beginning of paragraphs within poetry sections. I'm also not 100% sure of the @endpe test, but it seems to work.

\documentclass{article}
\usepackage{scripture}
\scripturesetup{
  poetry/indent=0pt
}
\usepackage{xpatch}
\ExplSyntaxOn
\bool_new:N \g__dedded_at_para_start_bool
\xpretocmd { \__scripture_verse_output:n }
  {
    \legacy_if:nTF { @endpe }
      { \bool_gset_false:N \g__dedded_at_para_start_bool }
      { \bool_gset_true:N \g__dedded_at_para_start_bool }
    \mode_if_vertical:F
      { \bool_gset_false:N \g__dedded_at_para_start_bool }
  }
  { }
  { }
\AddToHook { scripture/verse/before }
  {
    \bool_if:NF \l__scripture_active_inner_bool
      {
        \bool_if:NT \g__dedded_at_para_start_bool
          {
            \cs_set:Nn \__scripture_verse_format:n { \textbf{ #1 } \enspace }
          }
      }
    \bool_gset_false:N \g__dedded_at_para_start_bool
  }
\ExplSyntaxOff
\begin{document}
\begin{scripture}
  \vs{1}This is the start of a paragraph. \vs{2}This is not the start of a
  paragraph. \vs{3}This is not the start of a paragraph.
  \begin{poetry}
    Start of verse
    End of verse.
  \end{poetry}

\vs{4}This is the start of a paragraph. \vs{5}This is not the start of a paragraph. \vs{6}This is not the start of a paragraph. \begin{poetry} Start of verse End of verse. \end{poetry} \vs{7}This is not the start of a paragraph. \vs{8}This is not the start of a paragraph. \vs{9}This is not the start of a paragraph.

This is the start of a paragraph. \vs{10}This is not the start of a paragraph. \vs{11}This is not the start of a paragraph. \end{scripture} \end{document}

output

David Purton
  • 25,884
  • Thanks. But it doesn't look like I can take the whole package. Is this @endpe part of your package, or built into Latex? – dedded Nov 12 '22 at 12:17
  • @dedded @endpe is in the LaTeX kernel. You could use a similar test in your own macro probably \if@endpe ...\else ... \fi Let me see if I can have a go for you. – David Purton Nov 12 '22 at 13:11
  • @dedded, how's that? – David Purton Nov 12 '22 at 13:19
  • This works in the MWE and in a non-trivial real case. Thanks. (Clearly I don't know how to make the @-thing work for people who display Firstname Lastname.) – dedded Nov 13 '22 at 00:45