% Article-class styles and page layout for CDSC paper documents.
%
% This file replaces the older cdsc-memoir.sty. It targets the
% standard `article' class so the LaTeX tagging project can produce
% tagged, accessible PDFs --- memoir is currently incompatible with
% that work. The look-and-feel is kept as close to the previous
% cdsc-article chapterstyle as is practical.
%
% Headings and the title block are built from the article class's own
% \@startsection and \@maketitle hooks rather than from titlesec and
% titling. The tagging code hooks into \@startsection to emit the H1,
% H2, and H3 tags a screen reader navigates by; titlesec bypasses that
% hook, so loading it silently produces a PDF with no headings in the
% structure tree. See the Accessibility section of the README.
%
% Copyright 2009-2026 Benjamin Mako Hill <mako@atdot.cc>
% Copyright 2008-2009 Kieran Healy <kjhealy@soc.duke.edu>

% Distributed as free software under the GNU GPL v3

\usepackage{xcolor}

%%% Page styles (replaces memoir's \makepagestyle / \makeevenhead etc.)
\usepackage{fancyhdr}
\setlength{\headheight}{14.5pt}
\addtolength{\topmargin}{-2.5pt}

% Basic: page number in small caps in the upper-right corner
\fancypagestyle{cdsc-page}{%
  \fancyhf{}%
  \fancyhead[R]{\scshape\thepage}%
  \renewcommand{\headrulewidth}{0pt}%
}

% Variant with git revision info in the footer (requires the vc package).
\fancypagestyle{cdsc-page-git}{%
  \fancyhf{}%
  \fancyhead[R]{\scshape\thepage}%
  \fancyfoot[C]{\texttt{\footnotesize\textcolor{BrickRed}{git revision \VCRevision\ on \VCDateTEX}}}%
  \renewcommand{\headrulewidth}{0pt}%
}

% Variant with a build timestamp in the footer (useful on Overleaf/etc.)
\fancypagestyle{cdsc-page-overleaf}{%
  \fancyhf{}%
  \fancyhead[R]{\scshape\thepage}%
  \fancyfoot[C]{\texttt{\footnotesize\textcolor{BrickRed}{Buildstamp/Version:~\today}}}%
  \renewcommand{\headrulewidth}{0pt}%
}

\pagestyle{cdsc-page}

%%% Section heading styles.
%%%
%%% Each heading is declared through \@startsection, which takes:
%%%   {name}{level}{indent}{beforeskip}{afterskip}{style}
%%% A negative beforeskip suppresses the paragraph indent that would
%%% otherwise follow the heading; a negative afterskip makes the
%%% heading run into the paragraph text rather than sit on its own
%%% line. The style argument receives the whole heading as its
%%% argument, so a case-changing command may be appended to it.

\makeatletter

% Sections: large small caps
\renewcommand\section{\@startsection{section}{1}{\z@}%
  {-1.8ex \@plus -1ex \@minus -.2ex}%
  {1.7ex \@plus .2ex}%
  {\large\scshape}}

% Subsections: italic
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
  {-3.25ex \@plus -1ex \@minus -.2ex}%
  {1.5ex \@plus .2ex}%
  {\normalsize\itshape}}

% Subsubsections: small bold, run in to the following paragraph
% (the negative afterskip is what makes it run in)
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
  {-3.25ex \@plus -1ex \@minus -.2ex}%
  {-0.5em}%
  {\small\bfseries}}

% Period after the section number, when numbering is switched on below
\renewcommand{\@seccntformat}[1]{\csname the#1\endcsname.\hspace{0.5em}}

% By default, suppress numbering at the section level (matches the
% memoir template's default of \setsecnumdepth{chapter}). To enable
% numbered sections and subsections, comment the line below and
% uncomment the alternative.
\setcounter{secnumdepth}{0}
% \setcounter{secnumdepth}{2}

%%% Title block: flush left, italic title, author below it.
%%
%% \published{...}: a note about the publication status, printed in
%% small type at the very top of the title block. Use this for
%% draft/working-paper notices.
\newcommand{\puB}{}
\newcommand{\published}[1]{\gdef\puB{#1}}

% \raggedright rather than \flushleft: the flushleft environment is a
% trivlist, and starting one as a bare declaration leaves a list open
% in the structure tree. That produces "the number of automatic begin
% and end text-unit para hooks differ" and a mis-nested PDF.
% The vertical skips reproduce what titling's \pretitle/\posttitle,
% \preauthor/\postauthor, and \predate/\postdate produced. The date
% slot keeps its space even when \date{} is empty, which is what the
% previous title block did and what the template's spacing assumes.
\renewcommand{\@maketitle}{%
  \null
  \vskip 2em%
  \par\noindent\footnotesize\puB\par
  \vskip 0.79em%
  {\raggedright\LARGE\itshape\@title\par}%
  \vskip 1.04em%
  {\raggedright\large\lineskip 1em\@author\par}%
  \vskip 0.79em%
  {\raggedright\footnotesize\@date\par}%
  \vskip 1em%
  \par\vskip 2.44em%
}

\makeatother

%%% Abstract: runin style ("**Abstract:** the quick brown fox..."),
%%% indented from both margins (via the quote environment, which gives
%%% the side indent without adding first-line paragraph indentation).
\renewenvironment{abstract}%
  {\par\addvspace{\medskipamount}\small
   \begin{quote}\noindent\textbf{Abstract:}\hspace{0.5em}\ignorespaces}%
  {\end{quote}\par\medskip}

%%% List spacing (replaces memoir's \firmlists --- tighter lists)
\usepackage{enumitem}
\setlist{topsep=0pt, partopsep=0pt}

%%% Caption font
\usepackage{caption}
\captionsetup{font=small}

%%% Footnote symbol command (for \thanks{} footnotes that should not
%%% have a numeric mark). Use as \symbolfootnote[0]{Footnote text}.
\long\def\symbolfootnote[#1]#2{\begingroup%
  \def\thefootnote{\fnsymbol{footnote}}\footnote[#1]{#2}\endgroup}

\endinput
