% \iffalse meta-comment
%
%% File: latex-lab-titlesec.dtx (C) Copyright 2021-2026 LaTeX Project
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version.  The latest version
% of this license is in the file
%
%    https://www.latex-project.org/lppl.txt
%
\def\ltlabtitlesecdate{2026-10-18}
\def\ltlabtitlesecversion{0.6b}

%<*driver>
\DocumentMetadata{tagging=on,pdfstandard=ua-2}
\documentclass[kernel]{l3in2edoc}

\tagpdfsetup {math/mathml/luamml/load=false}

\usepackage{xltabular,longtable,tikz}
\EnableCrossrefs
\CodelineIndex

\usepackage{todonotes}

\begin{document}
  \DocInput{latex-lab-titlesec.dtx}
\end{document}
%</driver>
%
% \fi
%
%
% \title{The \textsf{latex-lab-titlesec} package\\
% Emulating titlesec}
% \author{\LaTeX{} Project\thanks{Initial implementation done by Frank Mittelbach}}
% \date{v\ltlabtitlesecversion\ \ltlabtitlesecdate}
%
% \maketitle
%
% \newcommand{\xt}[1]{\textsl{\textsf{#1}}}
% \newcommand{\TODO}[1]{\textbf{[TODO:} #1\textbf{]}}
% \newcommand{\docclass}{document class \marginpar{\raggedright document class
% customizations}}
%
% \newcommand\insttype[1]{\texttt{#1}}
%
%
% \providecommand\hook[1]{\texttt{#1}}
% \providecommand\option[1]{\texttt{#1}}
% \providecommand\key[1]{\texttt{#1}}
%
% \ProvideDocumentCommand\fmi{sO{}m}
%   {\IfBooleanTF{#1}{\todo[inline,#2]{#3}}^^A
%                    {\todo[#2]{#3}}}
%
%
% \begin{abstract}
%
%    The \pkg{titlesec} package is incomatible with the new tagging
%    code and if it is used together with \cs{DocumentMetadata} (with
%    or without tagging turned on) it will generate a number of
%    warnings followed by package errors---in other words the
%    combination is not usable.
%
%    The following code implements an emulation of \pkg{titlesec}
%    usable with the tagging support code. For now only some of the
%    package interfaces are supported and all others will bail out
%    with a suitable error message.

%    If \cs{DocumentMetadata} is used and \pkg{titlesec} is
%    requested then the emulation is loaded instead.
%    As long as the emulation is still being worked on the emulation
%    is also available under the name \pkg{latex-lab-titlesec}.
% \end{abstract}
%
%
% \section{Introduction}
%
%    The \pkg{titlesec} package offers customizable heading commands
%    but is not compatible with the tagging support code where headings are
%    reimplemented with templates.
%
%    The following code partly emulates \pkg{titlesec}; missing
%    functionality will be added near future.
%
%  \section{Package options}
%
%    The \pkg{titlesec} package has a number of package options that
%    implement basic layout choices across all headings. They are
%    listed in table~\ref{tab:options}. A few are no longer relevant
%    as the functionality is already available in core \LaTeX{}. The
%    others are emulated.
%
%  \begin{xltabular}{\linewidth}{>{\ttfamily}lcX}
%  \caption[]{List of titlesec package options}\\
%  \multicolumn{1}{c}{\pkg{titlesec} option} & supported & comments\\\hline\endhead
%    rm\label{tab:options} & yes & \\
%    sf & yes & \\
%    tt & yes & \\
%    md & yes & \\
%    bf & yes & \\
%    up & yes & \\
%    it & yes & \\
%    sl & yes & \\
%    sc & yes & \\
% \hline
%    big         & yes & \\
%    medium      & yes & \\
%    small       & yes & \\
%    tiny        & yes & \\
% \hline
%    raggedleft  & yes & \\
%    center      & yes & \\
%    raggedright & yes & \\
% \hline
%    compact     & yes & \\
% \hline
%    uppercase   & yes & \\
% \hline
%    indentafter   & yes & relationship with \cs{titlespacing} needs verification\\
%    noindentafter & yes & \\
% \hline
%    rigidchapters   & & needs extra support in all templates first \\
%    rubberchapters  & yes &  \LaTeX{}'s default \\
% \hline
%    bottomtitles    & yes & \\
%    nobottomtitles  & & needs extra support in all templates first \\
%    nobottomtitles* & & needs extra support in all templates first \\
% \hline
%    innermarks  & yes & \\
%    outermarks  & & needs extra support in all templates first \\
%    topmarks    & & needs extra support in all templates first \\
%    extramarks  & n/a & \LaTeX's mark mechanism offers this directly \\
% \hline
%    nopatches   & n/a & no longer useful; silently accepted \\
% \hline
%    aftersep   & yes & default behavior \\
%    largestsep &     & needs extra support in \cs{__sec_vertical_before_spacing:} \\
% \hline
%    pageatnewline & no & strange legacy option, ignored \\
% \hline
%    nostruts   &     & needs extra support in all templates first\\
% \hline
%    calcwidth  &     & needs extra support in all templates first\\
% \hline
%    explicit & & to be implemented as part of \cs{titleformat}\\
%    newparttoc & n/a & default behavior, silently accepted \\
%    oldparttoc & no & ignored with a warning\\
% \hline
%    clearempty & yes & \\
% \hline
%    toctitles  & yes & \\
% \hline
%    notocpart* & n/a & automatically applied; mechanism is different
%                       these days \\
% \hline
%    loadonly  & n/a & no longer useful; silently accepted \\
% \hline
%  \end{xltabular}
%
%
%
%
%
%
%  \section{Commands}
%
%    The list of support commands offered by \pkg{titlesec} is given in
%    table~\ref{tab:cmds}. We expect to emulate all of them eventually.
%
%  \begin{longtable}{lll}
%  \caption{List of titlesec user commands}\\
%  name & emulated & comment\\\hline\endhead
%  \cs{titlelabel}\label{tab:cmds} & & \\
% \hline
%  \cs{titleformat} & & \\
%  \cs{titleformat*} & & \\
%  \cs{chaptertitlename} & yes & \\
%  \cs{titlespacing} & & \\
%  \cs{titlespacing*} & & \\
% \hline
%  \cs{filright}  & yes &  use cases need checking \\
%  \cs{filcenter} & yes &  use cases need checking \\
%  \cs{filleft}   & yes &  use cases need checking \\
%  \cs{fillast}   & yes &  use cases need checking \\
%  \cs{filinner}  & yes &  use cases need checking \\
%  \cs{filouter}  & yes &  use cases need checking \\
% \hline
%  \cs{wordsep}   & yes & \\
% \hline
%  \cs{bottomtitlespace} & yes & but not yet used\\
% \hline
%  \cs{nostruts}   & & \\
% \hline
%  \cs{titleline}  & & \\
%  \cs{titlerule}  & & \\
%  \cs{titlerule*} & & \\
% \hline
%  \cs{iftitlemeasuring} & & \\
% \hline
%  \cs{titleline*} & & \\
% \hline
%  \end{longtable}
%
%
%
%
%
% ^^A  \section{Key emulation}
%
%
%
% \section{Implementation}
%
%
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
%    \begin{macrocode}
\ProvidesExplPackage {latex-lab-titlesec} {\ltlabtitlesecdate}
                     {\ltlabtitlesecversion}
                     {Emulating titlesec}
%    \end{macrocode}
%
%
%
%
% \subsection{Package options}
%
%
%
%    \begin{macrocode}
%<@@=ttl>
%    \end{macrocode}
%
% \subsubsection{Options for font family, series, and shape}
%
%  \begin{macro}{\l_@@_fonts_tl}
%    Font options are collected in \cs{l_@@_fonts_tl} which is then
%    used in the \key{heading-decls}.
%    \begin{macrocode}
\tl_new:N \l_@@_fonts_tl
%    \end{macrocode}
%  \end{macro}
%
%    \begin{macrocode}
\DeclareOption{rm}{
  \tl_put_right:Nn \l_@@_fonts_tl {\rmfamily} }
\DeclareOption{sf}{
  \tl_put_right:Nn \l_@@_fonts_tl {\sffamily} }
\DeclareOption{tt}{
  \tl_put_right:Nn \l_@@_fonts_tl {\ttfamily} }
\DeclareOption{md}{
  \tl_put_right:Nn \l_@@_fonts_tl {\mdseries} }
\DeclareOption{bf}{
  \tl_put_right:Nn \l_@@_fonts_tl {\bfseries} }
\DeclareOption{up}{
  \tl_put_right:Nn \l_@@_fonts_tl {\upshape} }
\DeclareOption{it}{
  \tl_put_right:Nn \l_@@_fonts_tl {\itshape} }
\DeclareOption{sl}{
  \tl_put_right:Nn \l_@@_fonts_tl {\slshape} }
\DeclareOption{sc}{
  \tl_put_right:Nn \l_@@_fonts_tl {\scshape} }
%    \end{macrocode}
%
%
%
% \subsubsection{Option for font sizes}
%
%  \begin{macro}[no-user-doc]{\ttl@sizes}
%    Macro that holds the font sizes for different heading levels. We
%    keep the original \LaTeXe{} name as used in the package just in
%    case somebody has redefined that macro in a document preamble (or
%    in a class file after loading \pkg{titlesec}.
%    \begin{macrocode}
\cs_new_protected:Npn \ttl@sizes #1 {
  \ifcase#1\relax\Huge\or\Large\or\large
  \or\normalsize\or\or\or\huge\fi
}
%    \end{macrocode}
%  \end{macro}
%
%    The package options then redefine the list.
%    \begin{macrocode}
\DeclareOption{big}{
  \cs_set_protected:Npn \ttl@sizes #1
     {\ifcase#1\relax\Huge\or\Large\or\large
       \or\normalsize\or\or\or\huge\fi}}
\DeclareOption{medium}{
  \cs_set_protected:Npn \ttl@sizes #1
     {\ifcase#1\relax\huge\or\Large\or\large
       \or\normalsize\or\or\or\LARGE\fi}}
\DeclareOption{small}{
  \cs_set_protected:Npn \ttl@sizes #1
     {\ifcase#1\relax\LARGE\or\large
       \or\normalsize\or\normalsize\or\or\or\Large\fi}}
\DeclareOption{tiny}{
  \cs_set_protected:Npn \ttl@sizes #1
     {\ifcase#1\relax\large\or\normalsize\or
       \normalsize\or\normalsize\or\or\or\normalsize\fi}}
%    \end{macrocode}
%
%
%
% \subsubsection{Option \option{compact}}
%
%
%  \begin{macro}{\g_@@_compact_bool}
%    Boolean to indicate that the \texttt{compact} option was used.
%    \begin{macrocode}
\bool_new:N \g_@@_compact_bool
%    \end{macrocode}
%  \end{macro}
%
%    \begin{macrocode}
\DeclareOption{compact}{ \bool_gset_true:N \g_@@_compact_bool }
%    \end{macrocode}
%
%
% \subsubsection{Option \option{uppercase}}
%
%
%  \begin{macro}{\@@_case:n}
%    Unprotected macro to be used in key values. There we expand and
%    thus get the value inside.
%    \begin{macrocode}
\cs_new_eq:NN \@@_case:n \use:n
%    \end{macrocode}
%  \end{macro}
%
%    Using \cs{cs_set:Npn} instead of \cs{cs_set_eq:NN} below allows
%    us to get \cs{MakeUppercase} into the key values below through a
%    one-level expansion.
%    \begin{macrocode}
\DeclareOption{uppercase}{ \cs_set:Npn \@@_case:n #1 { \MakeUppercase {#1} } }
%    \end{macrocode}
%
%
% \subsubsection{Options for shifting text}
%
%
%  \begin{macro}{\@@_fil:}
%    Unprotected macro to be used in key values. There we expand and
%    thus get the value inside.
%    \begin{macrocode}
\cs_new:Npn \@@_fil: {}
%    \end{macrocode}
%  \end{macro}
%
%    \begin{macrocode}
\DeclareOption{raggedleft} { \cs_set:Npn \@@_fil: { \filleft}   }
\DeclareOption{center}     { \cs_set:Npn \@@_fil: { \filcenter} }
\DeclareOption{raggedright}{ \cs_set:Npn \@@_fil: { \filright}  }
%    \end{macrocode}
%
%
%
%
% \subsubsection{Options for indentation after a display header}
%
%
%  \begin{macro}{\l_@@_indentafter_tl}
%
%    \begin{macrocode}
\tl_new:N  \l_@@_indentafter_tl
\tl_set:Nn \l_@@_indentafter_tl {false}
%    \end{macrocode}
%  \end{macro}
%
%    \begin{macrocode}
\DeclareOption{indentafter}{
  \tl_set:Nn \l_@@_indentafter_tl {true}
  %  \gdef\@afterindentfalse{\let\if@afterindent\iftrue}%
  %  \@afterindenttrue
  %  \def\titlespacing{%
  %    \@ifstar{\ttl@spacing@i{\@ne}}{\ttl@spacing@i{\@ne}}}
}
\DeclareOption{noindentafter}{
  \tl_set:Nn \l_@@_indentafter_tl {false}
  %  \def\titlespacing{%
  %    \@ifstar{\ttl@spacing@i{\z@}}{\ttl@spacing@i{\z@}}}
}
%    \end{macrocode}
%
%
%
%
%
%
% \subsubsection{Options that are no longer useful}
%
%
%    \begin{macrocode}
\DeclareOption{pageatnewline}
    {\PackageWarning{titlesec~ emulation}{Option~ 'pageatnewline'~ ignored}}
%    \end{macrocode}
%
%    \begin{macrocode}
\DeclareOption{oldparttoc}
    {\PackageWarning{titlesec~ emulation}{Option~ 'oldparttoc'~ ignored}}
%    \end{macrocode}
%
%    \begin{macrocode}
\DeclareOption{extramarks}
    {\PackageWarning{titlesec~ emulation}{Option~ 'extramarks'~ ignored}}
%    \end{macrocode}
%
%    \begin{macrocode}
\DeclareOption{newparttoc}
    {\PackageInfo{titlesec~ emulation}{Option~ 'newparttoc'~ is~ the~ default}}
%    \end{macrocode}
%
%    \begin{macrocode}
\DeclareOption{notocpart*}
    {\PackageInfo{titlesec~ emulation}{Option~ 'notocpart*'~ is~ the~ default}}
%    \end{macrocode}
%
%    \begin{macrocode}
\DeclareOption{loadonly}
    {\PackageInfo{titlesec~ emulation}{Option~ 'loadonly~ no~ longer~ applicable}}
%    \end{macrocode}
%
%
%
%
%
% \subsubsection{Option \option{clearempty}}
%
%
%
%
%    \begin{macrocode}
\DeclareOption{clearempty}{
  \def\cleardoublepage{
    \clearpage{\ps@empty\if@twoside\ifodd\c@page\else
    \hbox{}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}}}
%    \end{macrocode}
%
%
%
% \subsubsection{Spacing between conscutive headings}
%
%
%
%
%    TODO: The option \option{largestsep} needs support in latex-lab-sec-template.
%    \begin{macrocode}
\DeclareOption{aftersep}{
  \let\ttl@titlespace\@gobble}
\DeclareOption{largestsep}{
  \let\ttl@titlespace\addvspace}
%    \end{macrocode}
%
%
%
%
% \subsubsection{Option \option{toctitles}}
%
%
%
%
%    \begin{macrocode}
\DeclareOption{toctitles} {
  \keys_define:nn {heading}
       { shorttitle .meta:n  =
         { running = {#1} , bookmark = {#1} , nameref= {#1} }
       }
}
%    \end{macrocode}
%
%
% \subsubsection{Options for setting marks}
%
% In modern \LaTeX{} kernels, the core team introduced the new native marks
% mechanism (ltmarks). This system native to the core eliminates the
% need for titleps or extramarks hacky workarounds by natively tracking
% independent mark classes (such as columns vs. pages) and fixing
% long-standing bugs where LaTeX floats could corrupt \cs{topmark}.
%
% When you use standard sectioning commands, modern LaTeX automatically
% populates two core internal mark classes:
% \begin{description}
% \item[\ttfamily 2e-left] (controlled legacy-wise via \cs{leftmark},
%   historically mapped to the higher-level section, like Chapter)
%
% \item[\ttfamily 2e-right] (controlled legacy-wise via \cs{rightmark},
%   historically mapped to the lower-level section, like Section)
% \end{description}
%
% The standard modern commands to query these are \cs{TopMark}, \cs{FirstMark},
% and \cs{LastMark}.
%
% Here is how you can directly implement the titlesec/titleps behaviors
% (innermarks, outermarks, topmarks, and botmarks) using pure modern
% LaTeX interfaces (for instance, inside a header-management package
% like fancyhdr or standard page styles).
%
%
% \paragraph{Replicating \option{innermarks} (The Standard Default)}
%
% \texttt{innermarks} uses the first section appearing on odd pages and
% the last section on even pages.
% \begin{itemize}
% \item  Even Page Layout (Left): Prints the last mark bound to the
%   current page (\cs{LastMark}).
% \item  Odd Page Layout (Right): Prints the first mark appearing on the
%   page (\cs{FirstMark}).
% \end{itemize}
%
% \begin{verbatim}
% \usepackage{fancyhdr}
% \pagestyle{fancy}
% \fancyhf{}
%
% % Even (Left) Pages: use the last top-level section
% %   (e.g. Chapter) on this page
% \fancyhead[EL]{\TopMark{2e-left}}
% \fancyhead[ER]{\LastMark{2e-right}}  % Last sub-level section
%                                      % on even page
%
% % Odd (Right) Pages: use the first sub-level section
% %   (e.g. Section) starting on this page
% \fancyhead[OL]{\FirstMark{2e-right}}
% \fancyhead[OR]{\thepage}
% \end{verbatim}
%
%
%
% \paragraph{Replicating \option{outermarks} (The Textbook Classic)}
%
%    \texttt{outermarks} flips the behavior, making even pages show
%    the section that was active at the very top of the page, and odd
%    pages show the final section.
%    \begin{itemize}
%    \item  Even Page Layout (Left): Prints the top mark inherited from the
%      previous page's state (\cs{TopMark}).
%    \item  Odd Page Layout (Right): Prints the last mark on the page
%      (\cs{LastMark}).
%    \end{itemize}
%
% \begin{verbatim}
% % Even Pages: Show the section title current at the VERY TOP of the page
% \fancyhead[EL]{\TopMark{2e-left}}
% \fancyhead[ER]{\TopMark{2e-right}}
%
% % Odd Pages: Show the LAST section title appearing on this page
% \fancyhead[OL]{\LastMark{2e-right}}
% \fancyhead[OR]{\thepage}
% \end{verbatim}
%
%
%
% \paragraph{Replicating \option{topmarks} (Top-of-Page Anchored)}
%
%    The \texttt{topmarks} configuration ensures both even and odd pages
%    emphasize what content is current at the immediate top of the page
%    boundary when it gets rendered.
%
% \begin{verbatim}
% % Both pages show exactly what section is current when
% % the page text begins
% \fancyhead[EL]{\TopMark{2e-left}}
% \fancyhead[OR]{\TopMark{2e-right}}
% \end{verbatim}
%
%
% \paragraph{Replicating \option{botmarks} (Bottom-of-Page Anchored)}
%
%    The botmarks option forces headers to reflect the final state of
%    section headers reached before the page breaks.
% \begin{verbatim}
% % Both pages show the last updated section content from that specific page
% \fancyhead[EL]{\LastMark{2e-left}}
% \fancyhead[OR]{\LastMark{2e-right}}
% \end{verbatim}
%
%
%    TODO: not handled yet; has to wait for support in templates.
%    \begin{macrocode}
\DeclareOption{outermarks}{
  \def\ttl@titlemarks{\outertitlemarks}}
\DeclareOption{topmarks}{
  \def\ttl@titlemarks{\toptitlemarks}}
\DeclareOption{botmarks}{
  \def\ttl@titlemarks{\bottitlemarks}}
\DeclareOption{innermarks}{
  \def\ttl@titlemarks{\innertitlemarks}}
\DeclareOption{nopatches}{\let\ttl@atbegin\relax}
%    \end{macrocode}
%
%
%
%
%
%
%    Not yet emulated \ldots
%    \begin{macrocode}
\DeclareOption{bottomtitles}{%
  \def\bottomtitlespace{-1\p@}}
\DeclareOption{nobottomtitles}{%
  \def\bottomtitlespace{.2\textheight}}
\DeclareOption{nobottomtitles*}{%
  \let\ttl@addstretch\relax
  \def\bottomtitlespace{.2\textheight}}
%    \end{macrocode}
%
%
%
%
%
%
%
%    \begin{macrocode}
%    \end{macrocode}
%
%
%
%
%
%
%
%    \begin{macrocode}
%    \end{macrocode}
%
%
%
%
%
%
%
% \subsection{Option execution and final adustments}
%
%
%    \begin{macrocode}
\ExecuteOptions{
%  rubberchapters,
  bottomtitles,      % this defines \bottomtitlespace
%  aftersep,
%  oldparttoc,
%  innermarks
}
%    \end{macrocode}
%
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
%
%    If no font options used we apply \cs{bfseries} as the default for
%    all headings:
%    \begin{macrocode}
\tl_if_empty:NT \l_@@_fonts_tl { \tl_set:Nn \l_@@_fonts_tl {\bfseries} }
%    \end{macrocode}
%
%
%
%  \begin{macro}[no-user-doc]{\beforetitleunit,\aftertitleunit}
%    Two skips that are used if the \option{compact} option is used.
%    \begin{macrocode}
\skip_new:N \beforetitleunit
\skip_new:N \aftertitleunit
%    \end{macrocode}
%
%    \begin{macrocode}
\skip_set:Nn \beforetitleunit {1ex plus .3ex minus .06ex}
\skip_set:Nn \aftertitleunit  {1ex plus .1ex}
%    \end{macrocode}
%  \end{macro}
%
%
%
%
%\subsection{Command emulation}
%
%
%
%
%  \begin{macro}[no-user-doc]{\chaptertitlename}
%
%    \begin{macrocode}
\cs_new_protected:Npn \chaptertitlename { \@chapapp }
%    \end{macrocode}
%  \end{macro}
%
%
%
%  \begin{macro}[no-user-doc]{\wordsep}
%
%    \begin{macrocode}
\cs_new_protected:Npn \wordsep {\fontdimen\tw@\font \@plus
  \fontdimen\thr@@\font \@minus \fontdimen4\font}
%    \end{macrocode}
%  \end{macro}
%
%
%
%
%  \begin{macro}[no-user-doc]{\filcenter,\filright,\filleft}
%
%    \begin{macrocode}
\cs_new_protected:Npn \filcenter { \centering   }
\cs_new_protected:Npn \filright  { \raggedright }
\cs_new_protected:Npn \filleft   { \raggedleft  }
%    \end{macrocode}
%  \end{macro}
%
%
%
%
%  \begin{macro}[no-user-doc]{\filinner,\filouter}
%
%    These two commands are incorrectly implemented in \pkg{titlesec}
%    and can produce wrong results. We can do better.
%
%    We want those to expand to the next level so no protection.
%    \begin{macrocode}
\cs_new:Npn \filinner { \IfVersoHeadingTF \filright \filleft }
\cs_new:Npn \filouter { \IfVersoHeadingTF \filleft \filright }
%    \end{macrocode}
%  \end{macro}
%
%
%
% \DescribeMacro\titleformat
%
% The \cs{titleformat} declaration has the following syntax:
% \begin{verbatim}
%  \titleformat{cmd}[shape]{format}{label}{sep}{before-code}[after-code]
% \end{verbatim}
%
% \noindent
% \DescribeMacro\titlespacing
%
% The \cs{titlespacing} declaration has the following syntax:
% \begin{verbatim}
%  \titlespacing*{cmd}{left-sep}{before-vspace}{after-vspace}[right-sep]
% \end{verbatim}
%
%
%    All commands that do not have an emulation yet simply raise an
%    error (we try to pick up the arguments that follow but that may
%    not always work).
%    \begin{macrocode}
\newcommand\csnotyetprovided[1]{
  \PackageError{titlesec~ emulation}{Command~ \noexpand#1 not~ yet~ emulated}
  {The~ titlesec~ emulation~ is~ not~ yet~ complete~ and~ this~
    command~ can't
    \MessageBreak
    be~ used~ in~ documents~ using~ \string\DocumentMetadata.~ \@eha}
}
%    \end{macrocode}
%
%    \begin{macrocode}
\DeclareDocumentCommand\titleformat {smommmmo}{ \csnotyetprovided \titleformat }
\DeclareDocumentCommand\titlespacing{smmmmo}  { \csnotyetprovided \titlespacing }
\DeclareDocumentCommand\titlelabel  {som}     { \csnotyetprovided \titlelabel }
\DeclareDocumentCommand\nostruts    {}        { \csnotyetprovided \nostruts }
\DeclareDocumentCommand\titleline   {som}     { \csnotyetprovided \titleline }
%    \end{macrocode}
%
%    \begin{macrocode}
\DeclareDocumentCommand\titlerule{so}
                       { \IfBooleanTF #1 \titleruleleaders \titlerulenormal }
\DeclareDocumentCommand\titleruleleaders{m} { \csnotyetprovided \titlerule }
\DeclareDocumentCommand\titlerulenormal {}  { \csnotyetprovided \titlerule }
%    \end{macrocode}
%
%    \begin{macrocode}
\newcommand \iftitlemeasuring { \csnotyetprovided \iftitlemeasuring \@secondoftwo}
%    \end{macrocode}
%
%
%
%
%\subsection{Instance adjustments based on options}
%
%
%
%    \begin{macrocode}
\IfInstanceExistsT{heading}{chapter}{
  \EditInstance{heading}{chapter}    {
%    \end{macrocode}
%    We expand as much as reasonably possible to make the key values
%    look nice in \cs{ShowInstanceValues}, e.g., instead of
%    \cs{l_@@_fonts_tl} we then get something like
%    \cs{sffamily}\cs{bfseries}.
%    \begin{macrocode}
       heading-decls:e = \exp_not:o \l_@@_fonts_tl
                         \exp_not:n {\setlength\parindent{0pt}}
                         \@@_fil:
                         \exp_not:N \ttl@sizes{6}
     , title-decls     = \ttl@sizes{0} ,
     , title-format:o  = \@@_case:n {#1}
     , para-indent:o   = \l_@@_indentafter_tl
  }
  \EditInstance{headformat}{chapter} {
      separator-b = \par \nobreak \vspace {.8\baselineskip}
  }
}
%    \end{macrocode}
%
%    \begin{macrocode}
\EditInstance{heading}{section}
{
   heading-decls:e = \exp_not:o \l_@@_fonts_tl
                     \@@_fil:
                     \exp_not:N \ttl@sizes{1}
  , title-format:o  = \@@_case:n {#1}
  , para-indent:o   = \l_@@_indentafter_tl
}
\EditInstance{heading}{subsection}
{
    heading-decls:e = \exp_not:o \l_@@_fonts_tl
                      \@@_fil:
                      \exp_not:N \ttl@sizes{2}
  , title-format:o  = \@@_case:n {#1}
  , para-indent:o   = \l_@@_indentafter_tl
}
\EditInstance{heading}{subsubsection}
{
    heading-decls:e = \exp_not:o \l_@@_fonts_tl
                      \@@_fil:
                      \exp_not:N \ttl@sizes{3}
  , title-format:o  = \@@_case:n {#1}
  , para-indent:o   = \l_@@_indentafter_tl
}
\EditInstance{heading}{paragraph}
{
    heading-decls:e = \exp_not:o \l_@@_fonts_tl
                      \exp_not:N
                      \ttl@sizes{4}
  , title-format:o  = \@@_case:n {#1}
}
\EditInstance{heading}{subparagraph}
{
    heading-decls:e = \exp_not:o \l_@@_fonts_tl
                      \exp_not:N \ttl@sizes{5}
  , title-format:o  = \@@_case:n {#1}
}
%    \end{macrocode}
%
%    We do the setting for option \texttt{compact} separately:
%    \begin{macrocode}
\bool_if:NT \g_@@_compact_bool {
  \IfInstanceExistsT{heading}{chapter}{
    \EditInstance{heading}{chapter} { after-vspace = 30pt }
  }
  \EditInstance{heading}{section}
     { before-vspace = \beforetitleunit , after-vspace = \aftertitleunit }
  \EditInstance{heading}{subsection}
     { before-vspace = \beforetitleunit , after-vspace = \aftertitleunit }
  \EditInstance{heading}{subsubsection}
     { before-vspace = \beforetitleunit , after-vspace = \aftertitleunit }
%    \end{macrocode}
%
%    \begin{macrocode}
  \EditInstance{heading}{paragraph}    { before-vspace = \beforetitleunit }
  \EditInstance{heading}{subparagraph} { before-vspace = \beforetitleunit }
}

%    \end{macrocode}
%
%
%
%
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}


\endinput




%------------------------------------ for later use

%    \begin{macrocode}
\cs_new:Npn \skip_multiply:nn #1#2{
  \tex_glueexpr:D
    #1 \tex_glueexpr:D #2 \scan_stop:
  plus
    \dim_to_decimal:n
      { #1 \tex_gluestretch:D \tex_glueexpr:D #2 \scan_stop: }
    \if_case:w
      \tex_gluestretchorder:D \tex_glueexpr:D #2 \scan_stop:
      pt  \or:  fil  \or:  fill  \or: filll
    \fi:
  minus
    \dim_to_decimal:n
      { #1 \tex_glueshrink:D \tex_glueexpr:D #2 \scan_stop: }
    \if_case:w
       \tex_glueshrinkorder:D \tex_glueexpr:D #2 \scan_stop:
      pt  \or:  fil  \or:  fill  \or: filll
    \fi:
  \scan_stop:
}
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_new_protected:Npn \skip_mult:Nn #1#2 {
  #1 = \skip_multiply:nn {#2} #1
}
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_new_protected:Npn \skip_gmult:Nn #1#2 {
  \tex_global:D #1 = \skip_multiply:nn {#2} #1
}
%    \end{macrocode}
%
%
%
