% \iffalse meta-comment
%
% Copyright (c) 2022-2023 David Purton <dcpurton@marshwiggle.net>
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, either version 1.3c of this license
% or (at your option) any later version. The latest version of this
% license is in
%    http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
%<*driver>
\DocumentMetadata{}
\documentclass[a4paper]{l3doc}
\usepackage[parindent=1em]{scripture}
\usepackage[skins]{tcolorbox}
\newtcolorbox{scriptureexample}[1][]{%
  bicolor, colframe=cyan, colback=cyan!10, colbacklower=white, left=2mm,
  fonttitle=\normalsize\sffamily\bfseries,
  subtitle style={before skip=3mm, after skip=3mm},
  right=2mm, fontupper=\footnotesize, fontlower=\footnotesize, sidebyside,
  sidebyside gap=6mm, sidebyside align=top, lefthand ratio=0.6, before
  skip=\bigskipamount, after skip=\bigskipamount, #1
}
\tcbset{%
  sidebysidecompare/.style={%
    enhanced, colback=white, lefthand ratio=0.5, segmentation empty},
  compare/.style={%
    standard, colback=white, sidebyside=false}
}
\ExplSyntaxOn
\makeatletter
\cs_new_protected:Npn \__dcp_codedoc_environment_index:n #1
  {
    \@bsphack
    \begingroup
      \__codedoc_target:
      \index
        {
          #1\actualchar{\protect\ttfamily#1}~(environment)
          \encapchar hdclindex{\the\c@HD@hypercount}{usage}
        }
      \index
        {
          environments:\levelchar#1\actualchar{\protect\ttfamily#1}
          \encapchar hdclindex{\the\c@HD@hypercount}{usage}
        }
    \endgroup
    \@esphack
  }
\cs_new_protected:Npn \__dcp_codedoc_envmacro_index:nN #1#2
  {
    \DoNotIndex {#1}
    \bool_if:NT #2
      {
        \__codedoc_if_macro_internal:nF {#1}
          { \seq_gput_right:Nn \g_doc_macros_seq {#1} }
        \hbox_set:Nw \l__codedoc_macro_index_box
          \hbox_unpack_drop:N \l__codedoc_macro_index_box
          \int_gincr:N \c@CodelineNo
          \@bsphack
          \begingroup
            \__codedoc_target:
            \index
              {
                #1\actualchar{\protect\ttfamily#1}~(environment)
                \encapchar hdclindex{\the\c@HD@hypercount}{main}
              }
            \index
              {
                environments:\levelchar#1\actualchar{\protect\ttfamily#1}
                \encapchar hdclindex{\the\c@HD@hypercount}{main}
              }
          \endgroup
          \@esphack
          \int_gdecr:N \c@CodelineNo
        \exp_args:NNNo \hbox_set_end:
          \tl_set:Nn \saved@indexname { \l__codedoc_index_key_tl }
      }
  }
\cs_new_protected:Npn \__dcp_codedoc_hook_index:n #1
  {
    \@bsphack
    \begingroup
      \__codedoc_target:
      \index
        {
          #1\actualchar{\protect\ttfamily#1}~(hook)
          \encapchar hdclindex{\the\c@HD@hypercount}{usage}
        }
      \index
        {
          hooks:\levelchar#1\actualchar{\protect\ttfamily#1}
          \encapchar hdclindex{\the\c@HD@hypercount}{usage}
        }
    \endgroup
    \@esphack
  }
\cs_new_protected:Npn \__dcp_codedoc_hookmacro_index:nN #1#2
  {
    \DoNotIndex {#1}
    \bool_if:NT #2
      {
        \__codedoc_if_macro_internal:nF {#1}
          { \seq_gput_right:Nn \g_doc_macros_seq {#1} }
        \hbox_set:Nw \l__codedoc_macro_index_box
          \hbox_unpack_drop:N \l__codedoc_macro_index_box
          \int_gincr:N \c@CodelineNo
          \@bsphack
          \begingroup
            \__codedoc_target:
            \index
              {
                #1\actualchar{\protect\ttfamily#1}~(hook)
                \encapchar hdclindex{\the\c@HD@hypercount}{main}
              }
            \index
              {
                hooks:\levelchar#1\actualchar{\protect\ttfamily#1}
                \encapchar hdclindex{\the\c@HD@hypercount}{main}
              }
          \endgroup
          \@esphack
          \int_gdecr:N \c@CodelineNo
        \exp_args:NNNo \hbox_set_end:
          \tl_set:Nn \saved@indexname { \l__codedoc_index_key_tl }
      }
  }
\DeclareDocumentEnvironment { environment } { O{} +v }
  {
    \cs_set_eq:NN \__codedoc_function_index:n \__dcp_codedoc_environment_index:n
    \__codedoc_function:nnw {#1} {#2}
  }
  { \__codedoc_function_end: }
\DeclareDocumentEnvironment { hooks } { O{} +v }
  {
    \bool_if:NTF \l__codedoc_in_implementation_bool
      {
        \cs_set_eq:NN \__codedoc_macro_index:nN \__dcp_codedoc_hookmacro_index:nN
        \__codedoc_macro:nnw { var , #1 } {#2}
      }
      {
        \cs_set_eq:NN \__codedoc_function_index:n \__dcp_codedoc_hook_index:n
        \__codedoc_function:nnw {#1} {#2}
      }
  }
  {
    \bool_if:NTF \l__codedoc_in_implementation_bool
      { \__codedoc_macro_end: }
      { \__codedoc_function_end: }
  }
\DeclareDocumentEnvironment { option } { O{} +v }
  {
    \cs_set_eq:NN \__codedoc_function_index:n \SpecialOptionIndex
    \__codedoc_function:nnw {#1} {#2}
  }
  { \__codedoc_function_end: }
\DeclareDocumentEnvironment { envmacro } { O{} +v }
  {
    \cs_set_eq:NN \__codedoc_macro_index:nN \__dcp_codedoc_envmacro_index:nN
    \__codedoc_macro:nnw {#1} {#2}
  }
  { \__codedoc_macro_end: }
\DeclareDocumentCommand \opt { m }
  {
    \SpecialOptionIndex {#1}
    \texttt{#1}
  }
\DeclareDocumentCommand \hook { m }
  {
    \__dcp_codedoc_hook_index:n {#1}
    \texttt {#1}
  }
\DeclareRobustCommand \val {\texttt}
\makeatother
\ExplSyntaxOff
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \changes{v1.0}{2022/07/27}{First public release}
% \changes{v1.1}{2022/08/27}{Bug fixes}
% \changes{v1.2}{2022/11/02}{Bug fixes}
% \changes{v1.3}{2023/01/08}{Bug fixes}
%
% \title{The \pkg{scripture} package}
% \author{David Purton\thanks{Email: \url{dcpurton@marshwiggle.net}}}
% \date{2023/01/08 v1.3}
%
% \maketitle
%
% \begin{abstract}
%   The \pkg{scripture} package provides a set of macros for typesetting
%   quotations from the Bible. It provides many features commonly seen in
%   Bibles such as dropped text for chapter numbers, superscripts for verse
%   numbers, indented lines for poetry sections, narrow sections and hanging
%   paragraphs. A reference for the quotation can optionally be added.
% \end{abstract}
%
% \tableofcontents
%
% \begin{documentation}
%
% \section{Introduction}
%
% Bibles tend to use a number of standard features when laying out chapters
% and verses. The main goal for the \pkg{scripture} package is to be able to
% quickly and easily input text and have it output nicely with minimal manual
% adjustment.
%
% The package supports dropped text for chapter numbers, superscripts for
% verse numbers, appropriately indented lines for the first and second halves
% of poetry, flush right sections, centred sections, narrow sections and
% hanging sections.
%
% The package could be used for typesetting an entire Bible, but it is mainly
% envisioned that it will be used for producing Scripture quotations. The
% passage reference can be included on the last line if there is space or
% failing that on the following line.
%
% \subsection{Bug reports and feature requests}
%
% Bug reports and feature requests can be made at the \pkg{scripture} package
% GitHub repository. See \url{https://github.com/dcpurton/scripture}.
%
% \subsection{Limitations}
%
% The \pkg{scripture} package makes extensive use of \LaTeX{} \env{list}
% environments and the \cs{parshape} command. This means there are some
% limitations. In particular, you should not:
% \begin{itemize}
%   \item Nest the \env{scripture} environment or any of its internal
%     environments.
%   \item Modify the \cs{parshape} within a \env{scripture} environment.
%   \item Include any other \env{list} based environment within a
%     \env{scripture} environment.
% \end{itemize}
%
% The \env{poetry} environment uses \cs{obeylines}. This means that it can not
% be placed in the argument of a macro.
%
% Some attempt is made to encourage appropriate page breaks, especially just
% before a reference is added to a quotation, but this can still sometimes
% fail and a reference will end up on the following page. Usually a little
% more stretchable space on the page before the incorrect break is enough to
% obtain acceptable output.
%
% At least version 2022-06-01 of the \LaTeX\ format is required.
%  
% \section{Documentation}
%
% \subsection{Basic usage}
%
% Scripture quotations must be set within a \env{scripture} environment. A
% simple quotation might be produced as follows:
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[Isaiah 56:1--2][version=NIVUK]
%   \ch{56}This is what the \name{Lord} says:
%   \begin{poetry}
%     `Maintain justice
%     and do what is right,
% 
%     for my salvation is close at hand
%     and my righteousness will soon be revealed.
% 
%     \vs{2}Blessed is the one who does this---
%     the person who holds it fast,
% 
%     who keeps the Sabbath without desecrating it,
%     and keeps their hands from doing any evil.'
%   \end{poetry}
% \end{scripture}
% \end{verbatim}
%
% \tcblower
% 
% \begin{scripture}[Isaiah 56:1--2][version=NIVUK]
%   \ch{56}This is what the \name{Lord} says:
%   \begin{poetry}
%     `Maintain justice
%     and do what is right,
% 
%     for my salvation is close at hand
%     and my righteousness will soon be revealed.
% 
%     \vs{2}Blessed is the one who does this---
%     the person who holds it fast,
% 
%     who keeps the Sabbath without desecrating it,
%     and keeps their hands from doing any evil.'
%   \end{poetry}
% \end{scripture}
% \end{scriptureexample}
%
% \subsection{Macros for typesetting scripture quotations}
%
% \subsubsection{Functions}
%
% \begin{function}{\ch, \ch*}
%   \begin{syntax}
%     |\ch|\marg{chapter number}
%     |\ch*|\marg{chapter number}
%   \end{syntax}
%   Format a chapter number. By default these are formatted using drop text
%   taking up two lines and the text is separated from the chapter number by a
%   horizontal space of 0.5\,em.
%
%   If the \opt{dropchap} option is \val{true} (default), then this function
%   attempts to add sufficient space for the dropped chapter when its
%   paragraph contains only one line. The starred version suppresses this
%   behaviour.
% \end{function}
%
% \begin{scriptureexample}[lefthand ratio=0.55]
% \textbf{\sffamily|\cs{ch}| example}
%
% \begin{verbatim}
% \begin{scripture}[Exodus 20:1--2]
%   \ch{20}And God spoke all these words:
%   \begin{hanging}
%     \noindent\vs{2}`I am the \name{Lord}
%     your God, who brought you out of Egypt,
%     out of the land of slavery.
%   \end{hanging}
% \end{scripture}
% \end{verbatim}
%
% \medskip
%
% \textbf{\sffamily|\cs{ch*}| example}
%
% \begin{verbatim}
% \begin{scripture}[Exodus 20:1--2]
%   \ch*{20}And God spoke all these words:
%   \begin{hanging}
%     \nohang\vs{2}`I am the \name{Lord} your
%     God, who brought you out of Egypt, out of
%     the land of slavery.
%   \end{hanging}
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \textbf{\sffamily|\cs{ch}| example}
%
% \medskip
%
% \begin{scripture}[Exodus 20:1--2]
%   \ch{20}And God spoke all these words:
%   \begin{hanging}
%     \noindent\vs{2}`I am the \name{Lord}
%     your God, who brought you out of Egypt,
%     out of the land of slavery.
%   \end{hanging}
% \end{scripture}
%
% \bigskip
%
% \textbf{\sffamily|\cs{ch*}| example}
%
% \medskip
%
% \begin{scripture}[Exodus 20:1--2]
%   \ch*{20}And God spoke all these words:
%   \begin{hanging}
%     \nohang\vs{2}`I am the \name{Lord} your
%     God, who brought you out of Egypt, out of
%     the land of slavery.
%   \end{hanging}
% \end{scripture}
% \end{scriptureexample}
%
% \begin{function}{\extraskip}
%   \begin{syntax}
%     |\extraskip|
%   \end{syntax}
%   Add a small vertical space of \opt{extraskip} between a paragraph. This
%   function attempts to add additional space to avoid a clash with a drop
%   chapter if required.
% \end{function}
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[Colossians 1:2]
%   \vs{2}To God's holy people in Colossae, the
%   faithful brothers and sisters in Christ:
%
%   \extraskip
%
%   Grace and peace to you from God our Father.
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \begin{scripture}[Colossians 1:2]
%   \vs{2}To God's holy people in Colossae, the
%   faithful brothers and sisters in Christ:
%
%   \extraskip
%
%   Grace and peace to you from God our Father.
% \end{scripture}
% \end{scriptureexample}
%
% \changes{v1.3}{2022/11/15}{Add feature to highlight translator added words}
% \begin{function}[added=2022-11-15]{\added}
%   \begin{syntax}
%     |\added|\marg{words}
%   \end{syntax}
%   Some Bible translations mark out words added for clarity not found in the
%   original language (e.g., in italics). This can be done using the \cs{added}
%   function. The font and format can be set using the \opt{added/font} and
%   \opt{added/format} options.
% \end{function}
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[John 1:18][verse/font=\bfseries,
%     verse/format=#1, verse/sep=0.5em, version=KJV]
%   \vs{18}No man hath seen God at any time, the
%   only begotten Son, which is in the bosom of the
%   Father, he hath declared \added{him}.
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \begin{scripture}[John 1:18][verse/font=\bfseries,
%     verse/format=#1, verse/sep=0.5em, version=KJV]
%   \vs{18}No man hath seen God at any time, the
%   only begotten Son, which is in the bosom of the
%   Father, he hath declared \added{him}.
% \end{scripture}
% \end{scriptureexample}
%
% \changes{v1.2}{2022/09/01}{Add divine name feature}
% \begin{function}[added=2022-09-01]{\name, \LORD, \GOD}
%   \begin{syntax}
%     |\name|\marg{divine name}
%     |\LORD|
%     |\GOD|
%   \end{syntax}
%   Modern Bible translations frequently represent God's personal divine name
%   using a small capitals typeface. This can be done using the \cs{name}
%   function. The font and format can be set using the \opt{name/font} and
%   \opt{name/format} options. The \cs{LORD} and \cs{GOD} macros equivalent to
%   \cs{name}|{Lord}| and \cs{name}|{God}| respectively.
%
%   \textbf{Note:} Watch out that trailing spaces are not eaten by \cs{LORD}
%   and \cs{GOD}. Using \cs{name} is safer and semantically better.
% \end{function}
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[Genesis 15:1--2][version=ESV]
%   \ch{15}After these things the word of the
%   \name{Lord} came to Abram in a vision: ``Fear
%   not, Abram, I am your shield; your reward shall
%   be very great.'' \vs{2}But Abram said, ``O Lord
%   \name{God}, what will you give me, for I
%   continue childless, and the heir of my house is
%   Eliezer of Damascus?''
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \begin{scripture}[Genesis 15:1--2][version=ESV]
%   \ch{15}After these things the word of the
%   \name{Lord} came to Abram in a vision: ``Fear
%   not, Abram, I am your shield; your reward shall
%   be very great.'' \vs{2}But Abram said, ``O Lord
%   \name{God}, what will you give me, for I
%   continue childless, and the heir of my house is
%   Eliezer of Damascus?''
% \end{scripture}
% \end{scriptureexample}
%
% \changes{v1.3}{2022/11/13}{Add \cs{nofirstverse} function}
% \begin{function}[added=2022-11-13]{\nofirstverse}
%   \begin{syntax}
%     |\nofirstverse|
%   \end{syntax}
%   When \opt{verse/first} is |true|, this causes the next \cs{vs} to print
%   normally, rather than using the format specified by
%   \opt{verse/firstformat}. You might do this if your quote begins half way
%   through a paragraph and the first verse should be printed normally.
% \end{function}
%
% \begin{function}{\nohang}
%   \begin{syntax}
%     |\nohang|
%   \end{syntax}
%   In a \env{hanging} environment, this function indents the first line of
%   the paragraph a length of \opt{hanging/hang} $+$ \opt{parindent}.
%   Remaining lines continue to be indented by a length of \opt{hanging/hang}.
% \end{function}
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[Genesis 1:10--11]
%   \begin{hanging}
%     \noindent\vs{10}God called the dry ground
%     `land', and the gathered waters he called
%     `seas'. And God saw that it was good.
%
%     \nohang\vs{11}Then God said, `Let the land
%     produce vegetation: seed-bearing plants and
%     trees on the land that bear fruit with seed
%     in it, according to their various kinds.'
%     And it was so.
%   \end{hanging}
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \begin{scripture}[Genesis 1:10--11]
%   \begin{hanging}
%     \noindent\vs{10}God called the dry ground
%     `land', and the gathered waters he called
%     `seas'. And God saw that it was good.
%
%     \nohang\vs{11}Then God said, `Let the land
%     produce vegetation: seed-bearing plants and
%     trees on the land that bear fruit with seed
%     in it, according to their various kinds.'
%     And it was so.
%   \end{hanging}
% \end{scripture}
% \end{scriptureexample}
%
% \changes{v1.2}{2022/08/31}{Add red letter feature}
% \begin{function}[added=2022-08-31]{\redletteron, \redletteroff}
%   \begin{syntax}
%     |\redletteron|
%     |\redletteroff|
%   \end{syntax}
%   Use \cs{redletteron} and \cs{redletteroff} to mark the beginning and end
%   of sections of text that should be attributed to Jesus speaking. Some
%   attempt is made to ensure that the correct colour continues after an inner
%   environment if \cs{redletteron} or \cs{redletteroff} occurs inside the
%   inner environment. If you experience problems with unexpected colour, try
%   to ensure that matching \cs{redletteron} and \cs{redletteroff} marks occur
%   at the same group level. The colour of the text can be set using the
%   \opt{redletter/colour} option. These commands only have an effect when the
%   \opt{redletter} option is \val{true}.
% \end{function}
%
% \begin{scriptureexample}[lefthand ratio=0.67]
% \begin{verbatim}
% \begin{scripture}[Matthew 21:16--17][redletter]
%   \vs{16}`Do you hear what these children are saying?'
%   they asked him.
%
%   \redletteron `Yes,' \redletteroff replied Jesus,
%   \redletteron `have you
%   never read,
%   \begin{poetry}
%     `\thinspace ``From the lips of children and infants
%     you, Lord, have called forth your praise''?'
%   \end{poetry}\redletteroff
%
%   \vs{17}And he left them and went out of the city to
%   Bethany, where he spent the night.
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \begin{scripture}[Matthew 21:16--17][redletter]
%   \vs{16}`Do you hear what these children are saying?'
%   they asked him.
%
%   \redletteron `Yes,' \redletteroff replied Jesus,
%   \redletteron `have you
%   never read,
%   \begin{poetry}
%     `\thinspace ``From the lips of children and infants
%     you, Lord, have called forth your praise''?'
%   \end{poetry}\redletteroff
%
%   \vs{17}And he left them and went out of the city to
%   Bethany, where he spent the night.
% \end{scripture}
% \end{scriptureexample}
%
% \begin{function}{\scripturesetup}
%   \begin{syntax}
%     |\scripturesetup|\marg{options}
%   \end{syntax}
%   Set default format for quotations. See section \ref{options} for
%   supported formatting \meta{|options|}.
% \end{function}
%
% \changes{v1.1}{2022/08/07}{Add \cs{scripturecurrentchapter} and
% \cs{scripturecurrentverse} variables}
% \begin{function}[added=2022-08-07]{\scripturecurrentchapter,
% \scripturecurrentverse}
%   \begin{syntax}
%     |\scripturecurrentchapter|
%     |\scripturecurrentverse|
%   \end{syntax}
%   \cs{scripturecurrentcapter} and \cs{scripturecurrentverse} globally hold
%   the most recent values parsed to \cs{ch} and \cs{vs}. They can initialised
%   with \cs{renewcommand*} if required and could be used in hooks, for
%   example.
% \end{function}
%
% \changes{v1.1}{2022/07/29}{Add \cs{selah} function}
% \begin{function}[added=2022-07-29]{\selah}
%   \begin{syntax}
%     |\selah|
%   \end{syntax}
%   In a \env{poetry} environment, this function inserts \emph{Selah} at the
%   end of the current line or the end of the following line if there is
%   insufficient room. See options \opt{selah/font}, \opt{selah/format},
%   \opt{selah/sep} and \opt{selah/text} for options controlling the output.
% \end{function}
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[Psalm 3:2][version=NIV84]
%   \begin{poetry}
%     \vs{2}Many are saying of me,
%     ``God will not deliver him.''\selah
%   \end{poetry}
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \begin{scripture}[Psalm 3:2][version=NIV84]
%   \begin{poetry}
%     \vs{2}Many are saying of me,
%     ``God will not deliver him.''\selah
%   \end{poetry}
% \end{scripture}
% \end{scriptureexample}
%
% \begin{function}{\scripturesetup}
%   \begin{syntax}
%     |\scripturesetup|\marg{options}
%   \end{syntax}
%   Set default format for quotations. See section \ref{options} for
%   supported formatting \meta{|options|}.
% \end{function}
%
% \changes{v1.2}{2022/08/30}{Add \cs{textright} function}
% \begin{function}[added=2022-08-30]{\textright}
%   \begin{syntax}
%     |\textright|\marg{text}
%   \end{syntax}
%   This function inserts \meta{|text|} at the end of the current line or the
%   end of the following line if there is insufficient room. The
%   \opt{textright/sep} option controls the minimum allowed space before the
%   \meta{|text|} to be right aligned.
% \end{function}
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[Jeremiah 2:29]
%   \begin{poetry}
%     \vs{5}`Why do you bring charges against me?
%     You have all rebelled against me,'
%     \textright{declares the \name{Lord}.}
%   \end{poetry}
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \begin{scripture}[Jeremiah 2:29]
%   \begin{poetry}
%     \vs{5}`Why do you bring charges against me?
%     You have all rebelled against me,'
%     \textright{declares the \name{Lord}.}
%   \end{poetry}
% \end{scripture}
% \end{scriptureexample}
%
% \changes{v1.3}{2023/01/07}{Add \cs{textscripture} function}
% \begin{function}[added=2023-01-07]{\textscripture}
%   \begin{syntax}
%     |\textscripture|\oarg{reference}\oarg{options}\marg{quotation}
%   \end{syntax}
%   \cs{textscripture} sets an inline scripture quotation. The quotation is
%   surrounded be the values of \opt{inline/begin} and \opt{inline/end} which
%   default to |``\,| and |\,''|, respectively. This function also changes the
%   defaults of some options as follows:
%   \begin{itemize}
%     \item \opt{compact} is set
%     \item \opt{reference/align} is set to |inline|
%     \item \opt{reference/sep} is set to |0.5em|
%     \item \opt{reference/format} is set to |(#1)|
%     \item \opt{version/format} is set to |#1|
%   \end{itemize}
%
%   This function is equivalent to using the \env{scripture} environment with
%   the \opt{inline} option.
%
%   \textbf{Warning:} \cs{par} is redefined to \cs{relax} inside the
%   \cs{textscripture} function. If you have anything other than expected
%   macros and environments inside your \cs{textscripture} function \TeX{}
%   will likely get stuck in an infinite loop.
% \end{function}
%
% \begin{scriptureexample}
% \begin{verbatim}
% A famous verse in the Bible is:
% \textscripture[John 3:16][verse/hide]{\vs{16}For
% God so loved the world that he gave his one and
% only Son, that whoever believes in him shall not
% perish but have eternal life.}.
% \end{verbatim}
%
% \tcblower
%
% A famous verse in the Bible is:
% \textscripture[John 3:16][verse/hide]{\vs{16}For
% God so loved the world that he gave his one and
% only Son, that whoever believes in him shall not
% perish but have eternal life.}.
% \end{scriptureexample}
%
% \begin{function}{\vs}
%   \begin{syntax}
%     |\vs|\marg{verse number}
%   \end{syntax}
%   Format a verse number. By default these are formatted using a superscript.
% \end{function}
%
% \subsubsection{Environments}
% 
% All scripture quotations must be set within a \env{scripture} environment.
% The rest of the environments documented below are only defined with the
% \env{scripture} environment. In most cases there is a default small
% \meta{\opt{aboveskip}} and \meta{\opt{belowskip}} inserted above and below
% these internal environments, but these are ignored if the environment is at
% the start or end of a \env{scripture} environment.
%
% \begin{environment}{center}
%   \begin{syntax}
%     |\begin{center}|\oarg{options}
%       \quad\meta{centred text}
%     |\end{center}|
%   \end{syntax}
% \end{environment}
%
% \noindent Environment for typesetting centred sections of scripture
% quotations.
%
% See section \ref{centeroptions} for supported formatting \meta{|options|}.
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[Daniel 5:25]
%   \vs{25}`This is the inscription that was
%   written:
%   \begin{center}
%     \textsc{mene, mene, tekel, parsin}
%   \end{center}
% \end{scripture}
% \end{verbatim}
%
% \tcblower
% 
% \begin{scripture}[Daniel 5:25]
%   \vs{25}`This is the inscription that was
%   written:
%   \begin{center}
%     \textsc{mene, mene, tekel, parsin}
%   \end{center}
% \end{scripture}
% \end{scriptureexample}
%
% \begin{environment}{flushright}
%   \begin{syntax}
%     |\begin{flushright}|\oarg{options}
%       \quad\meta{right aligned text}
%     |\end{flushright}|
%   \end{syntax}
% \end{environment}
%
% \noindent Environment for typesetting right aligned sections of scripture
% quotations.
%
% See section \ref{flushrightoptions} for supported formatting
% \meta{|options|}.
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[Isaiah 40:5]
%   \begin{poetry}[belowskip = 0pt]
%     \vs{5}And the glory of the \name{Lord}\ldots
%     and all people will see it together.
%   \end{poetry}
%
%   \begin{flushright}[aboveskip = 0pt]
%     For the mouth of the \name{Lord} \\
%     has spoken.'
%   \end{flushright}
% \end{scripture}
% \end{verbatim}
%
% \tcblower
% 
% \begin{scripture}[Isaiah 40:5]
%   \begin{poetry}[belowskip = 0pt]
%     \vs{5}And the glory of the \name{Lord}\ldots
%     and all people will see it together.
%   \end{poetry}
%
%   \begin{flushright}[aboveskip = 0pt]
%     For the mouth of the \name{Lord} \\
%     has spoken.'
%   \end{flushright}
% \end{scripture}
% \end{scriptureexample}
%
% \begin{environment}{hanging}
%   \begin{syntax}
%     |\begin{hanging}|\oarg{options}
%       \quad\meta{hanging text}
%     |\end{hanging}|
%   \end{syntax}
% \end{environment}
%
% \noindent Environment for typesetting hanging sections of scripture
% quotations.
%
% See section \ref{hangingoptions} for supported formatting \meta{|options|}.
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[Genesis 1:3--5]
%   \begin{hanging}
%     \vs{3}And God said, `Let there be light,' and
%     there was light. \vs{4}God saw that the light
%     was good, and he separated the light from the
%     darkness. \vs{5}God called the light `day',
%     and the darkness he called `night'. And there
%     was evening, and there was morn\-ing---the
%     first day.
%   \end{hanging}
% \end{scripture}
% \end{verbatim}
%
% \tcblower
% 
% \begin{scripture}[Genesis 1:3--5]
%   \begin{hanging}
%     \vs{3}And God said, `Let there be light,' and
%     there was light. \vs{4}God saw that the light
%     was good, and he separated the light from the
%     darkness. \vs{5}God called the light `day',
%     and the darkness he called `night'. And there
%     was evening, and there was morn\-ing---the
%     first day.
%   \end{hanging}
% \end{scripture}
% \end{scriptureexample}
%
% \begin{environment}{midparachap}
%   \begin{syntax}
%     |\begin{midparachap}|\oarg{options}
%       \quad\meta{text containing a chapter break}
%     |\end{midparachap}|
%   \end{syntax}
% \end{environment}
%
% \noindent Environment for typesetting paragraph with a chapter break within
% it.
%
% See section \ref{midparachapoptions} for supported formatting
% \meta{|options|}.
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[1 Corinthians 10:31--11:1]
%   \begin{midparachap}
%     \vs{31}So whether you eat or drink or
%     whatever you do, do it all for the glory of
%     God. \vs{32}Do not cause anyone to stumble,
%     whether Jews, Greeks or the church of
%     God---\vs{33}even as I try to please everyone
%     in every way. For I am not seeking my own
%     good but the good of many, so that they may
%     be saved. \ch{11}Follow my example, as I
%     follow the example of Christ.
%   \end{midparachap}
% \end{scripture}
% \end{verbatim}
%
% \tcblower
% 
% \begin{scripture}[1 Corinthians 10:31--11:1]
%   \begin{midparachap}
%     \vs{31}So whether you eat or drink or
%     whatever you do, do it all for the glory of
%     God. \vs{32}Do not cause anyone to stumble,
%     whether Jews, Greeks or the church of
%     God---\vs{33}even as I try to please everyone
%     in every way. For I am not seeking my own
%     good but the good of many, so that they may
%     be saved. \ch{11}Follow my example, as I
%     follow the example of Christ.
%   \end{midparachap}
% \end{scripture}
% \end{scriptureexample}
%
% \begin{environment}{narrow}
%   \begin{syntax}
%     |\begin{narrow}|\oarg{options}
%       \quad\meta{quotation}
%     |\end{narrow}|
%   \end{syntax}
% \end{environment}
%
% \noindent Environment for typesetting narrow sections of scripture
% quotations.
%
% See section \ref{narrowoptions} for supported formatting \meta{|options|}.
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[2 Kings 18:18--19]
%   \vs{18}They called for the king; and Eliakim
%   son of Hilkiah the palace administrator, Shebna
%   the secretary, and Joah son of Asaph the
%   recorder went out to them.
%
%   \vs{19}The field commander said to them, `Tell
%   Hezekiah:
%   \begin{narrow}
%     `\thinspace``This is what the great king, the
%     king of Assyria, says: on what are you basing
%     this confidence of yours?
%   \end{narrow}
% \end{scripture}
% \end{verbatim}
%
% \tcblower
% 
% \begin{scripture}[2 Kings 18:18--19]
%   \vs{18}They called for the king; and Eliakim
%   son of Hilkiah the palace administrator, Shebna
%   the secretary, and Joah son of Asaph the
%   recorder went out to them.
%
%   \vs{19}The field commander said to them, `Tell
%   Hezekiah:
%   \begin{narrow}
%     `\thinspace``This is what the great king, the
%     king of Assyria, says: on what are you basing
%     this confidence of yours?
%   \end{narrow}
% \end{scripture}
% \end{scriptureexample}
%
% \begin{environment}{poetry}
%   \begin{syntax}
%     |\begin{poetry}|\oarg{options}
%       \quad\meta{first half of verse}
%       \quad\meta{second half of verse}
%       \quad
%       \quad\meta{first half of verse}
%       \quad\meta{second half of verse}
%     |\end{poetry}|
%   \end{syntax}
% \end{environment}
%
% \noindent Environment for typesetting poetry sections of scripture
% quotations.
%
% Poetry sections of the Bible often have a first half and a parallel second
% half which is indented a little. These should be set on separate consecutive
% lines. Leaving a blank line indicates that the next line should return to
% the first half indent.
%
% See section \ref{poetryoptions} for supported formatting \meta{|options|}.
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[Isaiah 1:2]
%   \begin{poetry}
%     \vs{2}Hear me, you heavens! Listen, earth!
%     For the \name{Lord} has spoken:
%
%     `I reared children and brought them up,
%     but they have rebelled against me.
%   \end{poetry}
% \end{scripture}
% \end{verbatim}
%
% \tcblower
% 
% \begin{scripture}[Isaiah 1:2]
%   \begin{poetry}
%     \vs{2}Hear me, you heavens! Listen, earth!
%     For the \name{Lord} has spoken:
%
%     `I reared children and brought them up,
%     but they have rebelled against me.
%   \end{poetry}
% \end{scripture}
% \end{scriptureexample}
%
% \begin{environment}{scripture}
%   \begin{syntax}
%     |\begin{scripture}|\oarg{reference}\oarg{options}
%       \quad\meta{quotation}
%     |\end{scripture}|
%   \end{syntax}
% \end{environment}
%
% \noindent Main environment for typesetting scripture quotations.
%
% The optional \meta{|reference|} is printed at the end of the quotation. See
% section \ref{options} for supported formatting \meta{|options|}.
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[John 3:16][version=NIV]
%   \vs{16}For God so loved the world that he gave
%   his one and only Son, that whoever believes in
%   him shall not perish but have eternal life.
% \end{scripture}
% \end{verbatim}
%
% \tcblower
% 
% \begin{scripture}[John 3:16][version=NIV]
%   \vs{16}For God so loved the world that he gave
%   his one and only Son, that whoever believes in
%   him shall not perish but have eternal life.
% \end{scripture}
% \end{scriptureexample}
%
% \subsection{Provided hooks}
%
% \changes{v1.1}{2022/08/07}{Add before and after hooks for verses and
% chapters}
% \begin{hooks}[added=2022-08-07]{scripture/chap/before, scripture/chap/after,
%   scripture/verse/before, scripture/verse/after}
% The following public hooks are available:
%
% \begin{description}
%   \item[\hook{scripture/chap/before}] This hook is executed immediately
%     before the \opt{chap/font} is set for the chapter.
%   \item[\hook{scripture/chap/after}] This hook is executed immediately after
%     the \opt{chap/sep} space is inserted.
%   \item[\hook{scripture/verse/before}] This hook is executed immediately
%     before the \opt{verse/font} is set for the verse.
%   \item[\hook{scripture/chap/after}] This hook is executed immediately after
%     the \opt{verse/sep} space is inserted.
% \end{description}
% \end{hooks}
%
% The following example illustrates how these hooks could be used to place the
% first and last verse on the page into the header.
%
% \begin{scriptureexample}
% \begin{verbatim}
% \documentclass{article}
% \usepackage{scripture}
% \AddToHook{scripture/chap/after}{%
%   \markboth
%     {Mark \scripturecurrentchapter
%        :\scripturecurrentverse}
%     {Mark \scripturecurrentchapter
%        :\scripturecurrentverse}}
% \AddToHook{scripture/verse/after}{%
%   \markboth
%     {Mark \scripturecurrentchapter
%        :\scripturecurrentverse}
%     {Mark \scripturecurrentchapter
%        :\scripturecurrentverse}}
% \renewcommand*{\scripturecurrentchapter}{1}
% \usepackage{fancyhdr}
% \pagestyle{fancy}
% \fancyhf{}
% \lhead{\textbf{\rightmark}}
% \rhead{\textbf{\leftmark} \textbar\ \thepage}
% \begin{document}
% \noindent
% \begin{scripture}
%   \vs{45}Instead he went out and began to talk
%   freely, spreading the news. As a result, Jesus
%   could no longer enter a town openly but stayed
%   outside in lonely places. Yet the people still
%   came to him from everywhere.
%
%   \extraskip
%
%   \ch{2}A few days later, when Jesus again
%   entered Capernaum, the people heard that he had
%   come home.
% \end{scripture}
% \end{document}
% \end{verbatim}
%
% \tcblower
%
% \textbf{Mark 1:45\hfill Mark 2:1} \textbar\ 1
%
% \rule[2mm]{\linewidth}{0.4pt}
%
% \noindent
% \begin{scripture}
%   \vs{45}Instead he went out and began to talk
%   freely, spreading the news. As a result, Jesus
%   could no longer enter a town openly but stayed
%   outside in lonely places. Yet the people still
%   came to him from everywhere.
%
%    \extraskip
%
%   \ch{2}A few days later, when Jesus again
%   entered Capernaum, the people heard that he had
%   come home.
% \end{scripture}
% \end{scriptureexample}
%
% \subsection{Options}
% \label{options}
%
% \changes{v1.3}{2023/01/08}{Remove \opt{reference/delim} option}
%
% Default formatting \meta{|options|} can be set using
% \cs{usepackage}|[|\meta{|options|}|]{scripture}| or
% \cs{scripturesetup}|{|\meta{|options|}|}|. Local formatting \meta{|options|}
% can be set by passing them to the various environments described above.
%
% \textbf{Note:} It's not possible to pass non-expandable macros as key-value
% options to the optional argument of \cs{usepackage}. So if you want to set
% |font=|\cs{bfseries} as the default, you must use
% \cs{scripturesetup}|{font=|\cs{bfseries}|}|. It is not possible to use
% \cs{usepackage}|[font=|\cs{bfseries}|]{scripture}| (you will get a compile
% error).
%
% \begin{option}{aboveskip}
%   \begin{syntax}
%     aboveskip = \meta{skip} \hfill Default: 0pt
%   \end{syntax}
%   \meta{|skip|} inserted above the \env{scripture} environment.
% \end{option}
%
% \changes{v1.3}{2022/11/15}{Add \opt{added/font} option}
% \begin{option}[added=2022-11-15]{added/font}
%   \begin{syntax}
%     added/font = \meta{font} \hfill Default: \emph{Empty}
%   \end{syntax}
%   \meta{|font|} used for the \cs{added} function.
% \end{option}
%
% \changes{v1.3}{2022/11/15}{Add \opt{added/format} option}
% \begin{option}[added=2022-11-15]{added/format}
%   \begin{syntax}
%     added/format = \meta{macro} \hfill Default: \cs{emph}\{\#1\}
%   \end{syntax}
%   \meta{|macro|} used to format the words that should be highlighted as
%   added by the translators using the \cs{added} function. |#1| contains the
%   text of the argument to \cs{added}.
% \end{option}
%
% \begin{option}{belowskip}
%   \begin{syntax}
%     belowskip = \meta{skip} \hfill Default: 0pt
%   \end{syntax}
%   \meta{|skip|} inserted below the \env{scripture} environment.
% \end{option}
%
% \changes{v1.2}{2022/09/07}{Add \opt{chapter/colour} option}
% \begin{option}[added=2022-09-07]{chapter/colour, chapter/color}
%   \begin{syntax}
%     chapter/colour = \meta{colour expression} \hfill Default: .
%   \end{syntax}
%   The \pkg{l3color} \meta{|colour expression|} to be used for chapter
%   numbers. By default the current colour is inherited. \opt{chapter/color}
%   is an alias for \opt{chapter/colour}.
% \end{option}
%
% \begin{option}{chapter/drop}
%   \begin{syntax}
%     chapter/drop = \meta{boolean} \hfill Default: true
%   \end{syntax}
%   Whether the chapter should be set as a drop letter taking up two
%   lines or as a normal letter taking up one line. The value of
%   \meta{|boolean|} is optional and assumed to be \val{true} if not present.
%   This option is the opposite of \opt{chapter/nodrop}.
% \end{option}
%
% \begin{option}{chapter/font}
%   \begin{syntax}
%     chapter/font = \meta{font} \hfill Default: \cs{bfseries}
%   \end{syntax}
%   \meta{|font|} used for the \cs{ch} function.
% \end{option}
%
% \changes{v1.1}{2022/07/28}{Add \opt{chapter/format} option}
% \begin{option}[added=2022-07-28]{chapter/format}
%   \begin{syntax}
%     chapter/format = \meta{macro} \hfill Default: \#1
%   \end{syntax}
%   \meta{|macro|} used to format the \val{chapter} for a \env{scripture}
%   quotation. |#1| contains the text of the \val{chapter}.
% \end{option}
%
% \changes{v1.1}{2022/08/15}{Add \opt{chapter/hide} option}
% \begin{option}[added=2022-08-15]{chapter/hide}
%   \begin{syntax}
%     chapter/hide = \meta{boolean} \hfill Default: false
%   \end{syntax}
%   Whether chapters should be shown or hidden. The value of \meta{|boolean|}
%   is optional and assumed to be \val{true} if not present. This option is
%   the opposite of \opt{chapter/show}. Note that the \hook{scripture/chap/before}
%   and \hook{scripture/chap/after} hooks are still executed when chapters are
%   hidden.
% \end{option}
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[Romans 5:1--2][chapter/hide]
%   \ch{5}Therefore, since we have been justified
%   through faith, we have peace with God through
%   our Lord Jesus Christ, \vs{2}through whom we
%   have gained access by faith into this grace in
%   which we now stand. And we boast in the hope of
%   the glory of God.
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \begin{scripture}[Romans 5:1--2][chapter/hide]
%   \ch{5}Therefore, since we have been justified
%   through faith, we have peace with God through
%   our Lord Jesus Christ, \vs{2}through whom we
%   have gained access by faith into this grace in
%   which we now stand. And we boast in the hope of
%   the glory of God.
% \end{scripture}
% \end{scriptureexample}
%
% \begin{option}{chapter/nodrop}
%   \begin{syntax}
%     chapter/nodrop = \meta{boolean} \hfill Default: false
%   \end{syntax}
%   Whether the chapter should be set as a drop letter taking up two lines or
%   as a normal letter taking up one line. The value of \meta{|boolean|} is
%   optional and assumed to be \val{true} if not present. This option is the
%   opposite of \opt{chapter/drop}.
% \end{option}
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[John 1:1--3][chapter/nodrop]
%   \ch{1}In the beginning was the Word, and the
%   Word was with God, and the Word was God.
%   \vs{2}He was with God in the beginning.
%   \vs{3}Through him all things were made; without
%   him nothing was made that has been made.
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \begin{scripture}[John 1:1--3][chapter/nodrop]
%   \ch{1}In the beginning was the Word, and the
%   Word was with God, and the Word was God.
%   \vs{2}He was with God in the beginning.
%   \vs{3}Through him all things were made; without
%   him nothing was made that has been made.
% \end{scripture}
% \end{scriptureexample}
%
% \begin{option}{chapter/sep}
%   \begin{syntax}
%     chapter/sep = \meta{dimen} \hfill Default: 0.5em
%   \end{syntax}
%   \meta{|dimen|} used to separate a \cs{ch} from the following text.
% \end{option}
%
% \changes{v1.1}{2022/08/15}{Add \opt{chapter/show} option}
% \begin{option}[added=2022-08-15]{chapter/show}
%   \begin{syntax}
%     chapter/show = \meta{boolean} \hfill Default: true
%   \end{syntax}
%   Whether chapters should be shown or hidden. The value of \meta{|boolean|}
%   is optional and assumed to be \val{true} if not present. This option is
%   the opposite of \opt{chapter/hide}.
% \end{option}
%
% \changes{v1.1}{2022/11/14}{Add \opt{chapter/showverse} option}
% \begin{option}[added=2022-11-14]{chapter/showverse}
%   \begin{syntax}
%     chapter/showverse = \meta{boolean} \hfill Default: false
%   \end{syntax}
%   Whether \cs{vs}|\{1\}| should be automatically inserted after \cs{ch}. The
%   value of \meta{|boolean|} is optional and assumed to be \val{true} if not
%   present. See also \opt{midparachap/showverse} and
%   \opt{midparachap/hideverse}. Note that \opt{chapter/showverse} take
%   precedence over \opt{midparachap/hideverse}.
% \end{option}
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[John 1:1][chapter/showverse]
%   \ch{1}In the beginning was the Word, and the
%   Word was with God, and the Word was God.
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \begin{scripture}[John 1:1][chapter/showverse]
%   \ch{1}In the beginning was the Word, and the
%   Word was with God, and the Word was God.
% \end{scripture}
% \end{scriptureexample}
%
% \changes{v1.2}{2022/08/31}{Add \opt{colour} option}
% \begin{option}[added=2022-08-31]{colour, color}
%   \begin{syntax}
%     colour = \meta{colour expression} \hfill Default: .
%   \end{syntax}
%   The \pkg{l3color} \meta{|colour expression|} to be used for the
%   \env{scripture} environment. By default the current colour is inherited.
%   \opt{color} is an alias for \opt{colour}.
% \end{option}
%
% \changes{v1.1}{2022/08/15}{Add \opt{compact} option}
% \begin{option}[added=2022-08-15]{compact}
%   \begin{syntax}
%     compact = \meta{boolean} \hfill Default: false
%   \end{syntax}
%   This option removes all paragraph breaks along with any \cs{extraskip} in
%   the quotation so the whole quotation is a single paragraph of running
%   prose. This option implies \opt{chapter/nodrop} and all options relating
%   to inner environments are ignored.
%
%   The value of \meta{|boolean|} is optional and assumed to be \val{true} if
%   not present.
%
%   \textbf{Warning:} This option redefines \cs{par} to \cs{relax} inside the
%   \env{scripture} environment. If you have anything other than expected
%   macros and environments inside your \env{scripture} environment \TeX{}
%   will likely get stuck in an infinite loop.
% \end{option}
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[Jonah 1:17--2:2a][compact]
%   \begin{midparachap}
%     \vs{17}Now the \name{Lord} provided a huge
%     fish to swallow Jonah, and Jonah was in the
%     belly of the fish three days and three
%     nights. \ch{2}From inside the fish Jonah
%     prayed to the \name{Lord} his God. \vs{2}He
%     said:
%   \end{midparachap}
%   \begin{poetry}
%     `In my distress I called to the Lord,
%     and he answered me.
%   \end{poetry}
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \begin{scripture}[Jonah 1:17--2:2a][compact]
%   \begin{midparachap}
%     \vs{17}Now the \name{Lord} provided a huge
%     fish to swallow Jonah, and Jonah was in the
%     belly of the fish three days and three
%     nights. \ch{2}From inside the fish Jonah
%     prayed to the \name{Lord} his God. \vs{2}He
%     said:
%   \end{midparachap}
%   \begin{poetry}
%     `In my distress I called to the Lord,
%     and he answered me.
%   \end{poetry}
% \end{scripture}
% \end{scriptureexample}
%
% \begin{option}{extraskip}
%   \begin{syntax}
%     extraskip = \meta{skip} \hfill Default: \cs{medskipamount}
%   \end{syntax}
%   \meta{|skip|} used for the \cs{extraskip} function.
% \end{option}
%
% \begin{option}{font}
%   \begin{syntax}
%     font = \meta{font} \hfill Default: \emph{Empty}
%   \end{syntax}
%   \meta{|font|} used for the \env{scripture} environment.
% \end{option}
%
% \changes{v1.3}{2023/01/07}{Add \opt{inline} option}
% \begin{option}[added=2023-01-07]{inline}
%   \begin{syntax}
%     inline
%   \end{syntax}
%   Set the scripture quotation inline. The quotation is surrounded be the
%   values of \opt{inline/begin} and \opt{inline/end} which default to |``\,|
%   and |\,''|, respectively. This option also changes the defaults of some
%   other options as follows:
%   \begin{itemize}
%     \item \opt{compact} is set
%     \item \opt{reference/align} is set to |inline|
%     \item \opt{reference/sep} is set to |0.5em|
%     \item \opt{reference/format} is set to |(#1)|
%     \item \opt{version/format} is set to |#1|
%   \end{itemize}
%
%   \textbf{Warning:} \cs{par} is redefined to \cs{relax} when the
%   \opt{inline} option is set. If you have anything other than expected
%   macros and environments inside your quotation \TeX{} will likely get stuck
%   in an infinite loop.
% \end{option}
%
% \changes{v1.3}{2023/01/07}{Add \opt{inline/begin} option}
% \begin{option}[added=2023-01-07]{inline/begin}
%   \begin{syntax}
%     inline/begin = \meta{text} \hfill Default: |``\,|
%   \end{syntax}
%   Text inserted at the beginning of \cs{textscripture} or a \env{scripture}
%   environment with the \opt{inline} option set.
% \end{option}
%
% \changes{v1.3}{2023/01/07}{Add \opt{inline/end} option}
% \begin{option}[added=2023-01-07]{inline/end}
%   \begin{syntax}
%     inline/end = \meta{text} \hfill Default: |\,''|
%   \end{syntax}
%   Text inserted between the end of \cs{textscripture} or a \env{scripture}
%   environment with the \opt{inline} option set and the \meta{|reference|}
%   (if specified).
% \end{option}
%
% \begin{option}{indent}
%   \begin{syntax}
%     indent = \meta{boolean} \hfill Default: true
%   \end{syntax}
%   Whether to indent the first line of a \env{scripture} environment or not
%   by \opt{parindent}. The value of \meta{|boolean|} is optional and assumed
%   to be \val{true} if not present. This option is the opposite of
%   \opt{noindent}.
% \end{option}
%
% \changes{v1.2}{2022/11/02}{Add \opt{language} option}
% \begin{option}[added=2022-11-02]{language}
%   \begin{syntax}
%     language = \meta{language name} \hfill Default: \emph{Empty}
%   \end{syntax}
%   \pkg{babel} or \pkg{polyglossia} \meta{|language name|} to be used for the
%   \env{scripture} environment. This calls
%   \cs{selectlanguage}|{|\meta{|language name|}|}| at the start of the
%   environment. Make sure you have \pkg{babel} or \pkg{polyglossia} loaded
%   and correctly set up for your specified language. If unset the current
%   active language is used.
% \end{option}
%
% \changes{v1.2}{2022/11/02}{Add \opt{language/variant} option}
% \begin{option}[added=2022-11-02]{language/variant}
%   \begin{syntax}
%     language/variant = \meta{language variant name} \hfill Default: \emph{Empty}
%   \end{syntax}
%   \pkg{polyglossia} \meta{|language variant name|} to be used along with the
%   specified \opt{language} for the \env{scripture} environment. This inserts
%   \cs{selectlanguage}|[|\meta{|language variant name|}|]{|\meta{language
%   name}|}| at the start of the environment. Make sure you have
%   \pkg{polyglossia} loaded and correctly set up for your specified language.
% \end{option}
%
% \begin{option}{leftmargin}
%   \begin{syntax}
%     leftmargin = \meta{dimen} \hfill Default: 0pt
%   \end{syntax}
%   \meta{|dimen|} used for the left margin of the \env{scripture}
%   environment.
% \end{option}
%
% \changes{v1.2}{2022/09/01}{Add \opt{name/font} option}
% \begin{option}[added=2022-09-01]{name/font}
%   \begin{syntax}
%     name/font = \meta{font} \hfill Default: \cs{scshape}
%   \end{syntax}
%   \meta{|font|} used for the \cs{name} function.
% \end{option}
%
% \changes{v1.2}{2022/09/01}{Add \opt{name/format} option}
% \begin{option}[added=2022-09-01]{name/format}
%   \begin{syntax}
%     name/format = \meta{macro} \hfill Default: \#1
%   \end{syntax}
%   \meta{|macro|} used to format the \val{divine name} using the \cs{name}
%   function. |#1| contains the text of the argument to \cs{name}.
% \end{option}
%
% \begin{option}{noindent}
%   \begin{syntax}
%     noindent = \meta{boolean} \hfill Default: false
%   \end{syntax}
%   Whether to indent the first line of a \env{scripture} environment or not
%   by \opt{parindent}. The value of \meta{|boolean|} is optional and assumed
%   to be \val{true} if not present. This option is the opposite of
%   \opt{indent}.
% \end{option}
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[1 Peter 3:18][noindent]
%   \vs{18}For Christ also suffered once for sins,
%   the righteous for the unrighteous, to bring you
%   to God. He was put to death in the body but
%   made alive in the Spirit.
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \begin{scripture}[1 Peter 3:18][noindent]
%   \vs{18}For Christ also suffered once for sins,
%   the righteous for the unrighteous, to bring you
%   to God. He was put to death in the body but
%   made alive in the Spirit.
% \end{scripture}
% \end{scriptureexample}
%
% \begin{option}{parindent}
%   \begin{syntax}
%     parindent = \meta{dimen} \hfill Default: \cs{parindent}
%   \end{syntax}
%   \meta{|dimen|} to use when indenting the first line of a paragraph in the
%   \env{scripture} environment.
% \end{option}
%
% \begin{option}{parskip}
%   \begin{syntax}
%     parskip = \meta{skip} \hfill Default: \cs{parskip}
%   \end{syntax}
%   \meta{|skip|} to use between paragraphs in the \env{scripture} environment.
% \end{option}
%
% \changes{v1.2}{2022/08/31}{Add \opt{redletter} option}
% \begin{option}[added=2022-08-31]{redletter}
%   \begin{syntax}
%     redletter = \meta{boolean} \hfill Default: false
%   \end{syntax}
%   Whether to enable highlighting of Jesus' words in red. The value of
%   \meta{|boolean|} is option and assumed to be \val{true} if not present.
%   The text needs to be marked up with \cs{redletteron} and \cs{redletteroff}
%   for this option to have any effect.
% \end{option}
%
% \changes{v1.2}{2022/08/31}{Add \opt{redletter/colour} option}
% \begin{option}[added=2022-08-31]{redletter/colour, redletter/color}
%   \begin{syntax}
%     redletter/colour = \meta{colour expression} \hfill Default: red!80!black
%   \end{syntax}
%   The \pkg{l3color} \meta{|colour expression|} to be used for the words of
%   Jesus when the \opt{redletter} option is \val{true}. \cs{redletteron} and
%   \cs{redletteroff} must be used to mark up the text. \opt{redletter/color}
%   is an alias for \opt{redletter/colour}.
% \end{option}
%
% \changes{v1.3}{2023/01/08}{Add \opt{reference/align} option}
% \begin{option}[added=2023-01-08]{reference/align}
%   \begin{syntax}
%     reference/align = inline \textbar\ left \textbar\ right \hfill Default: right
%   \end{syntax}
%   Set the alignment of the reference. For |left| and |right| the reference
%   will not break across lines, but a line break is permitted for |inline|.
% \end{option}
%
% \changes{v1.2}{2022/09/07}{Add \opt{reference/colour} option}
% \begin{option}[added=2022-09-07]{reference/colour, reference/color}
%   \begin{syntax}
%     reference/colour = \meta{colour expression} \hfill Default: .
%   \end{syntax}
%   The \pkg{l3color} \meta{|colour expression|} to be used for the reference
%   and version. By default the current colour is inherited.
%   \opt{reference/color} is an alias for \opt{reference/colour}.
% \end{option}
%
% \begin{option}{reference/font}
%   \begin{syntax}
%     reference/font = \meta{font} \hfill Default: \cs{bfseries}
%   \end{syntax}
%   \meta{|font|} used when printing the \val{reference} for a \env{scripture}
%   quotation.
% \end{option}
%
% \begin{option}{reference/format}
%   \begin{syntax}
%     reference/format = \meta{macro} \hfill Default: \#1
%   \end{syntax}
%   \meta{|macro|} used to format the \val{reference} for a \env{scripture}
%   quotation. |#1| contains the text of the \val{reference} and \val{version}
%   (if specified).
% \end{option}
%
% \changes{v1.3}{2023/01/08}{Add \opt{reference/newline} option}
% \begin{option}[added=2023-01-8]{reference/newline}
%   \begin{syntax}
%     reference/newline
%   \end{syntax}
%   Always push the \val{reference} to a newline even if there is space for it
%   to fit on the last line of the quotation. The option sets
%   \opt{reference/sep} to \cs{linewidth} so there is never room for the
%   reference on the final line of the quotation.
% \end{option}
%
% \begin{option}{reference/sep}
%   \begin{syntax}
%     reference/sep = \meta{dimen} \hfill Default: 2em
%   \end{syntax}
%   The minimum \meta{|dimen|} allowed between the end of a \env{scripture}
%   quotation and its \val{reference} before the \val{reference} is pushed to
%   the following line.
% \end{option}
%
% \begin{option}{rightmargin}
%   \begin{syntax}
%     rightmargin = \meta{dimen} \hfill Default: 0pt
%   \end{syntax}
%   \meta{|dimen|} used for the right margin of the \env{scripture}
%   environment.
% \end{option}
%
% \begin{option}{selah/font}
%   \begin{syntax}
%     selah/font = \meta{font} \hfill Default: \cs{itshape}
%   \end{syntax}
%   \meta{|font|} used when printing \cs{selah} in a \env{poetry} environment.
% \end{option}
%
% \begin{option}{selah/format}
%   \begin{syntax}
%     selah/format = \meta{macro} \hfill Default: \#1
%   \end{syntax}
%   \meta{|macro|} used to format the \cs{selah} in a \env{poetry}
%   environment. |#1| contains the value of \opt{selah/text}.
% \end{option}
%
% \begin{option}{selah/sep}
%   \begin{syntax}
%     selah/sep = \meta{dimen} \hfill Default: 1em
%   \end{syntax}
%   The minimum \meta{|dimen|} allowed between the end of a poetry line and
%   \emph{Selah} before the \emph{Selah} is pushed to the following line.
% \end{option}
%
% \begin{option}{selah/text}
%   \begin{syntax}
%     selah/text = \meta{text} \hfill Default: Selah
%   \end{syntax}
%   \meta{|text|} used to for \cs{selah} in a \env{poetry} environment.
% \end{option}
%
% \changes{v1.2}{2022/08/30}{Add \opt{textright/sep} option}
% \begin{option}[added=2022-08-30]{textright/sep}
%   \begin{syntax}
%     textright/sep = \meta{dimen} \hfill Default: 1em
%   \end{syntax}
%   The minimum \meta{|dimen|} allowed between the end of a line and text
%   aligned to the right with \cs{textright} before the right aligned text is
%   pushed to the following line.
% \end{option}
%
% \changes{v1.2}{2022/09/07}{Add \opt{verse/colour} option}
% \begin{option}[added=2022-09-07]{verse/colour, verse/color}
%   \begin{syntax}
%     verse/colour = \meta{colour expression} \hfill Default: .
%   \end{syntax}
%   The \pkg{l3color} \meta{|colour expression|} to be used for verse numbers.
%   By default the current colour is inherited. \opt{verse/color} is an alias
%   for \opt{verse/colour}.
% \end{option}
%
% \changes{v1.3}{2022/11/13}{Add \opt{verse/first} option}
% \begin{option}[added=2022-11-13]{verse/first}
%   \begin{syntax}
%     verse/first = \meta{boolean} \hfill Default: false
%   \end{syntax}
%   In prose sections, print the verse number in a different format if it is
%   at the start of the paragraph. The format and separation between verse and
%   text are controlled with the \opt{verse/firstformat} and
%   \opt{verse/firstsep} options. Use \cs{noversefirst} to suppress this at
%   the next verse (e.g., if your quote starts mid-way though a paragraph and
%   a normal verse should be printed). The value of \meta{|boolean|} is optional
%   and assumed to be true if not present.
% \end{option}
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[Luke 18:25--28][noindent,
%     verse/first, version=NRSV]
%   \nofirstverse\vs{25}Indeed, it is easier for a
%   camel to go through the eye of a needle than for
%   someone who is rich to enter the kingdom of
%   God.''
%
%   \vs{26}Those who heard it said, ``Then who can
%   be saved?'' \vs{27}He replied, ``What is
%   impossible for mortals is possible for God.''
%
%   \vs{28}Then Peter said, ``Look, we have left our
%   homes and followed you.''
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \begin{scripture}[Luke 18:25--28][noindent,
%     verse/first, version=NRSV]
%   \nofirstverse\vs{25}Indeed, it is easier for a
%   camel to go through the eye of a needle than for
%   someone who is rich to enter the kingdom of
%   God.''
%
%   \vs{26}Those who heard it said, ``Then who can
%   be saved?'' \vs{27}He replied, ``What is
%   impossible for mortals is possible for God.''
%
%   \vs{28}Then Peter said, ``Look, we have left our
%   homes and followed you.''
% \end{scripture}
% \end{scriptureexample}
%
% \changes{v1.3}{2022/11/13}{Add \opt{verse/firstformat} option}
% \begin{option}[added=2022-11-13]{verse/firstformat}
%   \begin{syntax}
%     verse/firstformat = \meta{macro} \hfill Default: \#1
%   \end{syntax}
%   \meta{|macro|} used to format the first \cs{vs} in a paragraph. |#1|
%   contains the argument of \cs{vs}. Only used if \opt{verse/first} is
%   |true|.
% \end{option}
%
% \changes{v1.3}{2022/11/13}{Add \opt{verse/firstsep} option}
% \begin{option}[added=2022-11-13]{verse/firstsep}
%   \begin{syntax}
%     verse/firstsep = \meta{dimen} \hfill Default: 0.5em
%   \end{syntax}
%   \meta{|dimen|} used to separate the first \cs{vs} in a paragraph from the
%   following text. Only used if \opt{verse/first} is |true|.
% \end{option}
%
% \begin{option}{verse/font}
%   \begin{syntax}
%     verse/font = \meta{font} \hfill Default: \emph{Empty}
%   \end{syntax}
%   \meta{|font|} used for the \cs{vs} function.
% \end{option}
%
% \begin{option}{verse/format}
%   \begin{syntax}
%     verse/format = \meta{macro} \hfill Default: \cs{textsuperscript}\{\#1\}
%   \end{syntax}
%   \meta{|macro|} used to format the \cs{vs} function. |#1| contains the
%   argument of \cs{vs}.
% \end{option}
%
% \changes{v1.1}{2022/08/15}{Add \opt{verse/hide} option}
% \begin{option}[added=2022-08-15]{verse/hide}
%   \begin{syntax}
%     verse/hide = \meta{boolean} \hfill Default: false
%   \end{syntax}
%   Whether verses should be shown or hidden. The value of \meta{|boolean|} is
%   optional and assumed to be \val{true} if not present. This option is the
%   opposite of \opt{verse/show}. Note that the \hook{scripture/verse/before}
%   and \hook{scripture/verse/after} hooks are still executed when verses are
%   hidden.
% \end{option}
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[Colossians 1:15--16][verse/hide]
%   \vs{15}The Son is the image of the invisible
%   God, the firstborn over all creation.
%   \vs{16}For in him all things were created:
%   things in heaven and on earth, visible and
%   invisible, whether thrones or powers or rulers
%   or authorities; all things have been created
%   through him and for him.
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \begin{scripture}[Colossians 1:15--16][verse/hide]
%   \vs{15}The Son is the image of the invisible
%   God, the firstborn over all creation.
%   \vs{16}For in him all things were created:
%   things in heaven and on earth, visible and
%   invisible, whether thrones or powers or rulers
%   or authorities; all things have been created
%   through him and for him.
% \end{scripture}
% \end{scriptureexample}
%
% \changes{v1.1}{2022/07/28}{Add \opt{verse/sep} option with small default}
% \begin{option}[added=2022-07-28]{verse/sep}
%   \begin{syntax}
%     verse/sep = \meta{dimen} \hfill Default: 0.05 em
%   \end{syntax}
%   \meta{|dimen|} used to separate a \cs{vs} from the following text.
% \end{option}
%
% \changes{v1.1}{2022/08/15}{Add \opt{verse/show} option}
% \begin{option}[added=2022-08-15]{verse/show}
%   \begin{syntax}
%     verse/show = \meta{boolean} \hfill Default: true
%   \end{syntax}
%   Whether verses should be shown or hidden. The value of \meta{|boolean|}
%   is optional and assumed to be \val{true} if not present. This option is
%   the opposite of \opt{verse/hide}.
% \end{option}
%
% \begin{option}{version}
%   \begin{syntax}
%     version = \meta{version} \hfill Default: \emph{Empty}
%   \end{syntax}
%   \meta{|version|} added to the \val{reference} for a \env{scripture}
%   quotation.
% \end{option}
%
% \begin{option}{version/delim}
%   \begin{syntax}
%     version/delim = \meta{delim} \hfill Default: \{\ \}
%   \end{syntax}
%   \meta{|delim|} to use between the \val{reference} and the \val{version} of a
%   \env{scripture} quotation.
% \end{option}
%
% \begin{option}{version/format}
%   \begin{syntax}
%     version/format = \meta{macro} \hfill Default: (\#1)
%   \end{syntax}
%   \meta{|macro|} used to format the \val{version} for a \env{scripture}
%   quotation. |#1| contains the text of the \val{version}.
% \end{option}
%
% \subsubsection{Options for the \env{center} environment}
% \label{centeroptions}
%
% If these options are passed directly to the \env{center} environment rather
% than to the package, \cs{scripturesetup} or the \env{scripture} environment,
% then the |center/| prefix should be dropped.
%
% \begin{option}{center/aboveskip}
%   \begin{syntax}
%     center/aboveskip = \meta{skip} \hfill Default: \cs{medskipamount}
%   \end{syntax}
%   \meta{|skip|} inserted above the \env{center} environment.
% \end{option}
%
% \begin{option}{center/belowskip}
%   \begin{syntax}
%     center/belowskip = \meta{skip} \hfill Default: \cs{medskipamount}
%   \end{syntax}
%   \meta{|skip|} inserted below the \env{center} environment.
% \end{option}
%
% \begin{option}{center/leftmargin}
%   \begin{syntax}
%     center/leftmargin = \meta{dimen} \hfill Default: 0pt
%   \end{syntax}
%   \meta{|dimen|} used for the left margin of the \env{center} environment.
% \end{option}
%
% \begin{option}{center/rightmargin}
%   \begin{syntax}
%     center/rightmargin = \meta{dimen} \hfill Default: 0pt
%   \end{syntax}
%   \meta{|dimen|} used for the right margin of the \env{center} environment.
% \end{option}
%
% \subsubsection{Options for the \env{flushright} environment}
% \label{flushrightoptions}
%
% If these options are passed directly to the \env{flushright} environment rather
% than to the package, \cs{scripturesetup} or the \env{scripture} environment,
% then the |flushright/| prefix should be dropped.
%
% \begin{option}{flushright/aboveskip}
%   \begin{syntax}
%     flushright/aboveskip = \meta{skip} \hfill Default: \cs{medskipamount}
%   \end{syntax}
%   \meta{|skip|} inserted above the \env{flushright} environment.
% \end{option}
%
% \begin{option}{flushright/belowskip}
%   \begin{syntax}
%     flushright/belowskip = \meta{skip} \hfill Default: \cs{medskipamount}
%   \end{syntax}
%   \meta{|skip|} inserted below the \env{flushright} environment.
% \end{option}
%
% \begin{option}{flushright/leftmargin}
%   \begin{syntax}
%     flushright/leftmargin = \meta{dimen} \hfill Default: 0pt
%   \end{syntax}
%   \meta{|dimen|} used for the left margin of the \env{flushright} environment.
% \end{option}
%
% \begin{option}{flushright/rightmargin}
%   \begin{syntax}
%     flushright/rightmargin = \meta{dimen} \hfill Default: 0pt
%   \end{syntax}
%   \meta{|dimen|} used for the right margin of the \env{flushright} environment.
% \end{option}
%
% \subsubsection{Options for the \env{hanging} environment}
% \label{hangingoptions}
%
% If these options are passed directly to the \env{hanging} environment rather
% than to the package, \cs{scripturesetup} or the \env{scripture} environment,
% then the |hanging/| prefix should be dropped.
%
% \begin{option}{hanging/aboveskip}
%   \begin{syntax}
%     hanging/aboveskip = \meta{skip} \hfill Default: \cs{medskipamount}
%   \end{syntax}
%   \meta{|skip|} inserted above the \env{hanging} environment.
% \end{option}
%
% \begin{option}{hanging/belowskip}
%   \begin{syntax}
%     hanging/belowskip = \meta{skip} \hfill Default: \cs{medskipamount}
%   \end{syntax}
%   \meta{|skip|} inserted below the \env{hanging} environment.
% \end{option}
%
% \begin{option}{hanging/hang}
%   \begin{syntax}
%     hanging/hang = \meta{dimen} \hfill Default: 2em
%   \end{syntax}
%   \meta{|dimen|} used for the indent of subsequent lines of the
%   \env{hanging} environment.
% \end{option}
%
% \begin{option}{hanging/leftmargin}
%   \begin{syntax}
%     hanging/leftmargin = \meta{dimen} \hfill Default: 1em
%   \end{syntax}
%   \meta{|dimen|} used for the left margin of the \env{hanging} environment.
% \end{option}
%
% \begin{option}{hanging/rightmargin}
%   \begin{syntax}
%     hanging/rightmargin = \meta{dimen} \hfill Default: 1em
%   \end{syntax}
%   \meta{|dimen|} used for the right margin of the \env{hanging} environment.
% \end{option}
%
% \subsubsection{Options for the \env{midparachap} environment}
% \label{midparachapoptions}
%
% If these options are passed directly to the \env{midparachap} environment
% rather than to the package, \cs{scripturesetup} or the \env{scripture}
% environment, then the |midparachap/| prefix should be dropped.
%
% \begin{option}{midparachap/hideverse}
%   \begin{syntax}
%     midparachap/hideverse = \meta{boolean} \hfill Default: false
%   \end{syntax}
%   Whether a \cs{vs}|{1}| should automatically be inserted after a \cs{ch}
%   when the \cs{ch} occurs mid-paragraph. This also affects \cs{ch} in
%   \env{poetry} environments. \cs{extraskip} begins a new paragraph in a
%   \env{poetry} environment. The value of \meta{|boolean|} is optional and
%   assumed to be \val{true} if not present. This option is the opposite of
%   \opt{midparachap/showverse}. See also \opt{chapter/showverse}.
% \end{option}
%
% \begin{scriptureexample}
% \begin{verbatim}
% \begin{scripture}[Hosea 11:12--12:1]%
%     [midparachap/hideverse]
%   \begin{poetry}
%     \vs{12}Ephraim has surrounded me with lies,
%     Israel with deceit.
%
%     And Judah is unruly against God,
%     even against the faithful Holy One.
%
%     \ch{12}Ephraim feeds on the wind;
%     he pursues the east wind all day
%     and multiplies lies and violence.
%
%     He makes a treaty with Assyria
%     and sends olive oil to Egypt.
%   \end{poetry}
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \begin{scripture}[Hosea 11:12--12:1]%
%     [midparachap/hideverse]
%   \begin{poetry}
%     \vs{12}Ephraim has surrounded me with lies,
%     Israel with deceit.
%
%     And Judah is unruly against God,
%     even against the faithful Holy One.
%
%     \ch{12}Ephraim feeds on the wind;
%     he pursues the east wind all day
%     and multiplies lies and violence.
%
%     He makes a treaty with Assyria
%     and sends olive oil to Egypt.
%   \end{poetry}
% \end{scripture}
% \end{scriptureexample}
%
% \begin{option}{midparachap/showverse}
%   \begin{syntax}
%     midparachap/showverse = \meta{boolean} \hfill Default: true
%   \end{syntax}
%   Whether a \cs{vs}|{1}| should automatically be inserted after a \cs{ch}
%   when the \cs{ch} occurs mid-paragraph. This also affects \cs{ch} in
%   \env{poetry} environments. \cs{extraskip} begins a new paragraph in a
%   \env{poetry} environment. The value of \meta{|boolean|} is optional and
%   assumed to be \val{true} if not present. This option is the opposite of
%   \opt{midparachap/hideverse}. See also \opt{chapter/showverse}.
% \end{option}
%
% \subsubsection{Options for the \env{narrow} environment}
% \label{narrowoptions}
%
% If these options are passed directly to the \env{narrow} environment rather
% than to the package, \cs{scripturesetup} or the \env{scripture} environment,
% then the |narrow/| prefix should be dropped.
%
% \begin{option}{narrow/aboveskip}
%   \begin{syntax}
%     narrow/aboveskip = \meta{skip} \hfill Default: \cs{medskipamount}
%   \end{syntax}
%   \meta{|skip|} inserted above the \env{narrow} environment.
% \end{option}
%
% \begin{option}{narrow/belowskip}
%   \begin{syntax}
%     narrow/belowskip = \meta{skip} \hfill Default: \cs{medskipamount}
%   \end{syntax}
%   \meta{|skip|} inserted below the \env{narrow} environment.
% \end{option}
%
% \begin{option}{narrow/leftmargin}
%   \begin{syntax}
%     narrow/leftmargin = \meta{dimen} \hfill Default: 1em
%   \end{syntax}
%   \meta{|dimen|} used for the left margin of the \env{narrow} environment.
% \end{option}
%
% \begin{option}{narrow/rightmargin}
%   \begin{syntax}
%     narrow/rightmargin = \meta{dimen} \hfill Default: 1em
%   \end{syntax}
%   \meta{|dimen|} used for the right margin of the \env{narrow} environment.
% \end{option}
%
% \subsubsection{Options for the \env{poetry} environment}
% \label{poetryoptions}
%
% If these options are passed directly to the \env{poetry} environment rather
% than to the package, \cs{scripturesetup} or the \env{scripture} environment,
% then the |poetry/| prefix should be dropped.
%
% \begin{option}{poetry/aboveskip}
%   \begin{syntax}
%     poetry/aboveskip = \meta{skip} \hfill Default: \cs{medskipamount}
%   \end{syntax}
%   \meta{|skip|} inserted above the \env{poetry} environment.
% \end{option}
%
% \begin{option}{poetry/belowskip}
%   \begin{syntax}
%     poetry/belowskip = \meta{skip} \hfill Default: \cs{medskipamount}
%   \end{syntax}
%   \meta{|skip|} inserted below the \env{poetry} environment.
% \end{option}
%
% \begin{option}{poetry/bigindent}
%   \begin{syntax}
%     poetry/bigindent = \meta{dimen} \hfill Default: 4em
%   \end{syntax}
%   \meta{|dimen|} used for the indent subsequent lines of a line of poetry in
%   a \env{poetry} environment if it needs to flow on to the following line.
% \end{option}
%
% \begin{option}{poetry/indent}
%   \begin{syntax}
%     poetry/indent = \meta{dimen} \hfill Default: 1em
%   \end{syntax}
%   \meta{|dimen|} used for the second half of a line of poetry in a
%   \env{poetry} environment.
% \end{option}
%
% \begin{option}{poetry/leftmargin}
%   \begin{syntax}
%     poetry/leftmargin = \meta{dimen} \hfill Default: 1em
%   \end{syntax}
%   \meta{|dimen|} used for the left margin of the \env{poetry} environment.
% \end{option}
%
% \begin{option}{poetry/rightmargin}
%   \begin{syntax}
%     poetry/rightmargin = \meta{dimen} \hfill Default: 0pt
%   \end{syntax}
%   \meta{|dimen|} used for the right margin of the \env{poetry} environment.
% \end{option}
%
% \changes{v1.1}{2022/07/31}{Add \opt{poetry/verse/left} option}
% \begin{option}[added=2022-07-31]{poetry/verse/left}
%   \begin{syntax}
%     poetry/verse/left = \meta{boolean} \hfill Default: false
%   \end{syntax}
%   Align verse numbers in \env{poetry} environments at the left margin of the
%   \env{scripture} environment. This option is the opposite of
%   \opt{poetry/verse/right}.
% \end{option}
%
% \begin{scriptureexample}[lefthand ratio=0.65]
% \begin{verbatim}
% \begin{scripture}[Atcs 15:15--18]%
%     [poetry/leftmargin=2em, poetry/verse/left]
%   \vs{15}The words of the prophets are in
%   agreement with this, as it is written:
%   \begin{poetry}
%     \vs{16}`\thinspace``After this I will return
%     and rebuild David's fallen tent.
%
%     Its ruins I will rebuild,
%     and I will restore it,
%
%     \vs{17}that the rest of mankind may seek the Lord,
%     even all the Gentiles who bear my name,
%
%     says the Lord, who does these things''---
%     \vs{18}things known from long ago.
%   \end{poetry}
% \end{scripture}
% \end{verbatim}
%
% \tcblower
%
% \begin{scripture}[Atcs 15:15--18]%
%     [poetry/leftmargin=2em, poetry/verse/left]
%   \vs{15}The words of the prophets are in
%   agreement with this, as it is written:
%   \begin{poetry}
%     \vs{16}`\thinspace``After this I will return
%     and rebuild David's fallen tent.
%
%     Its ruins I will rebuild,
%     and I will restore it,
%
%     \vs{17}that the rest of mankind may seek the Lord,
%     even all the Gentiles who bear my name,
%
%     says the Lord, who does these things''---
%     \vs{18}things known from long ago.
%   \end{poetry}
% \end{scripture}
% \end{scriptureexample}
%
% \changes{v1.1}{2022/07/31}{Add \opt{poetry/verse/right} option}
% \begin{option}[added=2022-07-31]{poetry/verse/right}
%   \begin{syntax}
%     poetry/verse/right = \meta{boolean} \hfill Default: true
%   \end{syntax}
%   Align verse numbers in \env{poetry} environments at the left margin of the
%   poetry environment. The verse numbers overlap to the left. This option is
%   the opposite of \opt{poetry/verse/left}.
% \end{option}
%
% \changes{v1.1}{2022/07/31}{Add \opt{poetry/verse/sep} option}
% \begin{option}[added=2022-07-31]{poetry/verse/sep}
%   \begin{syntax}
%     poetry/verse/sep = \meta{dimen} \hfill Default: 0.05 em
%   \end{syntax}
%   \meta{|dimen|} used to separate a \cs{vs} from the following text in a
%   \env{poetry} environment. This is only used for verses at the start of a
%   line.
% \end{option}
%
% \end{documentation}
%
% \begin{implementation}
% 
% \section{Implementation}
%
%    \begin{macrocode}
%<*package>
%<@@=scripture>
%    \end{macrocode}
%
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[2022-06-01]
\ProvidesExplPackage{scripture}{2023/01/08}{1.3}
  {Format Scripture Quotations (DCP)}
%    \end{macrocode}
%
% \subsection{Messages}
%
% \env{scripture} environments along with all internal environments can not be
% nested.
%
%    \begin{macrocode}
\msg_new:nnnn { scripture } { nested-environment }
  { Nesting~of~scripture~environments~not~supported. }
  { You~have~tried~to~nest~a~scripture~environment~or \\
    one~of~its~internal~environments,~which~is~not~supported. }
%    \end{macrocode}
%
% Make sure \pkg{polyglossia} languages and variants are set up.
%
%    \begin{macrocode}
\msg_new:nnnn { scripture } { language-error }
  { Language~`#1'~not~set~up. }
  { Language~`#1'~has~not~been~set~up.~Make~sure~you~set~up~languages~
    before~using~the~language~option~of~the~scripture~environment. }
%    \end{macrocode}
%
% Warn if a \opt{language} is requested and neither \pkg{babel} nor
% \pkg{polyglossia} is loaded.
%
%    \begin{macrocode}
\msg_new:nnnn { scripture } { language-warning }
  { Language~requested~without~support. }
  { You~have~requested~language=#1,~but~neither~babel~nor~polyglossia~
    have~been~loaded~and~set~up.~Ignoring~option~language=#1. }
%    \end{macrocode}
%
% \subsection{Options}
%
% Key-value settings for the \env{scripture} environment and its inner
% environments.
%    \begin{macrocode}
\keys_define:nn { scripture }
  {
    , aboveskip                .tl_set:N           = \l_@@_aboveskip_tl
    , aboveskip                .value_required:n   = true
    , aboveskip                .initial:n          = \c_zero_skip
    , added / font             .tl_set:N           = \l_@@_added_font_tl
    , added / font             .value_required:n   = true
    , added / font             .initial:n          =
    , added / format           .cs_set:Np          = \@@_added_format:n #1
    , added / format           .value_required:n   = true
    , added / format           .initial:n          = \emph { #1 }
    , belowskip                .tl_set:N           = \l_@@_belowskip_tl
    , belowskip                .value_required:n   = true
    , belowskip                .initial:n          = \c_zero_skip
    , colour                   .tl_set:N           = \l_@@_colour_tl
    , colour                   .value_required:n   = true
    , colour                   .initial:n          = .
    , color                    .meta:n             = { colour = { #1 } }
    , compact                  .bool_set:N         = \l_@@_compact_bool
    , compact                  .default:n          = true
    , compact                  .initial:n          = false
    , chapter / font           .tl_set:N           = \l_@@_chap_font_tl
    , chapter / font           .value_required:n   = true
    , chapter / font           .initial:n          = \bfseries
    , chapter / colour         .tl_set:N           = \l_@@_chapter_colour_tl
    , chapter / colour         .value_required:n   = true
    , chapter / colour         .initial:n          = .
    , chapter / color          .meta:n             = { chapter / colour = { #1 } }
    , chapter / drop           .bool_set:N         = \l_@@_chap_drop_bool
    , chapter / drop           .default:n          = true
    , chapter / drop           .initial:n          = true
    , chapter / format         .cs_set:Np          = \@@_chap_format:n #1
    , chapter / format         .value_required:n   = true
    , chapter / format         .initial:n          = #1
    , chapter / hide           .bool_set_inverse:N = \l_@@_chap_show_bool
    , chapter / hide           .default:n          = true
    , chapter / nodrop         .bool_set_inverse:N = \l_@@_chap_drop_bool
    , chapter / nodrop         .default:n          = true
    , chapter / sep            .tl_set:N           = \l_@@_chap_sep_tl
    , chapter / sep            .value_required:n   = true
    , chapter / sep            .initial:n          = 0.5 em
    , chapter / show           .bool_set:N         = \l_@@_chap_show_bool
    , chapter / show           .default:n          = true
    , chapter / show           .initial:n          = true
    , chapter / showverse      .bool_set:N         = \l_@@_chap_show_verse_bool
    , chapter / showverse      .default:n          = true
    , chapter / showverse      .initial:n          = false
    , extraskip                .tl_set:N           = \l_@@_extraskip_tl
    , extraskip                .value_required:n   = true
    , extraskip                .initial:n          = \medskipamount
    , font                     .tl_set:N           = \l_@@_font_tl
    , font                     .value_required:n   = true
    , font                     .initial:n          =
    , indent                   .bool_set:N         = \l_@@_indent_bool
    , indent                   .default:n          = true
    , indent                   .initial:n          = true
    , _inline                  .bool_set:N         = \l_@@_inline_bool
    , _inline                  .initial:n          = false
    , inline                   .meta:n             = {
                                                       _inline = true ,
                                                       compact ,
                                                       reference / format = (##1) ,
                                                       reference / align = inline ,
                                                       reference / sep = 0.5 em,
                                                       version / format = ##1
                                                     }
    , inline                   .value_forbidden:n  = true
    , inline / begin           .tl_set:N           = \l_@@_inline_begin_tl
    , inline / begin           .value_required:n   = true
    , inline / begin           .initial:n          = ``\,
    , inline / end             .tl_set:N           = \l_@@_inline_end_tl
    , inline / end             .value_required:n   = true
    , inline / end             .initial:n          = \,''
    , language                 .tl_set:N           = \l_@@_language_tl
    , language                 .value_required:n   = true
    , language                 .initial:n          =
    , language / variant       .tl_set:N           = \l_@@_language_variant_tl
    , language / variant       .value_required:n   = true
    , language / variant       .initial:n          =
    , leftmargin               .tl_set:N           = \l_@@_leftmargin_tl
    , leftmargin               .value_required:n   = true
    , leftmargin               .initial:n          = \c_zero_dim
    , name / font              .tl_set:N           = \l_@@_name_font_tl
    , name / font              .value_required:n   = true
    , name / font              .initial:n          = \scshape
    , name / format            .cs_set:Np          = \@@_name_format:n #1
    , name / format            .value_required:n   = true
    , name / format            .initial:n          = #1
    , noindent                 .bool_set_inverse:N = \l_@@_indent_bool
    , noindent                 .default:n          = true
    , parindent                .tl_set:N           = \l_@@_parindent_tl
    , parindent                .value_required:n   = true
    , parindent                .initial:n          = \parindent
    , parskip                  .tl_set:N           = \l_@@_parskip_tl
    , parskip                  .value_required:n   = true
    , parskip                  .initial:n          = \parskip
    , redletter                .bool_set:N         = \l_@@_red_letter_bool
    , redletter                .default:n          = true
    , redletter                .initial:n          = false
    , redletter / colour       .tl_set:N           = \l_@@_red_letter_colour_tl
    , redletter / colour       .value_required:n   = true
    , redletter / colour       .initial:n          = red!80!black
    , redletter / color        .meta:n             = { redletter / colour = { #1 } }
    , reference / align        .choices:nn         = { inline, left, right }
                                                     {
                                                       \tl_if_exist:NF \l_@@_ref_align_tl
                                                         { \tl_new:N \l_@@_ref_align_tl }
                                                       \tl_set_eq:NN \l_@@_ref_align_tl \l_keys_choice_tl
                                                     }
    , reference / align        .value_required:n   = true
    , reference / align        .initial:n          = right
    , reference / colour       .tl_set:N           = \l_@@_ref_colour_tl
    , reference / colour       .value_required:n   = true
    , reference / colour       .initial:n          = .
    , reference / color        .meta:n             = { reference / colour = { #1 } }
    , reference / font         .tl_set:N           = \l_@@_ref_font_tl
    , reference / font         .value_required:n   = true
    , reference / font         .initial:n          = \bfseries
    , reference / format       .cs_set:Np          = \@@_ref_format:n #1
    , reference / format       .value_required:n   = true
    , reference / format       .initial:n          = #1
    , reference / newline      .meta:n             = { reference / sep = \linewidth }
    , reference / newline      .value_forbidden:n  = true
    , reference / sep          .tl_set:N           = \l_@@_ref_sep_tl
    , reference / sep          .value_required:n   = true
    , reference / sep          .initial:n          = 2 em
    , rightmargin              .tl_set:N           = \l_@@_rightmargin_tl
    , rightmargin              .value_required:n   = true
    , rightmargin              .initial:n          = \c_zero_dim
    , selah / text             .tl_set:N           = \l_@@_selah_text_tl
    , selah / text             .value_required:n   = true
    , selah / text             .initial:n          = Selah
    , selah / font             .tl_set:N           = \l_@@_selah_font_tl
    , selah / font             .value_required:n   = true
    , selah / font             .initial:n          = \itshape
    , selah / format           .cs_set:Np          = \@@_selah_format:n #1
    , selah / format           .value_required:n   = true
    , selah / format           .initial:n          = #1
    , selah / sep              .tl_set:N           = \l_@@_selah_sep_tl
    , selah / sep              .value_required:n   = true
    , selah / sep              .initial:n          = 1 em
    , textright / sep          .tl_set:N           = \l_@@_text_right_sep_tl
    , textright / sep          .value_required:n   = true
    , textright / sep          .initial:n          = 1 em
    , verse / colour           .tl_set:N           = \l_@@_verse_colour_tl
    , verse / colour           .value_required:n   = true
    , verse / colour           .initial:n          = .
    , verse / color            .meta:n             = { verse / colour = { #1 } }
    , verse / first            .bool_set:N         = \l_@@_verse_first_bool
    , verse / first            .default:n          = true
    , verse / first            .initial:n          = false
    , verse / firstformat      .cs_set:Np          = \@@_verse_first_format:n #1
    , verse / firstformat      .value_required:n   = true
    , verse / firstformat      .initial:n          = #1
    , verse / firstsep         .tl_set:N           = \l_@@_verse_first_sep_tl
    , verse / firstsep         .value_required:n   = true
    , verse / firstsep         .initial:n          = 0.5em
    , verse / font             .tl_set:N           = \l_@@_verse_font_tl
    , verse / font             .value_required:n   = true
    , verse / font             .initial:n          = 
    , verse / format           .cs_set:Np          = \@@_verse_format:n #1
    , verse / format           .value_required:n   = true
    , verse / format           .initial:n          = \textsuperscript{#1}
    , verse / hide             .bool_set_inverse:N = \l_@@_verse_show_bool
    , verse / hide             .default:n          = true
    , verse / sep              .tl_set:N           = \l_@@_verse_sep_tl
    , verse / sep              .value_required:n   = true
    , verse / sep              .initial:n          = 0.05 em
    , verse / show             .bool_set:N         = \l_@@_verse_show_bool
    , verse / show             .default:n          = true
    , verse / show             .initial:n          = true
    , version                  .tl_set:N           = \l_@@_version_tl
    , version                  .value_required:n   = true
    , version                  .initial:n          =
    , version / delim          .tl_set:N           = \l_@@_version_delim_tl
    , version / delim          .value_required:n   = true
    , version / delim          .initial:n          = \c_space_tl
    , version / format         .cs_set:Np          = \@@_version_format:n #1
    , version / format         .value_required:n   = true
    , version / format         .initial:n          = (#1)
%    \end{macrocode}
% Options for the \env{center} environment.
%    \begin{macrocode}
    , center / aboveskip       .tl_set:N           = \l_@@_center_aboveskip_tl
    , center / aboveskip       .value_required:n   = true
    , center / aboveskip       .initial:n          = \medskipamount
    , center / belowskip       .tl_set:N           = \l_@@_center_belowskip_tl
    , center / belowskip       .value_required:n   = true
    , center / belowskip       .initial:n          = \medskipamount
    , center / leftmargin      .tl_set:N           = \l_@@_center_leftmargin_tl
    , center / leftmargin      .value_required:n   = true
    , center / leftmargin      .initial:n          = \c_zero_dim
    , center / rightmargin     .tl_set:N           = \l_@@_center_rightmargin_tl
    , center / rightmargin     .value_required:n   = true
    , center / rightmargin     .initial:n          = \c_zero_dim
%    \end{macrocode}
% Options for the \env{flushright} environment.
%    \begin{macrocode}
    , flushright / aboveskip   .tl_set:N           = \l_@@_flushright_aboveskip_tl
    , flushright / aboveskip   .value_required:n   = true
    , flushright / aboveskip   .initial:n          = \medskipamount
    , flushright / belowskip   .tl_set:N           = \l_@@_flushright_belowskip_tl
    , flushright / belowskip   .value_required:n   = true
    , flushright / belowskip   .initial:n          = \medskipamount
    , flushright / leftmargin  .tl_set:N           = \l_@@_flushright_leftmargin_tl
    , flushright / leftmargin  .value_required:n   = true
    , flushright / leftmargin  .initial:n          = \c_zero_dim
    , flushright / rightmargin .tl_set:N           = \l_@@_flushright_rightmargin_tl
    , flushright / rightmargin .value_required:n   = true
    , flushright / rightmargin .initial:n          = \c_zero_dim
%    \end{macrocode}
% Options for the \env{hanging} environment.
%    \begin{macrocode}
    , hanging / aboveskip      .tl_set:N           = \l_@@_hanging_aboveskip_tl
    , hanging / aboveskip      .value_required:n   = true
    , hanging / aboveskip      .initial:n          = \medskipamount
    , hanging / belowskip      .tl_set:N           = \l_@@_hanging_belowskip_tl
    , hanging / belowskip      .value_required:n   = true
    , hanging / belowskip      .initial:n          = \medskipamount
    , hanging / hang           .tl_set:N           = \l_@@_hanging_hang_tl
    , hanging / hang           .value_required:n   = true
    , hanging / hang           .initial:n          = 2 em
    , hanging / leftmargin     .tl_set:N           = \l_@@_hanging_leftmargin_tl
    , hanging / leftmargin     .value_required:n   = true
    , hanging / leftmargin     .initial:n          = 1 em
    , hanging / rightmargin    .tl_set:N           = \l_@@_hanging_rightmargin_tl
    , hanging / rightmargin    .value_required:n   = true
    , hanging / rightmargin    .initial:n          = \c_zero_dim
%    \end{macrocode}
% Options for the mid-paragraph chapters (including the \env{midparachap} environment).
%    \begin{macrocode}
    , midparachap / hideverse  .bool_set_inverse:N = \l_@@_midparachap_show_verse_bool
    , midparachap / hideverse  .default:n          = true
    , midparachap / showverse  .bool_set:N         = \l_@@_midparachap_show_verse_bool
    , midparachap / showverse  .default:n          = true
    , midparachap / showverse  .initial:n          = true
%    \end{macrocode}
% Options for the \env{narrow} environment.
%    \begin{macrocode}
    , narrow / aboveskip       .tl_set:N           = \l_@@_narrow_aboveskip_tl
    , narrow / aboveskip       .value_required:n   = true
    , narrow / aboveskip       .initial:n          = \medskipamount
    , narrow / belowskip       .tl_set:N           = \l_@@_narrow_belowskip_tl
    , narrow / belowskip       .value_required:n   = true
    , narrow / belowskip       .initial:n          = \medskipamount
    , narrow / leftmargin      .tl_set:N           = \l_@@_narrow_leftmargin_tl
    , narrow / leftmargin      .value_required:n   = true
    , narrow / leftmargin      .initial:n          = 1 em
    , narrow / rightmargin     .tl_set:N           = \l_@@_narrow_rightmargin_tl
    , narrow / rightmargin     .value_required:n   = true
    , narrow / rightmargin     .initial:n          = 1 em
%    \end{macrocode}
% Options for the \env{poetry} environment.
%    \begin{macrocode}
    , poetry / aboveskip       .tl_set:N           = \l_@@_poetry_aboveskip_tl
    , poetry / aboveskip       .value_required:n   = true
    , poetry / aboveskip       .initial:n          = \medskipamount
    , poetry / belowskip       .tl_set:N           = \l_@@_poetry_belowskip_tl
    , poetry / belowskip       .value_required:n   = true
    , poetry / belowskip       .initial:n          = \medskipamount
    , poetry / bigindent       .tl_set:N           = \l_@@_poetry_big_indent_tl
    , poetry / bigindent       .value_required:n   = true
    , poetry / bigindent       .initial:n          = 4 em
    , poetry / indent          .tl_set:N           = \l_@@_poetry_indent_tl
    , poetry / indent          .value_required:n   = true
    , poetry / indent          .initial:n          = 1 em
    , poetry / leftmargin      .tl_set:N           = \l_@@_poetry_leftmargin_tl
    , poetry / leftmargin      .value_required:n   = true
    , poetry / leftmargin      .initial:n          = 1 em
    , poetry / rightmargin     .tl_set:N           = \l_@@_poetry_rightmargin_tl
    , poetry / rightmargin     .value_required:n   = true
    , poetry / rightmargin     .initial:n          = \c_zero_dim
    , poetry / verse / left    .bool_set_inverse:N = \l_@@_poetry_verse_right_bool
    , poetry / verse / left    .default:n          = true
    , poetry / verse / right   .bool_set:N         = \l_@@_poetry_verse_right_bool
    , poetry / verse / right   .default:n          = true
    , poetry / verse / right   .initial:n          = true
    , poetry / verse / sep     .tl_set:N           = \l_@@_poetry_verse_sep_tl
    , poetry / verse / sep     .value_required:n   = true
    , poetry / verse / sep     .initial:n          = 0.05 em
  }
%    \end{macrocode}
% Process package options.
%    \begin{macrocode}
\ProcessKeyOptions
%    \end{macrocode}
%
% \subsection{Hooks}
%
% \begin{hooks}{scripture/chap/before, scripture/chap/after,
%   scripture/verse/before, scripture/verse/after}
% Hooks for before and after chapters and verses. The current chapter and
% verse is available in the hooks as \cs{scripturecurrentchapter} and
% \cs{scripturecurrentverse} respectively. These are global.
%    \begin{macrocode}
\hook_new_pair:nn { scripture / chap / before } { scripture / chap / after }
\hook_new_pair:nn { scripture / verse / before } { scripture / verse / after }
%    \end{macrocode}
% \end{hooks}
%
% \subsection{The main \env{scripture} environment}
%
% \begin{macro}{\l_@@_active_bool, \l_@@_active_inner_bool}
%   Flags to ensure that environments are not nested.
%    \begin{macrocode}
\bool_new:N \l_@@_active_bool
\bool_new:N \l_@@_active_inner_bool
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_clubpenalty_saved_int}
%   Holds saved club penalty so we can change and restore it around chapter
%   breaks.
%    \begin{macrocode}
\int_new:N \l_@@_clubpenalty_saved_int
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_extra_skip:}
%   Insert a little extra vertical space between two paragraphs. This function
%   tests if the previous paragraph is only one line in length and began
%   with a \cs{ch} function. If this condition is met, more space is added
%   if necessary to avoid the following paragraph clashing with the drop
%   chapter.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_extra_skip:
  {
    \int_compare:nNnT
      \g_@@_chap_par_prevgraf_int = 1
      {
        \dim_compare:nNnT
          { \parskip + \glueexpr \l_@@_extraskip_tl } < \baselineskip
          {
            \addvspace { \baselineskip }
          }
        \int_gzero:N \g_@@_chap_par_prevgraf_int
      }
    \addvspace { \l_@@_extraskip_tl }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_text_right:nn}
%   Align a word to the right and finish a paragraph, pushing to the next line
%   if there is not space for the word.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_text_right:nn
  {
    \bool_lazy_or:nnTF
      { \str_if_eq_p:Vn \l_@@_currenvir_str { flushright } }
      { \str_if_eq_p:Vn \l_@@_currenvir_str { center } }
      {
        \unskip
        \break
        \strut
        \hfill
        #2
        \para_end:
      }
      {
        {
          \unskip
          \hfil
          \penalty 50
          \skip_horizontal:n { #1 }
          \hbox:n {}
          \nobreak
          \hfill
          #2
          \skip_zero:N \parfillskip
          \int_zero:N \finalhyphendemerits
          \para_end:
        }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Formatting and printing quotation references}
%
% \begin{macro}{\l_@@_ref_box}
%   Box to hold the formatted reference.
%    \begin{macrocode}
\box_new:N \l_@@_ref_box
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_format_full_ref:n}
%   Format a scripture quotation with its reference.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_format_full_ref:n
  {
    \group_begin:
    \l_@@_ref_font_tl
    \str_if_eq:VnF \l_@@_ref_colour_tl { . }
      { \exp_args:NV \color_select:n \l_@@_ref_colour_tl }
    \@@_ref_format:n
      {
        #1
%    \end{macrocode}
% Append a Bible version if it has been specified.
%    \begin{macrocode}
        \tl_if_empty:NF \l_@@_version_tl
          {
            \l_@@_version_delim_tl
            \@@_version_format:n { \l_@@_version_tl }
          }
      }
    \group_end:
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_reference:n}
%   Output the reference for the Scripture quotation.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_reference:n
  {
    \hbox_set:Nn \l_@@_ref_box
      {
        \@@_format_full_ref:n { #1 }
      }
%    \end{macrocode}
% Since the \env{poetry} environment uses \cs{@@_obeylines:} there is always
% an extra \cs{parskip} when a \env{scripture} quotation ends with a
% \env{poetry}
% environment.
%    \begin{macrocode}
    \bool_if:NT \g_@@_poetry_end_bool
      { \skip_vertical:n { -\parskip } }
    \dim_compare:nNnT
      { \box_wd:N \l_@@_ref_box + \g_@@_final_line_dim + \l_@@_ref_sep_tl }
      >
      \linewidth
      { \skip_vertical:N \baselineskip }
%    \end{macrocode}
% If a \env{scripture} quotation ends with an inner environment, there will
% be an extra space of \cs{baselineskip}.
%    \begin{macrocode}
    \int_compare:nNnT \prevgraf = \c_zero_int
      { \skip_vertical:n { -\baselineskip } }
    \tl_if_eq:NnT \l_@@_ref_align_tl { right }
      { \hfill }
    \tl_if_eq:NnT \l_@@_ref_align_tl { left }
      {
        \mode_leave_vertical:
        \dim_compare:nNnT
          { \box_wd:N \l_@@_ref_box + \g_@@_final_line_dim + \l_@@_ref_sep_tl }
          <
          \linewidth
          { \skip_horizontal:n { \g_@@_final_line_dim + \l_@@_ref_sep_tl } }
      }
    \box_use:N \l_@@_ref_box
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Red lettering}
%
% \begin{macro}{\g_@@_red_letter_active_bool}
%   Flag indicating if currently in a red letter block of text.
%    \begin{macrocode}
\bool_new:N \g_@@_red_letter_active_bool
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_red_letter_on:}
%   Mark the beginning of a section of text attributed to Jesus Christ.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_red_letter_on:
  {
    \bool_if:NT \l_@@_red_letter_bool
      {
        \bool_gset_true:N \g_@@_red_letter_active_bool
        \exp_args:NV \color_select:n \l_@@_red_letter_colour_tl
        \str_if_eq:VnF \l_@@_currenvir_str { scripture }
          {
            \hook_gput_next_code:nn { env / \l_@@_currenvir_str / after }
              {
                \exp_args:NV \color_select:n \l_@@_red_letter_colour_tl
              }
          }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_red_letter_off:}
%   Mark the beginning of a section of text attributed to Jesus Christ.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_red_letter_off:
  {
    \bool_if:NT \l_@@_red_letter_bool
      {
        \color_select:n { scripture default colour }
        \bool_gset_false:N \g_@@_red_letter_active_bool
        \str_if_eq:VnF \l_@@_currenvir_str { scripture }
          {
            \hook_gput_next_code:nn { env / \l_@@_currenvir_str / after }
              {
                \color_select:n { scripture default colour }
              }
          }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Selecting language}
%
% \begin{macro}{\@@_select_language:}
%   Select specified language if required.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_select_language:
  {
    \tl_if_empty:NF \l_@@_language_tl
      {
        \@ifpackageloaded { babel }
          {
            \selectlanguage { \l_@@_language_tl }
          }
          {
            \@ifpackageloaded { polyglossia }
              {
                \iflanguageloaded { \l_@@_language_tl }
                  {
                    \tl_if_empty:NTF \l_@@_language_variant_tl
                      {
                        \selectlanguage { \l_@@_language_tl }
                      }
                      {
                        \selectlanguage
                          [ variant = \l_@@_language_variant_tl ]
                          { \l_@@_language_tl }
                      }
                  }
                  {
                    \msg_error:nnx
                      { scripture }
                      { language-error }
                      { \l_@@_language_tl }
                  }
              }
              {
                \msg_warning:nnx
                  { scripture }
                  { language-waning }
                  { \l_@@_language_tl }
              }
          }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Formatting and printing chapter numbers}
%
% \begin{macro}{\l_@@_chap_box, l_@@_chap_tmp_box}
%   Boxes use to store and calculate drop chapter.
%    \begin{macrocode}
\box_new:N \l_@@_chap_box
\box_new:N \l_@@_chap_tmp_box
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_chap_fontsize_dim}
%   Calculated font size of a drop chapter number.
%    \begin{macrocode}
\dim_new:N \l_@@_chap_fontsize_dim
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_chap_height_dim}
%   Calculated height of a drop chapter number.
%    \begin{macrocode}
\dim_new:N \l_@@_chap_height_dim
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_chap_width_dim}
%   Calculated width of drop chapter number.
%    \begin{macrocode}
\dim_new:N \l_@@_chap_width_dim
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\g_@@_chap_par_prevgraf_int}
%   Store the number of lines a chapter paragraph takes up.
%    \begin{macrocode}
\int_new:N \g_@@_chap_par_prevgraf_int
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_chap_X_height_dim}
%   Calculated height of X at current font size. This is used as the height
%   for a drop chapter.
%    \begin{macrocode}
\dim_new:N \l_@@_chap_X_height_dim
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_drop_chap_set_up:n}
%   Set up chapter drop cap and calculate its various dimensions.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_drop_chap_set_up:n
  {
    \cs_gset_nopar:Npn \scripturecurrentchapter { #1 }
    \cs_gset_nopar:Npn \scripturecurrentverse { 1 }
    \hbox_set:Nn \l_@@_chap_tmp_box { X }
    \dim_set:Nn \l_@@_chap_X_height_dim
      { \box_ht:N \l_@@_chap_tmp_box }
    \dim_set:Nn \l_@@_chap_height_dim
      { \baselineskip + \l_@@_chap_X_height_dim }
    \dim_set:Nn \l_@@_chap_fontsize_dim
      {
        \f@size pt *
        \dim_ratio:nn
          { \l_@@_chap_height_dim }
          { \l_@@_chap_X_height_dim }
      }
    \hbox_set:Nn \l_@@_chap_tmp_box
      {
        \l_@@_chap_font_tl
        \fontsize
          { \l_@@_chap_fontsize_dim }
          { \l_@@_chap_fontsize_dim }
          \selectfont
        \str_if_eq:VnF \l_@@_chapter_colour_tl { . }
          { \exp_args:NV \color_select:n \l_@@_chapter_colour_tl }
        \@@_chap_format:n { #1 }
      }
    \dim_set:Nn \l_@@_chap_width_dim
      { \box_wd:N \l_@@_chap_tmp_box }
%    \end{macrocode}
%   Avoid breaks in the middle of drop chapters.
%    \begin{macrocode}
    \int_set_eq:NN \l_@@_clubpenalty_saved_int \clubpenalty
    \clubpenalty 10000
    \hook_gput_next_code:nn { para / after }
      {
        \int_gset_eq:NN \g_@@_chap_par_prevgraf_int \prevgraf
        \int_compare:nNnT
          \g_@@_chap_par_prevgraf_int = 1
          { \penalty 10000 }
        \hook_gput_next_code:nn { para / before }
          { \int_set_eq:NN \clubpenalty \l_@@_clubpenalty_saved_int }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_drop_chap_output:}
%   Output a drop chapter.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_drop_chap_output:
  {
    \noindent
    \parshape 3 ~
      \dim_eval:n
        { \@totalleftmargin + \l_@@_chap_width_dim + \l_@@_chap_sep_tl } ~
      \dim_eval:n
        { \linewidth - \l_@@_chap_width_dim - \l_@@_chap_sep_tl } ~
      \dim_eval:n
        { \@totalleftmargin + \l_@@_chap_width_dim + \l_@@_chap_sep_tl } ~
      \dim_eval:n
        { \linewidth - \l_@@_chap_width_dim - \l_@@_chap_sep_tl } ~
      \@totalleftmargin ~
      \linewidth
    \group_begin:
    \hook_use:n { scripture / chap / before }
    \box_use:N \l_@@_chap_box
    \hook_use:n { scripture / chap / after }
    \group_end:
    \bool_if:NT \l_@@_chap_show_verse_bool
      {
        \@@_verse_output:n { 1 }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_nodrop_chap:n}
%   Format a non-drop chapter.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_nodrop_chap:n
  {
    \cs_gset_nopar:Npn \scripturecurrentchapter { #1 }
    \cs_gset_nopar:Npn \scripturecurrentverse { 1 }
    \group_begin:
    \bool_if:NTF \l_@@_chap_show_bool
      {
        \hook_use:n { scripture / chap / before }
        \group_begin:
        \str_if_eq:VnF \l_@@_chapter_colour_tl { . }
          { \exp_args:NV \color_select:n \l_@@_chapter_colour_tl }
        \l_@@_chap_font_tl
        \@@_chap_format:n { #1 }
        \group_end:
        \skip_horizontal:N \l_@@_chap_sep_tl
        \hook_use:n { scripture / chap / after }
        \bool_if:NT \l_@@_chap_show_verse_bool
          {
            \@@_verse_output:n { 1 }
          }
      }
      {
        \hook_use:n { scripture / chap / before }
        \hook_use:n { scripture / chap / after }
        \vs { 1 }
      }
    \group_end:
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_chap:n}
%   Position a drop chapter.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_chap:n
  {
    \@@_drop_chap_set_up:n { #1 }
    \hbox_set:Nn \l_@@_chap_box
      {
        \box_move_down:nn
          { \baselineskip }
          { 
            \hbox_overlap_left:n
              {
                \box_use:N \l_@@_chap_tmp_box
                \skip_horizontal:N \l_@@_chap_sep_tl
              }
          }
      }
    \box_set_ht:Nn \l_@@_chap_box { \c_zero_dim }
    \box_set_dp:Nn \l_@@_chap_box { \c_zero_dim }
    \bool_if:NTF \l_@@_mid_para_chap_bool
      { \@@_mid_para_drop_chap_output: }
      {
        \par
        \@@_drop_chap_output:
      }
    \hook_gput_next_code:nn { para / before }
      {
        \int_compare:nNnT
          \g_@@_chap_par_prevgraf_int = 1
          { \extraskip }
        \int_gzero:N \g_@@_chap_par_prevgraf_int
        \int_compare:nNnT
          \@listdepth > \c_zero_int
          { \parshape 1 ~ \@totalleftmargin ~ \linewidth }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Formatting and printing verse numbers}
%
% \begin{macro}{\l_@@_verse_par_start_bool}
%   Flag for whether the current verse is at the start of a paragraph.
%    \begin{macrocode}
\bool_new:N \l_@@_verse_par_start_bool
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_no_verse_first_bool}
%   Suppress the next verse from formatting differently if it begins a new
%   paragraph.
%    \begin{macrocode}
\bool_new:N \l_@@_no_verse_first_bool
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_verse_output:n}
%   Output a formatted verse.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_verse_output:n
  {
    \cs_gset_nopar:Npn \scripturecurrentverse { #1 }
    \legacy_if:nTF { @endpe }
      { \bool_set_false:N \l_@@_verse_par_start_bool }
      { \bool_set_true:N \l_@@_verse_par_start_bool }
    \mode_if_vertical:TF
      { \mode_leave_vertical: }
      { \bool_set_false:N \l_@@_verse_par_start_bool }
    \bool_if:NT \l_@@_no_verse_first_bool
      {
        \bool_set_false:N \l_@@_verse_par_start_bool
        \bool_set_false:N \l_@@_no_verse_first_bool
      }
    \group_begin:
    \hook_use:n { scripture / verse / before }
    \bool_if:NT \l_@@_verse_show_bool
      {
        \group_begin:
        \l_@@_verse_font_tl
        \str_if_eq:VnF \l_@@_verse_colour_tl { . }
          { \exp_args:NV \color_select:n \l_@@_verse_colour_tl }
        \bool_lazy_all:nTF
          {
            { \l_@@_verse_first_bool }
            { \l_@@_verse_par_start_bool }
            { \bool_not_p:n { \str_if_eq_p:Vn \l_@@_currenvir_str { poetry } } }
          }
          {
            \@@_verse_first_format:n { #1 }
            \group_end:
            \kern \l_@@_verse_first_sep_tl
          }
          {
            \@@_verse_format:n { #1 }
            \group_end:
            \kern \l_@@_verse_sep_tl
          }
      }
    \hook_use:n { scripture / verse / after }
    \group_end:
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Calculating the length of the final line in a paragraph}
%
% \begin{macro}{\g_@@_final_line_dim}
%   Store the length of the final line in a paragraph.
%    \begin{macrocode}
\dim_new:N \g_@@_final_line_dim
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_calc_final_line_length:}
%   Calculate the length of the final line in a paragraph.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_calc_final_line_length:
  {
    \skip_set:Nn \abovedisplayshortskip { -\baselineskip }
    \skip_set_eq:NN \abovedisplayskip \abovedisplayshortskip
    \skip_zero:N \belowdisplayshortskip
    \skip_zero:N \belowdisplayskip
    $$
      \dim_compare:nNnT \predisplaysize > \c_zero_dim
        {
          \dim_gset:Nn \g_@@_final_line_dim
            { \predisplaysize - 2 em }
        }
      \cs_gset_nopar:Nx \@@_reset_spacing:
        {
          \dim_set:Nn \predisplaysize { \dim_use:N \predisplaysize }
          \int_set:Nn \prevgraf { \int_use:N \prevgraf }
        }
    $$
    \@@_reset_spacing:
    \dim_compare:nNnT \g_@@_final_line_dim > \linewidth
      {
        \dim_gset_eq:NN \g_@@_final_line_dim \linewidth
      }
    \dim_compare:nNnT \g_@@_final_line_dim > { \c_zero_dim - 1 sp }
      {
        \skip_vertical:n { -\baselineskip - \parskip }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{The \env{scripture} environment}
%
% \begin{macro}{\l_@@_currenvir_str}
%   Store the current \pkg{scripture} environment.
%    \begin{macrocode}
\str_new:N \l_@@_currenvir_str
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_parskip_correction_skip}
%   Correction to ensure consistent \cs{parskip} at start of \env{scripture}
%   environment with non-zero \opt{parskip} option.
%    \begin{macrocode}
\skip_new:N \l_@@_parskip_correction_skip
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\g_@@_start_bool}
%   Flag indicating whether we are currently setting the first paragraph in a
%   \env{scripture} environment. If this is \val{true}, any \opt{aboveskip}
%   for an inner environment will be ignored.
%    \begin{macrocode}
\bool_new:N \g_@@_start_bool
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_begin:n}
%   Begin a scripture quotation.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_begin:n
  {
    \bool_if:NT \l_@@_active_bool
      {
        \msg_error:nn { scripture } { nested-environment }
      }
    \bool_set_true:N \l_@@_active_bool
    \tl_set:Nn \l_@@_currenvir_str { scripture }
    \tl_if_novalue:nF { #1 }
      {
        \keys_set:nn { scripture } { #1 }
      }
    \@@_select_language:
%    \end{macrocode}
% If the \env{scripture} environment begins immediately after an \cs{item},
% then insert a new paragraph and apply a negative skip. Life is much easier
% if all paragraphs in a \env{scripture} are the same rather than the first
% one being in the first paragraph of an \cs{item}.
%    \begin{macrocode}
    \legacy_if:nT { @newlist }
      {
        \strut
        \par
        \vspace* { \dim_eval:n { -\baselineskip - \parskip } }
      }
    \mode_if_vertical:T
      {
        \addvspace { \l_@@_aboveskip_tl }
      }
    \DeclareDocumentCommand { \ch } { sm }
      {
        \bool_if:NTF \l_@@_chap_show_bool
          {
            \bool_if:NTF \l_@@_chap_drop_bool
              {
                \@@_chap:n { ##2 }
                \bool_if:nT { ##1 }
                  {
                    \hook_gput_next_code:nn { para / after }
                      { \int_gzero:N \g_@@_chap_par_prevgraf_int }
                  }
              }
              { \@@_nodrop_chap:n { ##2 } }
          }
          { \@@_nodrop_chap:n { ##2 } }
      }
%    \end{macrocode}
% Empty \cs{everydisplay} to ensure it isn't interring with spacing.
%    \begin{macrocode}
    \everydisplay { }
    \int_set:Nn \predisplaypenalty { 10000 }
    \int_set_eq:NN \postdisplaypenalty \@lowpenalty
    \bool_gset_true:N \g_@@_start_bool
    \bool_gset_false:N \g_@@_poetry_end_bool
    \dim_set_eq:NN \parindent \l_@@_parindent_tl
    \cs_set_eq:NN \extraskip \@@_extra_skip:
    \cs_set_eq:NN \redletteron \@@_red_letter_on:
    \cs_set_eq:NN \redletteroff \@@_red_letter_off:
    \cs_set_eq:NN \vs \@@_verse_output:n
    \cs_set_protected_nopar:Npn \added ##1
      {
        \group_begin:
        \l_@@_added_font_tl
        \@@_added_format:n { ##1 }
        \group_end:
      }
    \cs_set_protected_nopar:Npn \name ##1
      {
        \group_begin:
        \l_@@_name_font_tl
        \@@_name_format:n { ##1 }
        \group_end:
      }
    \cs_set_protected_nopar:Npn \nofirstverse
      {
        \bool_set_true:N \l_@@_no_verse_first_bool
      }
    \cs_set_protected_nopar:Npn \LORD
      {
        \name { Lord }
      }
    \cs_set_protected_nopar:Npn \GOD
      {
        \name { God }
      }
    \cs_set_protected_nopar:Npn \textright ##1
      {
        \@@_text_right:nn { \l_@@_text_right_sep_tl } { ##1 }
      }
    \hook_gclear_next_code:n { para / before }
    \skip_set:Nn \l_@@_parskip_correction_skip { \parskip - \l_@@_parskip_tl }
    \mode_if_vertical:T
      {
        \addvspace { \l_@@_parskip_correction_skip }
      }
    \skip_set_eq:NN \parskip \l_@@_parskip_tl
    \l_@@_font_tl
    \exp_args:NnV \color_set:nn { scripture default colour } \l_@@_colour_tl
    \str_if_eq:VnF \l_@@_colour_tl { . }
      {
        \color_select:n { scripture default colour }
      }
%    \end{macrocode}
% For left and right margins, use \cs{parshape} is already in a list,
% otherwise use \cs{leftskip} and \cs{rightskip}
%    \begin{macrocode}
    \bool_lazy_or:nnT
      { \dim_compare_p:n { \l_@@_leftmargin_tl > 0pt } }
      { \dim_compare_p:n { \l_@@_rightmargin_tl > 0pt } }
      {
        \dim_sub:Nn \linewidth
          { \l_@@_leftmargin_tl + \l_@@_rightmargin_tl }
        \int_compare:nNnTF
          \@listdepth > \c_zero_int
          {
            \dim_add:Nn \@totalleftmargin \l_@@_leftmargin_tl
            \parshape 1 ~ \@totalleftmargin ~ \linewidth
          }
          {
            \dim_add:Nn \leftskip \l_@@_leftmargin_tl
            \dim_add:Nn \rightskip \l_@@_rightmargin_tl
          }
      }
    \bool_if:NF \l_@@_indent_bool
      {
        \hook_gput_next_code:nn { para / begin }
          {
            \bool_lazy_any:nT
              {
                { \str_if_eq_p:Vn \l_@@_currenvir_str { midparachap } }
                { \str_if_eq_p:Vn \l_@@_currenvir_str { narrow } }
                { \str_if_eq_p:Vn \l_@@_currenvir_str { scripture } }
              }
              { \para_omit_indent: }
          }
      }
    \bool_if:NT \l_@@_inline_bool
      { \l_@@_inline_begin_tl }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_end:n}
%   End a scripture quotation with a reference.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_end:n
  {
    \tl_if_eq:NnTF \l_@@_ref_align_tl { inline }
      {
        \bool_lazy_or:nnF
          { \tl_if_novalue_p:n { #1 } }
          { \tl_if_empty_p:n { #1 } }
          {
            \unskip
            \@@_red_letter_off:
            \bool_if:NT \l_@@_inline_bool
              { \l_@@_inline_end_tl }
            \skip_horizontal:N \l_@@_ref_sep_tl
            \@@_format_full_ref:n { #1 }
          }
      }
      {
%    \end{macrocode}
% Normally \cs{unskip} does not work in vertical mode, but there are some
% situations where it does work. The following condition is true if the
% \env{scripture} environment has ended with one of its internal
% environments. This removes any unwanted \opt{belowskip} if present and
% leaves the previously calculated line length of the final paragraph intact.
%    \begin{macrocode}
      \mode_if_vertical:TF
        {
          \unskip
          \unskip
        }
        {
          \tl_if_novalue:nTF { #1 }
            { \int_zero:N \postdisplaypenalty }
            { \int_set_eq:NN \postdisplaypenalty \@highpenalty }
          \@@_calc_final_line_length:
        }
%    \end{macrocode}
% Restore left margin by resetting the \cs{parshape} if in a list
% based environment, otherwise the space required for the reference is
% incorrectly calculated.
%    \begin{macrocode}
      \bool_lazy_or:nnTF
        { \dim_compare_p:n { \l_@@_leftmargin_tl > 0pt } }
        { \dim_compare_p:n { \l_@@_rightmargin_tl > 0pt } }
        {
          \dim_add:Nn \linewidth \l_@@_leftmargin_tl
          \int_compare:nNnT
            \@listdepth > \c_zero_int
            {
              \dim_sub:Nn \@totalleftmargin \l_@@_leftmargin_tl
              \parshape 1 ~ \@totalleftmargin ~ \linewidth
            }
        }
        { \parshape 1 ~ \@totalleftmargin ~ \linewidth }
      \@@_red_letter_off:
      \bool_lazy_or:nnF
        { \tl_if_novalue_p:n { #1 } }
        { \tl_if_empty_p:n { #1 } }
        { \@@_reference:n { #1 } }
      \par
%    \end{macrocode}
% Restore right margin by resetting the \cs{parshape} if in a \LaTeX{} list
% based environment, since only the left margin was restored above.
%    \begin{macrocode}
      \bool_lazy_or:nnT
        { \dim_compare_p:n { \l_@@_leftmargin_tl > 0pt } }
        { \dim_compare_p:n { \l_@@_rightmargin_tl > 0pt } }
        {
          \int_compare:nNnT
            \@listdepth > \c_zero_int
            {
              \dim_add:Nn \linewidth \l_@@_rightmargin_tl
              \parshape 1 ~ \@totalleftmargin ~ \linewidth
            }
        }
      \dim_compare:nNnTF
        { \glueexpr \l_@@_belowskip_tl } > \parskip
        {
          \addvspace
            {
              \skip_eval:n { \l_@@_belowskip_tl - \parskip }
            }
        }
        {
          \addvspace { \l_@@_belowskip_tl }
        }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{Scripture internal environments}
%
% \begin{macro}{\l_@@_delta_below_skip}
%   Correction to \tn{@topsepadd} for internal environments. This enables a
%   different \opt{aboveskip} and \opt{belowskip} which are normally the
%   same for \LaTeX{} lists.
%    \begin{macrocode}
\skip_new:N \l_@@_delta_below_skip
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{The \env{center} environment}
%
% \begin{macro}{\@@_center_begin:n}
%   Begin a centred section in a scripture quotation.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_center_begin:n
  {
    \bool_if:NT \l_@@_active_inner_bool
      {
        \msg_error:nn { scripture } { nested-environment }
      }
    \bool_set_true:N \l_@@_active_inner_bool
    \tl_set:Nn \l_@@_currenvir_str { center }
    \tl_if_novalue:nF { #1 }
      {
        \keys_set:nn
          { scripture / center }
          { #1 }
      }
    \mode_if_horizontal:T
      { \par }
    \list { }
      {
        \skip_set_eq:NN \l_@@_delta_below_skip \l_@@_center_belowskip_tl
%    \end{macrocode}
% Ignore \opt{aboveskip} if at the beginning of a \env{scripture} environment.
%    \begin{macrocode}
        \bool_if:NTF \g_@@_start_bool
          {
            \skip_zero:N \topsep
            \skip_sub:Nn \topsep \parskip
            \skip_add:Nn \l_@@_delta_below_skip \parskip
            \bool_gset_false:N \g_@@_start_bool
          }
          {
            \dim_compare:nTF
              { \parskip >= \glueexpr \l_@@_center_aboveskip_tl > \c_zero_skip }
              {
                \skip_zero:N \topsep
                \skip_zero:N \l_@@_delta_below_skip
              }
              {
                \skip_set_eq:NN \topsep \l_@@_center_aboveskip_tl
                \skip_sub:Nn \l_@@_delta_below_skip \l_@@_center_aboveskip_tl
              }
            \int_compare:nNnT \g_@@_chap_par_prevgraf_int = 1
              { \addvspace { \baselineskip } }
            \int_gzero:N \g_@@_chap_par_prevgraf_int
          }
        \skip_set_eq:NN \parsep \parskip
        \skip_zero:N \partopsep
        \dim_zero:N \leftmargin
        \dim_zero:N \labelsep
      }
    \centering
    \item
    \relax
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_center_end:}
%   End a centred section in a scripture quotation.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_center_end:
  {
    \@@_calc_final_line_length:
    \skip_add:Nn \@topsepadd \l_@@_delta_below_skip
    \int_set_eq:NN \@endparpenalty \@lowpenalty
    \endlist
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{The \env{flushright} environment}
%
% \begin{macro}{\@@_flushright_begin:n}
%   Begin a flushright section in a scripture quotation.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_flushright_begin:n
  {
    \bool_if:NT \l_@@_active_inner_bool
      {
        \msg_error:nn { scripture } { nested-environment }
      }
    \bool_set_true:N \l_@@_active_inner_bool
    \tl_set:Nn \l_@@_currenvir_str { flushright }
    \tl_if_novalue:nF { #1 }
      {
        \keys_set:nn
          { scripture / flushright }
          { #1 }
      }
    \mode_if_horizontal:T
      { \par }
    \list { }
      {
        \skip_set_eq:NN \l_@@_delta_below_skip \l_@@_flushright_belowskip_tl
%    \end{macrocode}
% Ignore \opt{aboveskip} if at the beginning of a \env{scripture} environment.
%    \begin{macrocode}
        \bool_if:NTF \g_@@_start_bool
          {
            \skip_zero:N \topsep
            \skip_sub:Nn \topsep \parskip
            \skip_add:Nn \l_@@_delta_below_skip \parskip
            \bool_gset_false:N \g_@@_start_bool
          }
          {
            \dim_compare:nTF
              { \parskip >= \glueexpr \l_@@_flushright_aboveskip_tl > \c_zero_skip }
              {
                \skip_zero:N \topsep
                \skip_zero:N \l_@@_delta_below_skip
              }
              {
                \skip_set_eq:NN \topsep \l_@@_flushright_aboveskip_tl
                \skip_sub:Nn \l_@@_delta_below_skip \l_@@_flushright_aboveskip_tl
              }
            \int_compare:nNnT \g_@@_chap_par_prevgraf_int = 1
              { \addvspace { \baselineskip } }
            \int_gzero:N \g_@@_chap_par_prevgraf_int
          }
        \dim_set_eq:NN \leftmargin \l_@@_flushright_leftmargin_tl
        \dim_set_eq:NN \rightmargin \l_@@_flushright_rightmargin_tl
        \skip_set_eq:NN \parsep \parskip
        \skip_zero:N \partopsep
        \dim_zero:N \leftmargin
        \dim_zero:N \labelsep
      }
    \raggedleft
    \item
    \relax
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_flushright_end:}
%   End a flushright section in a scripture quotation.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_flushright_end:
  {
    \@@_calc_final_line_length:
    \skip_add:Nn \@topsepadd \l_@@_delta_below_skip
    \int_set_eq:NN \@endparpenalty \@lowpenalty
    \endlist
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{The \env{hanging} environment}
%
% \begin{macro}{\l_@@_hanging_parindent_saved_dim}
%   Save the \cs{parindent} for later use in \env{hanging} environment.
%    \begin{macrocode}
\dim_new:N \l_@@_hanging_parindent_saved_dim
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_hanging_chap:n}
%   Position a drop chapter in a \env{hanging} environment.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_hanging_chap:n
  {
    \@@_drop_chap_set_up:n { #1 }
    \dim_compare:nNnTF
      \l_@@_chap_width_dim < \leftmargin
      {
        \tl_set:Nx \l_@@_chap_sep_tl
          {
            \dim_eval:n { \leftmargin - \l_@@_chap_width_dim }
          }
      }
      {
        \parshape 3 ~
          \dim_eval:n
            {
              \@totalleftmargin - \leftmargin + \l_@@_chap_width_dim +
              \l_@@_chap_sep_tl
            } ~
          \dim_eval:n
            {
              \linewidth + \leftmargin - \l_@@_chap_width_dim -
              \l_@@_chap_sep_tl
            } ~
          \dim_eval:n
            {
              \@totalleftmargin - \leftmargin + \l_@@_chap_width_dim +
              \l_@@_chap_sep_tl
            } ~
          \dim_eval:n
            {
              \linewidth + \leftmargin - \l_@@_chap_width_dim -
              \l_@@_chap_sep_tl
            } ~
          \@totalleftmargin ~ \linewidth
      }
    \mode_if_vertical:T
      {
        \tl_set:Nx \l_@@_chap_sep_tl
          {
            \dim_eval:n
              {
                \l_@@_chap_sep_tl + \l_@@_hanging_parindent_saved_dim
              }
          }
        \@@_nohang:
      }
    \hbox_set:Nn \l_@@_chap_box
      {
        \box_move_down:nn
          { \baselineskip }
          { 
            \hbox_overlap_left:n
              {
                \box_use:N \l_@@_chap_tmp_box
                \skip_horizontal:N \l_@@_chap_sep_tl
              }
          }
      }
    \box_set_ht:Nn \l_@@_chap_box { \c_zero_dim }
    \box_set_dp:Nn \l_@@_chap_box { \c_zero_dim }
    \group_begin:
    \hook_use:n { scripture / chap / before }
    \box_use:N \l_@@_chap_box
    \hook_use:n { scripture / chap / after }
    \group_end:
    \bool_if:NT \l_@@_chap_show_verse_bool
      {
        \@@_verse_output:n { 1 }
      }
    \hook_gput_next_code:nn { para / begin }
      { \parshape 1 ~ \@totalleftmargin ~ \linewidth }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_hanging_verse:n}
%   Position a \cs{vs} in a \env{hanging} environment. The verse is set to
%   overlap to the left if at the beginning of a hanging paragraph.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_hanging_verse:n
  {
    \mode_if_vertical:TF
      {
        \strut
        \hbox_overlap_left:n
          {
            \@@_verse_output:n { #1 }
          }
      }
      { \@@_verse_output:n { #1 } }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_nohang:}
%   Don't hang a paragraph in a \env{hanging} environment. Instead the
%   paragraph is indented by \cs{parindent} from its normal hanging position.
%    \begin{macrocode}
\cs_new_protected_nopar:Nn \@@_nohang:
  {
    \para_raw_noindent:
    \hbox_to_wd:nn { \l_@@_hanging_parindent_saved_dim } { }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_hanging_begin:n}
%   Begin a hanging section in a scripture quotation.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_hanging_begin:n
  {
    \bool_if:NT \l_@@_active_inner_bool
      {
        \msg_error:nn { scripture } { nested-environment }
      }
    \bool_set_true:N \l_@@_active_inner_bool
    \tl_set:Nn \l_@@_currenvir_str { hanging }
    \tl_if_novalue:nF { #1 }
      {
        \keys_set:nn
          { scripture / hanging }
          { #1 }
      }
    \mode_if_horizontal:T
      { \par }
    \list { }
      {
        \skip_set_eq:NN \l_@@_delta_below_skip \l_@@_hanging_belowskip_tl
%    \end{macrocode}
% Ignore \opt{aboveskip} if at the beginning of a \env{scripture} environment.
%    \begin{macrocode}
        \bool_if:NTF \g_@@_start_bool
          {
            \dim_zero:N \topsep
            \skip_sub:Nn \topsep \parskip
            \skip_add:Nn \l_@@_delta_below_skip \parskip
            \bool_gset_false:N \g_@@_start_bool
          }
          {
            \dim_compare:nTF
              { \parskip >= \glueexpr \l_@@_hanging_aboveskip_tl > \c_zero_skip }
              {
                \skip_zero:N \topsep
                \skip_zero:N \l_@@_delta_below_skip
              }
              {
                \skip_set_eq:NN \topsep \l_@@_hanging_aboveskip_tl
                \skip_sub:Nn \l_@@_delta_below_skip \l_@@_hanging_aboveskip_tl
              }
            \int_compare:nNnT \g_@@_chap_par_prevgraf_int = 1
              { \addvspace { \baselineskip } }
            \int_gzero:N \g_@@_chap_par_prevgraf_int
          }
        \dim_set:Nn \leftmargin
          { \l_@@_hanging_leftmargin_tl + \l_@@_hanging_hang_tl }
        \dim_set_eq:NN \rightmargin \l_@@_hanging_rightmargin_tl
        \dim_set:Nn \itemindent { -\l_@@_hanging_hang_tl }
        \dim_set:Nn \listparindent { -\l_@@_hanging_hang_tl }
        \skip_set_eq:NN \parsep \parskip
        \skip_zero:N \partopsep
        \dim_zero:N \labelsep
        \dim_set_eq:NN \l_@@_hanging_parindent_saved_dim \parindent
      }
    \DeclareDocumentCommand { \ch } { sm }
      {
        \bool_if:NTF \l_@@_chap_show_bool
          {
            \bool_if:NTF \l_@@_chap_drop_bool
              { \@@_hanging_chap:n { ##2 } }
              { \@@_nodrop_chap:n { ##2 } }
          }
          { \@@_nodrop_chap:n { ##2 } }
      }
    \cs_set_eq:NN \vs \@@_hanging_verse:n
    \cs_set_eq:NN \nohang \@@_nohang:
    \item
    \relax
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_hanging_end:}
%   End a hanging section in a scripture quotation.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_hanging_end:
  {
    \@@_calc_final_line_length:
    \skip_add:Nn \@topsepadd \l_@@_delta_below_skip
    \int_set_eq:NN \@endparpenalty \@lowpenalty
    \endlist
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{The \env{midparachap} environment}
%
% \begin{macro}{\@@_vbox_set_top:Nw}
%   Define missing \cs{vbox_set_top:Nw} function.
%    \begin{macrocode}
\cs_new_protected:Npn \@@_vbox_set_top:Nw #1
  {
    \tex_setbox:D #1 \tex_vtop:D
      \c_group_begin_token
        \color_group_begin:
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_mid_para_chap_bool}
%   Flag if setting a paragraph containing a mid-paragraph chapter.
%    \begin{macrocode}
\bool_new:N \l_@@_mid_para_chap_bool
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_mid_para_chap_line_box}
%   Store last line before a mid-paragraph chapter.
%    \begin{macrocode}
\box_new:N \l_@@_mid_para_chap_line_box
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\g_@@_mid_para_chap_prevdepth_dim}
%   Store the \cs{prevdepth} of the final paragraph in a \env{midparachap}
%   environment.
%    \begin{macrocode}
\dim_new:N \g_@@_mid_para_chap_prevdepth_dim
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\g_@@_mid_para_chap_prevgraf_int}
%   Store the \cs{prevgraf} of the final paragraph in a \env{midparachap}
%   environment.
%    \begin{macrocode}
\int_new:N \g_@@_mid_para_chap_prevgraf_int
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_mid_para_chap_snap_box}
%   Store unpacked last line before a mid-paragraph chapter.
%    \begin{macrocode}
\box_new:N \l_@@_mid_para_chap_snap_box
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_mid_para_chap_spacefactor_int}
%   Store space factor before a mid-paragraph chapter.
%    \begin{macrocode}
\int_new:N \l_@@_mid_para_chap_spacefactor_int
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_mid_para_chap_box,
%               \l_@@_mid_para_chap_split_box,
%               \l_@@_mid_para_chap_split_top_box}
%   Boxes containing a paragraph with a chapter break and its split if needed.
%    \begin{macrocode}
\box_new:N \l_@@_mid_para_chap_box
\box_new:N \l_@@_mid_para_chap_split_box
\box_new:N \l_@@_mid_para_chap_split_top_box
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_mid_para_drop_chap_output:}
%   Output a mid-paragraph drop chapter.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_mid_para_drop_chap_output:
  {
    \unskip
    \int_set_eq:NN \l_@@_mid_para_chap_spacefactor_int \spacefactor
    \strut
    \par
    \box_set_to_last:N \l_@@_mid_para_chap_line_box
    \hbox_set:Nn \l_@@_mid_para_chap_snap_box
      {
        \hbox_unpack_drop:N \l_@@_mid_para_chap_line_box
        \unskip
        \unskip
        \unpenalty
      }
    \nointerlineskip
    \dim_compare:nNnTF
      {
        \box_wd:N \l_@@_mid_para_chap_snap_box +
        \l_@@_chap_width_dim +
        \l_@@_chap_sep_tl
      }
      <
      { \linewidth - \leftskip - \rightskip - 3 em }
      {
        \@@_drop_chap_output:
        \hbox_unpack_drop:N \l_@@_mid_para_chap_snap_box
        \int_set_eq:NN \spacefactor \l_@@_mid_para_chap_spacefactor_int
        \c_space_tl
        \@@_verse_output:n { 1 }
      }
      {
        \group_begin:
        \noindent
        \skip_horizontal:n { -\leftskip }
        \hbox_unpack_drop:N \l_@@_mid_para_chap_snap_box
        \skip_zero:N \parfillskip
        \par
        \group_end:
        \@@_drop_chap_output:
        \bool_if:NT \l_@@_midparachap_show_verse_bool
          {
            \@@_verse_output:n { 1 }
          }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_mid_para_chap_begin:n}
%   Begin a paragraph containing a mid-paragraph chapter.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_mid_para_chap_begin:n
  {
    \tl_set:Nn \l_@@_currenvir_str { midparachap }
    \tl_if_novalue:nF { #1 }
      {
        \keys_set:nn
          { scripture / midparachap }
          { #1 }
      }
    \bool_lazy_and:nnT
      { \bool_if_p:n \l_@@_chap_show_verse_bool }
      { \bool_if_p:n \l_@@_chap_drop_bool }
      {
        \bool_set_true:N \l_@@_midparachap_show_verse_bool
        \bool_set_false:N \l_@@_chap_show_verse_bool
      }
    \par
    \bool_set_true:N \l_@@_mid_para_chap_bool
    \@@_vbox_set_top:Nw \l_@@_mid_para_chap_box
    \skip_zero:N \parskip
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_mid_para_chap_end:}
%   End a paragraph containing a mid-paragraph chapter.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_mid_para_chap_end:
  {
    \par
    \int_gset_eq:NN \g_@@_mid_para_chap_prevgraf_int \prevgraf
    \dim_gset_eq:NN \g_@@_mid_para_chap_prevdepth_dim \prevdepth
    \box_set_to_last:N \l_@@_mid_para_chap_line_box
    \hbox_set:Nn \l_@@_mid_para_chap_snap_box
      {
        \hbox_unpack:N \l_@@_mid_para_chap_line_box
        \unskip
        \unskip
        \unpenalty
      }
    \dim_gset:Nn \g_@@_final_line_dim { \box_wd:N \l_@@_mid_para_chap_snap_box }
    \box_clear:N \l_@@_mid_para_chap_snap_box
    \nointerlineskip
    \int_compare:nNnT
      \prevgraf < 3
      {
        \noindent
        \skip_horizontal:n { \l_@@_chap_width_dim + \l_@@_chap_sep_tl }
        \dim_gadd:Nn \g_@@_final_line_dim { \l_@@_chap_width_dim + \l_@@_chap_sep_tl }
      }
    \box_use_drop:N \l_@@_mid_para_chap_line_box
    \vbox_set_end:
%    \end{macrocode}
% Attempt to allow the mid-paragraph chapter box to break across pages.
%    \begin{macrocode}
    \mode_if_inner:TF
      {
        \noindent
        \box_use_drop:N \l_@@_mid_para_chap_box
      }
      {
        \dim_compare:nNnTF
          { \box_ht_plus_dp:N \l_@@_mid_para_chap_box }
          >
          { \pagegoal - \pagetotal - \baselineskip }
          {
            \int_set:Nn \vbadness { 10000 }
            \vbox_set_split_to_ht:NNn
              \l_@@_mid_para_chap_split_box \l_@@_mid_para_chap_box
              { \pagegoal - \pagetotal - \baselineskip }
            \vbox_set_top:Nn \l_@@_mid_para_chap_split_top_box
              { \vbox_unpack_drop:N \l_@@_mid_para_chap_split_box }
            \noindent
            \box_use_drop:N \l_@@_mid_para_chap_split_top_box
            \goodbreak
            \box_use_drop:N \l_@@_mid_para_chap_box
          }
          {
            \noindent
            \box_use_drop:N \l_@@_mid_para_chap_box
          }
      }
    \par
    \dim_set_eq:NN \prevdepth \g_@@_mid_para_chap_prevdepth_dim
    \int_zero:N \prevgraf
    \skip_vertical:n { -\parskip - \baselineskip }
    \noindent
    \skip_horizontal:N \g_@@_final_line_dim
    \int_gset_eq:NN \g_@@_chap_par_prevgraf_int \g_@@_mid_para_chap_prevgraf_int
    \hook_gput_next_code:nn { para / before }
      {
        \int_gzero:N \g_@@_chap_par_prevgraf_int
        \int_compare:nNnT
          \@listdepth > \c_zero_int
          { \parshape 1 ~ \@totalleftmargin ~ \linewidth }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{The \env{narrow} environment}
%
% \begin{macro}{\@@_narrow_begin:n}
%   Begin a narrow section in a scripture quotation.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_narrow_begin:n
  {
    \bool_if:NT \l_@@_active_inner_bool
      {
        \msg_error:nn { scripture } { nested-environment }
      }
    \bool_set_true:N \l_@@_active_inner_bool
    \tl_set:Nn \l_@@_currenvir_str { narrow }
    \tl_if_novalue:nF { #1 }
      {
        \keys_set:nn
          { scripture / narrow }
          { #1 }
      }
    \mode_if_horizontal:T
      { \par }
    \list { }
      {
        \skip_set_eq:NN \l_@@_delta_below_skip \l_@@_narrow_belowskip_tl
%    \end{macrocode}
% Ignore \opt{aboveskip} if at the beginning of a \env{scripture} environment.
%    \begin{macrocode}
        \bool_if:NTF \g_@@_start_bool
          {
            \skip_zero:N \topsep
            \skip_sub:Nn \topsep \parskip
            \skip_add:Nn \l_@@_delta_below_skip \parskip
            \bool_gset_false:N \g_@@_start_bool
          }
          {
            \dim_compare:nTF
              { \parskip >= \glueexpr \l_@@_narrow_aboveskip_tl > \c_zero_skip }
              {
                \skip_zero:N \topsep
                \skip_zero:N \l_@@_delta_below_skip
              }
              {
                \skip_set_eq:NN \topsep \l_@@_narrow_aboveskip_tl
                \skip_sub:Nn \l_@@_delta_below_skip \l_@@_narrow_aboveskip_tl
              }
            \int_compare:nNnT \g_@@_chap_par_prevgraf_int = 1
              { \addvspace { \baselineskip } }
            \int_gzero:N \g_@@_chap_par_prevgraf_int
          }
        \dim_set_eq:NN \leftmargin \l_@@_narrow_leftmargin_tl
        \dim_set_eq:NN \rightmargin \l_@@_narrow_rightmargin_tl
        \dim_set_eq:NN \listparindent \parindent
        \dim_set_eq:NN \itemindent \parindent
        \skip_set_eq:NN \parsep \parskip
        \skip_zero:N \partopsep
        \dim_zero:N \labelsep
      }
    \item
    \relax
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_narrow_end:}
%   End a narrow section in a scripture quotation.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_narrow_end:
  {
    \@@_calc_final_line_length:
    \skip_add:Nn \@topsepadd \l_@@_delta_below_skip
    \int_set_eq:NN \@endparpenalty \@lowpenalty
    \endlist
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{The \env{poetry} environment}
%
% \begin{hooks}{scripture/poetry/para/after}
%   This hook is an internal hook used to adjust the \cs{parshape} within a
%   \env{poetry} environment after drop chapter numbers.
%    \begin{macrocode}
\hook_new:n { scripture / poetry / para / after }
%    \end{macrocode}
% \end{hooks}
%
% \begin{macro}{\g_@@_poetry_end_bool}
%   Flag indicating that a \env{poetry} environment just ended.
%    \begin{macrocode}
\bool_new:N \g_@@_poetry_end_bool
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\g_@@_poetry_midparachap_show_verse_bool}
%   Flag indicating whether the verse number should be printed immediately
%   after a \cs{ch} or not in a \env{poetry} environment.
%    \begin{macrocode}
\bool_new:N \g_@@_poetry_midparachap_show_verse_bool
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_poetry_chap_indent_dim, \l_@@_poetry_chap_sep_dim}
%   Store calculated indent and sep when a drop chapter appears in a
%   \env{poetry} environment.
%    \begin{macrocode}
\dim_new:N \l_@@_poetry_chap_indent_dim
\dim_new:N \l_@@_poetry_chap_sep_dim
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_poetry_chap_parshape_correction_dim}
%   Correction to \cs{parshape} in chapter affected lines in a \env{poetry}
%   environment.
%    \begin{macrocode}
\dim_new:N \l_@@_poetry_chap_parshape_correction_dim
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_poetry_prevgraf_int}
%   Store the number of lines a line of poetry takes up.
%    \begin{macrocode}
\int_new:N \l_@@_poetry_prevgraf_int
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_poetry_extra_skip:}
%   Insert a little extra vertical space between two lines in a \env{poetry}
%   environment.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_poetry_extra_skip:
  {
    \skip_vertical:n { \l_@@_extraskip_tl - \baselineskip - \parskip }
    \bool_gset_false:N \g_@@_poetry_midparachap_show_verse_bool
    \strut
    \hook_gput_next_code:nn { para / after }
      {
        \hook_gput_next_code:nn { para / after }
          {
            \bool_gset_eq:NN
              \g_@@_poetry_midparachap_show_verse_bool
              \l_@@_midparachap_show_verse_bool
          }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_poetry_text_right:nn}
%   Align a word to the right and finish a paragraph, pushing to the next line
%   if there is not space for the word.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_poetry_text_right:nn
  {
    {
      \unskip
      \hfil
      \penalty 50
      \skip_horizontal:n { #1 }
      \hbox:n {}
      \nobreak
      \hfill
      #2
      \skip_zero:N \parfillskip
      \int_zero:N \finalhyphendemerits
    }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_selah_output:}
%   Output Selah at the end of a line.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_selah_output:
  {
    \group_begin:
    \l_@@_selah_font_tl
    \@@_poetry_text_right:nn
      { \l_@@_selah_sep_tl }
      { \@@_selah_format:n { \l_@@_selah_text_tl } }
    \group_end:
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_poetry_chap:n}
%   Position a chapter in a \env{poetry} environment.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_poetry_chap:n
  {
    \@@_drop_chap_set_up:n { #1 }
    \mode_if_vertical:TF
      {
        \dim_set_eq:NN \l_@@_poetry_chap_indent_dim \l_@@_poetry_indent_tl
        \mode_leave_vertical:
      }
      { \dim_zero:N \l_@@_poetry_chap_indent_dim }
    \dim_set_eq:NN \l_@@_poetry_chap_sep_dim \l_@@_chap_sep_tl
    \dim_compare:nNnT
      { \l_@@_chap_width_dim + \l_@@_chap_sep_tl }
      <
      { \l_@@_poetry_leftmargin_tl + \l_@@_poetry_chap_indent_dim }
      {
        \dim_set:Nn \l_@@_poetry_chap_sep_dim
          {
            \l_@@_poetry_leftmargin_tl + \l_@@_poetry_chap_indent_dim -
            \l_@@_chap_width_dim
          }
      }
    \hbox_set:Nn \l_@@_chap_box
      {
        \box_move_down:nn
          { \baselineskip }
          { 
            \hbox_overlap_left:n
              {
                \box_use:N \l_@@_chap_tmp_box
                \skip_horizontal:N \l_@@_poetry_chap_sep_dim
              }
          }
      }
    \box_set_ht:Nn \l_@@_chap_box { \c_zero_dim }
    \box_set_dp:Nn \l_@@_chap_box { \c_zero_dim }
    \dim_set:Nn \l_@@_poetry_chap_parshape_correction_dim
      {
        \l_@@_chap_width_dim + \l_@@_poetry_chap_sep_dim -
        \l_@@_poetry_leftmargin_tl - \l_@@_poetry_chap_indent_dim
      }
    \parshape 2 ~
      \dim_eval:n
        { \@totalleftmargin + \l_@@_poetry_chap_parshape_correction_dim } ~
      \dim_eval:n
        { \linewidth - \l_@@_poetry_chap_parshape_correction_dim } ~
      \dim_eval:n
        { \@totalleftmargin + \l_@@_poetry_big_indent_tl } ~
      \dim_eval:n
        { \linewidth - \l_@@_poetry_big_indent_tl }
%    \end{macrocode}
%   Because of interactions with \LaTeX{} \env{list} environments and
%   \cs{@@_obeylines:}, \cs{@@_poetry_par:} setting the \cs{parshape} for the
%   second line after a drop chapter number is more difficult than it should
%   be. There's probably a better way.
%    \begin{macrocode}
    \dim_compare:nNnT
      { \l_@@_chap_width_dim + \l_@@_poetry_chap_sep_dim }
      >
      \l_@@_poetry_leftmargin_tl
      {
        \hook_gput_next_code:nn { scripture / poetry / para / after }
          {
            \int_compare:nNnT \l_@@_poetry_prevgraf_int = 1
              {
%    \end{macrocode}
%   This \cs{parshape} is in effect when the next line is the second half of a
%   poetry verse.
%    \begin{macrocode}
                \dim_compare:nNnTF
                  { \l_@@_chap_width_dim + \l_@@_chap_sep_tl }
                  <
                  { \l_@@_poetry_leftmargin_tl + \l_@@_poetry_indent_tl }
                  { \dim_zero:N \l_@@_poetry_chap_parshape_correction_dim }
                  {
                    \dim_set:Nn \l_@@_poetry_chap_parshape_correction_dim
                      {
                        \l_@@_chap_width_dim + \l_@@_chap_sep_tl -
                        \l_@@_poetry_leftmargin_tl - \l_@@_poetry_indent_tl
                      }
                  }
                \parshape 2 ~
                  \dim_eval:n
                    { \@totalleftmargin + \l_@@_poetry_chap_parshape_correction_dim } ~
                  \dim_eval:n
                    { \linewidth - \l_@@_poetry_chap_parshape_correction_dim } ~
                  \dim_eval:n
                    { \@totalleftmargin + \l_@@_poetry_big_indent_tl } ~
                  \dim_eval:n
                    { \linewidth - \l_@@_poetry_big_indent_tl }
                \hook_gput_next_code:nn { para / after }
                  {
                    \hook_gclear_next_code:n { scripture / poetry / para / after }
                  }
                \hook_gput_next_code:nn { scripture / poetry / para / after }
                  {
%    \end{macrocode}
%   This \cs{parshape} is in effect when the next line is the first half of a
%   poetry verse.
%    \begin{macrocode}
                    \dim_compare:nNnTF
                      { \l_@@_chap_width_dim + \l_@@_chap_sep_tl }
                      <
                      \l_@@_poetry_leftmargin_tl
                      { \dim_zero:N \l_@@_poetry_chap_parshape_correction_dim }
                      {
                        \dim_set:Nn \l_@@_poetry_chap_parshape_correction_dim
                          {
                            \l_@@_chap_width_dim + \l_@@_chap_sep_tl -
                            \l_@@_poetry_leftmargin_tl
                          }
                      }
                    \parshape 2 ~
                      \dim_eval:n
                        { \@totalleftmargin + \l_@@_poetry_chap_parshape_correction_dim } ~
                      \dim_eval:n
                        { \linewidth - \l_@@_poetry_chap_parshape_correction_dim } ~
                      \dim_eval:n
                        { \@totalleftmargin + \l_@@_poetry_big_indent_tl } ~
                      \dim_eval:n
                        { \linewidth - \l_@@_poetry_big_indent_tl }
                  }
              }
          }
      }
    \group_begin:
    \hook_use:n { scripture / chap / before }
    \box_use:N \l_@@_chap_box
    \hook_use:n { scripture / chap / after }
    \group_end:
    \bool_lazy_or:nnT
      { \bool_if_p:n \l_@@_chap_show_verse_bool }
      { \bool_if_p:n \g_@@_poetry_midparachap_show_verse_bool }
      {
        \@@_verse_output:n { 1 }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_poetry_nodrop_chap:n}
%   Format a non-drop chapter for \env{poetry} environment in a
%   \env{scripture} quotation.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_poetry_nodrop_chap:n
  {
    \cs_gset_nopar:Npn \scripturecurrentchapter { #1 }
    \cs_gset_nopar:Npn \scripturecurrentverse { 1 }
    \group_begin:
    \bool_if:NTF \l_@@_chap_show_bool
      {
        \hbox_overlap_left:n
          {
            \hook_use:n { scripture / chap / before }
            \group_begin:
            \l_@@_chap_font_tl
            \str_if_eq:VnF \l_@@_chapter_colour_tl { . }
              { \exp_args:NV \color_select:n \l_@@_chapter_colour_tl }
            \@@_chap_format:n { #1 }
            \group_end:
            \skip_horizontal:N \l_@@_chap_sep_tl
            \hook_use:n { scripture / chap / after }
          }
        \bool_lazy_or:nnT
          { \bool_if_p:n \l_@@_chap_show_verse_bool }
          { \bool_if_p:n \g_@@_poetry_midparachap_show_verse_bool }
          {
            \@@_verse_output:n { 1 }
          }
      }
      {
        \hook_use:n { scripture / chap / before }
        \hook_use:n { scripture / chap / after }
        \vs { 1 }
      }
    \group_end:
  }
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@@_poetry_mode_vertical_verse:n}
%   Format a verse for poetry scripture quotations in vertical and horizontal
%   mode.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_poetry_mode_vertical_verse:n
  {
    \group_begin:
    \tl_set_eq:NN \l_@@_verse_sep_tl \l_@@_poetry_verse_sep_tl
    \strut
    \bool_if:NTF \l_@@_poetry_verse_right_bool
      {
        \hbox_overlap_left:n
          {
            \@@_verse_output:n { #1 }
          }
      }
      {
        \hbox_overlap_left:n
          {
            \hbox_overlap_right:n
              {
                \@@_verse_output:n { #1 }
              }
            \skip_horizontal:N \l_@@_poetry_leftmargin_tl
          }
      }
    \group_end:
  }
\cs_new_protected:Nn \@@_poetry_mode_horizontal_verse:n
  {
    \group_begin:
    \tl_set_eq:NN \l_@@_verse_sep_tl \l_@@_poetry_verse_sep_tl
    \skip_horizontal:n { -\listparindent }
    \@@_poetry_mode_vertical_verse:n { #1 }
    \skip_horizontal:N \listparindent
    \group_end:
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_poetry_par:}
%   par macro for poetry sections
%    \begin{macrocode}
\cs_new_protected:Nn \@@_poetry_par:
  {
    \mode_if_vertical:TF
      {
        \cs_set_eq:NN \vs \@@_poetry_mode_vertical_verse:n
        \noindent
      }
      {
        \cs_set_eq:NN \vs \@@_poetry_mode_horizontal_verse:n
        \@@_tmp_para_end:
        \int_set_eq:NN \l_@@_poetry_prevgraf_int \prevgraf
      }
    \parshape 2 ~ 
      \@totalleftmargin ~
      \linewidth ~
      \dim_eval:n
        { \@totalleftmargin + \l_@@_poetry_big_indent_tl } ~
      \dim_eval:n
        { \linewidth - \l_@@_poetry_big_indent_tl }
    \hook_use:n { scripture / poetry / para / after }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_obeylines:}
%   Special version of obeylines which doesn't insert par at end of
%   environment.
%    \begin{macrocode}
\group_begin:
  \char_set_catcode_active:N \^^M
  \cs_gset_protected_nopar:Nn \@@_obeylines: %
    {%
      \char_set_catcode_active:N \^^M%
      \cs_set_eq:NN ^^M \@@_obeylines_end:%
    }%
\group_end:
\cs_new_protected:Nn \@@_obeylines_end:
  {
    \peek_meaning:NF \end
      {
        \par
        \int_set:Nn \l_@@_poetry_prevgraf_int { \int_use:N \prevgraf }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_poetry_begin:}
%   Begin a poetry section in a scripture quotation.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_poetry_begin:
  {
    \bool_if:NT \l_@@_active_inner_bool
      {
        \msg_error:nn { scripture } { nested-environment }
      }
    \bool_set_true:N \l_@@_active_inner_bool
    \tl_set:Nn \l_@@_currenvir_str { poetry }
    \mode_if_horizontal:T
      { \par }
    \list { }
      {
        \skip_set_eq:NN \l_@@_delta_below_skip \l_@@_poetry_belowskip_tl
        \bool_if:NTF \g_@@_start_bool
          {
            \skip_zero:N \topsep
            \skip_sub:Nn \topsep \parskip
            \skip_add:Nn \l_@@_delta_below_skip \parskip
            \bool_gset_false:N \g_@@_start_bool
          }
          {
            \dim_compare:nTF
              { \parskip >= \glueexpr \l_@@_poetry_aboveskip_tl > \c_zero_skip }
              {
                \skip_zero:N \topsep
                \skip_zero:N \l_@@_delta_below_skip
              }
              {
                \skip_set_eq:NN \topsep \l_@@_poetry_aboveskip_tl
                \skip_sub:Nn \l_@@_delta_below_skip \l_@@_poetry_aboveskip_tl
              }
            \int_compare:nNnT \g_@@_chap_par_prevgraf_int = 1
              { \addvspace { \baselineskip } }
            \int_gzero:N \g_@@_chap_par_prevgraf_int
          }
        \dim_set_eq:NN \leftmargin \l_@@_poetry_leftmargin_tl
        \dim_set_eq:NN \rightmargin \l_@@_poetry_rightmargin_tl
        \dim_set_eq:NN \itemindent \l_@@_poetry_indent_tl
        \dim_set_eq:NN \listparindent \l_@@_poetry_indent_tl
        \skip_zero:N \parsep
        \skip_zero:N \partopsep
        \dim_zero:N \labelsep
      }
    \raggedright
    \dim_set_eq:NN \listparindent \l_@@_poetry_indent_tl
    \dim_set_eq:NN \parindent \l_@@_poetry_indent_tl
    \bool_gset_false:N \g_@@_poetry_midparachap_show_verse_bool
    \DeclareDocumentCommand { \ch } { sm }
      {
        \bool_if:NTF \l_@@_chap_show_bool
          {
            \bool_if:NTF \l_@@_chap_drop_bool
              { \@@_poetry_chap:n { ##2 } }
              { \@@_poetry_nodrop_chap:n { ##2 } }
          }
          { \@@_poetry_nodrop_chap:n { ##2 } }
      }
    \cs_set_eq:NN \vs \@@_poetry_mode_vertical_verse:n
    \cs_set_eq:NN \extraskip \@@_poetry_extra_skip:
    \cs_set_eq:NN \selah \@@_selah_output:
    \cs_set_protected_nopar:Npn \textright ##1
      {
        \@@_poetry_text_right:nn { \l_@@_text_right_sep_tl } { ##1 }
      }
    \item
    \relax
    \cs_set_eq:NN \@@_tmp_para_end: \par
    \cs_set_eq:NN \par \@@_poetry_par:
    \hook_gput_next_code:nn { para / after }
      { \bool_gset_eq:NN \g_@@_poetry_midparachap_show_verse_bool \l_@@_midparachap_show_verse_bool }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_poetry_end:}
%   End a poetry section in a scripture quotation.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_poetry_end:
  {
    \@@_calc_final_line_length:
    \skip_add:Nn \@topsepadd \l_@@_delta_below_skip
    \int_set_eq:NN \@endparpenalty \@lowpenalty
    \endlist
    \bool_gset_true:N \g_@@_poetry_end_bool
    \hook_gput_next_code:nn { para / begin }
      { \bool_gset_false:N \g_@@_poetry_end_bool }
  }
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Public \LaTeX{} Interface}
%
% \begin{macro}{\scripturecurrentchapter, \scripturecurrentverse}
%   Globally stores the most recent argument of \cs{ch} and \cs{vs}. These
%   could be used in hooks, for example.
%    \begin{macrocode}
\cs_set_nopar:Npn \scripturecurrentchapter { }
\cs_set_nopar:Npn \scripturecurrentverse { }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\scripturesetup}
%   \begin{arguments}
%     \item \meta{|options|} to set.
%   \end{arguments}
%   Set key-value settings.
%    \begin{macrocode}
\NewDocumentCommand { \scripturesetup } { m }
  {
    \keys_set:nn { scripture } { #1 }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\textscripture}
%   \begin{arguments}
%     \item \meta{|reference|} of quotation.
%     \item \meta{|options|} to set.
%     \item \meta{|quotation|} text.
%   \end{arguments}
%   Set an inline quotation. This is equivalent to calling the
%   \env{scripture} environment with the \opt{inline} option set.
%    \begin{macrocode}
\NewDocumentCommand { \textscripture } { oo+m }
  {
    \tl_if_novalue:nTF { #2 }
      {
        \begin { scripture } [ #1 ] [ inline ]
      }
      {
        \begin { scripture } [ #1 ] [ inline, #2 ]
      }
    #3
    \end { scripture }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{envmacro}{scripture}
%   \begin{arguments}
%     \item \meta{|reference|} of quotation.
%     \item \meta{|options|} to set.
%   \end{arguments}
%   Format a scripture quotation with optional reference.
%    \begin{macrocode}
\NewDocumentEnvironment { scripture } { oo }
  {
    \@@_begin:n { #2 }
%    \end{macrocode}
% \begin{envmacro}{center}
%   \begin{arguments}
%     \item \meta{|options|} to set.
%   \end{arguments}
%    \begin{macrocode}
    \DeclareDocumentEnvironment { center } { o }
      {
        \@@_center_begin:n { ##1 }
        \ignorespaces
      }
      { \@@_center_end: }
%    \end{macrocode}
% \end{envmacro}
% \begin{envmacro}{flushright}
%   \begin{arguments}
%     \item \meta{|options|} to set.
%   \end{arguments}
%    \begin{macrocode}
    \DeclareDocumentEnvironment { flushright } { o }
      {
        \@@_flushright_begin:n { ##1 }
        \ignorespaces
      }
      { \@@_flushright_end: }
%    \end{macrocode}
% \end{envmacro}
% \begin{envmacro}{hanging}
%   \begin{arguments}
%     \item \meta{|options|} to set.
%   \end{arguments}
%    \begin{macrocode}
    \DeclareDocumentEnvironment { hanging } { o }
      {
        \@@_hanging_begin:n { ##1 }
        \ignorespaces
      }
      { \@@_hanging_end: }
%    \end{macrocode}
% \end{envmacro}
% \vspace{-2\baselineskip}
% \begin{envmacro}{midparachap}
%    \begin{macrocode}
    \DeclareDocumentEnvironment { midparachap } { o }
      {
        \@@_mid_para_chap_begin:n { ##1 }
        \ignorespaces
      }
      { \@@_mid_para_chap_end: }
%    \end{macrocode}
% \end{envmacro}
% \begin{envmacro}{narrow}
%   \begin{arguments}
%     \item \meta{|options|} to set.
%   \end{arguments}
%    \begin{macrocode}
    \DeclareDocumentEnvironment { narrow } { o }
      {
        \@@_narrow_begin:n { ##1 }
        \ignorespaces
      }
      { \@@_narrow_end: }
%    \end{macrocode}
% \end{envmacro}
% \begin{envmacro}{poetry}
%   \begin{arguments}
%     \item \meta{|options|} to set.
%   \end{arguments}
% The \env{poetryaux} environment is required because \cs{@@_obeylines:}
% breaks the reading of optional arguments.
%    \begin{macrocode}
    \DeclareDocumentEnvironment { poetryaux } { o }
      {
        \tl_if_novalue:nF { ##1 }
        {
          \keys_set:nn
            { scripture / poetry }
            { ##1 }
        }
        \@@_poetry_begin:
        \ignorespaces
      }
      { \@@_poetry_end: }
    \DeclareDocumentEnvironment { poetry } { }
      {
        \@@_obeylines:
        \poetryaux
      }
      { \endpoetryaux }
%    \end{macrocode}
% \end{envmacro}
%    \begin{macrocode}
    \bool_if:NT \l_@@_inline_bool
      {
        \tl_set:Nn \l_@@_aboveskip_tl { 0pt }
        \tl_set:Nn \l_@@_belowskip_tl { 0pt }
        \tl_set:Nn \l_@@_leftmargin_tl { 0pt }
        \tl_set:Nn \l_@@_rightmargin_tl { 0pt }
      }
    \bool_if:NT \l_@@_compact_bool
      {
        \scripturesetup { chapter / nodrop }
        \RenewDocumentEnvironment { center } { o } { \ignorespaces } { \unskip }
        \RenewDocumentEnvironment { flushright } { o } { \ignorespaces } { \unskip }
        \RenewDocumentEnvironment { hanging } { o } { \ignorespaces } { \unskip }
        \RenewDocumentEnvironment { midparachap } { o } { \ignorespaces } { \unskip }
        \RenewDocumentEnvironment { narrow } { o } { \ignorespaces } { \unskip }
        \RenewDocumentEnvironment { poetry } { o } { \ignorespaces } { \unskip }
        \cs_set_eq:NN \\ \unskip
        \cs_set_eq:NN \par \relax
        \cs_set_eq:NN \extraskip \relax
        \cs_set_eq:NN \nohang \relax
        \cs_set:Npn \selah
          {
            \group_begin:
            \l_@@_selah_font_tl
            \c_space_tl
            \@@_selah_format:n { \l_@@_selah_text_tl }
            \c_space_tl
            \group_end:
          }
        \cs_set_protected_nopar:Npn \textright ##1
          {
            \unskip
            \c_space_tl
            ##1
          }
        \mode_leave_vertical:
      }
    \peek_remove_spaces:n
      {
        \peek_meaning:NF \begin
          { \bool_gset_false:N \g_@@_start_bool }
      }
  }
  {
    \bool_if:NT \l_@@_compact_bool
      { \cs_set_eq:NN \par \endgraf }
    \@@_end:n { #1 }
  }
%    \end{macrocode}
% \end{envmacro}
%    \begin{macrocode}
%</package>
%    \end{macrocode}
% \end{implementation}
%
% \PrintChanges
%
% \PrintIndex
