% \iffalse meta-comment -------------------------------------------------------
% Copyright 2015 Matthias Vogelgesang and the LaTeX community. A full list of
% contributors can be found at
%
%     https://github.com/matze/mtheme/graphs/contributors
%
% and the original template was based on the HSRM theme by Benjamin Weiss.
%
% This work is licensed under a Creative Commons Attribution-ShareAlike 4.0
% International License (https://creativecommons.org/licenses/by-sa/4.0/).
%% --------------------------------------------------------------------------- 
%% Copyright 2024 Johan Larsson and contributors
% ------------------------------------------------------------------------- \fi
% \iffalse
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{beamerouterthememoloch}[2025-09-25 v1.1.0 Moloch outer theme]
%</package>
% \fi
% \CheckSum{0}
% \StopEventually{}
% \iffalse
%<*package>
% ------------------------------------------------------------------------- \fi
%
% \subsection{\themename outer theme}
%
% A |beamer| outer theme dictates the style of the frame elements traditionally
% set outside the body of each slide: the head, footline, and frame title.
%
%
%
% \subsubsection{Package dependencies}
%
%    \begin{macrocode}
\RequirePackage{calc}
\RequirePackage{pgfopts}
%    \end{macrocode}
%
%
% \subsubsection{Memoization and Tikz Externalization}
%
% To avoid generating externalized figures of the progressbar we have to disable
% them with ``tikzexternalenable'' and ``tikzexternaldisable''. However, if the
% ``external'' library is not loaded we would get undefined control sequence
% problems, hence we define them as no-ops if they are not defined yet.
% We do the same for the ``mmzUnmemoizable'' command from the memoize package, in
% order to avoid memoization of the progress bars.
%
%    \begin{macrocode}
\providecommand{\tikzexternalenable}{}
\providecommand{\tikzexternaldisable}{}
\providecommand{\mmzUnmemoizable}{}
%    \end{macrocode}
%
% \subsubsection{Options}
%
% \begin{macro}{progressbar}
%    Adds a progress bar to the top, bottom, or frametitle of each slide.
%    \begin{macrocode}
\pgfkeys{
  /moloch/outer/progressbar/.cd,
  .is choice,
  none/.code={%
      \setbeamertemplate{headline}[plain]
      \setbeamertemplate{frametitle}[plain]
      \setbeamertemplate{footline}[plain]
    },
  head/.code={\pgfkeys{/moloch/outer/progressbar=none}
      \addtobeamertemplate{headline}{}{%
        \usebeamertemplate*{progress bar in head/foot}
      }
    },
  frametitle/.code={\pgfkeys{/moloch/outer/progressbar=none}
      \addtobeamertemplate{frametitle}{}{%
        \usebeamertemplate*{progress bar in head/foot}
      }
    },
  foot/.code={\pgfkeys{/moloch/outer/progressbar=none}
      \addtobeamertemplate{footline}{}{%
        \usebeamertemplate*{progress bar in head/foot}%
      }
    },
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{progressbar linewidth}
%    Sets the linewidth of the progress bar for sectionpages and frames.
%    \begin{macrocode}
\newlength{\moloch@progressonsectionpage}
\newlength{\moloch@progressonsectionpage@linewidth}
\newlength{\moloch@progressinheadfoot}
\newlength{\moloch@progressinheadfoot@linewidth}
\pgfkeys{
  /moloch/outer/.cd,
  progressbarlinewidth/.code={
      \setlength{\moloch@progressonsectionpage@linewidth}{#1}
      \setlength{\moloch@progressinheadfoot@linewidth}{#1}
    },
  progressbarlinewidth/.default=0.4pt,
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{progressbar aliases}
%    Allows |progressbar linewidth| to be used in |\molochset|.
%    \begin{macrocode}
\pgfkeys{
  /moloch/outer/.cd,
  progressbar linewidth/.code=\pgfkeysalso{progressbarlinewidth=#1},
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\moloch@outer@setdefaults}
%    Sets default values for outer theme options.
%    \begin{macrocode}
\newcommand{\moloch@outer@setdefaults}{
  \pgfkeys{/moloch/outer/.cd,
    progressbar=none,
    progressbar linewidth=0.4pt,
  }
}
%    \end{macrocode}%
% \end{macro}
%
% \subsubsection{Deprecated Options}
%
% These options are deprecated and will be removed in a future version.
%
% \begin{macro}{numbering}
%    Adds slide numbers to the bottom right of each slide.
%    \begin{macrocode}
\pgfkeys{
  /moloch/outer/numbering/.cd,
  .is choice,
  none/.code={%
      \PackageWarning{moloch}{The ``numbering'' option is deprecated.
        Use beamer's ``page number in head/foot'' template instead}%
      \setbeamertemplate{page number in head/foot}[default]
    },
  counter/.code={%
      \PackageWarning{moloch}{The ``numbering'' option is deprecated.
        Use beamer's ``page number in head/foot'' template instead}%
      \setbeamertemplate{page number in head/foot}[framenumber]
    },
  fraction/.code={%
      \PackageWarning{moloch}{The ``numbering'' option is deprecated.
        Use beamer's ``page number in head/foot'' template instead}%
      \setbeamertemplate{page number in head/foot}[totalframenumber]
    },
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Slide Numbering}
%
% Moloch defaults to numbering frames. To modify this, simply copy this line to your
% preamble and replace |framenumber|.
%
%    \begin{macrocode}
\setbeamertemplate{page number in head/foot}[framenumber]
%    \end{macrocode}
%
% \subsubsection{Head and footline}
%
% All good |beamer| presentations should already remove the navigation symbols,
% but \themename removes them automatically (just in case).
%
%    \begin{macrocode}
\setbeamertemplate{navigation symbols}{}
%    \end{macrocode}
%
%
% \begin{macro}{headline}
% \begin{macro}{footline}
%    Templates for the head- and footline at the top and bottom of each frame.
%    \begin{macrocode}
\defbeamertemplate{headline}{plain}{}
\defbeamertemplate{footline}{plain}{%
  \begin{beamercolorbox}[
      leftskip=4pt,%
      rightskip=5pt,%
      wd=\textwidth,%
    ]{footline}%
    \usebeamercolor[fg]{page number in head/foot}%
    \usebeamerfont{page number in head/foot}%
    \usebeamertemplate*{frame footer}%
    \hfill%
    \usebeamertemplate*{page number in head/foot}\vskip4pt%
  \end{beamercolorbox}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
%
% \subsubsection{Frametitle}
%
% \begin{macro}{frametitle}
%    Templates for the frame title, which is optionally underlined with a
%    progress bar.
%    \begin{macrocode}
\newlength{\moloch@frametitle@padding}
\setlength{\moloch@frametitle@padding}{2ex}
\newcommand{\moloch@frametitlestrut@start}{%
  \rule{0pt}{\moloch@frametitle@padding + \ht\strutbox}%
}%

\newcommand{\moloch@frametitlestrut@end}{%
  \rule[-\moloch@frametitle@padding]{0pt}{\moloch@frametitle@padding}%
}
\defbeamertemplate{frametitle}{plain}{%
  \nointerlineskip%
  \begin{beamercolorbox}[%
      wd=\paperwidth,%
      leftskip=1.6ex,%
      rightskip=\the\glueexpr 1.6ex plus 1fil\relax,%
    ]{frametitle}%
    \usebeamerfont{frametitle}%
    \moloch@frametitlestrut@start%
    \moloch@frametitleformat{\insertframetitle}%
    {%
      \ifx\insertframesubtitle\@empty%
        \else%
        {%
          \par%
          \usebeamerfont{framesubtitle}%
          \vspace{-0.8ex}%
          \usebeamercolor[fg]{framesubtitle}%
          \insertframesubtitle%
        }%
      \fi
    }%
    \moloch@frametitlestrut@end%
  \end{beamercolorbox}%
}
\setbeamertemplate{frametitle continuation}{%
  \romannumeral\insertcontinuationcount}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{progress bar in head/foot}
%    Template for the progress bar optionally displayed below the frame title
%    on each page. Much of this code is duplicated in the inner theme's
%    template |progress bar in section page|.
%    \begin{macrocode}
\setbeamertemplate{progress bar in head/foot}{
  \nointerlineskip%
  \pgfmathsetlength{\moloch@progressinheadfoot}{%
    \paperwidth * min(1,\insertframenumber/\inserttotalframenumber)%
  }%
  \begin{beamercolorbox}[wd=\paperwidth]{progress bar in head/foot}
    \tikzexternaldisable%
    \begin{tikzpicture}
      \mmzUnmemoizable%
      \fill[bg]
      (0,0)
      rectangle
      (\paperwidth, \moloch@progressinheadfoot@linewidth);
      \fill[fg]
      (0,0)
      rectangle
      (\moloch@progressinheadfoot, \moloch@progressinheadfoot@linewidth);
    \end{tikzpicture}
    \tikzexternalenable%
  \end{beamercolorbox}
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Process package options}
%
%    \begin{macrocode}
\moloch@outer@setdefaults
\ProcessPgfPackageOptions{/moloch/outer}
%    \end{macrocode}
%
% \iffalse
%</package>
% \fi
% \Finale
\endinput
