%%
%% This is file `sblbook.cls',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% sblbook.dtx  (with options: `class')
%% 
%% This is a generated file.
%% 
%% Copyright (c) 2026 David Purton <dcpurton@marshwiggle.net>
%% 
%% This work may be distributed and/or modified under the conditions of
%% the LaTeX Project2 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.
%% 
%% This work is "maintained" (as per the LPPL maintenance status)
%% by David Purton.
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesExplClass{sblbook}{2026-07-22}{1.1}
  {Society of Biblical Literature Book Class (DCP)}
\clist_new:N \l__sblbook_options_to_book_class_clist
\keys_define:nn { sblbook }
  {
    , biblatex .clist_set:N = \l__sblbook_options_to_biblatex_clist
    , sblfonts .clist_set:N = \l__sblbook_options_to_sblfonts_clist
    , sblidx   .clist_set:N = \l__sblbook_options_to_sblidx_clist
    , trim     .bool_set:N  = \l__sblbook_trim_bool
    , trim     .default:n   = true
    , trim     .initial:n   = false
    , unknown  .code:n = {
                           \clist_put_right:No
                             \l__sblbook_options_to_book_class_clist
                             { \CurrentOption }
                         }
  }
\ProcessKeyOptions
\clist_put_left:Nn \l__sblbook_options_to_book_class_clist
  { }
\clist_put_left:Nn \l__sblbook_options_to_biblatex_clist
  {
    , style    = sbl
    , language = auto
    , autolang = hyphen
  }
\sys_if_engine_opentype:TF
  {
    \clist_put_left:Nn \l__sblbook_options_to_sblfonts_clist
      {
        , mainfont        = Baskervaldx
        , mainfontoptions = {
                              , Extension      = .otf
                              , UprightFont    = *-Reg
                              , ItalicFont     = *-Ita
                              , BoldFont       = *-Bol
                              , BoldItalicFont = *-BolIta
                            }
        , sblfonts        = true
      }
  }
  {
    \clist_put_left:Nn \l__sblbook_options_to_sblfonts_clist
      {
        , mainfont = Baskervaldx
        , grfont   = Alegreya-LF
        , hefont   = frank
      }
  }
\exp_args:No \PassOptionsToClass
  { \l__sblbook_options_to_book_class_clist }
  { book }
\LoadClass { book }
\exp_args:No \PassOptionsToPackage
  { \l__sblbook_options_to_sblfonts_clist }
  { sblfonts }
\RequirePackage { sblfonts }
\sys_if_engine_opentype:T
  {
    \hook_gput_code:nnn
      { cmd / MakeUppercase / before }
      { sblbook }
      { \addfontfeature { Kerning = Uppercase } }
    \hook_gput_code:nnn
      { cmd / MakeUppercase / after }
      { sblbook }
      { \addfontfeature { Kerning = UppercaseOff } }
  }
\exp_args:No \PassOptionsToPackage
  { \l__sblbook_options_to_biblatex_clist }
  { biblatex }
\RequirePackage { biblatex }
\RequirePackage { csquotes }
\clist_if_exist:NT \l__sblbook_options_to_sblidx_clist
  {
    \exp_args:No \PassOptionsToPackage
      { \l__sblbook_options_to_sblidx_clist }
      { sblidx }
    \RequirePackage { sblidx }
    \@ifpackageloaded { bibleref }
      {
        \RequirePackage { bibleref-parse }
      }
      { }
  }
\bool_if:NTF \l__sblbook_trim_bool
  {
    \RequirePackage
      [
        , paperwidth  = 6in
        , paperheight = 9in
      ]
      { geometry }
  }
  {
    \RequirePackage { geometry }
  }
\dim_new:N \l__sblbook_top_margin_dim
\dim_new:N \l__sblbook_inner_margin_dim
\dim_set:Nn \l__sblbook_top_margin_dim
  { 0.5 \paperheight - 3.75in }
\dim_set:Nn \l__sblbook_inner_margin_dim
  { 0.5 \paperwidth - 2.25in }
\geometry
  {
    , includehead    = true
    , marginparwidth = 0.5in
    , textwidth      = 4.5in
    , height         = 7.5in
    , top            = \l__sblbook_top_margin_dim
    , inner          = \l__sblbook_inner_margin_dim
    , headsep        = 12pt
    , headheight     = 12pt
    , footskip       = 12pt
  }
\dim_set:Nn \parindent { 0.25in }
\RequirePackage [ all ] { nowidow }
\RequirePackage [ hyphenation , lastparline ] { impnattypo }
\RequirePackage { microtype }
\cs_new_protected:Nn \__sblbook_lastparline_off:
  {
    \sys_if_engine_luatex:T
      {
        \lua_now:e
          {
            luatexbase.remove_from_callback("pre_linebreak_filter",
              "lastparline")
          }
      }
  }
\cs_new_protected:Nn \__sblbook_lastparline_on:
  {
    \sys_if_engine_luatex:T
      {
        \lua_now:e
          {
            luatexbase.add_to_callback("pre_linebreak_filter",
              last_line_minimal_length, "lastparline")
          }
      }
  }
\RequirePackage { fancyhdr }
\pagestyle { fancy }
\fancyhf { }
\fancyhead [ LE , RO ] { \thepage }
\fancyhead [ CE ] { \itshape \nouppercase { \leftmark } }
\fancyhead [ CO ] { \itshape \nouppercase { \rightmark } }
\cs_set_nopar:Npn \headrulewidth { 0pt }
\cs_set_nopar:Npn \chaptermark #1
  {
    \markboth { \@title } { #1 }
  }
\cs_set_nopar:Npn \sectionmark #1 { }
\fancypagestyle { plain }
  {
    \fancyhf { }
    \fancyfoot
      [ C ]
      {
        \smash { \raisebox { 12pt } { -\,\thepage\,- } }
      }
    \cs_set_nopar:Npn \headrulewidth { 0pt }
    \cs_set_nopar:Npn \footrulewidth { 0pt }
  }
\cs_set_nopar:Npn \thispagestyle #1
  {
    \cs_if_exist:cTF { ps@#1 }
      {
        \tl_if_eq:nnT {#1} { plain }
          {
            \enlargethispage { -24pt }
          }
        \legacy_if_gset_true:n { @specialpage }
        \cs_gset_nopar:Npn \@specialstyle {#1}
      }
      {
        \undefinedpagestyle
      }
  }
\cs_set_nopar:Npn \cleardoublepage
  {
    \clearpage
    \int_if_even:nT { \c@page }
      {
        \hbox:n { }
        \thispagestyle { empty }
        \newpage
      }
  }
\IfDocumentMetadataTF
  {
    \socket_new_plug:nnn { fntext / mark } { sblbook }
      {
        \skip_horizontal:N \footnotemargin
        \@thefnmark . \enspace
      }
    \socket_assign_plug:nn { fntext / mark } { sblbook }
    \socket_assign_plug:nn
      { build / column / outputbox }
      { floats-space-footnotes }
  }
  {

    \RequirePackage [ bottom ] { footmisc }
    \cs_set_protected:Npn \@makefntext #1
      {
        \dim_set_eq:NN \parindent \footnotemargin
        \@thefnmark . \enspace
        \footnotelayout #1
      }
}
\dim_set:Nn \footnotemargin { 0.25in }
\cs_set:Npn \footnoterule
  {
    \kern -3pt
    \hrule width 1.5in height .5pt depth 0pt
    \kern 0.0625in
  }
\skip_set:Nn \abovecaptionskip { 6pt }
\skip_set:Nn \belowcaptionskip { 6pt }
\cs_set:Npn \thefigure
  {
    \arabic { figure }
  }
\cs_set:Npn \thetable
  {
    \arabic { table }
  }
\counterwithout { figure } { chapter }
\counterwithout { table } { chapter }
\IfDocumentMetadataTF
  {
    \NewSocketPlug { caption / label } { sblbook }
     {
       \small
       #1:~
     }
    \AssignSocketPlug { caption / label } { sblbook }
  }
  {
    \RequirePackage [ font = small , skip = 6pt ] { caption }
  }
\IfDocumentMetadataTF
  {
    \EditInstance { blockenv } { quotation }
      {
        , final-code = \small \ignorespaces
      }
    \EditInstance { block } { quotation-1 }
      {
        , begin-extra-vspace = 0pt
        , begin-vspace       = 11pt plus 5pt minus 3pt
        , left-margin        = \parindent
        , right-margin       = \parindent
        , para-indent        = \parindent
        , para-vspace        = 0pt
      }
    \EditInstance { blockenv } { quote }
      {
        , final-code = \small \ignorespaces
      }
    \EditInstance { block } { quote-1 }
      {
        , begin-extra-vspace = 0pt
        , begin-vspace       = 11pt plus 5pt minus 3pt
        , left-margin        = \parindent
        , right-margin       = \parindent
        , para-indent        = 0pt
        , para-vspace        = 6pt plus 2pt minus 1pt
      }
  }
  {
    \renewenvironment { quotation }
      {
        \small
        \list { }
          {
            \dim_set_eq:NN \leftmargin \parindent
            \dim_set_eq:NN \rightmargin \leftmargin
            \skip_set:Nn   \topsep { 11pt plus 5pt minus 3pt }
            \skip_zero:N   \partopsep
            \skip_zero:N   \itemsep
            \skip_zero:N   \parsep
            \dim_set_eq:NN \itemindent \parindent
            \dim_set_eq:NN \listparindent \parindent
          }
        \item \ignorespaces
      }
      {
        \endlist
      }
    \renewenvironment { quote }
      {
        \small
        \list { }
          {
            \dim_set_eq:NN \leftmargin \parindent
            \dim_set_eq:NN \rightmargin \leftmargin
            \skip_set:Nn   \topsep { 11pt plus 5pt minus 3pt }
            \skip_zero:N   \partopsep
            \skip_zero:N   \itemsep
            \skip_set:Nn   \parsep { 6pt plus 2pt minus 1pt }
            \dim_zero:N    \itemindent
            \dim_zero:N    \listparindent
          }
        \item \ignorespaces
      }
      {
        \endlist
      }
  }
\cs_new_protected:Nn \__sblbook_supplied_page:
  {
    \group_begin:
      \vfill
      \normalfont
      \footnotesize
      \centering
      This ~ page ~ is ~ supplied ~ by ~ SBL ~ Press
      \para_end:
    \group_end:
  }
\tl_new:N \g__sblbook_subtitle_tl
\cs_set_protected:Npn \subtitle #1
  {
    \tl_gset:Nn \g__sblbook_subtitle_tl {#1}
  }
\tl_new:N \g__sblbook_series_tl
\cs_set_protected:Npn \series #1
  {
    \tl_gset:Nn \g__sblbook_series_tl {#1}
  }
\title    { [Title ~ of ~ Book] }
\subtitle { [Subtitle ~ of ~ Book] }
\author   { [Your ~ Name] }
\series   { [Series ~ Name] }
\NewTaggingSocket{ sblbook / flatblock / begin } { 1 }
\NewTaggingSocket{ sblbook / flatblock / end } { 0 }
\NewTaggingSocketPlug { sblbook / flatblock / begin } { default }
  {
    \tag_struct_begin:n
      {
        tag = #1
      }
    \tagpdfsetup { para / flattened = true }
  }
\NewTaggingSocketPlug { sblbook / flatblock / end } { default }
  {
    \para_end:
    \tag_struct_end:
  }
\AssignTaggingSocketPlug { sblbook / flatblock / begin } { default }
\AssignTaggingSocketPlug { sblbook / flatblock / end } { default }
\cs_set_protected:Npn \maketitle
  {
    \group_begin:
      \UseTaggingSocket { sblbook / flatblock / begin }
        { \UseStructureName { title / block } }
      \thispagestyle { empty }
      \centering
      \vspace* { 0.5in }
      \LARGE
      \IfDocumentMetadataTF
        {
          \UseTaggingSocket { title } { } { \MakeUppercase { \@title } }
        }
        {
          \MakeUppercase { \@title }
        }
      \para_end:
      \tl_if_empty:NF \g__sblbook_subtitle_tl
        {
          \vspace { 0.5in }
          \Large
          \g__sblbook_subtitle_tl
          \para_end:
        }
      \__sblbook_supplied_page:
      \UseTaggingSocket { sblbook / flatblock / end }
    \group_end:
  }
\RenewDocumentEnvironment { titlepage } { }
  {
    \clearpage
    \UseTaggingSocket { sblbook / flatblock / begin }
      { \UseStructureName { title / block } }
    \thispagestyle { empty }
    \centering
    \vspace* { 0.5in }
    \LARGE
    \IfDocumentMetadataTF
      {
        \UseTaggingSocket { title } { } { \MakeUppercase { \@title } }
      }
      {
        \MakeUppercase { \@title }
      }
    \para_end:
    \tl_if_empty:NF \g__sblbook_subtitle_tl
      {
        \vspace { 0.5in }
        \Large
        \g__sblbook_subtitle_tl
        \para_end:
      }
    \vspace { 0.5in }
    \large
    By
    \para_end:
    \@author
    \para_end:
    \normalsize
  }
  {
    \__sblbook_supplied_page:
    \UseTaggingSocket { sblbook / flatblock / end }
  }
\NewDocumentEnvironment { copyrightpage } { }
  {
    \clearpage
    \UseTaggingSocket { sblbook / flatblock / begin } { text-unit }
    \thispagestyle { empty }
    \vspace* { 0.5in }
    \noindent
    Copyright ~ © ~ \number \year \space by ~ \@author
  }
  {
    \__sblbook_supplied_page:
    \UseTaggingSocket { sblbook / flatblock / end }
  }
\NewDocumentEnvironment { seriespage } { }
  {
    \clearpage
    \UseTaggingSocket { sblbook / flatblock / begin } { text-unit }
    \thispagestyle { empty }
    \centering
    \vspace* { 0.5in }
    \LARGE
    \MakeUppercase { \g__sblbook_series_tl }
    \para_end:
    \normalsize
  }
  {
    \__sblbook_supplied_page:
    \UseTaggingSocket { sblbook / flatblock / end }
  }
\NewDocumentEnvironment { dedication } { }
  {
    \cleardoublepage
    \UseTaggingSocket { sblbook / flatblock / begin } { text-unit }
    \int_compare:nNnT { \c@page } < { 5 }
      {
        \int_gset:Nn \c@page { 5 }
      }
    \thispagestyle { empty }
    \centering
    \vspace* { 1.5in }
    \itshape
  }
  {
    \para_end:
    \UseTaggingSocket { sblbook / flatblock / end }
  }
\NewDocumentEnvironment { epigraph } { }
  {
    \cleardoublepage
    \UseTaggingSocket { sblbook / flatblock / begin } { text-unit }
    \int_compare:nNnT { \c@page } < { 5 }
      {
        \int_gset:Nn \c@page { 5 }
      }
    \thispagestyle { empty }
    \vspace* { 0.5in }
  }
  {
    \para_end:
    \UseTaggingSocket { sblbook / flatblock / end }
  }
\cs_new_nopar:Npn \acknowledgementsname { Acknowledgements }
\NewDocumentEnvironment { acknowledgements } { }
  {
    \chapter* { \acknowledgementsname }
    \chaptermark { \acknowledgementsname }
    \addcontentsline { toc } { chapter } { \acknowledgementsname }
  }
  { \para_end: }
\cs_new_nopar:Npn \forewordname { Foreword }
\NewDocumentEnvironment { foreword } { }
  {
    \chapter* { \forewordname }
    \chaptermark { \forewordname }
    \addcontentsline { toc } { chapter } { \forewordname }
  }
  { \para_end: }
\cs_new_nopar:Npn \introductionname { Introduction }
\NewDocumentEnvironment { introduction } { }
  {
    \chapter* { \introductionname }
    \chaptermark { \introductionname }
    \addcontentsline { toc } { chapter } { \introductionname }
  }
  { \para_end: }
\cs_new_nopar:Npn \prefacename { Preface }
\NewDocumentEnvironment { preface } { }
  {
    \chapter* { \prefacename }
    \chaptermark { \prefacename }
    \addcontentsline { toc } { chapter } { \prefacename }
  }
  { \para_end: }
\int_set:Nn \c@secnumdepth { 0 }
\cs_set_nopar:Npn \thepart { \arabic { part } }
\IfDocumentMetadataTF
  {
    \EditInstance { heading } { part }
      {
        , heading-decls = \normalfont \Large \scshape \centering
        , title-decls   =
        , start-code    = \cleardoublepage
                          \thispagestyle { empty }
                          \null \vfil
      }
    \EditInstance { headformat } { part }
      {
        , number-title-sep = 12pt
      }
    \DeclareDocumentCommand \part { s = { shorttitle } o m }
      {
        \ParseLaTeXeHeading { part } {#1} {#2} {#3}
      }
    \EditInstance { heading } { chapter }
      {
        , placement            = top
        , after-penalty-vspace = 0.5in
        , after-vspace         = 0.5in plus 12pt minus 6pt
        , prefix               =
        , heading-decls        = \normalfont \normalsize \Large \centering
        , title-decls          =
      }
    \EditInstance { headformat } { chapter }
      {
        , number-title-sep = 12pt
      }
    \DeclareDocumentCommand \chapter { s = { shorttitle } o m }
      {
        \bool_if:nF {#1}
          {
            \__sblbook_if_page_numbering:nT { roman }
              {
                \cleardoublepage
                \pagenumbering { arabic }
              }
            \addtocontents { toc } { \addvspace { 12pt ~ plus ~ 1pt } }
          }
        \legacy_if:nTF { @mainmatter }
          {
            \ParseLaTeXeHeading { chapter } {#1} {#2} {#3}
          }
          {
            \bool_if:nTF {#1}
              {
                \ParseLaTeXeHeading { chapter } {#1} {#2} {#3}
              }
              {
                \tl_if_novalue:nTF {#2}
                  {
                    \ParseLaTeXeHeading { chapter } { \c_true_bool }
                      { shorttitle = {#3} } {#3}
                  }
                  {
                    \ParseLaTeXeHeading { chapter } { \c_true_bool }
                      {#2} {#3}
                  }
              }
          }
      }
    \EditInstance { heading } { section }
      {
        , before-vspace = 12pt plus 2pt minus 1pt
        , after-vspace  = 10.5pt plus 4pt minus 2pt
        , heading-decls = \normalfont \normalsize \centering
      }
    \EditInstance { headformat } { section }
      {
        , title-format = \MakeUppercase {#1}
      }
    \EditInstance { heading } { subsection }
      {
        , before-vspace = 6pt plus 2pt minus 1pt
        , after-vspace  = 4pt plus 2pt minus 1pt
        , heading-decls = \normalfont \normalsize \scshape \raggedright
      }
    \DeclareInstance { heading } { subsubsection } { runin }
      {
        , name                = subsubsection
        , parent-name         = subsection
        , level               = 3
        , before-vspace       = 6pt plus 2pt minus 1pt
        , after-vspace        = 1em
        , heading-decls       = \normalfont \normalsize \scshape
        , mark-cmd            = \subsubsectionmark {#1}
        , headformat-instance = subsubsection
      }
    \DeclareInstance { headformat } { subsubsection } { runin }
      {
        , heading-indent = 0pt
      }
    \EditInstance { heading } { paragraph }
      {
        , before-vspace = 6pt plus 2pt minus 1pt
        , after-vspace  = 1em
        , heading-decls = \normalfont \normalsize \itshape
      }
    \EditInstance { heading } { subparagraph }
      {
        , before-vspace = 6pt plus 2pt minus 1pt
        , after-vspace  = 1em
        , heading-decls = \normalfont \normalsize \itshape
      }
    \EditInstance { headformat } { subparagraph }
      {
        , heading-indent = 0.25in
      }
  }
  {
    \RequirePackage [ newparttoc ] { titlesec }
    \titleclass { \part } { page }
    \assignpagestyle { \part } { empty }
    \titlespacing* { \part }         { 0pt }    { 0pt }
      { 0pt }
    \titlespacing* { \chapter }      { 0pt }    { 0.5in }
      { 0.5in plus 12pt minus 6pt }
    \titlespacing* { \section }      { 0pt }    { 12pt plus 4pt minus 2pt }
      { 10pt plus 4pt minus 2pt }
    \titlespacing* { \subsection }   { 0pt }    { 6pt plus 2pt minus 1pt }
      { 4pt plus 2pt minus 1pt }
    \titlespacing* {\subsubsection } { 0pt }    { 6pt plus 2pt minus 1pt }
      { 1em }
    \titlespacing* { \paragraph }    { 0pt }    { 6pt plus 2pt minus 1pt }
      { 1em }
    \titlespacing* { \subparagraph } { 0.25in } { 6pt plus 2pt minus 1pt }
      { 1em }
    \titleformat
      { \part }
      [ display ]
      { \vfil \normalfont \Large \scshape \filcenter }
      { \partname \space \thepart }
      { 12pt }
      { }
      [ \vfil ]
    \titleformat
      { \chapter }
      [ display ]
      { \normalfont \Large \filcenter }
      { \thechapter }
      { 12pt }
      { }
    \titleformat
      { \section }
      [ block ]
      { \normalfont \normalsize \filcenter }
      { \thesection }
      { 1em }
      { \MakeUppercase }
    \titleformat
      { \subsection }
      [ block ]
      { \normalfont \normalsize \scshape \filright }
      { \thesubsection }
      { 1em }
      { }
    \titleformat
      { \subsubsection }
      [ runin ]
      { \normalfont \normalsize \scshape }
      { \thesubsubsection }
      { 1em }
      { }
    \titleformat
      { \paragraph }
      [ runin ]
      { \normalfont \normalsize \itshape }
      { \theparagraph }
      { 1em }
      { }
    \titleformat
      { \subparagraph }
      [ runin ]
      { \normalfont \normalsize \itshape }
      { \thesubparagraph }
      { 1em }
      { }
  }
\int_set:Nn \c@tocdepth { 1 }
\cs_set_protected:Npn \tableofcontents
  {
    \chapter* { \contentsname }
    \@mkboth
      { \contentsname }
      { \contentsname }
    \int_compare:nNnT { \c@page } < { 5 }
      { \int_gset:Nn \c@page { 5 } }
    \__sblbook_lastparline_off:
    \@starttoc { toc }
    \__sblbook_lastparline_on:
  }
\cs_set_protected:Npn \listoffigures
  {
    \chapter* { \listfigurename }
    \addcontentsline { toc } { chapter } { \listfigurename }
    \@mkboth
      { \listfigurename }
      { \listfigurename }
    \__sblbook_lastparline_off:
    \@starttoc { lof }
    \__sblbook_lastparline_on:
  }
\cs_set_protected:Npn \listoftables
  {
    \chapter* { \listtablename }
    \addcontentsline { toc } { chapter } { \listtablename }
    \@mkboth
      { \listtablename }
      { \listtablename }
    \__sblbook_lastparline_off:
    \@starttoc { lot }
    \__sblbook_lastparline_on:
  }
\IfDocumentMetadataTF
  {
    \cs_set:Npn \@pnumwidth { 2em }
    \hook_gput_code_with_args:nnn { contentsline / text / after }
      { sblbook }
      {
        \int_compare:nNnT {#1} > { \c_zero_int }
          {
            \cs_set_nopar:Npn \leaders ##1 ##2 { }
          }
      }
    \socket_new:nn { sblbook / numberline } { 1 }
    \socket_new_plug:nnn { sblbook / numberline }
      { boxed }
      {
        \hbox_to_wd:nn
          { \@tempdima }
          {
            \hook_use:nnw { contentsline / number / before } { 1 } {#1}
            \hfill #1. \enspace
            \hook_use:nnw { contentsline / number / after } { 1 } {#1}
          }
      }
    \socket_new_plug:nnn { sblbook / numberline }
      { default }
      {
        \hook_use:nnw { contentsline / number / before } { 1 } {#1}
        #1. \enspace
        \hook_use:nnw { contentsline / number / after } { 1 } {#1}
      }
    \socket_new_plug:nnn { sblbook / numberline }
      { chapter }
      {
        \int_compare:nNnTF { \int_use:N \sblbook@appendices } = { 1 }
          {
            \hook_use:nnw { contentsline / number / before } { 1 } {#1}
            \chaptername
            \int_compare:nNnT { \sblbook@appendix@state } > { 1 }
              {
                \skip_horizontal:n
                  {
                    \InstanceValue
                      { headformat } { chapter } { prefix-number-sep }
                  }
                #1
              }
            : \enspace
            \hook_use:nnw { contentsline / number / after } { 1 } {#1}
          }
          {
            \hbox_to_wd:nn
              { \@tempdima }
              {
                \hook_use:nnw { contentsline / number / before } { 1 } {#1}
                \hfill #1. \enspace
                \hook_use:nnw { contentsline / number / after } { 1 } {#1}
              }
          }
      }
    \socket_new_plug:nnn { sblbook / numberline }
      { part }
      {
        \hook_use:nnw { contentsline / number / before } { 1 } {#1}
        \InstanceValue { heading } { part } { prefix }
        \skip_horizontal:n
          {
            \InstanceValue { headformat } { part } { prefix-number-sep }
          }
        #1
        : \enspace
        \hook_use:nnw { contentsline / number / after } { 1 } {#1}
      }
    \socket_assign_plug:nn
      { sblbook / numberline } { default }
    \cs_set_nopar:Npn \numberline #1
      {
        \socket_use:n { sblbook / numberline } {#1}
      }
    \cs_set_nopar:Npn \l@part #1#2
      {
        \int_compare:nNnT { \c@tocdepth } > { -2 }
          {
            \socket_assign_plug:nn { sblbook / numberline } { part }
            \addpenalty { -\@highpenalty }
            \addvspace { 12pt plus 1pt }
            \group_begin:
              \centering
              \skip_set:Nn \leftskip  { \@pnumwidth plus 1.0fil }
              \skip_set_eq:NN \rightskip \leftskip
              {
                \mode_leave_vertical:
                \scshape
                \hook_use:nnw { contentsline / text / before } { 4 }
                  { \toclevel@part }
                  {#1}
                  {#2}
                  { \@contentsline@destination }
                \use:c { contentsline@text@-1@format } {#1}
                \hook_use:nnw { contentsline / text / after } { 4 }
                  { \toclevel@part }
                  {#1}
                  {#2}
                  { \@contentsline@destination }
                \hook_use:nnw { contentsline / page / before } { 4 }
                  { \toclevel@part }
                  {#1}
                  {#2}
                  { \@contentsline@destination }
                \hook_use:nnw { contentsline / page / after } { 4 }
                  { \toclevel@part }
                  {#1}
                  {#2}
                  { \@contentsline@destination }
              }
              \par
              \nobreak
            \group_end:
          }
      }
    \cs_set_nopar:Npn \l@chapter
      {
        \socket_assign_plug:nn { sblbook / numberline } { chapter }
        \@dottedtocline { 0 } { 0em } { 2em }
      }
    \cs_set_nopar:Npn \l@section
      {
        \socket_assign_plug:nn { sblbook / numberline } { default }
        \@dottedtocline { 1 } { 2em } { 0em }
      }
    \cs_set_nopar:Npn \l@subsection
      {
        \socket_assign_plug:nn { sblbook / numberline } { default }
        \@dottedtocline { 2 } { 4em } { 0em }
      }
    \cs_set_nopar:Npn \l@subsubsection
      {
        \socket_assign_plug:nn { sblbook / numberline } { default }
        \@dottedtocline { 3 } { 6em } { 0em }
      }
    \cs_set_nopar:Npn \l@paragraph
      {
        \socket_assign_plug:nn { sblbook / numberline } { default }
        \@dottedtocline { 4 } { 8em } { 0em }
      }
    \cs_set_nopar:Npn \l@subparagraph
      {
        \socket_assign_plug:nn { sblbook / numberline } { default }
        \@dottedtocline { 5 } { 10em } { 0em }
      }
    \cs_set_nopar:Npn \l@figure
      {
        \socket_assign_plug:nn { sblbook / numberline } { boxed }
        \@dottedtocline { 0 } { 0em } { 2em }
      }
    \cs_set_eq:NN \l@table \l@figure
  }
  {
    \RequirePackage { titletoc }
    \contentsmargin { 2em }
    \cs_new_protected:Nn \__sblbook_hyperlink:nn
      {
        \cs_if_exist_use:NTF \hyperlink
          { { #1 } { #2 } }
          { #2 }
      }
    \cs_new_protected:Nn \__sblbook_contents_label_box:nn
      {
        \__sblbook_hyperlink:nn
          { \Hy@tocdestname }
          {
            \makebox [ #1 ] [ #2 ] { \thecontentslabel . \enspace }
          }
      }
    \cs_new_protected:Nn \__sblbook_contents_label:
      {
        \__sblbook_hyperlink:nn
          { \Hy@tocdestname }
          { \thecontentslabel . \enspace }
      }
    \cs_new_protected:Nn \__sblbook_contents_above:n
      {
        \hspace* { -#1 }
        \filright
      }
    \titlecontents { figure }
      [ 2em ]
      {
        \__sblbook_contents_above:n { 2em }
      }
      {
        \__sblbook_contents_label_box:nn { 2em } { r }
      }
      { }
      { \hspace { 0.5em } \titlerule* [ 0.65pc ] { . } \contentspage }
    \titlecontents { table }
      [ 2em ]
      {
        \__sblbook_contents_above:n { 2em }
      }
      {
        \__sblbook_contents_label_box:nn { 2em } { r }
      }
      { }
      { \hspace { 0.5em } \titlerule* [ 0.65pc ] { . } \contentspage }
    \titlecontents { part }
      [ 0pt ]
      {
        \addvspace { 12pt plus 1pt }
        \scshape \filcenter
        \skip_set:Nn \leftskip { \@pnumwidth plus 1.0fil }
        \skip_set_eq:NN \rightskip \leftskip
      }
      {
        \__sblbook_hyperlink:nn
          { \Hy@tocdestname }
          {
            \partname \space \thecontentslabel : \hspace { 0.5em }
          }
      }
      { }
      { }
    \titlecontents { chapter }
      [ 2em ]
      {
        \tl_if_empty:NF \thecontentslabel
          {
            \addvspace { 12pt plus 1pt }
          }
        \__sblbook_contents_above:n { 2em }
      }
      {
        \__sblbook_contents_label_box:nn { 2em } { r }
      }
      { }
      { \hspace { 0.5em } \titlerule* [ 0.65pc ] { . } \contentspage }
    \titlecontents { section }
      [ 2em ]
      {
        \__sblbook_contents_above:n { 1sp }
      }
      { \__sblbook_contents_label: }
      { }
      { \hfill \contentspage }
    \titlecontents { subsection }
      [ 4em ]
      {
        \__sblbook_contents_above:n { 1sp }
      }
      { \__sblbook_contents_label: }
      { }
      { \hfill \contentspage }
    \titlecontents { subsubsection }
      [ 6em ]
      {
        \__sblbook_contents_above:n { 1sp }
      }
      { \__sblbook_contents_label: }
      { }
      { \hfill \contentspage }
    \titlecontents { paragraph }
      [ 8em ]
      {
        \__sblbook_contents_above:n { 1sp }
      }
      { \__sblbook_contents_label: }
      { }
      { \hfill \contentspage }
    \titlecontents { subparagraph }
      [ 10em ]
      {
        \__sblbook_contents_above:n { 1sp }
      }
      { \__sblbook_contents_label: }
      { }
      { \hfill \contentspage }
  }
\hook_gput_code:nnn
  { cmd / backmatter / after }
  { sblbook }
  {
    \int_compare:nNnF { \int_use:N \sblbook@appendices } = { \c_zero_int }
      {
        \addtocontents { toc } { \addvspace { 12pt ~ plus ~ 1pt } }
      }
  }
\cs_set_eq:NN \sblbook@hyperlink \__sblbook_hyperlink:nn
\int_new:N \sblbook@appendices
\int_new:N \sblbook@appendix@state
\hook_gput_code:nnn { enddocument / afterlastpage } { sblbook }
  {
    \protected@write \@auxout
      { }
      {
        \exp_not:N \global
        \exp_not:N \sblbook@appendix@state
        \int_use:N \sblbook@appendix@state
      }
  }
\cs_new_protected:Nn \__sblbook_set_up_appendices:
  {
    \addtocontents { toc } { \sblbook@appendices 1 }
    \addtocontents { toc } { \addvspace { 12pt ~ plus ~ 1pt } }
    \int_compare:nNnT { \sblbook@appendix@state } = { 1 }
      { \int_gzero:N \sblbook@appendix@state }
    \cs_set_nopar:Npn \thechapter { \arabic { chapter } }
    \IfDocumentMetadataTF
      {
        \addtocontents { toc }
          { \def \protect \chaptername { \appendixname } }
        \cs_new:Nn \__sblbook_appendix_number_format:n
          {
            \int_compare:nNnT
              { \sblbook@appendix@state } > { 1 }
              { \theheading }
          }
        \cs_new:Nn \__sblbook_appendix_prefix_number_sep:
          {
            \int_compare:nNnTF
              { \sblbook@appendix@state } > { 1 }
              { 0.5em }
              { 0em }
          }
        \EditInstance { heading } { chapter }
          {
            , number-format = \__sblbook_appendix_number_format:n
            , prefix        = \appendixname
          }
        \EditInstance { headformat } { chapter }
          {
            , prefix-number-sep = \__sblbook_appendix_prefix_number_sep:
          }
        \DeclareDocumentCommand \chapter { s = { shorttitle } o m }
          {
            \legacy_if:nTF { @mainmatter }
              {
                \bool_if:nF {##1}
                  {
                    \int_compare:nNnT { \sblbook@appendix@state } < { 2 }
                      { \int_gincr:N \sblbook@appendix@state }
                  }
                \ParseLaTeXeHeading { chapter } {##1} {##2} {##3}
              }
              {
                \bool_if:nTF {##1}
                  {
                    \ParseLaTeXeHeading { chapter } {##1} {##2} {##3}
                  }
                  {
                    \tl_if_novalue:nTF {##2}
                      {
                        \ParseLaTeXeHeading { chapter } { \c_true_bool }
                          { shorttitle = {##3} } {##3}
                      }
                      {
                        \ParseLaTeXeHeading { chapter } { \c_true_bool }
                          {##2} {##3}
                      }
                  }
              }
          }
      }
      {
        \titleformat
          { \chapter }
          [ display ]
          {
            \normalfont \Large \filcenter
          }
          {
            \int_compare:nNnT { \sblbook@appendix@state } < { 2 }
              { \int_gincr:N \sblbook@appendix@state }
            \appendixname
            \int_compare:nNnT { \sblbook@appendix@state } > { 1 }
              {
                \space \thechapter
              }
          }
          { 12pt }
          { }
        \titlecontents { chapter }
          [ 2em ]
          {
            \hspace* { -2em }
            \filright
          }
          {
            \sblbook@hyperlink
              { \Hy@tocdestname }
              {
                \appendixname
                \ifnum \sblbook@appendix@state > 1
                  \strut \space \thecontentslabel
                \fi
                : \enspace
              }
          }
          { }
          { \hspace { 0.5em } \titlerule* [ 0.65pc ] { . } \contentspage }
      }
  }
\hook_gput_code:nnn
  { cmd / appendix / after }
  { sblbook }
  { \__sblbook_set_up_appendices: }
\cs_set_nopar:Npn \bibfont { \small }
\dim_set:Nn \bibhang { 0.25in }
\dim_set:Nn \biblabelsep { 0.25in }
\prg_new_protected_conditional:Npnn \__sblbook_if_page_numbering:n #1 { T }
  {
    \cs_set_nopar:Nn \__sblbook_thepage_test:
      { \csname @ #1 \endcsname \c@page }
    \if_meaning:w \thepage \__sblbook_thepage_test:
      \prg_return_true:
    \else:
      \prg_return_false:
    \fi:
  }
%% 
%%
%% End of file `sblbook.cls'.
