% From mitthesis package
% Documentation: https://ctan.org/pkg/mitthesis
% This file requires LuaLaTeX

\ProvidesFile{mydesign_libertinus_headings.tex}[2026/11/22 v1.02]

% ==> you can change this however you want. The content below is just for illustration. <==

% This illustration uses fontset=libertinus is selected under >> lualatex <<.
%	 Chapter and section headings use additional font features (historical ligatures, stylistic set 2, and stylistic alternates)
%	 Caption labels are set in boldface.
%
%	 To avoid distracting typographic design, you may want to limit the additional font features to the chapter headings only.
%
% See: https://github.com/alerque/libertinus/blob/a6487570b8fdcfa69557744f5e5c5d044de0a9db/documentation/Opentype-Features.pdf


%%%%%%%%%  Issue error if running pdftex %%%%%%%%%%%%%%%%%%%

\ExplSyntaxOn % Nov. 2026: expl syntax is now off when mydesign loads. Earlier versions had expl3 syntax on.

\sys_if_engine_pdftex:T
	{
	   	  \msg_new:nnn  { \ClassName } { wrong_engine } { Run~lualatex,~not~pdftex,\iow_newline: with~mydesign_libertinus_headings!}
		  \msg_error:nn { \ClassName } { wrong_engine }
		  \providecommand*{\addfontfeatures}[1]{\relax} % avoid a follow-on error
	}
% Note: when expl syntax is in effect, spaces are ignored (if you need a space, use the ~ separator as above.)
\ExplSyntaxOff

%%%%%%%%%%  Color support  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Color package: xcolor. 
%% Change this if you prefer something else

\RequirePackage[dvipsnames,svgnames,x11names]{xcolor}

%% can add option [table] to xcolor to use color in tables (see xcolor documentation)


%%%%%%%%%%  Hyperlink and line number colors  %%%%%%%%%%%%%%

\AtBeginDocument{
    % Using color names from xcolor package
    \hypersetup{
    	linkcolor=Blue3,
    	citecolor=Blue3,
    	urlcolor=violet,
    	filecolor=red,
%    	anchorcolor=yellow,%  not all pdf viewers recognize this field (although Firefox does): hyperref issues a warning, which can be ignored
    	}
    %
    \ifmitthesis@lineno
	    \renewcommand{\linenumberfont}{\sffamily\mdseries\tiny\color{violet}}% line numbers will be sans-serif, medium weight, tiny, and violet
	\fi
}

%%%%%%%%%  Caption support  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
\IfFormatAtLeastTF{2025/11/01}
{
    %% If your latex format is at least 2025/11/01, you should use this approach:
    \NewSocketPlug{caption/label}{plug-bold-quad}{\textbf{#1}\quad} % This strictly addresses the caption label, not caption text.
    \AssignSocketPlug{caption/label}{plug-bold-quad}
    %
    % \AddToHook{cmd/@makecaption/before}{\relax} % Contents of second argument would style the entire caption, but label socket above can override it in the label.
    %
    % These commands make caption label bold, with a space of one quad separating label from text; the hook command is empty.
    %
    % in case caption or subcaption are loaded in preamble, include this hook:
    \AddToHook{package/caption/after}{\captionsetup{labelfont=bf,labelsep=quad}}
}{
    %% For older formats, use the following. See documentation of caption package for details.
    \RequirePackage{caption}
    %% This sets caption labels in bold face type. 
    \captionsetup{labelfont=bf,labelsep=quad}% change to boldface label with separation of one \quad
}


%%%%%%%%%  Customize titles and section headings  %%%%%%%%%%

%% This forces the fontset to libertinus.
\ExplSyntaxOn

\str_if_eq:VnF \g__mitthesis_fontset_tl {libertinus}
	{ 
		\tl_gset:Nn \g__mitthesis_fontset_tl {libertinus}
	}

\ExplSyntaxOff

%% Font features for headings (fontspec keys; see fontspec documentation)
%%   Ligatures=Historic -> hlig;  StylisticSet=2 -> ss02 (J, K, R);  Alternate=0 -> salt
%%
\newcommand*\mydesign@chapterfeatures{\addfontfeatures{Ligatures=Historic,StylisticSet=2,Alternate=0}}
\newcommand*\mydesign@sectionfeatures{\mydesign@chapterfeatures}

\IfFormatAtLeastTF{2026/11/01} % need to use new LaTeX template mechanism for newer formats
  {
   \EditInstance{heading}{chapter}{
     heading-decls = \raggedright \parindent0pt \bfseries \huge \mydesign@chapterfeatures,
     title-decls = \Huge\mydesign@chapterfeatures,
    }
%   \EditInstance{headformat}{chapter}{
%   }
  }{
    \patchcmd{\@makechapterhead}{\Huge}{\mydesign@chapterfeatures\Huge}
        {}{\ClassWarning{\ClassName}{Patch of \string\@makechapterhead\space failed}}
    \patchcmd{\@makechapterhead}{\huge}{\mydesign@chapterfeatures\huge}{}{}
    \patchcmd{\@makeschapterhead}{\Huge}{\mydesign@chapterfeatures\Huge}{}{} % for UNnumbered chapter names
 }

% To directly modify section headings as follows, see https://latexref.xyz/dev/latex2e.html#g_t_005c_0040startsection
% This adds the same font features to section, subsection, and subsubsection headings (compare to report.cls)
% Note - libertinus-math has bold characters, but not a boldface math font (so don't include \mathversion{bold})
%
% To limit the features to chapter headings only, uncomment:
% \renewcommand*\mydesign@sectionfeatures{}

\IfFormatAtLeastTF{2026/11/01} % use new LaTeX template mechanism for newer formats
  {
   \EditInstance{heading}{section}{
     heading-decls = \normalfont\mydesign@sectionfeatures\Large\bfseries\raggedright,
    }
   \EditInstance{heading}{subsection}{
     heading-decls = \normalfont\mydesign@sectionfeatures\large\bfseries\raggedright,
    }
   \EditInstance{heading}{subsubsection}{
     heading-decls = \normalfont\mydesign@sectionfeatures\normalsize\bfseries\raggedright,
    }    
  }{
    \renewcommand\section{\@startsection {section}{1}{\z@}%
                                       {-3.5ex \@plus -1ex \@minus -.2ex}%
                                       {2.3ex \@plus.2ex}%
                                       {\normalfont\mydesign@sectionfeatures\Large\bfseries\raggedright}}
    \renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                       {-3.25ex\@plus -1ex \@minus -.2ex}%
                                       {1.5ex \@plus .2ex}%
                                       {\normalfont\mydesign@sectionfeatures\large\bfseries\raggedright}}
    \renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
                                       {-3.25ex\@plus -1ex \@minus -.2ex}%
                                       {1.5ex \@plus .2ex}%
                                       {\normalfont\mydesign@sectionfeatures\normalsize\bfseries\raggedright}}
  }
