%% *****************************************************************************
%%            Copyright 2024 by M.Y. XIA <xiamyphys@gmail.com>                 *
%%                                                                             *
%%   This work may be distributed and/or modified under the conditions of the  *
%%   LaTeX Project Public License                                              *
%%                                                                             *
%%               http://www.latex-project.org/lppl.txt                         *
%%                                                                             *
%%   either version 1.3c of this license or any later version.                 *
%%                                                                             *
%%   This work has the LPPL maintenance status `maintained'.                   *
%%                                                                             *
%%   The Current Maintainers of this work is M.Y. XIA                          *
%%                                                                             *
%%   This work consists of the files hduthesis.cls,                            *
%%                                   hduthesis-typeset-module.code,            *
%%                                   hduthesis-layout-module.code,             *
%%                                   hduthesis-bc.config-module.code,          *
%%                                   hduthesis-pg.config-module.code,          *
%%                                   hduthesis-hdu.l3doc-module.code,          *
%%                                   hduthesis-hdu.stationery-module.code,     *
%%                                   beamerthemehdu.sty,                       *
%%                               and README.md.                                *
%%   available at https://github.com/myhsia/hduthesis                          *
%% *****************************************************************************
\mode<presentation>

% info keyval
\RequirePackage{keyval,tikz,graphicx}
\usetikzlibrary{arrows,fadings,decorations.pathreplacing}
\tikzset{%
    every picture/.append style = {%
        line join = round, line cap = round, thick
    }
}
\graphicspath
  {
    {./figure/}{./figures/}{./image/}{./images/}
    {./graphics/}{./graphic/}{./pictures/}{./picture/}
  }

\ExplSyntaxOn

\keys_define:nn { infoset }
  {
    title     .tl_set:N = \@title,
    subtitle  .tl_set:N = \l__infoset_subtitle_tl,
    author    .tl_set:N = \@author,
    date      .tl_set:N = \@date,
    supervisor.tl_set:N = \l__infoset_supervisor_tl,
    reference .tl_set:N = \l__infoset_reference_tl,
  }
\NewDocumentCommand \infoset { m }
  {
    \keys_set:nn { infoset } { #1 }
    \title { \large \@title }
    \tl_set:Nn \insertshorttitle { \textsc { \l__infoset_subtitle_tl } }
    \author [ \@author ]
      {
        \@author
        \tl_if_empty:NF \l__infoset_supervisor_tl
          { 
            \texorpdfstring
              { \\[2ex] \small Supervised~by~\l__infoset_supervisor_tl }{}
          }
      }
    \date { \@date }
    \tl_if_empty:NF \l__infoset_reference_tl
      {
        \RequirePackage
          [ backend = biber, bibstyle = numeric, citestyle = numeric-comp,
            autocite = superscript, sorting = none
          ] { biblatex }
        \addbibresource { \l__infoset_reference_tl }
        \newcommand* \mkbibbracketsuperscript[1]
          { \mkbibsuperscript { \mkbibbrackets{#1} } }
        \DeclareCiteCommand \supercite [\mkbibbracketsuperscript]
          {
            \usebibmacro{cite:init}
            \let\multicitedelim=\supercitedelim
            \let\multicitesubentrydelim=\supercitesubentrydelim
            \let\multiciterangedelim=\superciterangedelim
            \let\multicitesubentryrangedelim=\supercitesubentryrangedelim
            \iffieldundef{prenote}{}
            {\BibliographyWarning{Ignoring prenote argument}}%
            \iffieldundef{postnote}{}
            {\BibliographyWarning{Ignoring postnote argument}}
          }
          {\usebibmacro{citeindex}\usebibmacro{cite:comp}}{}
          {\usebibmacro{cite:dump}}
      }
  }

\usebackgroundtemplate
  {
    \tikz [ remember~picture, overlay ]
      \node [ inner~sep = 0pt, outer~sep = auto, opacity = .1, xshift = -2em ]
       at (current~page.east)
       { \includegraphics [ height = .75\paperheight ] { hdulogo.pdf } };
  }
\titlegraphic
  {
    \tikz [ remember~picture, overlay ]
      \node [ below~right, yshift = -1em ] at (current~page.north~west) 
        { \includegraphics [ width = \textwidth/3 ]{ hdubadge.pdf } };
  }
\ExplSyntaxOff

% theme & colors
\useoutertheme{infolines}
\useinnertheme[shadow=false]{rounded}
\definecolor{hdu}{HTML}{214395}
\definecolor{hduRed}{HTML}{BF6236}
\usecolortheme[named=hdu]{structure}

\setbeamercolor*{palette primary}{use=structure,fg=black,bg=structure.fg!40!white}
\setbeamercolor*{palette secondary}{use=structure,fg=white,bg=structure.fg!60!white}
\setbeamercolor*{palette tertiary}{use=structure,fg=white,bg=structure.fg!90!white}

\setbeamercolor{block title}{use=structure,fg=structure.fg,bg=structure.fg!20!bg}
\setbeamercolor{block title alerted}{use=alerted text,fg=alerted text.fg,bg=alerted text.fg!20!bg}
\setbeamercolor{block title example}{use=example text,fg=example text.fg,bg=example text.fg!20!bg}
\setbeamercolor{block body}{parent=normal text,use=block title,bg=block title.bg!50!bg}
\setbeamercolor{block body alerted}{parent=normal text,use=block title alerted,bg=block title alerted.bg!50!bg}
\setbeamercolor{block body example}{parent=normal text,use=block title example,bg=block title example.bg!50!bg}

\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{page number in head/foot}{}
\addtobeamertemplate{headline}{}{
  \tikz[remember picture, overlay]{
    \filldraw [hduRed, ultra thick, line cap = butt] (0,0) --++ (\paperwidth*\fpeval{\insertpagenumber-1}/\fpeval{\insertdocumentendpage-1},0);
    \draw [white, very thick, yshift = -.6pt] (0,0) --++ (\paperwidth,0);
  }
}

\AtBeginSection[]{
  \begin{frame}
    \ifcsname @headlogo\endcsname
      \tikz [remember picture, overlay] \node [below right,yshift=-1em] at (current page.north west) {\includegraphics[width=\textwidth/3]{\@headlogo}};
    \fi
    \vfill
    \usebeamerfont{title}\insertsectionhead\par%
    \tikz{
        \draw [hdu!20, ultra thick] (0,0) --++ (2*\linewidth/3,0);
        \filldraw [hdu!60, ultra thick, path fading=west] (0,0) --++ (2*\linewidth*\fpeval{\insertframenumber-1}/\fpeval{\inserttotalframenumber-1}/3,0);
    }
  \vfill
  \end{frame}
}

\addtobeamertemplate{block begin}{\pgfsetfillopacity{0.75}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block alerted begin}{\pgfsetfillopacity{0.75}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block example begin}{\pgfsetfillopacity{0.75}}{\pgfsetfillopacity{1}}

\setbeamercolor{title}{parent=author in head/foot}
\setbeamertemplate{title page}[default][colsep=-4bp,rounded=true]
\usesubitemizeitemtemplate{%
    \tiny\raise1.5pt\hbox{\color{beamerstructure}$\blacktriangleright$}%
}
\usesubsubitemizeitemtemplate{%
    \tiny\raise1.5pt\hbox{\color{beamerstructure}$\bigstar$}%
}
% \setbeamersize{text margin left = 1em, text margin right=1em}

% math settings
\numberwithin{equation}{section}
\RequirePackage[mono=false]{libertine}
\RequirePackage{keytheorems,amssymb,mathtools,physics2,fixdif,derivative,cancel,siunitx,nicematrix}
\renewcommand\qedsymbol{$\color{gray}\blacksquare$}
\usephysicsmodule{ab,ab.braket,diagmat,doubleprod,xmat,ab.legacy,op.legacy}
\RequirePackage[e]{esvect}
\let\vec\vv
\def\i{\mathrm i}\def\e{\mathrm e}\def\T{\mathsf T}
\let\leq\leqslant\let\geq\geqslant

% Figure settings
\RequirePackage[labelsep=period,figurename=FIG,font=footnotesize]{caption}
\RequirePackage{subcaption,booktabs}
\captionsetup{belowskip=0pt}
\captionsetup[sub]{font=scriptsize}
\RequirePackage{anyfontsize}
\renewcommand{\raggedright}{\leftskip=0pt \rightskip=0pt plus 0cm}
\RequirePackage{ragged2e}
\justifying
\AtBeginEnvironment{columns}{\vspace*{-.5ex}}

\mode<all>
\endinput