% \iffalse meta-comment
%
% Copyright (c) 2026 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>
\RequirePackage{pdfmanagement}
\documentclass[a4paper]{l3doc}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{mlmodern}
\usepackage[font=small, skip=6pt]{caption}
\usepackage{xcolor}
\usepackage{listings}

\AddToHook{env/macrocode/before}{%
  \addvspace{\medskipamount}}

\AddToHook{env/macro/before}{%
  \addvspace{\medskipamount}}

\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \title{The \pkg{sblarticle} Class}
% \author{David Purton\thanks{Email: \url{dcpurton@marshwiggle.net}}}
% \date{2026-04-04 v1.0}
%
% \maketitle
%
% \begin{abstract}
%   \pkg{sblarticle} provides a LaTeX class for producing articles and papers
%   conforming to the style required by the Society of Biblical Literature. It
%   depends on \pkg{sblfonts} for language support and \pkg{biblatex-sbl} for
%   referencing.
% \end{abstract}
%
% \tableofcontents
%
% \section{Introduction}
%
% The \pkg{sblarticle} class creates a term paper matching the style specified
% in the \emph{Student Supplement for \emph{The SBL Handbook of Style}, Second
% Edition}. See
% \url{https://www.sbl-site.org/wp-content/uploads/2025/04/SBLHSsupp2015-02.pdf}.
%
% The class works with both |pdflatex| and the Unicode engines, but in order
% to make use of the SBL fonts you need to install them and use a Unicode
% engine (|lualatex| is recommended, especially for Hebrew).
%
% This class is not intended to be a general flexible starting point for the
% requirements of all theological colleges and seminaries. In such cases you
% are better off beginning with the \pkg{article} class and loading
% \pkg{biblatex-sbl} and (possibly) \pkg{sblfonts} directly. You could use
% the code in this class as a guide.
%
% \subsection{Usage}
%
% Load the class using |\documentclass{sblarticle}|. See
% |sbltex-termpaper.pdf| in the documentation directory for an extended usage
% example.
%
% The following standard commands and environments have been customised for
% this class:
% \begin{itemize}
%   \item |\author|, |\title|, |\maketitle|
%   \item |\tableofcontents|, |\listoffigure|, |\listoftables|
%   \item |\section|, |\subsection|, |\subsubsection|, |\paragraph|,
%     |\subparagraph|
%   \item |\appendix|
%   \item |\footnote|
%   \item |\caption|
%   \item |\printbibliography|, |\printbiblist{abbreviations}|
%   \item |abstract|, |quotation|, |quote|
% \end{itemize}
%
% American, Greek and Hebrew are set up using \pkg{sblfonts} (and
% \pkg{babel}). A different main language can be chosen by passing the
% \pkg{babel} language name to the class.
%
% \subsection{Acknowledgements}
%
% The \pkg{sblarticle} class depends on a number of other packages:
% \begin{itemize}
%   \item \pkg{sblfonts} (with \pkg{fontspec}, \pkg{fontenc} and \pkg{babel}),
%     \pkg{biblatex-sbl} (with \pkg{biblatex})
%   \item \pkg{csquotes}, \pkg{geometry}, \pkg{setspace}, \pkg{ragged2e},
%     \pkg{fancyhdr}
%   \item When \cs{DocumentMetadata} is not in use: \pkg{caption},
%     \pkg{footmisc}, \pkg{titlesec}, \pkg{titletoc}
% \end{itemize}
%
% \subsection{Bug Reports and Feature Requests}
%
% Bug reports and feature requests can be made at the \pkg{sbltex}
% GitHub repository. See \url{https://github.com/dcpurton/sbltex}.
%
% \begin{description}
%   \item[Note:] This class is only partially compatible with the \LaTeX{}
%   tagging project at this stage. As the tagging project stabilises and
%   dependent packages are updated, compatibility will improve.
% \end{description}
%
% \section{Package Commands}
%
% \begin{function}{\course}
%   \begin{syntax}
%     |\course| \marg{Course name}
%   \end{syntax}
%   Set the name of the course the paper is for. This is included on the title
%   page.
% \end{function}
%
% \begin{function}{\institution}
%   \begin{syntax}
%     |\institution| \marg{Institution name}
%   \end{syntax}
%   Set the name of the institution the paper will be submitted at. This is
%   included on the title page.
% \end{function}
%
% \begin{function}{\professor}
%   \begin{syntax}
%     |\professor| \marg{Professor name}
%   \end{syntax}
%   Set the name of the professor the paper will be submitted to. This is
%   included on the title page.
% \end{function}
%
% \section{Package Options}
%
% Items passed to the options below are \emph{appended} to the default options
% rather than replacing them.
%
% Any unrecognised options passed to the \pkg{sblarticle} class are passed
% through to the \pkg{article} class.
%
% \begin{function}{biblatex}
%   \begin{syntax}
%     biblatex = \marg{arguments}\hfill Default: \{style=sbl, language=auto, autolang=hyphen\}
%   \end{syntax}
%   These options are passed to the \pkg{biblatex} package.
% \end{function}
%
% See the \pkg{biblatex-sbl} package documentation for a full description of
% supported options and usage.
%
% \begin{function}{sblfonts}
%   \begin{syntax}
%     sblfonts = \marg{arguments}
%   \end{syntax}
%   Options to pass to the \pkg{sblfonts} package.
% \end{function}
%
% The defaults depend on whether the engine in use is 8bit or Unicode:
% \begin{description}
%   \item[8bit defaults:] \mbox{}\\
%     |{|\\
%     \strut\quad |mainfont=tempora,|\\
%     \strut\quad |grfont=Alegreya-LF,|\\
%     \strut\quad |hefont=frank|\\
%     |}|
%   \item[Unicode defaults:] \mbox{}\\
%     |{|\\
%     \strut\quad |mainfont=TeXGyreTermesX,|\\
%     \strut\quad |mainfontoptions={Extension=.otf, UprightFont=*-Regular,|\\
%     \strut\qquad |ItalicFont=*-Italic, BoldFont=*-Bold,|\\
%     \strut\qquad |BoldItalicFont=*-BoldItalic},|\\
%     \strut\quad |sblfonts=true|\\
%     |}|
% \end{description}
%
% Note that you will need to download and install the SBL fonts yourself from
% \url{https://www.sbl-site.org/resources/fonts/}.
%
% See the \pkg{sblfonts} package documentation for a full description of
% supported options and usage.
%
% \section{Implementation}
%
% \setlength{\parindent}{0em}
%
%    \begin{macrocode}
%<*class>
%<@@=sblarticle>
%    \end{macrocode}
%
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesExplClass{sblarticle}{2026-04-04}{1.0}
  {Society of Biblical Literature Article Class (DCP)}
%    \end{macrocode}
%
%    \begin{macrocode}
\clist_new:N \l_@@_options_to_article_class_clist
%    \end{macrocode}
%
%    \begin{macrocode}
\keys_define:nn { sblarticle }
  {
    , biblatex .clist_set:N = \l_@@_options_to_biblatex_clist
    , sblfonts .clist_set:N = \l_@@_options_to_sblfonts_clist
    , unknown  .code:n = {
                           \clist_put_right:No
                             \l_@@_options_to_article_class_clist
                             { \CurrentOption }
                         }
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\ProcessKeyOptions
%    \end{macrocode}
%
% Set default options.
%
%    \begin{macrocode}
\clist_put_left:Nn \l_@@_options_to_article_class_clist
  {
    , 12pt
    , titlepage
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\clist_put_left:Nn \l_@@_options_to_biblatex_clist
  {
    , style    = sbl
    , language = auto
    , autolang = hyphen
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\sys_if_engine_opentype:TF
  {
    \clist_put_left:Nn \l_@@_options_to_sblfonts_clist
      {
        , mainfont        = TeXGyreTermesX
        , mainfontoptions = {
                              , Extension      = .otf
                              , UprightFont    = *-Regular
                              , ItalicFont     = *-Italic
                              , BoldFont       = *-Bold
                              , BoldItalicFont = *-BoldItalic
                            }
        , sblfonts        = true
      }
  }
  {
    \clist_put_left:Nn \l_@@_options_to_sblfonts_clist
      {
        , mainfont = tempora
        , grfont   = Alegreya-LF
        , hefont   = frank
      }
  }
%    \end{macrocode}
%
% Load article class.
%
%    \begin{macrocode}
\exp_args:No \PassOptionsToClass
  { \l_@@_options_to_article_class_clist }
  { article }
\LoadClass { article }
%    \end{macrocode}
%
% Font and language set up.
%
%    \begin{macrocode}
\exp_args:No \PassOptionsToPackage
  { \l_@@_options_to_sblfonts_clist }
  { sblfonts }
\RequirePackage { sblfonts }
%    \end{macrocode}
%
% \pkg{biblatex} set up.
%
%    \begin{macrocode}
\exp_args:No \PassOptionsToPackage
  { \l_@@_options_to_biblatex_clist }
  { biblatex }
\RequirePackage { biblatex }
\RequirePackage { csquotes }
%    \end{macrocode}
%
% \subsection{Margins}
%
%    \begin{macrocode}
\RequirePackage [ margin = 1in, headheight = 14.5pt ] { geometry }
%    \end{macrocode}
%
% \subsection{Text layout}
%
%    \begin{macrocode}
\RequirePackage { setspace }
\RequirePackage { ragged2e }
\doublespacing
\frenchspacing
\dim_set:Nn \RaggedRightParindent { 0.5in }
\dim_set:Nn \RaggedLeftParindent  { 0.5in }
\dim_set:Nn \JustifyingParindent  { 0.5in }
\RaggedRight
\sloppy
\raggedbottom
\sys_if_engine_luatex:F
  {
    \AddBabelHook [ hebrew ] { sblarticle } { afterextras }
      {
        \raggedleft
        \parindent 0.5in
      }
    \AddBabelHook { sblarticle } { afterextras } { \RaggedRight }
  }
%    \end{macrocode}
%
% \subsection{Headers and footers}
%
%    \begin{macrocode}
\RequirePackage { fancyhdr }
\pagestyle { fancy }
\fancyhf { }
\fancyhead [ R ] { \thepage }
\cs_set_nopar:Npn \headrulewidth { 0pt }
\cs_set_nopar:Npn \sectionmark #1
  {
    \markboth
      { \int_compare:nNnT
          { \c@secnumdepth } > { \c_zero_int }
          { \thesection \skip_horizontal:n { 1em } }
        #1
      }
      { }
  }
%    \end{macrocode}
%
% \subsection{Footnotes}
%
% Different handling is required for footnotes when tagging code is loaded.
%
%    \begin{macrocode}
\IfDocumentMetadataTF
  {
    \hook_gput_code:nnn { fntext / para } { sblarticle }
      { \RaggedRight }
    \socket_new_plug:nnn { fntext / mark } { sblarticle }
      {
        \skip_horizontal:N \footnotemargin
        \@thefnmark . \enspace
      }
    \socket_assign_plug:nn { fntext / mark } { sblarticle }
    \socket_assign_plug:nn
      { build / column / outputbox }
      { floats-space-footnotes }
  }
  {
    \RequirePackage [ bottom, ragged ] { footmisc }
    \cs_set:Npn \@makefntext #1
      {
        \dim_set_eq:NN \parindent \footnotemargin
        \@thefnmark . \enspace
        \footnotelayout #1
      }
}
%    \end{macrocode}
%
%    \begin{macrocode}
\dim_set:Nn \footnotemargin { 0.5in }
\cs_set:Npn \footnoterule
  {
    \kern -3pt
    \hrule width 2in
    \kern 2.6pt
    \vskip -8pt
  }
\dim_set:Nn \footnotesep { 20pt }
%    \end{macrocode}
%
% \subsection{Captions}
%
%    \begin{macrocode}
\skip_set:Nn \abovecaptionskip { 6pt }
\skip_set:Nn \belowcaptionskip { 6pt }
\cs_set:Npn \thefigure
  {
    \arabic { figure }
  }
\cs_set:Npn \thetable
  {
    \arabic { table }
  }
\counterwithout { figure } { part }
\counterwithout { table } { part }
%    \end{macrocode}
%
%    \begin{macrocode}
\IfDocumentMetadataTF
  {
    \NewSocketPlug { caption / label } { sblarticle }
     {
       \small
       #1:~
     }
    \AssignSocketPlug { caption / label } { sblarticle }
  }
  {
    \RequirePackage [ font = small , skip = 6pt ] { caption }
  }
%    \end{macrocode}
%
% \subsection{Block quotes}
%
%    \begin{macrocode}
\IfDocumentMetadataTF
  {
    \hook_gput_code:nnn { begindocument / before } { sblarticle }
      {
        \RenewDocumentEnvironment { quotation } { !O { } }
          {
            \UseInstance { blockenv } { quotation }
              {
                , begin-extra-vspace = 0pt
                , begin-vspace = 0pt
                , left-margin  = 0.5in
                , right-margin = 0pt
                , para-indent  = 0.5in
                , para-vspace  = 0pt
                , final-code   = \singlespacing
                                 \vspace* { -5pt }
                                 \ignorespaces
                , #1
              }
          }
          { \endblockenv }
        \RenewDocumentEnvironment { quote } { !O { } }
          {
            \UseInstance { blockenv } { quote }
              {
                , begin-extra-vspace = 0pt
                , begin-vspace = 0pt
                , left-margin  = 0.5in
                , right-margin = 0pt
                , para-indent  = 0pt
                , para-vspace  = 7pt
                , final-code   = \singlespacing
                                 \vspace* { -5pt }
                                 \ignorespaces
                , #1
              }
          }
          { \endblockenv }
      }
  }
  {
    \renewenvironment { quotation }
      {
        \list { }
          {
            \dim_set:Nn \leftmargin { 0.5in }
            \dim_zero:N \rightmargin
            \dim_zero:N \topsep
            \dim_zero:N \partopsep
            \dim_zero:N \itemsep
            \dim_zero:N \parsep
            \dim_set:Nn \itemindent { 0.5in }
            \dim_set:Nn \listparindent { 0.5in }
          }
        \item \relax
        \singlespacing
        \vspace* { -5pt }
      }
      {
        \endlist
      }
%    \end{macrocode}
%
%    \begin{macrocode}
    \renewenvironment { quote }
      {
        \list { }
          {
            \dim_set:Nn \leftmargin { 0.5in }
            \dim_zero:N \rightmargin
            \dim_zero:N \topsep
            \dim_zero:N \partopsep
            \dim_zero:N \itemsep
            \dim_set:Nn \parsep { 7pt }
            \dim_zero:N \itemindent
            \dim_zero:N \listparindent
          }
        \item \relax
        \singlespacing
        \vspace* { -5pt }
      }
      {
        \endlist
      }
  }
%    \end{macrocode}
%
% \subsection{Title page}
%
%    \begin{macrocode}
\tl_new:N \g_@@_course_tl
\tl_new:N \g_@@_institution_tl
\tl_new:N \g_@@_professor_tl
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_new_protected:Npn \course #1
  {
    \tl_gset:Nn \g_@@_course_tl { #1 }
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_new_protected:Npn \institution #1
  {
    \tl_gset:Nn \g_@@_institution_tl { #1 }
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_new_protected:Npn \professor #1
  {
    \tl_gset:Nn \g_@@_professor_tl { #1 }
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\author { [Your ~ Name] }
\title { Title ~ of ~ Paper }
\tl_gset:Nn \g_@@_course_tl { [Course ~ Number ~ and ~ Title] }
\tl_gset:Nn \g_@@_institution_tl { [Name ~ of ~ Institution] }
\tl_gset:Nn \g_@@_professor_tl { [Name ~ of ~ Professor] }
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_set_protected:Npn \maketitle
  {
    \newgeometry { top=2in, bottom=2in }
    \pagenumbering { roman }
    \thispagestyle { empty }
    \group_begin:
      \singlespacing
      \centering
      \text_uppercase:n { \g_@@_institution_tl } \para_end:
      \vfill
      \doublespacing
      \text_uppercase:n { \@title } \para_end:
      \vfill
      \singlespacing
      \text_uppercase:n
        { Submitted ~ to ~ \g_@@_professor_tl } \para_end:
      \text_uppercase:n { in ~ Partial ~ Fulfilment ~ of } \para_end:
      \text_uppercase:n { \g_@@_course_tl } \para_end:
      \vfill
      \text_uppercase:n { By } \para_end:
      \text_uppercase:n { \@author } \para_end:
      \text_uppercase:n { \@date } \para_end:
    \group_end:
    \restoregeometry
  }
%    \end{macrocode}
%
% \subsection{Abstract}
%
% \begin{macro}{\@@_abstract_protected_end:n} \marg{abstract}
%
%   \medskip
%
%   This function is used to inject |\__sblarticle_fontmatter_peek:|
%
%    \begin{macrocode}
\cs_set_eq:Nc \@@_orig_protected_end:n { end~ }
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_new_nopar:Nn \@@_abstract_protected_end:n
  {
    \@@_orig_protected_end:n { #1 }
    \tl_if_eq:nnT { #1 } { abstract }
      {
        \cs_gset_eq:cN { end~ } \@@_orig_protected_end:n
        \peek_remove_spaces:n
          {
            \peek_analysis_map_inline:n
              {
                \exp_args:No \token_if_eq_meaning:NNF { ##1 } \para_end:
                  {
                    \peek_analysis_map_break:n
                      {
                        \exp_after:wN
                        \@@_frontmatter_peek:
                        ##1
                      }
                  }
                ##1
              }
          }
      }
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\renewenvironment { abstract }
  {
    \part* { \abstractname }
    \addcontentsline { toc } { part } { \abstractname }
    \cs_gset_eq:cN { end~ } \@@_abstract_protected_end:n
  }
  {
    \par
    \clearpage
    \pagestyle { fancy }
  }
%    \end{macrocode}
%
% \subsection{Section titles}
%
%    \begin{macrocode}
\int_set:Nn \c@secnumdepth { -1 }
\cs_set_nopar:Npn \thepart
  {
    \@arabic \c@part
  }
%    \end{macrocode}
%
% These two functions ensure consistent spacing after section headings whether
% body paragraph text follows or another section heading follows.
%
%    \begin{macrocode}
\cs_new_nopar:Nn \@@_before_head_correction:
  {
    \hook_gclear_next_code:n { para / before }
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_new_nopar:Nn \@@_after_head_correction:
  {
    \vspace* { -5.5pt }
    \hook_gput_next_code:nn { para / before } { \vspace* { 5.5pt } }
  }
%    \end{macrocode}
%
% For documents using \cs{DocumentMetadata} use standard kernel commands to
% redefine section headings, otherwise use the \pkg{titlesec} package. 
%
%    \begin{macrocode}
\IfDocumentMetadataTF
  {
    \cs_set:Npn \section
      {
        \hook_gput_next_code:nn { para / end }
          { \dim_zero:N \hangindent }
        \@@_before_head_correction:
        \hook_gput_next_code:nn { para / after }
          { \@@_after_head_correction: }
        \@startsection { section } { 1 } { 0pt } { -37pt } { 1sp }
          { \singlespacing \normalfont \normalsize \bfseries \centering }
      }
    \cs_set:Npn \subsection
      {
        \hook_gput_next_code:nn { para / end }
          { \dim_zero:N \hangindent }
        \@@_before_head_correction:
        \hook_gput_next_code:nn { para / after }
          { \@@_after_head_correction: }
        \@startsection { subsection } { 2 } { 0pt } { -37pt } { 1sp }
          { \singlespacing \normalfont \normalsize \centering }
      }
    \cs_set:Npn \subsubsection
      {
        \@@_before_head_correction:
        \hook_gput_next_code:nn { para / after }
          { \@@_after_head_correction: }
        \@startsection { subsubsection } { 3 } { 0pt } { -37pt } { 1sp }
          { \singlespacing \normalfont \normalsize \bfseries \itshape }
      }
    \cs_set:Npn \paragraph
      {
        \@@_before_head_correction:
        \@startsection { paragraph } { 4 } { 0pt } { -37pt } { 1sp }
          { \singlespacing \normalfont \normalsize }
      }
    \cs_set:Npn \subparagraph
      {
        \@startsection { subparagraph } { 5 } { 0pt } { -37pt } { -1em }
          { \normalfont \normalsize \bfseries }
      }
%    \end{macrocode}
%
% Redefine \cs{@part} and \cs{@spart} to format major headings.
%
%    \begin{macrocode}
    \hook_gput_code:nnn { cmd / part / before } { sblarticle }
      {
        \clearpage
        \mode_leave_vertical:
        \par
        \thispagestyle { plain }
      }
%    \end{macrocode}
%
%    \begin{macrocode}
    \cs_set_nopar:Npn \@part [#1]#2
      {
        \addvspace { 37pt }
        \int_compare:nNnTF { \c@secnumdepth } > { -1 }
          {
            \refstepcounter { part }
            \addcontentsline { toc } { part }
              { \chaptername \space \thepart : \enspace #1 }
          }
          {
            \addcontentsline { toc } { part } {#1}
          }
        \group_begin:
          \dim_zero:N \parindent
          \centering
          \interlinepenalty 10000
          \normalfont
          \int_compare:nNnT { \c@secnumdepth } > { -1 }
            {
              \MakeUppercase { \chaptername } \nobreakspace \thepart
              \par
              \nobreak
            }
          \singlespacing
          \MakeUppercase {#2}
          \hook_gput_next_code:nn { para / after }
            { \@@_after_head_correction: }
          \markboth { } { }
          \par
        \group_end:
        \nobreak
        \skip_vertical:n { 39pt }
        \@afterheading
      }
%    \end{macrocode}
%
%    \begin{macrocode}
    \cs_set_nopar:Npn  \@spart #1
      {
        \addvspace { 37pt }
        \group_begin:
          \dim_zero:N \parindent
          \centering
          \interlinepenalty 10000
          \normalfont
          \singlespacing
          \MakeUppercase {#1}
          \hook_gput_next_code:nn { para / after }
            { \@@_after_head_correction: }
          \par
        \group_end:
        \nobreak
        \skip_vertical:n { 39pt }
        \@afterheading
      }
  }
  {
    \RequirePackage [ newparttoc ] { titlesec }
    \providecommand \phantomsection { }
    \titleclass { \part } [ 0 ] { top }
%    \end{macrocode}
%
%    \begin{macrocode}
    \titlespacing* { \part }          { 0pt } { 41pt } { 37pt }
    \titlespacing* { \section }       { 0pt } { 37pt } { 0pt }
    \titlespacing* { \subsection }    { 0pt } { 37pt } { 0pt }
    \titlespacing* { \subsubsection } { 0pt } { 37pt } { 0pt }
    \titlespacing* { \paragraph }     { 0pt } { 37pt } { 0pt }
    \titlespacing* { \subparagraph }  { 0pt } { 37pt } { 1em }
%    \end{macrocode}
%
%    \begin{macrocode}
    \titleformat
      { \part }
      [ display ]
      { \normalfont \normalsize \singlespacing \filcenter }
      {
        \MakeUppercase { \chaptername } \space \thepart
      }
      { 12pt }
      { \MakeUppercase }
      [ \@@_after_head_correction: ]
    \titleformat
      { \section }
      [ block ]
      {
        \@@_before_head_correction:
        \normalfont \normalsize \singlespacing \bfseries \filcenter
      }
      { \thesection }
      { 0.5em }
      { }
      [ \@@_after_head_correction: ]
    \titleformat
      { \subsection }
      [ block ]
      {
        \@@_before_head_correction:
        \normalfont \normalsize \singlespacing \filcenter
      }
      { \thesubsection }
      { 0.5em }
      { }
      [ \@@_after_head_correction: ]
    \titleformat
      { \subsubsection }
      [ block ]
      {
        \@@_before_head_correction:
        \normalfont \normalsize \singlespacing \bfseries \itshape \filright
      }
      { \thesubsubsection }
      { 0.5em }
      { }
      [ \@@_after_head_correction: ]
    \titleformat
      { \paragraph }
      [ block ]
      {
        \@@_before_head_correction:
        \normalfont \normalsize \singlespacing \filright
      }
      { \theparagraph }
      { 0.5em }
      { }
    \titleformat
      { \subparagraph }
      [ runin ]
      { \normalfont \normalsize \bfseries }
      { \thesubparagraph }
      { 1em }
      { }
  }
%    \end{macrocode}
%
% \subsection{Table of contents and list of figures/tables}
%
%    \begin{macrocode}
\int_set:Nn \c@tocdepth { 2 }
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_set:Npn \tableofcontents
  {
    \part* { \contentsname }
    \@mkboth
      { \contentsname }
      { \contentsname }
    \@starttoc { toc }
    \clearpage
    \@@_frontmatter_peek:
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_set:Npn \listoffigures
  {
    \part* { \listfigurename }
    \addcontentsline { toc } { part } { \listfigurename }
    \@mkboth
      { \listfigurename }
      { \listfigurename }
    \@starttoc { lof }
    \clearpage
    \@@_frontmatter_peek:
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_set:Npn \listoftables
  {
    \part* { \listtablename }
    \addcontentsline { toc } { part } { \listtablename }
    \@mkboth
      { \listfigurename }
      { \listfigurename }
    \@starttoc { lot }
    \clearpage
    \@@_frontmatter_peek:
  }
%    \end{macrocode}
%
% For documents using \cs{DocumentMetadata} use standard kernel commands to
% redefine table of contents lines, otherwise use the \pkg{titletoc} package. 
%
%    \begin{macrocode}
\IfDocumentMetadataTF
  {
    \text_declare_expand_equivalent:Nn \numberline
      {
        \exp_not:n { \numberline }
      }
    \hook_gput_code:nnn { cmd / @dottedtocline / before }
      { sblarticle }
      {
        \addvspace { \baselineskip }
      }
    \hook_gput_code_with_args:nnn { contentsline / text / after }
      { sblarticle }
      {
        \int_compare:nNnT {#1} > { -1 }
          {
            \cs_set_nopar:Npn \leaders ##1 ##2 { }
            \hook_gput_next_code:nn { cmd / SuspendTagging / after }
              {
                \cs_set_nopar:Npn \leaders ##1 ##2 { }
              }
          }
      }
    \cs_set_nopar:cpn { contentsline@text@-1@format }
      { \MakeUppercase }
    \cs_set_nopar:Npn \numberline #1
      {
        \hook_use:nnw { contentsline / number / before } { 1 } {#1}
        #1 \enspace
        \hook_use:nnw { contentsline / number / after } { 1 } {#1}
      }
%    \end{macrocode}
%
%    \begin{macrocode}
    \cs_set_nopar:Npn \l@part
      {
        \@dottedtocline { -1 } { 0em } { 0em }
      }
    \cs_set_nopar:Npn \l@section
      {
        \@dottedtocline { 1 } { 1em } { 0em }
      }
    \cs_set_nopar:Npn \l@subsection
      {
        \@dottedtocline { 2 } { 2em } { 0em }
      }
    \cs_set_nopar:Npn \l@subsubsection
      {
        \@dottedtocline { 3 } { 3em } { 0em }
      }
    \cs_set_nopar:Npn \l@paragraph
      {
        \@dottedtocline { 4 } { 4em } { 0em }
      }
    \cs_set_nopar:Npn \l@subparagraph
      {
        \@dottedtocline { 5 } { 5em } { 0em }
      }
    \cs_set_nopar:Npn \l@figure
      {
        \@dottedtocline { 1 } { 0em } { 0em }
      }
    \cs_set_eq:NN \l@table \@figure
  }
  {
    \RequirePackage { titletoc }
%    \end{macrocode}
%
% \begin{macro}{\@@_hyperlink:nn} \marg{link} \marg{text}
%
%   \medskip
%
%   A convenience version of |\hyperlink| that just uses \meta{text} if
%   \pkg{hyperref} isn't loaded.
%
%    \begin{macrocode}
    \cs_new_protected:Nn \@@_hyperlink:nn
      {
        \cs_if_exist_use:NTF \hyperlink
          { { #1 } { #2 } }
          { #2 }
      }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
    \titlecontents { figure }
      [ 2em ]
      { \singlespacing \filright }
      {
        \@@_hyperlink:nn
          { \Hy@tocdestname }
          { \makebox [ 2em ] [ l ] { \thecontentslabel . \enspace } }
      }
      { }
      { \hspace { 0.5em } \titlerule* [ 0.5pc ] { . } \contentspage }
    \titlecontents { table }
      [ 2em ]
      { \singlespacing \filright }
      {
        \@@_hyperlink:nn
          { \Hy@tocdestname }
          { \makebox [ 2em ] [ l ] { \thecontentslabel . \enspace } }
      }
      { }
      { \hspace { 0.5em } \titlerule* [ 0.5pc ] { . } \contentspage }
    \titlecontents { part }
      [ 0pt ]
      { \singlespacing \filright }
      {
        \@@_hyperlink:nn
          { \Hy@tocdestname }
          {
            \MakeUppercase { \chaptername } \space
            \thecontentslabel : \enspace
          }
        \MakeUppercase
      }
      { \MakeUppercase }
      { \hspace { 0.5em } \titlerule* [ 0.5pc ] { . } \contentspage }
    \titlecontents { section }
      [ 1em ]
      { \singlespacing \filright }
      { }
      { }
      { \hfill \contentspage }
    \titlecontents { subsection }
      [ 2em ]
      { \singlespacing \filright }
      { }
      { }
      { \hfill \contentspage }
    \titlecontents { subsubsection }
      [ 3em ]
      { \singlespacing \filright }
      { }
      { }
      { \hfill \contentspage }
    \titlecontents { paragraph }
      [ 4em ]
      { \singlespacing \filright }
      { }
      { }
      { \hfill \contentspage }
    \titlecontents { subparagraph }
      [ 5em ]
      { \singlespacing \filright }
      { }
      { }
      { \hfill \contentspage }
  }
%    \end{macrocode}
%
% \subsection{Appendices}
%
% Set up appendix headings and table of contents.
%
%    \begin{macrocode}
\cs_set_eq:NN \sblarticle@hyperlink \@@_hyperlink:nn
\newcounter { sblarticle@appendix@count }
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_new_protected:Nn \@@_set_up_appendices:
  {
    \cs_set_eq:NN \section \part
    \int_set:Nn \c@secnumdepth { \c_one_int }
    \cs_set_nopar:Npn \chaptername { \appendixname }
    \addtocontents { toc } { \def \protect \chaptername { \appendixname } }
    \int_compare:nNnT { \c@sblarticle@appendix@count } = { \c_one_int }
      {
        \int_zero:N \c@sblarticle@appendix@count
      }
    \IfDocumentMetadataTF
      {
        \cs_set_nopar:Npn \@part [##1]##2
          {
            \addvspace { 37pt }
            \stepcounter { sblarticle@appendix@count }
            \int_compare:nNnTF { \c@secnumdepth } > { -1 }
              {
                \refstepcounter { part }
                \protected@write \@auxout
                  { }
                  {
                    \string \setcounter
                      { sblarticle@appendix@count } { \the \c@part }
                  }
                \addcontentsline { toc } { part }
                  {
                    \chaptername
                    \ifnum \c@sblarticle@appendix@count > 1
                      \space \thechapter
                    \fi
                    : \enspace ##1
                  }
              }
              {
                \addcontentsline { toc } { part } {##1}
              }
            \group_begin:
              \dim_zero:N \parindent
              \centering
              \interlinepenalty 10000
              \normalfont
              \int_compare:nNnT { \c@secnumdepth } > { -1 }
                {
                  \MakeUppercase { \chaptername }
                  \int_compare:nNnT
                    { \c@sblarticle@appendix@count } > { \c_one_int }
                    {
                       \nobreakspace \thechapter
                    }
                  \par
                  \nobreak
                }
              \singlespacing
              \MakeUppercase {##2}
              \hook_gput_next_code:nn { para / after }
                { \@@_after_head_correction: }
              \markboth { } { }
              \par
            \group_end:
            \nobreak
            \skip_vertical:n { 39pt }
            \@afterheading
          }
      }
      {
        \titleformat
          { \part }
          [ display ]
          {
            \stepcounter { sblarticle@appendix@count }
            \protected@write \@auxout
              { }
              {
                \string \setcounter
                  { sblarticle@appendix@count } { \the \c@part }
              }
            \singlespacing \normalfont \normalsize \filcenter
          }
          {
            \MakeUppercase { \chaptername }
            \ifnum \c@sblarticle@appendix@count > 1
              \strut \space \thepart
            \fi
          }
          { 12pt }
          { \MakeUppercase }
        \titlecontents { part }
          [ 0pt ]
          { \singlespacing \filright }
          {
            \sblarticle@hyperlink
              { \Hy@tocdestname }
              {
                \MakeUppercase { \chaptername }
                \ifnum \c@sblarticle@appendix@count > 1
                  \strut \space \thecontentslabel
                \fi
                : \enspace
              }
            \MakeUppercase
          }
          { \MakeUppercase }
          { \hspace { 0.5em } \titlerule* [ 0.5pc ] { . } \contentspage }
      }
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\hook_gput_code:nnn
  { cmd / appendix / after }
  { sblarticle }
  { \@@_set_up_appendices: }
%    \end{macrocode}
%
% \subsection{Bibliography and list of abbreviations}
%
%    \begin{macrocode}
\DefineBibliographyStrings { english }
  {
    shorthands = { List~of~Abbreviations }
  }
\cs_set_nopar:Npn \bibsetup { \singlespacing }
\dim_set:Nn \bibhang { 0.5in }
\dim_set:Nn \bibitemsep { 12pt }
\dim_set:Nn \biblabelsep { 0.5in }
\defbibheading { bibliography } [ \bibname ]
  {
    \part* {#1}
  }
\defbibheading { bibintoc } [ \bibname ]
  {
    \part* {#1}
    \addcontentsline { toc } { part } {#1}
  }
\defbibheading { biblist } [ \biblistname ]
  {
    \part* {#1}
  }
\defbibheading { biblistintoc } [ \biblistname ]
  {
    \part* {#1}
    \addcontentsline { toc } { part } {#1}
  }
%    \end{macrocode}
%
% Peeking ahead from the end of |\printbiblist| is slightly more complicated
% because we only want to do so when it's in the front matter and it's defined
% with |\newrobuscmd*| with optional arguments.
%
%    \begin{macrocode}
\cs_new:Npn \sblarticle@printbiblist@frontmatter@peek
  {
    \@@_if_page_numbering:nT { roman }
      {
        \@@_frontmatter_peek:
      }
  }
%    \end{macrocode}
%
% \subsection{Helper functions}
%
%    \begin{macrocode}
\ExplSyntaxOff
\expandafter\apptocmd\csname\string\printbiblist\endcsname
  {\sblarticle@printbiblist@frontmatter@peek}
  {}
  {}
\ExplSyntaxOn
%    \end{macrocode}
%
% \begin{macro}{\@@_if_page_numbering:nT} \marg{numbering style}
%     \marg{code if true}
%
%   \medskip
%
%   Test if the current page numbering style matches a particular style.
%   (e.g., |arabic| or |roman|).
%
%    \begin{macrocode}
\prg_new_conditional:Npnn \@@_if_page_numbering:n #1 { T }
  {
    \cs_set_nopar:Nn \@@_thepage_test:
      { \csname @ #1 \endcsname \c@page }
    \if_meaning:w \thepage \@@_thepage_test:
      \prg_return_true:
    \else:
      \prg_return_false:
    \fi:
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_frontmatter_peek:}
%
%   \medskip
%
%   Peek ahead and insert the title of the paper at the start of the main
%   matter.
%
%    \begin{macrocode}
\cs_new_protected:Nn \@@_frontmatter_peek:
  {
    \peek_analysis_map_inline:n
      {
%    \end{macrocode}
%
% Test if the next token is a control sequence of not.
%
%    \begin{macrocode}
        \int_compare:nNnTF {##2} = { -1 }
          {
            \exp_args:No \token_if_eq_meaning:NNF {##1} \par
              {
                \bool_case:nTF
                  {
                    {
                      \exp_args:No \token_if_eq_meaning_p:NN
                        {##1} \begin
                    }
                      { }
                    {
                      \exp_args:No \token_if_eq_meaning_p:NN
                        {##1} \tableofcontents
                    }
                      { }
                    {
                      \exp_args:No \token_if_eq_meaning_p:NN
                        {##1} \listoffigures
                    }
                      { }
                    {
                      \exp_args:No \token_if_eq_meaning_p:NN
                        {##1} \listoftables
                    }
                      { }
                    {
                      \exp_args:No \token_if_eq_meaning_p:NN
                        {##1} \printbiblist
                    }
                      { }
                  }
                  { \peek_analysis_map_break:n {##1} }
                  {
%    \end{macrocode}
%
% Insert the paper title if some control sequence other than the above is
% found.
%
%    \begin{macrocode}
                    \peek_analysis_map_break:n
                      {
                        \part { \@title }
                        \pagenumbering { arabic }
                        ##1
                      }
                  }
              }
          }
          {
%    \end{macrocode}
%
% Ignore spaces and insert the paper title if a token other than a control
% sequence is found.
%
%    \begin{macrocode}
            \exp_args:No \token_if_space:NF {##1}
              {
                \peek_analysis_map_break:n
                  {
                    \part { \@title }
                    \pagenumbering { arabic }
                    ##1
                  }
              }
          }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \medskip
%
% Add the code to peek ahead after |maketitle| at the end of preamble because
% \pkg{hyperref} (if loaded) takes over things.
%
%    \begin{macrocode}
\hook_gput_code:nnn
  { begindocument / before }
  { sblarticle }
  { 
    \g@addto@macro \maketitle { \@@_frontmatter_peek: }
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\endinput
%    \end{macrocode}
%
%    \begin{macrocode}
%</class>
%    \end{macrocode}
