% \iffalse meta-comment
%<*internal>
\begingroup
%</internal>
%<*install>
\input{l3docstrip.tex}
\keepsilent
\askforoverwritefalse
\preamble
-------------------------------------------------------------------------------
Template for the journal Philosophy and the Mind Sciences

Copyright (c) 2026 Ruhr-Universität Bochum

This file 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 available at:
http://www.latex-project.org/lppl.txt
-------------------------------------------------------------------------------
\endpreamble
\generate{\file{\jobname.cls}{\from{\jobname.dtx}{class}}}
%</install>
%<install>\endbatchfile
%<*internal>
\generate{\file{\jobname.ins}{\from{\jobname.dtx}{install}}}
\endgroup
%</internal>
%<*driver>
\documentclass{l3doc}
\usepackage{metalogo}
\usepackage{tgheros}
\usepackage[zerostyle=d]{newtxtt}
\let\familydefault\sfdefault
\hypersetup{linkcolor=blue,citecolor=blue,urlcolor=blue}
\usepackage[british]{babel}
\usepackage{biblatex}
\usepackage{booktabs}
\usepackage{multicol}
\usepackage{xcolor}
\usepackage{pifont}
\usepackage{parskip}
\definecolor{PhiMiSciHeadingBlue}{RGB}{10, 26, 97}
\definecolor{PhiMiSciBlueTwo}{RGB}{19, 47, 178}
\definecolor{PhiMiSciBlueThree}{RGB}{12, 30, 115}
\definecolor{PhiMiSciGrey}{RGB}{157, 164, 196}
\begin{filecontents}[overwrite]{\jobname.bib}
@book{Talbot2015,
    author = {Talbot, Nicola L. C.},
    year = {2015},
    title = {{LaTeX} for Administrative Work},
    publisher = {Dickimaw Books},
    url = {https://www.dickimaw-books.com/latex/admin}
}
@misc{Interface3,
    author = {{The \LaTeX{} Project}},
    year = {2023},
    url = {https://ctan.org/pkg/l3kernel},
    title = {The \LaTeX3 Interfaces},
    note = {Version 2023-06-30},
}
@misc{lthooks,
    author = {Frank Mittelbach},
    year = {2022},
    title = {\LaTeX's hook management},
    url = {https://www.latex-project.org/help/documentation/lthooks-doc.pdf},
    note = {Version 2022-05-19}
}
@misc{ltpara,
    author = {Frank Mittelbach},
    year = {2022},
    title = {The \texttt{ltpara.dtx} code},
    url = {https://www.latex-project.org/help/documentation/ltpara-doc.pdf},
    note = {Version 2022-05-13}
}
@misc{scrguide,
    author = {Markus Kohm},
    title = {{KOMA-Script}: {The} guide},
    year = {2023},
    note = {Version 2023-06-16},
    url = {https://texdoc.org/serve/scrartcl/0}
}
@article{Chernoff2022,
    author = {Max Chernoff},
    year = {2022},
    doi = {10.47397/tb/43-1/tb133chernoff-widows},
    title = {Automatically removing widows and orphans with lua-widow-control},
    journal = {TUGboat},
    volume = {43}, 
    number = {1},
    pages = {28-39}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
% \title{Technical documentation of the \texttt{phimisci} class}
% \author{Felix Kopecky}
% \date{20 March 2026}
% \maketitle
% \texttt{phimisci} is the document class for \emph{Philosophy and the Mind 
% Sciences} (PhiMiSci), a diamond open access journal in philosophy, 
% neuroscience and related disciplines.
% 
% This technical documentation covers the entire source code of \texttt{phimisci}. 
% A quick reference sheet is available separately. Submission guidelines can be
% found on the journal's web site, at \url{https://philosophymindscience.org/}.
%
% Issues should be reported to the editorial staff or on GitHub at 
% \url{https://github.com/phimisci/latex}.
% {\setlength{\parskip}{0pt}
% \tableofcontents}
% \section{Basic set-up}
% \subsection{Prerequisites}
% A \LaTeX{} installation from 2022 or newer is required. Additionally, the 
% following packages need to be installed:
%
% \begin{multicols}{4}
% \begin{itemize}
% \item \pkg{amsmath}
% \item \pkg{amsthm}
% \item \pkg{amssymb}
% \item \pkg{array}
% \item \pkg{babel}
% \item \pkg{biblatex}
% \item \pkg{booktabs}
% \item \pkg{csquotes}
% \item \pkg{enumitem}
% \item \pkg{etoolbox}
% \item \pkg{geometry}
% \item \pkg{fontspec}
% \item \pkg{graphicx}
% \item \pkg{hyperref}
% \item \pkg{hyphenat}
% \item \pkg{koma-script}
% \item \pkg{l3kernel}
% \item \pkg{l3packages}
% \item \pkg{libertinus}
% \item \pkg{lineno}
% \item \pkg{lua-widow-control}
% \item \pkg{microtype}
% \item \pkg{noto}
% \item \pkg{orcidlink}
% \item \pkg{xcolor}
% \item \pkg{xparse}
% \end{itemize}
% \end{multicols}
%
% \noindent Documents in the \texttt{phimisci} class can be compiled with 
% \LuaLaTeX{} and \XeLaTeX{}.
% \pagebreak
% \subsection{Class identification}
% Start by identifying the document class.
%    \begin{macrocode}
%<*class>
\NeedsTeXFormat {LaTeX2e} 
\ProvidesExplClass {phimisci} {2026-03-20} {1.0.4}  
                   {Philosophy and the Mind Sciences Journal Template}
%    \end{macrocode}
% \subsection{Messages, errors and warnings}
% These pre-defined messages are used at various points in the class.
% \begin{variable}{missing-logo-url}
% A message that warns the user in case the logo file cannot be found.
%    \begin{macrocode}
\msg_new:nnnn { phimisci } { missing-logo-url } 
              { I~didn't~find~a~logo~file~to~print~in~the~article's~header. }
              {
                Please~supply~the~file~location~with~the~document~class~
                option~'settings/logo-url~=~path/to/file.pdf'.
              }
%    \end{macrocode}
% \end{variable}
% \begin{variable}{missing-font}
% A message that warns the user about a missing font or font file.
%    \begin{macrocode}
\msg_new:nnnn { phimisci } { missing-font } 
              { A~font~could~not~be~found. } 
              {  
                Neither~the~file~"#1"~nor~a~system-installed~font~named~
                "#2"~could~be~found.~Please~install~the~font~(file)~or~
                adjust~your~font~settings.~
                For~now,~I'm~defaulting~to~the~default~sans~font.
              }
%    \end{macrocode}
% \end{variable}
% \begin{variable}{tex-installation-too-old}
% Inform the user that their \TeX\ installation is too old.
%    \begin{macrocode}
\msg_new:nnn {phimisci} { tex-installation-too-old }
             { 
               The~phimisci~class~requires~a~TeX~installation~from~2022~or~
               newer.~Please~update~your~TeX~installation.
             }
%    \end{macrocode}
% \end{variable}
% \begin{variable}{wrong-tex-engine}
% Inform the user that they have selected an unsupported \TeX\ engine.
%    \begin{macrocode}
\msg_new:nnn { phimisci } { wrong-tex-engine } 
             { 
               You~are~using~the~\str_use:N \c_sys_engine_str~engine,~but~
               your~document~can~only~be~compiled~with~the~#1~engine(s).
             }
%    \end{macrocode}
% \end{variable}
% \subsection{Version and engine checks}
% Perform a check whether the used \LaTeX\ installation is recent enough. If
% not, exit immediately and give user feedback.
%    \begin{macrocode}
\RequirePackage{xparse}
\@ifpackagelater {xparse} {2022/01/01}
  {}
  {
    \msg_fatal:nn { phimisci } { tex-installation-too-old }
  }
%    \end{macrocode}
% Check whether an appropriate engines is used and exit immediately if not.
%    \begin{macrocode}
\sys_if_engine_xetex:F
  {
    \sys_if_engine_luatex:F
      {
        \msg_fatal:nnn { phimisci } { wrong-tex-engine }
                       { lualatex~or~xelatex }
      }
  }
%    \end{macrocode}
% \subsection{Class inheritance}
% This class is based on Markus Kohm's \texttt{scrartcl} class. We load 
% this class with apropriate settings. We also load 
% \texttt{scrlayer-scrpage} for better controls of headers and 
% \texttt{scrlayer-notecolumn} for the paragraph counting feature.
%    \begin{macrocode}
\LoadClass [fontsize=10.5bp, oneside] {scrartcl}
\RequirePackage[autoenlargeheadfoot=off]{scrlayer-scrpage}
\RequirePackage{scrlayer-notecolumn}
%    \end{macrocode}
% The option \texttt{onpsinit} from \texttt{scrartcl} allows us to detect 
% paragraphs in the header and footer of the document. We use this anchor to 
% call \cs{PhiMiSci@DetectKomaHeader} (see Section~\ref{sec:parnumbering} 
% below).
%    \begin{macrocode}
\KOMAoption{onpsinit}{\protect\PhiMiSci@DetectKomaHeader{}}
%    \end{macrocode}
% \subsection{Basic packages}
% We load well-known packages that are used regularly in the preparation of 
% scientific texts.
%    \begin{macrocode}
\RequirePackage{amsmath, amsthm, amssymb, array, booktabs,
                csquotes, enumitem, graphicx, hyphenat}
%    \end{macrocode}
% We also load helper packages that are necessary to program features of this
% class. \texttt{hyperref} and \texttt{xcolor} are special in this regard, 
% because some of their options have to be loaded at initial package loading.
%    \begin{macrocode}
\RequirePackage[final, hyperfootnotes=false, pdfusetitle=true]{hyperref}
\RequirePackage[table]{xcolor}
\RequirePackage{etoolbox, expl3, l3keys2e, microtype, orcidlink}
%    \end{macrocode}
% \subsection{Data storage, Boolean switches and command variants}
% These Booleans, control sequences, integer variables, mappings, sequences and
% token lists are used by the class internally to organise data, make 
% decisions, and enable features of the class. They are only defined here but
% not documented individually -- please refer to their usage within other 
% functions.
%    \begin{macrocode}
\ExplSyntaxOn
\bool_new:N \l__phimisci_output_keywords_bool
\bool_new:N \l__phimisci_output_abstract_bool
\bool_new:N \l__phimisci_output_contact_bool
\bool_new:N \l__phimisci_output_rights_bool
\bool_new:N \l__phimisci_output_doi_bool
\bool_new:N \l__phimisci_output_authors_bool
\bool_new:N \l__phimisci_output_publication_header_footer_bool
\bool_new:N \l__phimisci_output_draft_footer_bool
\bool_new:N \l__phimisci_koma_head_mode_bool
\bool_new:N \l__phimisci_settings_sloppybottom_bool
\bool_new:N \l__phimisci_settings_luawidow_bool
\cs_new:Nn \__phimisci_affiliation_line_separator: { \thickspace }
\cs_new:Nn \__phimisci_affiliation_name_separator: { \thinspace }
\cs_generate_variant:Nn \seq_set_split:Nnn { NVn }
\cs_generate_variant:Nn \seq_set_split:Nnn { NVx }
\cs_generate_variant:Nn \int_set:Nn { Nx }
\cs_generate_variant:Nn \tl_rescan:nn { nx }
\int_new:N \l__phimisci_abstract_length_int
\int_new:N \l__phimisci_output_authors_int
\iow_new:N \l__phimisci_citation_file_stream
\prop_new:N \l__phimisci_authors_to_ids_prop
\prop_new:N \l__phimisci_author_ids_to_affiliations_prop
\prop_new:N \l__phimisci_author_ids_to_orcids_prop
\prop_new:N \l__phimisci_affiliation_id_resolver_prop
\seq_new:N \l__phimisci_keywords_seq
\seq_new:N \l__phimisci_authors_seq
\tl_const:Nn \l__phimisci_parnum_excluded_objects_base_tl
  {
    env/quote, env/quotation, env/itemize, env/enumerate, env/description, 
    env/list, env/table, env/figure, env/tabbing, env/lstlisting, 
    env/verbatim
  }
\tl_new:N \l_phimisci_header_authors_tl
\tl_new:N \l_phimisci_authors_tl
\tl_new:N \l__phimisci_authors_citation_footer_tl
\tl_new:N \l__phimisci_custom_header_authors_tl
\tl_new:N \l__phimisci_keywords_tl
\tl_new:N \l__phimisci_dedication_tl
\tl_new:N \l__phimisci_copyright_holder_tl
\tl_new:N \l__phimisci_contact_tl
\tl_new:N \l__phimisci_contact_author_tl
\tl_new:N \l__phimisci_tmp_orcid_link_tl
\ExplSyntaxOff
%    \end{macrocode}

% \subsection{Font loading}
% \textit{Philosophy and the Mind Sciences} uses Libertinus as its bread and
% butter type, which we load through the \LaTeX\ package \texttt{libertinus}.
% PhiMiSci uses Noto as its sans font, which we load as \texttt{noto-sans}.
%    \begin{macrocode}
\RequirePackage[semibold]{libertinus}
\RequirePackage[regular, semibold]{noto-sans}
%    \end{macrocode}
% Titles and section heads use Noto Sans Display, which was not distributed
% on CTAN when we created this class. The font is loaded additionally via 
% fontspec.
%    \begin{macrocode}
\RequirePackage{fontspec}
\ExplSyntaxOn
\IfFontExistsTF { NotoSansDisplay-Regular.ttf }
  {
    \newfontfamily \PhiMiSciTitleFont 
      { NotoSansDisplay-Regular.ttf }
      [ Ligatures = TeX,
        BoldFont = NotoSansDisplay-SemiBold.ttf,
        ItalicFont = NotoSansDisplay-SemiBoldItalic.ttf,
        BoldItalicFont = NotoSansDisplay-SemiBoldItalic.ttf ]
  }
  {
    \IfFontExistsTF { Noto~Sans~Display }
      {
        \newfontfamily \PhiMiSciTitleFont 
          { Noto~Sans~Display }
          [ Ligatures = TeX,
            BoldFont = Noto~Sans~Display~SemiBold,
            ItalicFont = Noto~Sans~Display~SemiBold~Italic,
            BoldItalicFont = Noto~Sans~Display~SemiBold~Italic ]
      }
      {
        \let\PhiMiSciTitleFont\sffamily
        \msg_warning:nnnn { phimisci } { missing-font }
                          { NotoSansDisplay-SemiBold.ttf }
                          { Noto~Sans~Display~SemiBold }
      }
  }
\ExplSyntaxOff
%    \end{macrocode}
%
% The font Noto Sans Medium is distributed on CTAN via the \texttt{noto} 
% package. We rely on it being available.
%    \begin{macrocode}
\newfontfamily \PhiMiSciMediumFont {NotoSans-Medium.ttf}
  [Ligatures = TeX, ItalicFont = NotoSans-MediumItalic.ttf]
%    \end{macrocode}
%
% The main text is set in 10.5pt with 13.5pt line spacing. \emph{Note:} We 
% are using big points (\texttt{bp}) as our design was layed out with 
% PostScript points.
%    \begin{macrocode}
\AtBeginDocument{\fontsize{10.5bp}{13.5bp}\selectfont}
%    \end{macrocode}
% 
% We adjust the font settings inherited from \texttt{scrartcl} and create new
% font commands for specific PhiMiSci elements.
%
% The first few elements cover presentation of title, author, and other meta
% data on the title page.
%    \begin{macrocode}
\setkomafont{title}
  {%
    \raggedright%
    \PhiMiSciTitleFont%
    \bfseries%
    \color{PhiMiSciHeadingBlue}%
    \fontsize{23bp}{28bp}\selectfont%
  }
\setkomafont{subtitle}
  {%
    \raggedright%
    \PhiMiSciTitleFont%
    \bfseries%
    \color{PhiMiSciHeadingBlue}%
    \fontsize{17.25bp}{22bp}\selectfont%
  }
\setkomafont{subject}
  {%
    \PhiMiSciMediumFont%
    \fontsize{9.8bp}{13.72bp}\selectfont%
    \color{PhiMiSciHeadingBlue}%
  }
\setkomafont{author}
  {%
    \raggedright%
    \PhiMiSciTitleFont%
    \color{PhiMiSciHeadingBlue}%
    \fontsize{12bp}{17bp}\selectfont%
    \bfseries%
  }
\newkomafont{PhiMiSciAffiliationItem}
  {%
    \sffamily\bfseries%
    \fontsize{10bp}{13.5bp}\selectfont%
    \color{PhiMiSciHeadingBlue}%
  }
\newkomafont{PhiMiSciAffiliationLine}
  {%
    \usekomafont{footnote}%
  }
\newkomafont{PhiMiSciDedication}
  {%
    \normalfont\normalsize%
    \fontsize{10bp}{13.72bp}\selectfont%
    \itshape\bfseries%
    \color{PhiMiSciHeadingBlue}%
  }
\newkomafont{PhiMiSciEmail}{\normalfont\slshape}
\newkomafont{PhiMiSciFooter}
  {%
    \raggedright%
    \usekomafont{footnote}%
    \color{PhiMiSciHeadingBlue}%
  }
\newkomafont{PhiMiSciKeywords}
  {%
    \normalfont\fontsize{10bp}{13.5bp}\selectfont%
    \color{PhiMiSciHeadingBlue}%
  }
\newkomafont{PhiMiSciTableBody}
  {%
    \sffamily\fontsize{9bp}{13.5bp}\selectfont%
  }
\newkomafont{PhiMiSciWatermark}
  {%
    \normalfont\normalcolor\color{black!15}%
  }
%    \end{macrocode}
% These next settings configure the font in the page header. Note that the 
% colour of the header separation line is also given as a ``font'' option.
%    \begin{macrocode}
\addtokomafont{pagefoot}{\normalfont\color{PhiMiSciHeadingBlue}}
\addtokomafont{pagehead}
  {%
    \normalfont%
    \PhiMiSciMediumFont%
    \footnotesize%
    \color{PhiMiSciBlueThree}%
  }
\addtokomafont{headsepline}{\sffamily\bfseries}
%    \end{macrocode}
% In KOMA's font settings, the key \texttt{disposition} is inherited by all
% section headers.
%    \begin{macrocode}
\addtokomafont{disposition}{%
    \PhiMiSciTitleFont%
    \bfseries%
    \color{PhiMiSciHeadingBlue}%
  }
\addtokomafont{section}
  {%
    \fontsize{15.25bp}{18.5bp}%
    \selectfont%
  }
\addtokomafont{subsection}
  {%
    \color{PhiMiSciBlueThree}%
    \fontsize{13.25bp}{17bp}%
    \selectfont%
  }
\addtokomafont{subsubsection}
  {%
    \color{PhiMiSciBlueThree}%
    \fontsize{12bp}{17bp}%
    \selectfont%
  }
\addtokomafont{paragraph}
  {%
    \color{PhiMiSciBlueThree}%
    \fontsize{10bp}{13.5bp}%
    \selectfont%
  }
%    \end{macrocode}
% The remaining font options configure elements in the text.
%    \begin{macrocode}
\setkomafont{dictum}{\normalfont\normalsize\itshape}
\setkomafont{dictumauthor}{\normalfont\normalsize}
\setkomafont{descriptionlabel}{\normalfont\bfseries}
\addtokomafont{footnote}{\fontsize{9.25bp}{11.5bp}\selectfont}
\setkomafont{footnotelabel}{\sffamily\bfseries\color{PhiMiSciBlueTwo}}
\addtokomafont{footnotereference}{\sffamily\small\bfseries\color{PhiMiSciBlueTwo}}
\setkomafont{caption}{\usekomafont{footnote}\bfseries}
\setkomafont{captionlabel}
  {%
    \sffamily\bfseries%
    \fontsize{8bp}{10bp}\selectfont%
    \color{PhiMiSciHeadingBlue}%
  }
\setkomafont{notecolumn.marginpar}{\normalfont\color{black!50}}
\newkomafont{PhiMiSciQuote}{\normalfont\fontsize{10bp}{13.5bp}\selectfont}
%    \end{macrocode}
%
% \subsection{Bibliography management through \texttt{biblatex}}
% The entire bibliography management is delegated to \texttt{biblatex}. We enable 
% \texttt{natbib} as well so that authors can use traditional commands, most notably
% \cs{citet}, \cs{citep} and \cs{citealt}. \emph{Philosophy and the Mind Sciences}
% strictly follows the citation rules of the APA.
%    \begin{macrocode}
\RequirePackage[style=apa, natbib=true]{biblatex}
%    \end{macrocode}
% \subsection{PDF meta data and links through \texttt{hyperref}}
% After loading hyperref earlier, we set all links to our blue color. 
%    \begin{macrocode}
\hypersetup{breaklinks=true,
            colorlinks=true,
            linkcolor=PhiMiSciBlueTwo,
            citecolor=PhiMiSciBlueTwo,
            urlcolor=PhiMiSciBlueTwo}
%    \end{macrocode}
% We delay setting the PDF title string to the end of the preamble 
% to allow for meta data processing first. The meta data is output only in 
% some publication stages (see Section~\ref{sec:stages}).
%    \begin{macrocode}
\ExplSyntaxOn
\AtEndPreamble
  {
    \hypersetup
      {
        pdftitle  = { \tl_use:N \l_phimisci_document_title_tl }
      }
  }
\ExplSyntaxOff
%    \end{macrocode}
% \subsection{Setting the stage (preparation, submission, draft, publication)}
% \label{sec:stages}
% Our \texttt{phimisci} class supports four document stages. These stages are
% intended to support different steps in the preparation and publication of a
% document: 
%
% \begin{description}
% \item[Preparation:] Used by authors to compose a paper for submission to the
% journal.
% \item[Submission:] Used to compile the document for the peer review process.
% \item[Draft:] Used internally by the PhiMiSci office for production of the
% proofs.
% \item[Final:] A stage to produce the publication PDF.
% \end{description}
%
% These stages control the appearance of the generated document (see 
% Table~\ref{tab:stages}). For example, no meta data are output in the 
% \texttt{submission} stage to ensure anonymity during peer review. 
% The modes are activated through the class setting \texttt{stage} 
% (see Section~\ref{sec:options} for more user options). For example, 
% \texttt{draft} mode is enabled with:
% \begin{center}
% \cs{documentclass}\texttt{[stage=draft]\{phimisci\}}
% \end{center}
%
% \begin{table}[h]
% \centering
% \caption{Possible values for \texttt{stage} and the document settings applied 
% at each stage.\label{tab:stages}}
% \begin{tabular}{lcccc}
% \toprule
%       &            & \multicolumn{3}{c}{Output}\\\cmidrule(lr){3-5}
% Stage & Draft mode & Authors & Contact info & Footer\\\midrule
% Preparation & \ding{55} & \ding{51} & \ding{51} & \ding{55}\\
% Submission & \ding{55} & \ding{55} & \ding{55} & \ding{55}\\
% Draft & \ding{51} & \ding{51} & \ding{51} & \ding{51}\\
% Final & \ding{55} & \ding{51} & \ding{51} & \ding{51}\\
% \bottomrule
% \end{tabular}
% \end{table}
% 
% \begin{function}{\__phimisci_stage_preparation:} 
% Enable settings for the \texttt{preparation} stage.
% \end{function}
%    \begin{macrocode}
\ExplSyntaxOn
\cs_new:Nn \__phimisci_stage_preparation:
  {
    \KOMAoptions{overfullrule=false}
    \bool_set_true:N \l__phimisci_output_authors_bool
    \bool_set_true:N \l__phimisci_output_contact_bool
    \bool_set_false:N \l__phimisci_output_publication_header_footer_bool
    \bool_set_false:N \l__phimisci_output_draft_footer_bool
    \bool_set_true:N \l__phimisci_output_rights_bool
    \bool_set_false:N \l__phimisci_output_doi_bool
  }
%    \end{macrocode}
%
% \begin{function}{\__phimisci_stage_submission:}
% Enable settings for the \texttt{submission} stage.
% \end{function}
%    \begin{macrocode}
\cs_new:Nn \__phimisci_stage_submission:
  {
    \KOMAoptions{overfullrule=false}
    \bool_set_false:N \l__phimisci_output_authors_bool
    \bool_set_false:N \l__phimisci_output_contact_bool
    \bool_set_false:N \l__phimisci_output_publication_header_footer_bool
    \bool_set_false:N \l__phimisci_output_draft_footer_bool
    \bool_set_false:N \l__phimisci_output_rights_bool
    \bool_set_false:N \l__phimisci_output_doi_bool
  }
%    \end{macrocode}
% \begin{function}{\__phimisci_stage_draft:}
% Enable settings for a \texttt{draft} after acceptance and during production.
% \end{function}
%    \begin{macrocode}
\cs_new:Nn \__phimisci_stage_draft:
  {
    \KOMAoptions{overfullrule=true}
    \RequirePackage{scrtime}
    \RequirePackage{tikz}
    \AddToHook{shipout/background}{%
      \put(0pt, 0pt) {%
        \begin{tikzpicture}[remember~picture, overlay]
          \node [rotate=45, scale=5] at (current~page.center) 
                {
                  \usekomafont{PhiMiSciWatermark}
                  \tl_use:N \l__phimisci_draft_watermark_tl
                };
        \end{tikzpicture}
      }
    }
    \RequirePackage[pagewise, switch]{lineno}
    \AtBeginDocument{\linenumbers}
    \bool_set_true:N \l__phimisci_output_authors_bool
    \bool_set_true:N \l__phimisci_output_contact_bool
    \bool_set_true:N \l__phimisci_output_publication_header_footer_bool
    \bool_set_true:N \l__phimisci_output_draft_footer_bool
    \bool_set_true:N \l__phimisci_output_rights_bool
    \bool_set_true:N \l__phimisci_output_doi_bool
  }
%    \end{macrocode}
% \begin{function}{\__phimisci_stage_final:}
% Enable settings for the \texttt{final} publication PDF.
% \end{function}
%    \begin{macrocode}
\cs_new:Nn \__phimisci_stage_final:
  {
    \KOMAoptions{overfullrule=false}
    \bool_set_true:N \l__phimisci_output_authors_bool
    \bool_set_true:N \l__phimisci_output_contact_bool
    \bool_set_true:N \l__phimisci_output_publication_header_footer_bool
    \bool_set_false:N \l__phimisci_output_draft_footer_bool
    \bool_set_true:N \l__phimisci_output_rights_bool
    \bool_set_true:N \l__phimisci_output_doi_bool
  }
%    \end{macrocode}
% \section{User-configurable options}
% \label{sec:options}
% Users can configure the output of \texttt{phimisci} documents using a 
% key-value interface. Options can be loaded \emph{early} or \emph{late}. Early
% settings are those passed to \cs{documentclass}:
%
% \begin{center}
% \cs{documentclass}\oarg{\meta{key\textsubscript{1}}=
%                           \meta{value\textsubscript{1}},
%                         \meta{key\textsubscript{2}}=
%                           \meta{value\textsubscript{2}},
%                         ...}\verb+{phimisci}+
% \end{center}
% \noindent Late configurations appear after \cs{documentclass} but ideally 
% before \verb+\begin{document}+. They are passed to \cs{PhiMiSciSettings}:
%
% \begin{center}
% \cs{PhiMiSciSettings}\marg{\meta{key\textsubscript{1}}=
%                           \meta{value\textsubscript{1}},
%                         \meta{key\textsubscript{2}}=
%                           \meta{value\textsubscript{2}},
%                         ...}
% \end{center}
%
% \begin{description}
% \item[Hint:] Later settings always override previous ones.
% \item[Warning:] Many of the options will take either no effect or cause 
% unexpected output if they are changed in the document body. It is recommended
% to change all settings in the preamble, before \verb+\begin{document}+.
% \end{description}
% A \meta{key} can be any of the settings described below. Possible settings 
% for the \meta{value} depend on the respective \meta{key}.
%
% There are three types of \meta{keys}. Document meta data can be configured 
% with the first group. These are described in Section~\ref{sec:document-data}.
% Settings for the layout and document element behavior are stored in the 
% \meta{settings/} sub-group of keys (Section~\ref{sec:settings-layout}). 
% Locale options are stored in the \meta{locale/} sub-group 
% (Section~\ref{sec:settings-locale}).
% \subsection{Configure document data}\label{sec:document-data}
% \begin{function}{\PhiMiSciSettings}
% \begin{syntax}
% \cs{PhiMiSciSettings} \{ \meta{key\textsubscript{1}} = \meta{value\textsubscript{1}}, \meta{key\textsubscript{2}} = \meta{value\textsubscript{2}}, ... \}
% \end{syntax}
% \end{function}
% Meta data that are not input through dedicated commands (such as \cs{author}
% or \cs{title}) can be configured with \cs{PhiMiSciSettings}. This command
% accepts a comma-separated key-value list of settings and values. 

% For example, to prepare a draft for in volume 100 in the year 2100, you 
% would set:
%
% \begin{quote}
% \verb+\PhiMiSciSettings{stage=draft, volume=100, year=2100}+
% \end{quote}
%
% The meaning of the settings below can be found in the quick reference sheet 
% for this class, available as a separate document.
%    \begin{macrocode}
\keys_define:nn { phimisci }
  {
    stage .choice:,
    stage / preparation .code:n = { \__phimisci_stage_preparation: },
    stage / submission .code:n = { \__phimisci_stage_submission: },
    stage / draft .code:n = { \__phimisci_stage_draft: },
    stage / final .code:n = { \__phimisci_stage_final: },
    stage .default:n = {preparation},
    volume .tl_set:N = \l_phimisci_volume_tl,
    volume .initial:n = { \int_eval:n { \the\year - 2019 } },
    number .tl_set:N = \l_phimisci_number_tl,
    number .initial:n = {00},
    doi .tl_set:N = \l_phimisci_doi_tl,
    doi .initial:n = {10.33735/phimisci.0000.0000},
    year .int_set:N = \l_phimisci_publication_year_int,
    year .initial:x = {\the\year},
    issue .tl_set:N = \l_phimisci_issue_title_tl,
    issue .initial:n = {},
    editor .code:n = 
      { \seq_set_split:Nnn \l_phimisci_issue_editor_seq { ; } { #1 } },
    discussed-book .tl_set:N = \l_phimisci_discussed_book_tl,
    discussed-book .initial:n = {},
    discussed-book-authors .code:n = 
      {
        \seq_set_split:Nnn \l_phimisci_discussed_book_authors_seq 
                           { ; } { #1 } 
      },
    language .clist_set:N = \l__phimisci_languages_clist,
    language .initial:n = {english}
  }
%    \end{macrocode}
% \subsection{Settings to document elements and layout}
% \label{sec:settings-layout}
% \begin{variable}{phimisci/settings}
% \begin{syntax}
% \cs{PhiMiSciSettings} \{ settings / \meta{key} = \meta{value} \}
% \end{syntax}
% \end{variable}
% These settings allow you to go deep into the behavior of the class. For 
% the features that a user is most likely to set, please refer to the quick
% reference sheet available as a separate document.
%    \begin{macrocode}
\keys_define:nn { phimisci / settings }
  {
    author-output-separator .tl_set:N = \l__phimisci_authors_osep_tl,
    author-output-separator .initial:n = {,~},
    author-output-final-separator .tl_set:N =
      \l__phimisci_authors_osep_final_tl,
    author-output-final-separator .initial:n = {~\&~},
    affiliations-input-separator .tl_set:N =
      \l__phimisci_affiliations_isep_tl,
    affiliations-input-separator .initial:n = { ; },
    citation-file .tl_set:N = \l__phimisci_citation_file_name_tl,
    citation-file .initial:n = { phimisci-current-article.bib },
    copyright-text .tl_set:N = \l__phimisci_copyright_tl,
    copyright-text .initial:n = { },
    emergency-stretch .dim_set:N = \l__phimisci_settings_emergencystretch_dim,
    emergency-stretch .initial:n = { 2em },
    paragraph-indent .dim_set:N = \parindent,
    paragraph-indent .initial:n = { 6.5mm },
    list-indent .dim_set:N = \leftmargini,
    list-indent .initial:n = { 6.5mm },
    extra-sentence-spacing .bool_set:N = 
      \l__phimisci_settings_extra_sentence_spacing_bool,
    extra-sentence-spacing .initial:n = {false},
    dictum-width .code:n = { \renewcommand* { \dictumwidth } { #1 } },
    dictum-width .initial:n = { 0.62\linewidth },
    draft-footer-text .tl_set:N = \l__phimisci_draft_footer_tl,
    draft-footer-text .initial:n = 
      {
        \textit{Draft~generated~on~\today{}~at~\thistime{}.}
      },
    draft-watermark .tl_set:N = \l__phimisci_draft_watermark_tl,
    draft-watermark .initial:n = {PhiMiSci~uncorrected~proofs},
    footnote-break-penalty .int_set:N = 
      \l__phimisci_settings_footnote_penalty_int,
    footnote-break-penalty .initial:n = { 1000 },
    footnote-distance-from-main .code:n = { \setlength{\skip\footins}{#1} },
    footnote-distance-from-main .initial:n = { 13.5bp plus 4pt minus 2pt },
    head-rule-thickness .dim_set:N = \l__phimisci_head_rule_height_dim,
    head-rule-thickness .initial:n = { 0.25bp },
    logo-url .tl_set:N = \l__phimisci_branding_logo_tl,
    logo-url .initial:n = { },
    logo-width .dim_set:N = \l__phimisci_logo_width_dim,
    logo-width .initial:n = { 20.6mm },
    submission-footer-text .tl_set:N = \l__phimisci_submission_footer_tl,
    submission-footer-text .initial:n = 
      {
        Submission~to~\textit{Philosophy~and~the~Mind~Sciences}
      },
    keyword-input-separator .tl_set:N = 
      \l__phimisci_keywords_isep_tl,
    keyword-input-separator .initial:n = { ; },
    keyword-output-separator .tl_set:N = 
      \l__phimisci_keywords_osep_tl,
    keyword-output-separator .initial:n = 
      {
        \nobreak\space
        \textsf{\textbullet}
        \space
      },
    number-authors-header .int_set:N =
      \l__phimisci_max_authors_in_header_int,
    number-authors-header .initial:n = { 2 },
    orcid-color .tl_set:N = \l__phimisci_orcid_color_tl,
    orcid-color .initial:n = { A6CE39 }, 
    orphan-penalty .int_set:N = \l__phimisci_settings_orphan_penalty_int,
    orphan-penalty .initial:n = { 300 },
    output-orcids .bool_set:N = \l__phimisci_output_orcids_bool,
    output-orcids .initial:n = {true},
    paragraph-numbering-excluded-objects .tl_set:N = 
      \l__phimisci_parnum_excluded_objects_tl,
    paragraph-numbering-excluded-objects .initial:n = {},
    widow-control .choice:,
    widow-control / arseneau .code:n = 
      { \bool_set_true:N \l__phimisci_settings_sloppybottom_bool }, 
    widow-control / chernoff .code:n = 
      { \bool_set_true:N \l__phimisci_settings_luawidow_bool }, 
    widow-penalty .int_set:N = \l__phimisci_settings_widow_penalty_int,
    widow-penalty .initial:n = { 500 },
  }
%    \end{macrocode}
% \subsection{Locale settings}\label{sec:settings-locale}
% \begin{variable}{phimisci/locale}
% \begin{syntax}
% \cs{PhiMiSciSettings} \{ locale / \meta{key} = \meta{value} \}
% \end{syntax}
% \end{variable}
% These settings control the names of document elements. For example, the 
% key \texttt{phimisci / locale / abstract} stores the header of the abstract
% on the title page.
%    \begin{macrocode}
\keys_define:nn { phimisci / locale }
  {
    abstract .tl_set:N = \l__phimisci_locale_abstract_tl,
    abstract .initial:n = {Abstract},
    contact .tl_set:N = \l__phimisci_locale_contact_tl,
    contact .initial:n = {Primary~contact:~},
    et-al .tl_set:N = \l__phimisci_locale_et_al_tl,
    et-al .initial:n = {et~al.},
    edited-by .tl_set:N = \l__phimisci_locale_edited_by_tl,
    edited-by .initial:n = {,~edited~by~},
    authored-by .tl_set:N = \l__phimisci_locale_authored_by_tl,
    authored-by .initial:n = {~by~},    
    journal-name .tl_set:N = \l__phimisci_journal_name_tl,
    journal-name .initial:n = {Philosophy~and~the~Mind~Sciences},
    journal-short-name .tl_set:N = \l__phimisci_journal_short_name_tl,
    journal-short-name .initial:n = {PhiMiSci},
    keywords .tl_set:N = \l__phimisci_locale_keywords_tl,
    keywords .initial:n = {Keywords:~},
    volume .tl_set:N = \l__phimisci_locale_volume_tl,
    volume .initial:n = {Vol.},
    number .tl_set:N = \l__phimisci_locale_number_tl,
    number .initial:n = {No.},
    book-symposium .tl_set:N = \l__phimisci_locale_book_symposium_tl,
    book-symposium .initial:n = {Book~symposium~on~},
    special-issue .tl_set:N = \l__phimisci_locale_special_issue_tl,
    special-issue .initial:n = {Special~Issue:~}
  }
%    \end{macrocode}
% \begin{function}{\PhiMiSciSettings}
% \begin{syntax} \cs{PhiMiSciSettings} \marg{ \#1 }
% \end{syntax}
% This is the implementation of the \cs{PhiMiSciSettings} command. It serves
% as an interface from user input to internal processing.
%    \begin{macrocode}
\NewDocumentCommand { \PhiMiSciSettings } { m } 
  { 
    \keys_set:nn { phimisci } { #1 }
  }
\ProcessKeysOptions{phimisci}
%    \end{macrocode}
% \end{function}
% \section{Metadata processing}
%
% \subsection{Manage author data}
% Author data, including affiliations and ORCiDs, are processed by an
% adjusted \cs{author} command. The input is stored and processed for the 
% output on the title page as well as in the page header and some other
% places.
% 
% \begin{function}{\author, \affiliation, \orcid}
% \begin{arguments}
% \item A shortened author string to be printed in the page header
% \item Author-affiliation-ORCiD triples, separated by \cs{and}
% \end{arguments}
% \begin{syntax}
% \cs{author} \oarg{\#1} \marg{\#2}
% \end{syntax}
% If the optional argument \oarg{\#1} is not given, the list of authors to
% be printed in the header is determined from the input in \marg{\#2} 
% according to APA citation guidelines.
% 
% In the input, author data is given as \texttt{author} -- \texttt{affiliation}
% -- \texttt{orcid} unordered triple, where the input follows the pattern:
% \begin{quote}
% \texttt{Author name}\cs{affiliation}\marg{list of affiliations}\cs{orcid}\marg{orcid}
% \end{quote}
%
% \begin{description}
% \item[Notes:]
% \begin{enumerate}
% \item[] 
% \item Affiliations and ORCiDs are optional for each author.
%
% \item The position of \cs{affiliation} and \cs{orcid} is 
% interchangeable.
%
% \item Within \marg{list of affiliations}, items are separated by
% \texttt{;}. Multiple authors are separated by the marker \cs{and}. 
%
% \item New lines are allowed in the argument to \cs{author}.
% 
% \item \cs{affiliation} and \cs{orcid} are \emph{not} 
% defined commands here, but merely elements parsing to hook on to 
% \cite[see][46]{Interface3}.
% \end{enumerate}
%
% \item[Example:] ~ 
% \begin{quote}
% \cs{author}\texttt{\{}\\
% Author 1\cs{affiliation} \marg{Affiliation 1; Affiliation 2}
% \cs{orcid}\marg{...}\\
% \cs{and} Author 2 \cs{orcid}\marg{...} \cs{affiliation}\marg{...}\\
% \cs{and} Author 3 \cs{affiliation}\marg{Affiliation 2}\\
% \texttt{\}}
% \end{quote} 
% \end{description}
% \end{function}
%    \begin{macrocode}
\RenewDocumentCommand {\author} { O{} +m }
 {
   \tl_set:Nx \l__phimisci_custom_header_authors_tl { #1 }
   \gdef \@author { #2 }
   \AtEndPreamble { \PhiMiSci@ProcessAuthorData { #2 } }
 }
%    \end{macrocode}
%    \begin{macrocode}
%    \end{macrocode}
% \begin{function}{\PhiMiSci@ProcessAuthorData}
% A document command that forwards user input to internal author data
% processing in \cs{phimisci_process_author_data:nNNN}.
% \end{function}
%    \begin{macrocode}
\NewDocumentCommand { \PhiMiSci@ProcessAuthorData } { +m }
  {%
    \exp_args:No \phimisci_process_author_data:nNNN
                   { #1 }
                   \l__phimisci_authors_to_ids_prop
                   \l__phimisci_author_ids_to_affiliations_prop
                   \l__phimisci_author_ids_to_orcids_prop
    \hypersetup { pdfauthor = { \tl_use:N \l_phimisci_authors_tl } }
  }
%    \end{macrocode}
% \begin{function}{\PhiMiSci@OutputAuthorData}
% Control the output of author data on the title page. This function is 
% called by \cs{maketitle}.
% \end{function}
%    \begin{macrocode}
\NewDocumentCommand { \PhiMiSci@OutputAuthorData } {}
  {
    \group_begin:
    \parindent 0pt
    \bool_if:NT \l__phimisci_output_authors_bool
      {
        \group_begin:
        \usekomafont{author}
            \phimisci_output_authors:NNN 
               \l__phimisci_authors_to_ids_prop
               \l__phimisci_author_ids_to_affiliations_prop
               \l__phimisci_author_ids_to_orcids_prop
        \group_end:
%    \end{macrocode}
% Check whether the article is part of a book symposium or a special issue.
% Articles cannot be part of both; if both are given, the special issue
% takes precedence. Whether or not the article is part of a special issue
% or a book symposium is determined through the article's meta data. If any
% title for a book symposium or special issue is given, the article is 
% considered part of such.
%    \begin{macrocode}
        \tl_if_blank:VTF \l_phimisci_issue_title_tl
          {
            \tl_if_blank:VF \l_phimisci_discussed_book_tl
              {
                \vskip 1em
                \group_begin:
                \usekomafont{subject}
                \tl_use:N \l__phimisci_locale_book_symposium_tl
                \textit{\tl_use:N \l_phimisci_discussed_book_tl}
                \seq_if_empty:NF \l_phimisci_discussed_book_authors_seq
                  {
                    \tl_use:N \l__phimisci_locale_authored_by_tl
                    \seq_use:Nnnn 
                      \l_phimisci_discussed_book_authors_seq
                        {~\&~}
                        {,~}
                        {,~\&~}
                  }
                \seq_if_empty:NF \l_phimisci_issue_editor_seq
                  {
                    \tl_use:N \l__phimisci_locale_edited_by_tl
                    \seq_use:Nnnn 
                      \l_phimisci_issue_editor_seq
                        {~\&~}
                        {,~}
                        {,~\&~}
                  }                  
                 \group_end:
                 \par
              }
          }
          {
            \vskip 1em
            \group_begin:
            \usekomafont{subject}
            \tl_use:N \l__phimisci_locale_special_issue_tl
            \textit{\tl_use:N \l_phimisci_issue_title_tl}
            \seq_if_empty:NF \l_phimisci_issue_editor_seq
              {
                \tl_use:N \l__phimisci_locale_edited_by_tl
                \seq_use:Nnnn 
                  \l_phimisci_issue_editor_seq
                    {~\&~}
                    {,~}
                    {,~\&~}
              }
             \group_end:
             \par
          }
        \tl_if_blank:VF \l__phimisci_dedication_tl
          {
            \vskip 1em
            \group_begin:
            \usekomafont{PhiMiSciDedication}
            \tl_use:N \l__phimisci_dedication_tl
            \par
            \group_end:
          }
        \vfill
        \group_begin:
        \phimisci_output_affiliations:N 
            \l__phimisci_affiliation_id_resolver_prop
        \group_end:
        \par
        \vspace* { 2\baselineskip }
      }
    \group_end:
  }
%    \end{macrocode}
% \begin{function}{\phimisci_process_author_data:nNNN}
% This command handles the internal author-affiliation-orcid processing.
% \begin{arguments}
% \item The input author-affiliation-orcid text,
% \item[] and the following outpus:
% \item A property map that assigns each author to a unique ID.
% \item A property map that assigns each ID to an affiliation.
% \item A property map that assigns each ID to an ORCiD.
% \end{arguments}
% \end{function}
%    \begin{macrocode}
\cs_new:Npn \phimisci_process_author_data:nNNN #1#2#3#4
  {
    \seq_clear_new:N \l__phimisci_authors_header_tmp_seq
%    \end{macrocode}
% We first split the input string by \cs{and}, the common separator between 
% authors in the \LaTeX\ world. The result is stored in a sequence. 
%    \begin{macrocode}    
    \seq_set_split:Nnn \l__phimisci_authors_seq
                       { \and~ }
                       { #1 }
%    \end{macrocode}
% We now loop over the items stored in the sequence. The sequence is a list of all
% authors and each item stores all information of a single author. The currently 
% processed author item is known to \LaTeX\ as \texttt{\#\#1}.
%    \begin{macrocode}
    \int_zero_new:N \l__phimisci_current_author_id_int
    \seq_map_inline:Nn \l__phimisci_authors_seq
      {
        \tl_clear_new:N \l__phimisci_author_tmp_tl
        \tl_set:Nn \l__phimisci_author_tmp_tl { ##1 }
%    \end{macrocode}
% The author's affiliation and ORCID are extracted using regex parsing. As stated
% above, \cs{affiliation} and \cs{orcid} are not defined control sequences, but 
% rather hooks for the regex parsing to attach to. The order of the author's name,
% the affiliation and ORCID is irrelevant to the regex parsing -- though it is 
% certainly best practice to advise users to always follow a conventional input
% pattern.
%
% These two regular expressions each match a brace group following, if provided in
% the input, \cs{affiliation} and \cs{orcid}. The resulting sequence variables 
% will contain the completely matched string as a frist item -- for example, 
% |\affiliation{ABC University}| -- and the contents of the brace group as the 
% second item -- for example, |ABC University|. 
%    \begin{macrocode}
      \regex_extract_once:nnN 
        {\c{affiliation} \cB. (\c[^BE].*) \cE.}
        { ##1 }
        \l__phimisci_tmp_author_affiliation_seq
          
      \regex_extract_once:nnN 
        {\c{orcid} \cB. (\c[^BE].*) \cE.}
        { ##1 }
        \l__phimisci_tmp_author_orcid_seq
%    \end{macrocode}
% Following extraction we remove the author's affiliation and ORCID from the input
% so that only the name remains in the data for the current author.
%    \begin{macrocode}
      \regex_replace_all:nnN {\c{orcid} \cB. (\c[^BE].*) \cE.} 
                             {} 
                             \l__phimisci_author_tmp_tl
      \regex_replace_all:nnN {\c{affiliation} \cB. (\c[^BE].*) \cE.} 
                             {}
                             \l__phimisci_author_tmp_tl
%    \end{macrocode}
% Next, we trim leading and trailing spaces and store the name of the author 
% in a sequence. 
%    \begin{macrocode}
      \tl_trim_spaces:N \l__phimisci_author_tmp_tl
      \seq_put_right:NV \l__phimisci_authors_header_tmp_seq
                        \l__phimisci_author_tmp_tl
%    \end{macrocode}
% Loop over the affiliation(s) of the current author and assign each ID to 
% an affiliation ID, if not already present. \#\#\#\#1 is the current 
% affiliation. We first split the sequence of affiliations for each author.
%    \begin{macrocode}
      \seq_clear_new:N \l__phimisci_author_affiliation_seq
      \seq_clear_new:N \l__phimisci_author_affiliation_ids_seq
      \tl_clear_new:N \l__phimisci_afil_loop_tl
      \seq_set_split:NVx \l__phimisci_author_affiliation_seq
                         \l__phimisci_affiliations_isep_tl 
                         { 
                           \seq_item:Nn 
                             \l__phimisci_tmp_author_affiliation_seq 
                             {2} 
                         } 
%    \end{macrocode}
% We now loop over all the affiliations of an author. We first check whether
% the current affiliation, \#\#\#\#1, is empty or is already assigned to an 
% affiliation ID. If neither is the case, we create a new global ID for this 
% affiliation. We then add the affiliation ID to the author's sequence of 
% affiliation IDs.
%    \begin{macrocode}
      \seq_map_inline:Nn \l__phimisci_author_affiliation_seq
        {
          \tl_if_blank:nF { ####1 } 
            {
              \prop_get:NnNTF \l__phimisci_affiliation_id_resolver_prop { ####1 }
                \l__phimisci_afil_loop_tl
                {
                  \seq_put_right:NV 
                    \l__phimisci_author_affiliation_ids_seq
                    \l__phimisci_afil_loop_tl
                }
                {
                  \prop_put:Nxx \l__phimisci_affiliation_id_resolver_prop
                    { ####1 }
                    {
                      \int_eval:n 
                        { 
                          \prop_count:N \l__phimisci_affiliation_id_resolver_prop 
                          + 1 
                        }
                    }
                  \seq_put_right:Nx \l__phimisci_author_affiliation_ids_seq
                    {
                      \prop_count:N \l__phimisci_affiliation_id_resolver_prop
                    }
                }
            }
        }
%    \end{macrocode}                    
% We now store all the data in three separate property lists. In the first we 
% assign authors to (lists of) affiliations. Seconly, we map authors to their 
% ORCIDs in a separate property list. And third, we store the e-mail address
% in another property map. The currently processed affiliation is given by 
% |####1|.
%    \begin{macrocode}
      \prop_put:Nxx { #2 }
                    { \int_use:N \l__phimisci_current_author_id_int }
                    { \tl_use:N \l__phimisci_author_tmp_tl }      
      
      \prop_put:Nxx { #3 }
                    { \int_use:N \l__phimisci_current_author_id_int }
                    { 
                      \seq_use:Nn 
                        \l__phimisci_author_affiliation_ids_seq 
                        {,~} 
                    }
                  
      \prop_put:Nxx { #4 }
                    { \int_use:N \l__phimisci_current_author_id_int }
                    { \seq_item:Nn \l__phimisci_tmp_author_orcid_seq {2} }
%    \end{macrocode}
% Increase the ID and continue the loop with the next author.
%    \begin{macrocode}
      \int_incr:N \l__phimisci_current_author_id_int
    }
%    \end{macrocode}
% When all authors are parsed, create a token list of authors to be placed 
% in the header. If there are more authors than are allowed, print the first
% author and the \textit{et al.} string. The author string in the header can
% be overwritten by the optional argument to \cs{author} (but only if author
% printing in the header is enabled).
%    \begin{macrocode}
    \bool_if:NTF \l__phimisci_output_authors_bool
      {
        \tl_if_blank:VTF \l__phimisci_custom_header_authors_tl
          {
            \tl_set:Nx \l_phimisci_header_authors_tl
              {
                \int_compare:nNnTF
                  { \seq_count:N \l__phimisci_authors_header_tmp_seq }
                  >
                  { \l__phimisci_max_authors_in_header_int }
                  { 
                    \seq_item:Nn \l__phimisci_authors_header_tmp_seq { 1 }
                    \ \tl_use:N \l__phimisci_locale_et_al_tl
                  }
                  {
                    \seq_use:Nnnn \l__phimisci_authors_header_tmp_seq
                                  {~\&~}
                                  {,~}
                                  {,~\&~}
                  }
              }
          }
          {
            \tl_set_eq:NN \l_phimisci_header_authors_tl
                          \l__phimisci_custom_header_authors_tl
          }
        \tl_set:Nx \l_phimisci_authors_tl
          {
            \seq_use:Nnnn \l__phimisci_authors_header_tmp_seq
                          { \l__phimisci_authors_osep_final_tl } 
                          { \l__phimisci_authors_osep_tl } 
                          { \l__phimisci_authors_osep_final_tl } 
          }
        \tl_set:Nx \l__phimisci_authors_citation_footer_tl
          {
            \seq_use:Nn \l__phimisci_authors_header_tmp_seq
                          { ~and~ } 
          }
        \int_compare:nNnTF
          { \seq_count:N \l__phimisci_authors_header_tmp_seq } = 1
          { 
            \tl_set:Nn \l__phimisci_copyright_holder_tl { The~author }
          }
          {
            \tl_set:Nn \l__phimisci_copyright_holder_tl { The~authors }
          }
      }
      {
        \tl_set:Nn \l_phimisci_header_authors_tl { Anonymized }
      }
  }
%    \end{macrocode}
% We have now sorted our data in two mappings, a \{author: <affiliations>\} and 
% an \{author: orcid\} mapping. These two are now output.
% \begin{function}{\phimisci_output_authors:NNN}
% \begin{arguments}
% \item A property mapping that assigns each author to an ID.
% \item A property map that assigns each ID to a list of affiliations.
% \item A property map that assigns each ID to an ORCiD.
% \end{arguments}
% \end{function}
%    \begin{macrocode}
\cs_new:Npn \phimisci_output_authors:NNN #1#2#3
  {
    \seq_clear_new:N \l__phimisci_output_authors_loop_seq
    \int_set:Nx \l__phimisci_output_authors_int
      { \prop_count:N \l__phimisci_author_ids_to_affiliations_prop }
    \int_do_until:nNnn { \seq_count:N \l__phimisci_output_authors_loop_seq }
                       =
                       { 
                         \l__phimisci_output_authors_int 
                       }
                       {
                         \seq_put_right:Nx 
                           \l__phimisci_output_authors_loop_seq
                           {
                             \seq_count:N 
                               \l__phimisci_output_authors_loop_seq
                           }
                       }
    \seq_map_inline:Nn \l__phimisci_output_authors_loop_seq
      {
        \tl_clear_new:N \l__phimisci_affiliation_ids_of_author_tl
        \tl_clear_new:N \l__phimisci_output_author_temp_tl
        \prop_get:NnN #2 { ##1 } \l__phimisci_affiliation_ids_of_author_tl
        \prop_get:NnN #1 { ##1 } \l__phimisci_output_author_temp_tl
        \tl_rescan:nx {} { \l__phimisci_output_author_temp_tl }
        \tl_if_empty:NF \l__phimisci_affiliation_ids_of_author_tl
          {
            \textsuperscript
              { 
                \tl_use:N \l__phimisci_affiliation_ids_of_author_tl
                \str_if_eq:eeT \l__phimisci_output_author_temp_tl
                               \l__phimisci_contact_author_tl
                               { ,\,* }
              }
          }
        \phimisci_print_orcid:n { ##1 }
        \int_compare:nNnT { ##1 } < { \l__phimisci_output_authors_int + 1 }
          {
           \par
          }
      }
  }   
%    \end{macrocode}
% \begin{function}{\phimisci_output_affiliations:N}
% \begin{arguments}
% \item A property map that assigns each affiliation ID to the name of the
%       affiliation.
% \end{arguments}
% \end{function}
%    \begin{macrocode}
\cs_new:Npn \phimisci_output_affiliations:N #1
  {
    \prop_map_inline:Nn #1
      {
        \group_begin: 
          \usekomafont { PhiMiSciAffiliationItem }
          \textsuperscript
            { 
              \tl_rescan:nn {} { ##2 } 
            }
        \group_end:
        \group_begin:
          \__phimisci_affiliation_name_separator:
          \usekomafont { PhiMiSciAffiliationLine }
          \tl_rescan:nn {} { ##1 }
        \group_end:
        \__phimisci_affiliation_line_separator:
      }
    \par
    \tl_if_blank:nF { \l__phimisci_contact_tl }
      {
        \group_begin:
          \usekomafont { PhiMiSciAffiliationItem }
          *
        \group_end:
        \group_begin:
          \__phimisci_affiliation_name_separator:
          \usekomafont { PhiMiSciAffiliationLine }
          \tl_use:N \l__phimisci_locale_contact_tl 
          \tl_use:N \l__phimisci_contact_tl
        \group_end:
        \par
      }
  }
%    \end{macrocode}
% \begin{function}{\phimisci_print_orcid:n}
% Outputs the ORCiD assigned to an author with the ID \marg{\#1}. No output
% is given when the author is not assigned to an ORCiD (usually because none 
% was given in user input). 
% 
% The ORCiD is output as a hyperlinked icon using \cs{orcidlink} from the 
% \texttt{orcidlink} package. The color of that icon can be configured via 
% \cs{PhiMiSciSettings}\texttt{\{settings / orcid-color = \meta{HTML color code}\}}.
% \end{function}
%    \begin{macrocode}
\cs_new:Npn \phimisci_print_orcid:n #1
  {
    \prop_get:NnNT 
      \l__phimisci_author_ids_to_orcids_prop 
      { #1 } 
      \l__phimisci_tmp_orcid_link_tl
      {
        \tl_if_empty:NF \l__phimisci_tmp_orcid_link_tl
          {
            \,
            \orcidlink{ \tl_use:N \l__phimisci_tmp_orcid_link_tl }
          }
      }
}
%    \end{macrocode}
% \subsection{Managing the title and a short title (\texttt{\textbackslash title})}
% \begin{function}{\title}
% \begin{syntax}
% \cs{title} \oarg{abbreviated title} \marg{full title}
% \end{syntax}
% The \marg{full title} is printed as the document title as well as in the PDF
% meta data. If an \oarg{abbreviated title} is given, this one is printed in
% the running head. If none is supplied, the \marg{full title} is used there.
% An \oarg{abbreviated title} should be used when the \marg{full title} is too
% long to fit one line in the header.
% \end{function}
%    \begin{macrocode}
\tl_new:N \l_phimisci_document_title_tl
\tl_new:N \l_phimisci_short_document_title_tl
\RenewDocumentCommand {\title} { O{#2} m }
  {
    \tl_set:Nn \l_phimisci_document_title_tl { #2 }
    \tl_set:Nn \l_phimisci_short_document_title_tl { #1 }
    \RenewDocumentCommand {\@title} {} { #2 }
  }
%    \end{macrocode}
% \subsection{Manage the abstract, keywords, contact details and information 
% about reviewed books}\label{sec:data:other}
% \begin{function}{\contact}
% \begin{syntax}
% \cs{contact} \oarg{type} \Arg{contact~name} \marg{address}
% \end{syntax}
% Store the contact details given on the title page. The \marg{contact~name}
% can be empty. When \marg{contact~name} matches one of the authors in 
% \cs{author}, an asterisk is placed after the author to indicate them as
% the primary author.
% The \marg{address} can be of different types. When \oarg{type} is not given
% or set to \texttt{email}, \marg{address} will be handled as an e-mail 
% address and will be formatted appropriately as
% \texttt{mailto:\meta{address}}. When \oarg{type} is set to \texttt{website},
% the output will be formatted as the URL given in \marg{address}. When 
% \oarg{type} is set to an other value, the \marg{address} will be output as
% free-form output without a link.
% \end{function}
%    \begin{macrocode}
\DeclareDocumentCommand {\contact} { O{email} m m }
  {%
    \bool_if:NT \l__phimisci_output_contact_bool
      {
        \tl_set:Nn \l__phimisci_contact_author_tl { #2 }
        \str_case:nnF { #1 }
          {
              {email}
              {
                \tl_set:Nn \l__phimisci_contact_tl 
                  { 
                    \href{mailto:#3}{#3} 
                  }
              }
              {website}
              {
                \tl_set:Nn \l__phimisci_contact_tl
                  {
                    \url{#3}
                  }
              }
          }
          {
            \tl_set:Nn \l__phimisci_contact_tl { #3 }
          }
      }
  }
%    \end{macrocode}
% \begin{function}{\abstract}
% Store the abstract of the article.
% \end{function}
%    \begin{macrocode}
\DeclareDocumentCommand {\abstract} {+m} 
  {%
    \tl_if_blank:nTF { #1 }
      {
        \bool_set_false:N \l__phimisci_output_abstract_bool
      }
      {
        \phimisci_check_abstract_length:n { #1 }
        \tl_set:Nn \l__phimisci_abstract_tl { #1 }
        \bool_set_true:N \l__phimisci_output_abstract_bool
      }
  }
%    \end{macrocode}
% \begin{function}{\keywords}
% Store a list of keywords, separated by a user-configurable input separator.
% (\cs{l__phimisci_keywords_isep_tl}).
% \end{function}
%    \begin{macrocode}
\DeclareDocumentCommand {\keywords} {m} 
  {%
    \tl_if_blank:nTF { #1 }
      {
        \bool_set_false:N \l__phimisci_output_keywords_bool
      }
      {
        \tl_set:No \l__phimisci_keywords_tl 
          { 
            \phimisci_process_keywords:n { #1 } 
          }
        \bool_set_true:N \l__phimisci_output_keywords_bool
        \hypersetup { pdfkeywords = { #1 } }
      }
  }
%    \end{macrocode}
%
% \begin{function}{\dedication}
% A user-interface for the authors to store the dedication for their article.
% \end{function}
%    \begin{macrocode}
\DeclareDocumentCommand {\dedication} { +m }
  {
    \tl_set:Nn \l__phimisci_dedication_tl { #1 }
  }
%    \end{macrocode}
% 
% \begin{function}{\phimisci_check_abstract_length:n, \phimisci_process_keywords:n}
% Functions to process the abstract and keyword. 
%
% The length of the abstract is 
% estimated based on an average of eight characters per word. A warning is 
% issued if the function suspects that the abstract might be longer than the 
% journal's limit of 250 words. Long abstract can break the layout of the 
% title page, but this function can give false warnings. 
%    \begin{macrocode}
\cs_new:Npn \phimisci_check_abstract_length:n #1
  {
    \int_set:Nn \l__phimisci_abstract_length_int { \tl_count:o { #1 } }
    \int_compare:nNnT { \l__phimisci_abstract_length_int } < { 100 }
      { \AtEndDocument{ \ClassWarning {phimisci} {Very~short~abstract.} } }
    \int_compare:nNnT { \l__phimisci_abstract_length_int } > { 2000 }
      { \AtEndDocument { \ClassWarning {phimisci} {Very~long~abstract.} } }
  }
\cs_new:Npn \phimisci_process_keywords:n #1
  {
    \seq_set_split:NVn \l__phimisci_keywords_seq   
                       \l__phimisci_keywords_isep_tl 
                       { #1 }
    \seq_use:Nn \l__phimisci_keywords_seq
                { \l__phimisci_keywords_osep_tl }
  }
%    \end{macrocode}
% \end{function}
% \begin{function}{\PhiMiSci@OutputMetadata}
% Conditionally output meta data if supplied in the preamble. This function is
% called by \cs{maketitle}.
% \end{function}
%    \begin{macrocode}
\NewDocumentCommand {\PhiMiSci@OutputMetadata} {}
  {
    \bool_if:nT 
      { 
        \l__phimisci_output_keywords_bool 
        || \l__phimisci_output_abstract_bool
      }
      {
        \bool_if:NT \l__phimisci_output_abstract_bool
          {
            \subsubsection*{\tl_use:N \l__phimisci_locale_abstract_tl}
            \group_begin: 
              \usekomafont{ PhiMiSciQuote }
              \tl_use:N \l__phimisci_abstract_tl
              \par
            \group_end:
          }
        \bool_if:NT \l__phimisci_output_keywords_bool
          {
            \vskip 1em
            \noindent
            \group_begin:
              \usekomafont{ PhiMiSciKeywords }
              \textbf{\tl_use:N \l__phimisci_locale_keywords_tl} 
              \tl_use:N \l__phimisci_keywords_tl
              \par
            \group_end:
          }
        \clearpage
      }
  }
%    \end{macrocode}
%
% We make sure that the meta data is only provided in the preamble so that we
% can process it before using \cs{maketitle}.
%    \begin{macrocode}
\AtBeginDocument
  {
    \RenewDocumentCommand {\keywords} {m} 
      {
        \ClassError {phimisci} {Command~can~only~be~used~in~preamble}
          {
            The command \string\keywords can only be used in the preamble.
            Please move your keywords before \string\begin\string{document\string}.
          }
      }
  }
%    \end{macrocode}
% \subsection{Generate an auxiliary bibliography file}
%
%    \begin{macrocode}
\AtBeginDocument
  {
    \iow_open:Nn \l__phimisci_citation_file_stream 
                 { \l__phimisci_citation_file_name_tl }
    \iow_now:Nx \l__phimisci_citation_file_stream
      {
        @article{phimisci-current-article,\iow_newline:
          author = { \tl_use:N \l__phimisci_authors_citation_footer_tl },
          \iow_newline:
          year   = { \int_use:N \l_phimisci_publication_year_int },
          \iow_newline:
          title  = { {\exp_not:V \l_phimisci_document_title_tl} },
          \iow_newline:
          \tl_if_blank:VF \@subtitle
            {
              subtitle = { {\unexpanded\expandafter{\@subtitle}} },
              \iow_newline:
            }
          journal = { \tl_use:N \l__phimisci_journal_name_tl },
          \iow_newline:
          volume = { \tl_use:N \l_phimisci_volume_tl },
          \iow_newline:
          doi = { \tl_use:N \l_phimisci_doi_tl },
          \iow_newline:
          options = { dataonly = true }
        }
      }
    \iow_close:N \l__phimisci_citation_file_stream
  }
\AtEndPreamble
  {
    \addbibresource { \tl_use:N \l__phimisci_citation_file_name_tl }
  }
%    \end{macrocode}
% \subsection{Configure the document language}
% The list passed as \cs{documentclass}\texttt{[language=\meta{list of 
% languages}]}\texttt{\{phimisci\}} is processed here. By \texttt{babel}'s 
% convention, if there is more than one language in the list, the last is 
% considered to be the main document language.
%    \begin{macrocode}
\RequirePackage [ \clist_use:Nn \l__phimisci_languages_clist {,} ] {babel}
\ExplSyntaxOff
%    \end{macrocode}
% \section{Layout and design}
% \subsection{Page geometry}
% We configure the paper size and the type area through the margins.
%    \begin{macrocode}
\RequirePackage[a4paper,
                landscape,
                twocolumn,
                hmargin=25mm,
                top=23.625mm,
                bottom=22.7375mm,
                footskip=0pt,
                columnsep=25mm,
                headsep=8.25mm,
                headheight=4.5mm
                ]
                {geometry}
%    \end{macrocode}
% 
% \subsection{Journal color definitions}
% \begin{function}{PhiMiSciHeadingBlue, PhiMiSciBlueTwo, PhiMiSciBlueThree,
%                  PhiMiSciGrey}
% The custom colors used in the journal's layout are:
% \begin{itemize}
% \item[] \fcolorbox{black}{PhiMiSciHeadingBlue}{\strut\hspace*{2em}}
%         \texttt{PhiMiSciHeadingBlue}, in titles
% \item[] \fcolorbox{black}{PhiMiSciBlueTwo}{\strut\hspace*{2em}} 
%         \texttt{PhiMiSciBlueTwo}, for hyperlinks
% \item[] \fcolorbox{black}{PhiMiSciBlueThree}{\strut\hspace*{2em}} 
%         \texttt{PhiMiSciBlueThree}, for subsections and the header line
% \item[] \fcolorbox{black}{PhiMiSciGrey}{\strut\hspace*{2em}}
%         \texttt{PhiMiSciGrey}, for some text elements
% \end{itemize}
%    \begin{macrocode}
\definecolor{PhiMiSciHeadingBlue}{RGB}{10, 26, 97}
\definecolor{PhiMiSciBlueTwo}{RGB}{19, 47, 178}
\definecolor{PhiMiSciBlueThree}{RGB}{12, 30, 115}
\definecolor{PhiMiSciGrey}{RGB}{157, 164, 196}
%    \end{macrocode}
% \end{function}
%
% \subsection{Layout of section headings}
% \begin{function}{\sectionformat, \subsectionformat, \subsubsectionformat,
%                  \paragraphformat}
% The section number width is set to 12.5mm, twice the \cs{parindent}, and
% the section header follows after that.
%    \begin{macrocode}
\renewcommand*{\sectionformat}
  {%
    \hbox to 12.5mm {\thesection\autodot}%
  }
\renewcommand*{\subsectionformat}
  {%
    \hbox to 12.5mm {\thesubsection\autodot}%
  }
\renewcommand*{\subsubsectionformat}
  {%
    \hbox to 12.5mm {\thesubsubsection\autodot}%
  }
\renewcommand*{\paragraphformat}
  {%
    \hbox to 12.5mm {\theparagraph\autodot}%
  }
%    \end{macrocode}
% \end{function}
%
% \begin{function}{\section, \subsection, \subsubsection}
% Our layout uses a slightly larger spacing before section headings.
%    \begin{macrocode}
\RedeclareSectionCommand[%
    afterindent=false, beforeskip=22bp plus 22bp, afterskip=8.5bp%
    ]{section}
\RedeclareSectionCommand[%
    afterindent=false, beforeskip=13.5bp plus 13.5bp, afterskip=10bp%
    ]{subsection}
\RedeclareSectionCommand[%
    afterindent=false, beforeskip=13.5bp plus 13.5bp, afterskip=10bp%
    ]{subsubsection}    
%    \end{macrocode}
% \end{function}
% 
% \begin{function}{\paragraph}
% We use \cs{paragraph} as a heading on the fourth level (e.g., 1.1.1.1).
% The following settings follow an example from the KOMA manual.
%    \begin{macrocode}
\RedeclareSectionCommand[%
    afterindent=false, afterskip=6.75bp, beforeskip=6.75bp plus 6.75bp,%
    indent=0pt, counterwithin=subsubsection, level=4%
    ]{paragraph}
%    \end{macrocode}
% \end{function}
%
% \begin{variable}{secnumdepth, tocdepth}
% We want \cs{paragraphs} to be numbered and listed in the table of contents
% (i.e., in the PDF meta data). We set \texttt{secnumdepth} and 
% \texttt{tocdepth} accordingly.
%    \begin{macrocode}
\setcounter{secnumdepth}{\paragraphnumdepth}
\setcounter{tocdepth}{\paragraphtocdepth}
%    \end{macrocode}
% \end{variable}
%
% \subsection{Footnotes}
% These options configure how the footnotes are typed at the bottom of the
% page. 
%    \begin{macrocode}
\setfootnoterule[0pt]{0pt}
\deffootnote{3.125mm}{3.125mm}{%
  \makebox[3.125mm][r]{\textsuperscript{\thefootnotemark\ }}%
  }
%    \end{macrocode}
% Automatically type a superscripted comma in case two \cs{footnote}s are
% called immediately following each other.
%    \begin{macrocode}
\KOMAoption{footnotes}{multiple}
%    \end{macrocode}
% \subsection{Tolerances and penalties: Optimisation of line and page breaks}
% Configure the penalties for widows and orphans, that is, for last lines of
% paragraphs on new pages and for first lines of a paragraph at the end of a 
% page.
%    \begin{macrocode}
\ExplSyntaxOn
\clubpenalty = \int_use:N \l__phimisci_settings_orphan_penalty_int
\widowpenalty = \int_use:N \l__phimisci_settings_widow_penalty_int
%    \end{macrocode}
% The class has two ways to automatically treat widows and orphans. The first
% is originally due to Donald Arseneau and selected via the 
% \texttt{settings/widow-control/arseneau} option. The code here follows
% the implementation in the \texttt{memoir} class.
%     \begin{macrocode}
\bool_if:NT \l__phimisci_settings_sloppybottom_bool
  {
    \def\@textbottom{\vskip \z@ \@plus.0001fil \@minus .95\topskip}
    \topskip=1\topskip \@plus 0.625\topskip \@minus .95\topskip
    \def\@texttop{\vskip \z@ \@plus -0.625\topskip \@minus -0.95\topskip}
  }
%    \end{macrocode}
%
% The second automatic processing for widows and orphans is provided through
% Max Chernoff's \texttt{lua-widow-control} package \cite{Chernoff2022}. It 
% adjusts interword spacing to reduce and remove orphans, widows and broken 
% hyphenation. It requires \LuaLaTeX{} but ensures flush page bottoms.
% It can be enabled via the \texttt{settings/widow-control/chernoff} option.
%    \begin{macrocode}
\bool_if:NT \l__phimisci_settings_luawidow_bool
  {
    \sys_if_engine_luatex:TF
      {
        \RequirePackage{lua-widow-control}
        \lwcsetup
          {
            emergencystretch=\int_use:N 
                             \l__phimisci_settings_emergencystretch_dim
          }
      }
      {
        \msg_fatal:nnn { phimisci } { wrong-tex-engine } { lualatex }
      }
  }
%    \end{macrocode}
%
% Footnotes should break across pages only if everything else fails. Set a high
% penalty to accomplish this. Sometimes, breaking a footnote is more desirable
% than having a sub-optimal break in the main text.
%    \begin{macrocode}
\interfootnotelinepenalty=\int_use:N \l__phimisci_settings_footnote_penalty_int
%    \end{macrocode}
% We set \cs{emergencystretch} for automatic treatment of overful lines. It 
% should be noted that overful lines can also be treated using better 
% \cs{hyphenation} patterns.
%    \begin{macrocode}
\emergencystretch=\dim_use:N \l__phimisci_settings_emergencystretch_dim
%    \end{macrocode}
% \LaTeX\ inserts a special spacing after punctuation by default. If requested
% by the user, use the usual inter-word space after punctuation.
%    \begin{macrocode}
\bool_if:NF \l__phimisci_settings_extra_sentence_spacing_bool
  { \frenchspacing }
%    \end{macrocode}
%
% \subsection{Float layout}
%
% All floats should be centered and use our custom font for float contents.
%    \begin{macrocode}
\addto\@floatboxreset
  {%
    \centering%
    \usekomafont{PhiMiSciTableBody}%
  }
%    \end{macrocode}
%
% We would like the captions to be of width \cs{columnwidth}. This will not 
% change the default behaviour of regular floats, it changes the caption in
% two-column floats.
%    \begin{macrocode}
\setcapwidth{111mm}
%    \end{macrocode}
%
% Captions should not have hanging indent:
%    \begin{macrocode}
\setcapindent{0pt}
%    \end{macrocode}
%
% \begin{variable}{\heavyrulewidth, \lightrulewidth}
% We adjust the width of \cs{toprule} and \cs{bottomrule} from 
% \texttt{booktabs}. The width of \cs{midrule} is given as 5/8 of the other
% rules
%    \begin{macrocode}
\dim_set:Nn \heavyrulewidth { 0.25bp }
\dim_set:Nn \lightrulewidth { 0.15625bp }
\ExplSyntaxOff
%    \end{macrocode}
% \end{variable}
% \begin{variable}{\arrayrulecolor}
% We set the color of rules in tables to our journal colors.
%    \begin{macrocode}
\arrayrulecolor{PhiMiSciHeadingBlue}
%    \end{macrocode}
% \end{variable}
% \begin{variable}{\topfraction, ...}
% More liberal values for the placement of floats. These liberal values 
% increase the likelihood that a float can be placed near the location 
% desired by the author(s).
%    \begin{macrocode}
 \renewcommand{\topfraction}{.9} 
 \renewcommand{\dbltopfraction}{.8}
 \renewcommand{\bottomfraction}{.8} 
 \renewcommand{\textfraction}{.1} 
 \renewcommand{\floatpagefraction}{.75}
 \renewcommand{\dblfloatpagefraction}{.75} 
 \setcounter{topnumber}{9} 
 \setcounter{bottomnumber}{9} 
 \setcounter{totalnumber}{20} 
 \setcounter{dbltopnumber}{9} 
%    \end{macrocode}
% \end{variable}
%
% \subsection{Indentation after lists and quotations}
% We add a hook to the end of \env{quote}, \env{quotation}, \env{itemize}, 
% \env{description} and \env{enumerate} to suppress indentation in the 
% following paragraphs.
%    \begin{macrocode}
\AfterEndEnvironment{quote}{\par\@afterindentfalse\@afterheading}
\AfterEndEnvironment{quotation}{\par\@afterindentfalse\@afterheading}
\AfterEndEnvironment{verse}{\par\@afterindentfalse\@afterheading}
\AfterEndEnvironment{itemize}{\par\@afterindentfalse\@afterheading}
\AfterEndEnvironment{enumerate}{\par\@afterindentfalse\@afterheading}
\AfterEndEnvironment{description}{\par\@afterindentfalse\@afterheading}
%    \end{macrocode}
%
% \subsection{Bibliography layout}
% We allow (almost) no breaking within entries in the list of references, and
% we are especially tolerant regarding interword spacing to avoid overful 
% lines. These tolerances follow a post by Enrico Gregorio on TeX.SE.
%    \begin{macrocode}
\defbibheading { bibliography } [ \refname ]
  {
    \addsec{ #1 }
    \clubpenalty=10000
    \@clubpenalty\clubpenalty
    \widowpenalty=10000
    \emergencystretch=3em
  }
\AtBeginBibliography{\usekomafont{footnote}}
\bibhang=6.25mm
%    \end{macrocode}
% In citations, we prefer to have a non-breakable thin space between ``p.''
% and the cited page number.
%    \begin{macrocode}
\RenewDocumentCommand {\ppspace} {} {\addnbthinspace}
%    \end{macrocode}
% \section{Document elements}
% \subsection{The document title}
% \begin{function}{\maketitle}
% We customise the document title page to our layout. A title page following
% this layout is produced through \cs{maketitle} in papers.
% \end{function}
%    \begin{macrocode}
\ExplSyntaxOn
\RenewDocumentCommand {\maketitle} {} 
  {%
    {
      \thispagestyle{plain.scrheadings}
%    \end{macrocode}
% The header, including journal logo, title, volume number, and 
% publication year, is only printed for some publication stages. It is printed
% for \texttt{final} and \texttt{draft} documents, but not for stages 
% \texttt{preparation} and \texttt{submission}.
%    \begin{macrocode}
     \bool_if:NT \l__phimisci_output_publication_header_footer_bool
       {
         \vspace*{-16.5mm}
         \raggedright
%    \end{macrocode}
% The following box contains the journal title, the volume, and publication 
% year. 
%    \begin{macrocode}         
         \parbox[c]
           {
             \dim_eval:n 
               { 
                 \columnwidth - 1cm - \l__phimisci_logo_width_dim 
               }
           }
           {
             \vskip\baselineskip
             \raggedright
             \addfontfeature{LetterSpace=2.0}
             \normalfont\normalsize
             \color{PhiMiSciHeadingBlue}
               {
                 \bfseries\fontsize{20bp}{24bp}\selectfont
                 \tl_use:N \l__phimisci_journal_short_name_tl \par
               }
               {
                 \fontsize{11.2bp}{16.8bp}\selectfont 
                 \tl_use:N \l__phimisci_journal_name_tl
                 \space |\space
                 \tl_use:N \l__phimisci_locale_volume_tl 
                 \space
                 \tl_use:N \l_phimisci_volume_tl
                 \space |\space
                 \int_use:N \l_phimisci_publication_year_int\par
               }
            }
           \hskip 1cm
%    \end{macrocode}
% The following box contains the journal logo. If a logo is not specified, the
% box remains empty and a warning is issued to the user.
%    \begin{macrocode}             
           \parbox[c]{\dim_use:N \l__phimisci_logo_width_dim}
             {
               \tl_if_blank:VTF \l__phimisci_branding_logo_tl
                 {
                   \msg_warning:nn { phimisci } { missing-logo-url }
                 }
                 {
                   \includegraphics
                     [ width=\dim_use:N \l__phimisci_logo_width_dim ]
                     { \tl_use:N \l__phimisci_branding_logo_tl }
                 }
            }
        }
    }
%    \end{macrocode}
% The command \cs{and} to separate authors is merely a hook for our internal
% processing (see our custom \cs{author} and auxiliary functions). We deactivate
% it to avoid the effects of its standard definition.
%    \begin{macrocode}      
    \let\and\relax
    \vskip 2.66\baselineskip
%    \end{macrocode}
% After a vertical skip, print the document title and subtitle (if given).
%    \begin{macrocode}        
    {
      \usekomafont{title}
      {
        \@title
        \par\vskip.5\baselineskip
      }
    }
    {
      \ifx\@subtitle\@empty
      \else
      \usekomafont{subtitle}\@subtitle\par\vskip.5\baselineskip
      \fi
    }
    \vskip .5em
%    \end{macrocode}
% Output the author data, including affiliations. \cs{PhiMiSci@OutputAuthorData}
% also outputs information about the special issue and/or book symposium, in 
% the article is part of one. Various \cs{enlargethispage} commands ensure there
% is enough space for the footer.
%    \begin{macrocode}    
    \PhiMiSci@OutputAuthorData{}
    \enlargethispage{-2.5\baselineskip}
%    \end{macrocode}
% The right column on the title page, started by a \cs{pagebreak}, contains the
% abstract and keywords.
%    \begin{macrocode}    
    \newpage
    \vspace*{3.25\baselineskip}
    \enlargethispage{-4\baselineskip}
    \PhiMiSci@OutputMetadata{}
%    \end{macrocode}
% Finally, ensure that the paper does not begin with a paragraph indent.
%    \begin{macrocode}    
    \@afterindentfalse\@afterheading
  }
%    \end{macrocode}
% \subsection{Epigraphs}
% Epigraphs can be inserted at any point of the document text using \cs{dictum}
% \oarg{source}\marg{text}. The command is inherited from \texttt{scrartcl}
% \cite[\S3.17]{scrguide}.
%
% The optional \oarg{source} can contain a citation command. 
% The following settings are adjustments to fit the needs of the journal:
%
%    \begin{macrocode}
\RenewDocumentCommand { \dictumrule } {} { \smallskip }
%    \end{macrocode}
%
% \subsection{Block quotes}
% Block quotes use a particular font in our layout. This setting
% is used for the abstract, too.
%    \begin{macrocode}
\AddToHook { env/quote/begin } { \usekomafont{PhiMiSciQuote} }
\AddToHook { env/quotation/begin } { \usekomafont{PhiMiSciQuote} }  
%    \end{macrocode}
% We overwrite the layout of block quotes in footnotes. These are typeset 
% smaller than block quotes in the main text.
%    \begin{macrocode}
\AddtoDoHook { footnote/text/begin } 
  {
    \AddToHook { env/quote/begin } [ PhiMiSciFnQuoteFont ] { \footnotesize }
    \AddToHook { env/quotation/begin } [ PhiMiSciFnQuoteFont ] { \footnotesize }
  }
%    \end{macrocode}
% The font setting for footnotes is cleaned up at the end of each footnote.
%    \begin{macrocode}
\AddtoDoHook { footnote/text/end }
  {
    \RemoveFromHook { env/quote/begin } [ PhiMiSciFnQuoteFont ]
    \RemoveFromHook { env/quotation/begin } [ PhiMiSciFnQuoteFont ]
  }
%    \end{macrocode}
%
% \subsection{Lists}
% In our layout, list labels are snug with the \cs{parindent}, which we achieve 
% using the \texttt{enumitem} package.
%    \begin{macrocode}
\setlist[enumerate, itemize]
  { 
    labelindent=\parindent, 
    leftmargin=* 
  }
%    \end{macrocode}
%
% \subsection{Headers \& footers}
% There is a line between the header and paper content (though we use a custom
% line, see \cs{PhiMiSci@HeaderSepLine}). The title page has an enlarged foot
% height to accommodate citation recommendation and license information.
%    \begin{macrocode}
\KOMAoptions
  {
    headsepline = true
  }
\AddToLayerPageStyleOptions{plain.scrheadings}
  {
    onselect = 
      {
        \setlength { \footheight } { 3.25\baselineskip }
      } 
  }
%    \end{macrocode}
% \begin{function}{\PhiMiSci@OneColumnLine}
% A helper macro that generates a line spanning exactly the width of a 
% column, or \cs{columnwidth}. Its thickness can be set via
% \texttt{settings/head-rule-thickness}. The line is spread evenly to height 
% and depth of the line. 
%    \begin{macrocode}
\NewDocumentCommand{\PhiMiSci@OneColumnLine} {}
  {
    \vrule \@width \dimexpr \columnwidth \relax
           \@height .5 \dimexpr \l__phimisci_head_rule_height_dim \relax 
           \@depth  .5 \dimexpr \l__phimisci_head_rule_height_dim \relax
  }
%    \end{macrocode}
% \end{function}
% \begin{function}{\PhiMiSci@HeaderSepLine}
% Places two lines, each spanning a column. The margin between the 
% columns is filled with white space, and the current page number is 
% centered. ``Font'' options, such as colour of the line, are taken from
% \meta{headsepline}. See \cs{PhiMiSci@OneColumnLine} for configuration of
% the stroke thickness.
% \end{function}
%    \begin{macrocode}
\NewDocumentCommand{\PhiMiSci@HeaderSepLine} {}
  {
    \group_begin:
      \usekomafont{headsepline}
        {
          \vbox spread \z@
            {
              \PhiMiSci@OneColumnLine{}
              \hfill
                \lower .58ex \hbox{\thepage}
              \hfill
              \PhiMiSci@OneColumnLine{}
              \par
            }
        }
    \group_end:
  }
%    \end{macrocode}
% Configure the page style to use \cs{PhiMiSci@HeaderSepLine} for KOMA's 
% \texttt{headsepline}.
%    \begin{macrocode}
\DeclareLayer[
  background,
  hoffset=\sls@leftmargin{head},
  voffset=\sls@topmargin
          + \headheight
          - \ht\strutbox
          + \dimexpr \l__phimisci_head_rule_height_dim
          \relax,
  width=\sls@headwidth,
  height=0pt,
  align=tl,
  contents={{
    \normalfont
    \usekomafont{pageheadfoot}
      {
        \usekomafont{pagehead}
        {
          \PhiMiSci@HeaderSepLine{}
        }
      }
    }}
  ]{scrheadings.head.below.line}
%    \end{macrocode}
% The optional arguments for \cs{cfoot} and \cs{chead} determine the footer and
% header on pages with the style \texttt{plain} (typically the title page only).
% The header and footer for all other pages is determined by the mandatory 
% argument of both commands. Note that the title page does not have a header,
% but is configured with manual spacing due to the flexibility needed.
%    \begin{macrocode}
\cfoot[\PhiMiSci@Footer*{}]{\PhiMiSci@Footer{}}
\chead[]{\PhiMiSci@Header{}}
%    \end{macrocode}
% \begin{function}{\PhiMiSci@Footer, \PhiMiSci@Footer*}
% Two macros for the content of the footer.  The starred variant is intended to 
% produce the footer on the title page. The base variant produces the footer on 
% all other pages --- which is empty except in the \texttt{draft} stage.
% \end{function}
%    \begin{macrocode}
\NewDocumentCommand {\PhiMiSci@Footer} { s }
  {%
    \IfBooleanTF {#1}
      {
        \bool_if:NTF \l__phimisci_output_publication_header_footer_bool
          {
            \begin{minipage} [b] {\columnwidth}
                \usekomafont{PhiMiSciFooter}
                \fullcite{phimisci-current-article}
            \end{minipage}\hfill
            \begin{minipage} [b] {\columnwidth}
                \usekomafont{PhiMiSciFooter}
                \bool_if:NT \l__phimisci_output_rights_bool
                  {
                    \copyright{}~\tl_use:N \l__phimisci_copyright_holder_tl.~
                    \tl_use:N \l__phimisci_copyright_tl
                  }
            \end{minipage}
          }
          {
            \tl_use:N \l__phimisci_submission_footer_tl
          }
      }
      {
        \bool_if:NT \l__phimisci_output_draft_footer_bool
          {
            \vskip 1cm
            \tl_use:N \l__phimisci_draft_footer_tl
          }
      }
  }
%    \end{macrocode}
% \begin{function}{\PhiMiSci@Header}
% A macro to produce the header on pages that are not \texttt{plain}, typically
% all pages except the title page. The output differs depending on publication
% stage --- author names and journal volume information are not given for stages
% \texttt{submission} and \texttt{preparation}. A generic text is placed
% instead, informing the reader about the article's status.
% \end{function}
%    \begin{macrocode}
\NewDocumentCommand {\PhiMiSci@Header} { }      
  {%
    \bool_if:NTF \l__phimisci_output_publication_header_footer_bool
      {
        \tl_use:N \l__phimisci_journal_short_name_tl
        \c_space_token | \c_space_token
        \tl_use:N \l__phimisci_locale_volume_tl 
        \c_space_token
        \tl_use:N \l_phimisci_volume_tl
      }
      {
        \tl_use:N \l__phimisci_submission_footer_tl
      }
    \hfill
    \Ifthispageodd
      {
        \tl_use:N \l_phimisci_short_document_title_tl
      }
      {
        \tl_use:N \l_phimisci_header_authors_tl
      }
  }
%    \end{macrocode}
% \subsection{ORCiD logo settings}
% \begin{function}{orcidlogocol}
% The color used to print the ORCiD logo. ORCiD's policy prescribes this can
% be either black or the ORCiD green, HTML code \texttt{A6CE39}. We use this
% green by default.
%    \begin{macrocode}
\definecolor{orcidlogocol}{HTML}{\tl_use:N \l__phimisci_orcid_color_tl}
%    \end{macrocode}
% \end{function}
% \begin{function}{\@OrigHeightRecip}
% The ORCiD logo is slightly enlarged to match the layout of our printing of
% authors on the title page.
%    \begin{macrocode}
\renewcommand{\@OrigHeightRecip}{0.006}
%    \end{macrocode}
% \end{function}
% \subsection{Paragraph counting in the margin}
% \begin{function}{\PhiMiSciParagraphNumber}
% A dummy function to put paragraph numbers in the page margin. This feature is
% not yet fully implemented and tested.
%    \begin{macrocode}
\NewDocumentCommand{\PhiMiSciParagraphNumber}{m}
  {
    \makenote{ #1 }
  }
%    \end{macrocode}
% \end{function}
%
% \subsection{Automatic paragraph numbering}\label{sec:parnumbering}
% Passages in journal articles have traditionaly been identified by their page
% number. As journals move to publication on the web alongside PDF distribution,
% a different mechanic becomes necessary to identify passages in non-paginated
% media, such as web sites. The predominant approach has been to number 
% paragraphs instead.
%
% The \texttt{phimisci} class offers mechanisms for automatic (as well as
% manual) paragraph numbering. The classic implementation of this was described
% by Nicola Talbot \cite[\S6.5]{Talbot2015}. This method uses 
% \cs{everypar}, a command that does not appear to be advisable any longer 
% \cite[1--3]{ltpara}. Instead, we implement a similar mechanism through 
% \LaTeX's new hook management \cite{lthooks, ltpara}.
%
% \begin{description}
% \item[Note:] The implementation below is preliminary and subject to change in
% future versions of our class. It is also not sufficiently tested for 
% production use.
% \end{description}
%
% The environment \env{PhiMiSciNumberedParagraphs} automatically numbers 
% paragraphs according to the template \cs{PhiMiSci@PrintParNum}. 
% The \texttt{phimisci} class takes great care to exclude certain elements from
% paragraph counting, such as the document's header and footer (via
% \cs{PhiMiSci@DetectKomaHeader}) and from a pre-defined list of environments
% (using \cs{PhiMiSci@ParNumSwitch}) as well as the sectioning commands 
% (\cs{section}, \cs{subsection} and \cs{subsubsection}). The user can extend 
% this list in case additional environments should be included:
%
% \begin{quote}
% \cs{PhiMiSciSettings} \texttt{\{ settings / 
% paragraph-numbering-excluded-objects = \meta{list}\}}
% \end{quote}
%
% \begin{variable}{\l__phimisci_parnum_excluded_objects_base_tl}
% The following environments are excluded by default and do not need to be
% added:
% \end{variable}
% \begin{itemize}
% \item lists (\texttt{list}, \texttt{enumerate}, \texttt{itemize},
%       \texttt{description})
% \item quotes (\texttt{quote}, \texttt{quotation})
% \item floats (\texttt{figure}, \texttt{table})
% \item \texttt{tabbing}
% \item computer code (\texttt{verbatim}, \texttt{lstlisting})
% \end{itemize}
% By convention, these objects are either identified by their own identifier
% or through the paragraph that preceedes them.
%
% \begin{variable}{PhiMiSci@Paragraph}
% A paragraph counter. It is set to reset at every section, so that paragraphs
% are not counted throughout the paper, but separately for each section.
% \end{variable}
%    \begin{macrocode}
\newcounter{ PhiMiSci@Paragraph } [ section ]
%    \end{macrocode}
% \begin{function}{\PhiMiSci@PrintParNum}
% Provides a template to print the current value of \cmd{PhiMiSci@Paragraph}.
% \end{function}
%    \begin{macrocode}
\NewDocumentCommand {\PhiMiSci@PrintParNum} {}
  {
    \makebox[0pt][r]{ 
                      \color{gray}               
                      \oldstylenums{\thePhiMiSci@Paragraph\hspace*{1.5em}} 
                    }
  }
%    \end{macrocode}
% \begin{function}{\PhiMiSci@AddParNum, \PhiMiSci@RemoveParNum}
% Functions that add and remove counting to the hook \texttt{para/begin}.
% \end{function}
%    \begin{macrocode}
\NewDocumentCommand {\PhiMiSci@AddParNum} {}
  {
    \AddToHook {para/begin} [PhiMiSciParNumber]
     {
       \bool_if:NF \l__phimisci_koma_head_mode_bool
         {
           \refstepcounter{PhiMiSci@Paragraph}
           \PhiMiSci@PrintParNum{}
         }
     }
  }
  
\NewDocumentCommand {\PhiMiSci@RemoveParNum} {}
  {
    \RemoveFromHook {para/begin} [PhiMiSciParNumber]
  }
%    \end{macrocode}
% \begin{function}{\PhiMiSci@ParNumSwitch}
% \begin{syntax}
% \cs{PhiMiSci@ParNumSwitch} \marg{comma~separated~list}
% \end{syntax}
% Functions to add hooks from the list of objects that are ignored for counting.
% \end{function}
%    \begin{macrocode}
\NewDocumentCommand {\PhiMiSci@ParNumSwitch} {m}
  {
    \AddToHook { #1/before } [PhiMiSciParNumber] { \PhiMiSci@RemoveParNum{} }
    \AddToHook { #1/after } [PhiMiSciParNumber] { \PhiMiSci@AddParNum{} }
  }
%    \end{macrocode}
% \begin{function}{\PhiMiSci@ParNumSwitchDisable }
% \begin{syntax}
% \cs{PhiMiSci@ParNumSwitchDisable} \marg{comma~separated~list}
% \end{syntax}
% Functions to remove hooks from the list of objects that are ignored for 
% counting.
% \end{function}
%    \begin{macrocode}
\NewDocumentCommand {\PhiMiSci@ParNumSwitchDisable} {m}
  {
      \RemoveFromHook { #1/before } [PhiMiSciParNumber]
      \RemoveFromHook { #1/after } [PhiMiSciParNumber]
  }
%    \end{macrocode}
% \begin{function}{\PhiMiSci@ParNumSwitchKOMA }
% \begin{syntax}
% \cs{PhiMiSci@ParNumSwitchKOMA} \marg{KOMA~hook}
% \end{syntax}
% Functions to add and remove hooks.
% \end{function}
%    \begin{macrocode}
\NewDocumentCommand {\PhiMiSci@ParNumSwitchKOMA} {m}
  {
    \AddtoDoHook { heading/begingroup/#1 } { \PhiMiSci@RemoveParNum{} }
    \AddtoDoHook { heading/endgroup/#1 } { \PhiMiSci@AddParNum{} }
  }
%    \end{macrocode}
% \begin{function}{\PhiMiSci@DetectKomaHeader}
% A macro that is executed in \cls{scrartcl}'s header and footer. It prevents
% the paragraphs created there from being counted.
% \end{function}
%    \begin{macrocode}
\NewDocumentCommand{\PhiMiSci@DetectKomaHeader} {}
  {
    \bool_set_true:N \l__phimisci_koma_head_mode_bool
  }
%    \end{macrocode}
% \begin{function}{PhiMiSciNumberedParagraphs}
% An environment for encapsulating content in which the paragraphs are counted.
% Initialisation is made through commands previously defined in this section.
% \end{function}
%    \begin{macrocode}
\NewDocumentEnvironment { PhiMiSciNumberedParagraphs } {}
  {%
    \tl_concat:NNN \l__phimisci_parnum_excluded_objects_combined_tl
                   \l__phimisci_parnum_excluded_objects_base_tl
                   \l__phimisci_parnum_excluded_objects_tl
    \parindent=0pt
    \parskip=.5\baselineskip
    \PhiMiSci@AddParNum{}
    \PhiMiSci@ParNumSwitch{env/quote}
    \PhiMiSci@ParNumSwitch{env/quotation}
    \PhiMiSci@ParNumSwitch{env/table}
    \PhiMiSci@ParNumSwitch{env/figure}
    \PhiMiSci@ParNumSwitch{env/list}
    \PhiMiSci@ParNumSwitch{env/enumerate}
    \PhiMiSci@ParNumSwitch{env/itemize}
    \PhiMiSci@ParNumSwitch{env/description}
    \PhiMiSci@ParNumSwitch{env/lstlisting}
    \PhiMiSci@ParNumSwitch{env/verbatim}
    \PhiMiSci@ParNumSwitch{env/tabbing}
    \PhiMiSci@ParNumSwitchKOMA{section}
    \PhiMiSci@ParNumSwitchKOMA{subsection}
    \PhiMiSci@ParNumSwitchKOMA{subsubsection}
  }
  {%
    \PhiMiSci@RemoveParNum{}
    \PhiMiSci@ParNumSwitchDisable{env/quote}
    \PhiMiSci@ParNumSwitchDisable{env/quotation}
    \PhiMiSci@ParNumSwitchDisable{env/table}
    \PhiMiSci@ParNumSwitchDisable{env/figure}
    \PhiMiSci@ParNumSwitchDisable{env/list}
    \PhiMiSci@ParNumSwitchDisable{env/enumerate}
    \PhiMiSci@ParNumSwitchDisable{env/itemize}
    \PhiMiSci@ParNumSwitchDisable{env/description}
    \PhiMiSci@ParNumSwitchDisable{env/lstlisting}
    \PhiMiSci@ParNumSwitchDisable{env/verbatim}
    \PhiMiSci@ParNumSwitchDisable{env/tabbing}
  }
%    \end{macrocode}
%    \begin{macrocode}
\ExplSyntaxOff
%</class>
%    \end{macrocode}
% \section*{Acknowledgments}
% \addcontentsline{toc}{section}{Acknowledgments}
% The development of this class was funded by the DFG (project no. 514161146).
% \printbibliography[heading=bibintoc]
