% -*- coding: utf-8 -*-
%
% Some font hacks for my Sphinx PDF documents
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{my-doc-style}[%
  2026/05/17 v0.3 (Franz Glasner) Some style customizations (title et al.)]
\RequirePackage{xkeyval}

% A key compatible with options processing but bool (because DeclareBoolOptionX)
% If given than the Sphinx standard titlepage is used without changes.
\define@boolkey{my-doc-style.sty}{stdtitle}[true]{}

\ExecuteOptionsX{stdtitle=false}
\ProcessOptionsX\relax

%
% For the title page: "Last updated on ..."
%
\DeclareRobustCommand*\vcsrevision[1]{\gdef\mds@vcs@revision{#1}}
\DeclareRobustCommand*\builddate[1]{\gdef\mds@builddate{#1}}
\vcsrevision{}
\builddate{}
%
% If the option "stdtitle" was not enabled augment the titlepage with
% the documentation build date and the VCS revision id.
%
\csname ifKV@my-doc-style.sty@stdtitle\endcsname
  \relax
\else
  % \sphinxmaketitle calls the macro \@thanks: abuse this
  \gdef\@thanks{%
    \ifx\mds@builddate\@empty\relax%
      \ifx\mds@vcs@revision\@empty\relax%
      \else%
        \hfill\normalsize\textsf{(rev\ \mds@vcs@revision )}%
      \fi%
    \else%
      \hfill\normalsize\textsf{Last updated on \mds@builddate%
      \ifx\mds@vcs@revision\@empty\relax\else\enspace(rev\ \mds@vcs@revision )\fi}
    \fi%
  }
\fi

%
% Allow to suppress section numbering for some parts of the document
% (e.g. in changelog entries).
%
% Sphinx employs the "titlesec" package to style its chapter and section
% headings and uses its \titleformat command with a 0.5em separation
% (see \titleformat calls in sphinxlatexstyleheadings.sty).
% So make \the<section> output nothing (e.g. the section number)
% but just a compensation for this whitespace.
%
% Each suppress command suppresses its level and all levels below
% (compare with the \titleformat calls in sphinxlatexstyleheadings.sty).
%
% \EndSuppressNumbering ends exactly one preceding
% \SuppressSubsectionNumbering or \SuppressSubsubsectionNumbering.
%
\def\SuppressSectionNumbering{%
  \begingroup
  \renewcommand\thesection{\hspace{-0.5em}}  
  \renewcommand\thesubsection{\hspace{-0.5em}}
  \renewcommand\thesubsubsection{\hspace{-0.5em}}
  \renewcommand\theparagraph{\hspace{-0.5em}}
  \renewcommand\thesubparagraph{\hspace{-0.5em}}
}
\def\SuppressSubsectionNumbering{%
  \begingroup
  \renewcommand\thesubsection{\hspace{-0.5em}}
  \renewcommand\thesubsubsection{\hspace{-0.5em}}
  \renewcommand\theparagraph{\hspace{-0.5em}}
  \renewcommand\thesubparagraph{\hspace{-0.5em}}
}
\def\SuppressSubsubsectionNumbering{%
  \begingroup
  \renewcommand\thesubsubsection{\hspace{-0.5em}}
  \renewcommand\theparagraph{\hspace{-0.5em}}
  \renewcommand\thesubparagraph{\hspace{-0.5em}}
}
\def\EndSuppressNumbering{%
  \endgroup
}

\endinput
