% ============================================================
% beamertheme-niederrhein.sty
% Generic beamer theme in the style of Hochschule Niederrhein /
% Wirtschaftsingenieurwesen. Defines the slide types: title slide,
% section-divider slide, ordinary content slides with a source-
% citation line, and image slides with two, three or four images
% (each with one shared caption).
%
% This theme only covers the visual presentation (house colors,
% logo, slide types, bibliography styling). It does not load
% biblatex and does not configure a bibliography backend or
% resource file -- that is the document's job. See
% beamertheme-niederrhein-doc.pdf or hsnr-example.tex for a minimal
% biblatex setup that matches this theme's styling.
%
% The placeholder logo shipped with this package (hsnr-logo.png) is
% a generic graphic created for this package and released under the
% same license as the rest of the Work; it does not depict any
% institution's actual logo or mark. Institutions wishing to use
% their own real logo can replace hsnr-logo.png (or point
% \logofile{...} at a different file).
%
% Copyright 2026 Alexander Rachmann
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   https://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status 'maintained'.
%
% The Current Maintainer of this work is Alexander Rachmann
% (alexander.rachmann@hs-niederrhein.de).
%
% This work consists of the file beamertheme-niederrhein.sty and
% the image file hsnr-logo.png.
% ============================================================

\NeedsTeXFormat{LaTeX2e}

% Theme version. Printable with \themeversion (e.g. on a slide or in
% the footline), e.g. \themeversion\ or Version~\themeversion.
\newcommand{\themeversion}{1.6}
\newcommand{\version}{\themeversion}

\ProvidesPackage{beamertheme-niederrhein}[2026/11/19 v1.6 Generic Niederrhein-style Beamer Theme]

% -----------------------------------------------------------
% House colors and logo support (no external support package
% needed). The logo is always loaded from an external image file;
% see the "Logo" section below.
% -----------------------------------------------------------
\RequirePackage{xcolor}
\RequirePackage{graphicx}
\DeclareGraphicsRule{.svg}{pdf}{.pdf}{}

% -----------------------------------------------------------
% Colors
% -----------------------------------------------------------
\definecolor{themedarkblue}{RGB}{41,80,140}
\definecolor{themelightblue}{RGB}{72,159,220}

% -----------------------------------------------------------
% Logo
% By default a file "hsnr-logo.png" is expected next to your own
% .tex file (changeable via \logofile{...}, e.g. \logofile{mylogo}).
% The path is resolved relative to the main document, not to this
% file, since \includegraphics always resolves paths relative to
% the compiled main document. This applies with every engine
% (pdflatex, xelatex, lualatex) -- the theme does not embed or
% generate the logo itself.
%
% The logo shipped here (hsnr-logo.png) is a generic placeholder
% graphic, not a real institutional logo -- see the license notice
% at the top of this file.
% -----------------------------------------------------------
\newcommand{\logofile}[1]{\renewcommand{\@logofile}{#1}}
\newcommand{\@logofile}{hsnr-logo}

\newcommand{\themelogo}[1][0.20\paperwidth]{\includegraphics[width=#1]{\@logofile}}
\RequirePackage{tikz}
\RequirePackage[T1]{fontenc}
\RequirePackage{helvet}
\renewcommand{\familydefault}{\sfdefault}

% -----------------------------------------------------------
% Basic settings
% -----------------------------------------------------------
\setbeamertemplate{navigation symbols}{}
\setbeamercolor{background canvas}{bg=white}
\setbeamercolor{normal text}{fg=themedarkblue}

% -----------------------------------------------------------
% Bibliography styling
% This theme only styles the bibliography visually -- it does not
% load biblatex and does not call \addbibresource. Load biblatex
% (with the backend and citation style of your choice) and your
% .bib file(s) in your own document preamble; see
% beamertheme-niederrhein-doc.pdf or hsnr-example.tex for a working
% example (backend=bibtex8, style=authoryear).
% -----------------------------------------------------------
\setbeamertemplate{bibliography item}{\textcolor{themedarkblue}{\textbullet}}
\setbeamercolor{bibliography entry author}{fg=themedarkblue}
\setbeamercolor{bibliography entry title}{fg=themedarkblue}
\setbeamercolor{bibliography entry location}{fg=themedarkblue}
\setbeamercolor{bibliography entry note}{fg=themedarkblue}
% \AtBeginBibliography is a biblatex macro. biblatex is loaded by the
% document, not by this theme, and typically after \usepackage{
% beamertheme-niederrhein} -- so this call is deferred to
% \AtBeginDocument, by which point the document's own \usepackage{
% biblatex} in the preamble has already run. If the document does not
% load biblatex at all, this line is simply skipped.
\AtBeginDocument{%
  \@ifpackageloaded{biblatex}{%
    \AtBeginBibliography{\footnotesize\color{themedarkblue}\setlength{\bibhang}{0pt}\setlength{\leftmargin}{1.5em}\setlength{\itemindent}{0pt}\setlength{\bibitemsep}{0.8em}\raggedright\hypersetup{citecolor=themedarkblue,linkcolor=themedarkblue,urlcolor=themedarkblue}}%
  }{}%
}

% -----------------------------------------------------------
% Footline fields ("Author Name -- Course Name. Slide n.")
% \shortauthor does not add any title or form of address -- if you
% want "Prof. Dr. Lastname" or similar in the footline, include it
% in the argument yourself, e.g. \shortauthor{Prof. Dr. Lastname}.
% -----------------------------------------------------------
\newcommand{\shortauthor}[1]{\renewcommand{\@shortauthor}{#1}}
\newcommand{\@shortauthor}{Author Name}
\newcommand{\coursename}[1]{\renewcommand{\@coursename}{#1}}
\newcommand{\@coursename}{Course Name}

% -----------------------------------------------------------
% Source line: a narrow text box directly above the footline, same
% font size as the footline (\tiny). Call it anywhere in the frame,
% e.g. \sourceline{Own illustration}.
%
% \sourceline{} only remembers the text -- it is printed further
% below together with the footline, in the same tikzpicture. Only
% this way do both lines end up at exactly the same x-position: a
% separate tikzpicture at the call site inside the frame content
% would end up offset by a hair due to beamer's internal boxes,
% despite identical coordinates. The definition is deliberately
% global (\global\def), because beamer only draws the footline at
% shipout time -- i.e. after the frame (and with it a merely local
% definition) has already closed again. It is reset after output so
% it does not carry over to the next slide.
% -----------------------------------------------------------
\newcommand{\@sourceline}{}
\newcommand{\@sourcelinewidth}{0.68\paperwidth}
\newcommand{\sourceline}[2][0.68\paperwidth]{%
  \global\def\@sourcelinewidth{#1}%
  \global\def\@sourceline{#2}%
}

% -----------------------------------------------------------
% Footline + logo bottom right (for content slides)
% -----------------------------------------------------------
\setbeamertemplate{footline}{%
  % The actual content is drawn via an "overlay" and therefore
  % contributes no height of its own. So that beamer still reserves
  % space at the bottom (among other things for \sourceline{} and
  % automatic page breaks with [allowframebreaks]), invisible
  % reserved height is inserted here as well.
  \rule{0pt}{0.1\paperheight}%
  \begin{tikzpicture}[remember picture, overlay]
    \node[anchor=south west, xshift=0.07\paperwidth, yshift=0.082\paperheight,
          text=themedarkblue, font=\tiny] at (current page.south west)
          {\@shortauthor\ -- \@coursename.\ Slide~\insertframenumber.};
    \node[anchor=south east, xshift=-0.05\paperwidth, yshift=0.045\paperheight]
      at (current page.south east) {\themelogo};
    \ifx\@sourceline\@empty\else
      \node[anchor=south west, xshift=0.07\paperwidth, yshift=0.11\paperheight,
            text=themedarkblue, font=\tiny, text width=\@sourcelinewidth,
            align=left] at (current page.south west)
            {\@sourceline};
    \fi
  \end{tikzpicture}%
  \global\let\@sourceline\@empty
}

% -----------------------------------------------------------
% Content slide: slide title at the top, light blue, bold -- flush
% with the body text (no extra manual indentation needed, "text
% margin" below already takes care of that).
% -----------------------------------------------------------
\setbeamerfont{frametitle}{series=\bfseries, size=\Large}
\setbeamercolor{frametitle}{fg=themelightblue, bg=white}
\setbeamertemplate{frametitle}{%
  \vskip0.35cm
  \insertframetitle\par
  \vspace{0.2cm}
}

% Itemize: bullet points and text in the same house color.
\setbeamertemplate{itemize item}{\textcolor{themedarkblue}{\textbullet}}
\setbeamertemplate{itemize subitem}{\textcolor{themedarkblue}{\textendash}}
\setbeamercolor{itemize item}{fg=themedarkblue}
\setbeamercolor{itemize subitem}{fg=themedarkblue}
\setbeamercolor{itemize/enumerate body}{fg=themedarkblue}
\setbeamercolor{itemize/enumerate subbody}{fg=themedarkblue}

\setbeamersize{text margin left=0.07\paperwidth, text margin right=0.06\paperwidth}

% A plain \begin{frame}{Title} ... \end{frame} is therefore already
% a "content slide" in the intended style.

% -----------------------------------------------------------
% Title slide
% \titleslide{Title}{Subtitle}{Author}
% -----------------------------------------------------------
\newcommand{\titleslide}[3]{%
  \begin{frame}[plain]
    \begin{tikzpicture}[remember picture, overlay]
      \node[anchor=north west, xshift=0.07\paperwidth, yshift=-0.27\paperheight,
            text=themedarkblue, font=\bfseries\fontsize{32}{38}\selectfont,
            align=left, text width=0.82\paperwidth, inner sep=0pt]
            at (current page.north west) {#1};
      \node[anchor=north west, xshift=0.07\paperwidth, yshift=-0.63\paperheight,
            text=themedarkblue, font=\bfseries\large, inner sep=0pt]
            at (current page.north west) {#2};
      \node[anchor=north west, xshift=0.07\paperwidth, yshift=-0.695\paperheight,
            text=themelightblue, font=\bfseries\large, inner sep=0pt]
            at (current page.north west) {#3};
      \node[anchor=south west, xshift=0.07\paperwidth, yshift=0.038\paperheight,
            text=themedarkblue, font=\tiny] at (current page.south west)
            {\@shortauthor\ -- \@coursename.\ Slide~\insertframenumber.};
      \node[anchor=south east, xshift=-0.05\paperwidth, yshift=0.045\paperheight]
        at (current page.south east) {\themelogo};
    \end{tikzpicture}
  \end{frame}%
}

% -----------------------------------------------------------
% Section divider
% \sectionslide{Text}
% -----------------------------------------------------------
\newcommand{\sectionslide}[1]{%
  \begin{frame}[plain]
    \begin{tikzpicture}[remember picture, overlay]
      \fill[themelightblue] (current page.south west) rectangle (current page.north east);
      \node[anchor=center, text=white, font=\bfseries\fontsize{26}{30}\selectfont]
            at (current page.center) {#1};
    \end{tikzpicture}
  \end{frame}%
}

% -----------------------------------------------------------
% Image slides: two, three or four images plus one shared caption
% below them (no image gets its own caption -- there is exactly one
% for the whole slide). Images are included via \includegraphics and
% always keep their aspect ratio (keepaspectratio); width and height
% are constrained so that portrait images do not overflow the slide
% either.
%
% \twoimages{Title}{Image1}{Image2}{Caption}
% \threeimages{Title}{TopLeft}{TopRight}{Bottom}{Caption}
% \fourimages{Title}{TopLeft}{TopRight}{BottomLeft}{BottomRight}{Caption}
% -----------------------------------------------------------
\newcommand{\imagecaption}[1]{%
  \par\vspace{0.4cm}
  {\footnotesize\color{themedarkblue} #1\par}
}

% Two images side by side
\newcommand{\twoimages}[4]{%
  \begin{frame}{#1}
    \begin{center}
      \begin{minipage}[t]{0.47\textwidth}
        \centering
        \includegraphics[width=\linewidth, height=0.42\paperheight, keepaspectratio]{#2}
      \end{minipage}\hfill
      \begin{minipage}[t]{0.47\textwidth}
        \centering
        \includegraphics[width=\linewidth, height=0.42\paperheight, keepaspectratio]{#3}
      \end{minipage}
      \imagecaption{#4}
    \end{center}
  \end{frame}%
}

% Three images: two on top side by side, one centered below
\newcommand{\threeimages}[5]{%
  \begin{frame}{#1}
    \begin{center}
      \begin{minipage}[t]{0.47\textwidth}
        \centering
        \includegraphics[width=\linewidth, height=0.27\paperheight, keepaspectratio]{#2}
      \end{minipage}\hfill
      \begin{minipage}[t]{0.47\textwidth}
        \centering
        \includegraphics[width=\linewidth, height=0.27\paperheight, keepaspectratio]{#3}
      \end{minipage}
      \par\vspace{0.2cm}
      \begin{minipage}[t]{0.55\textwidth}
        \centering
        \includegraphics[width=\linewidth, height=0.27\paperheight, keepaspectratio]{#4}
      \end{minipage}
      \imagecaption{#5}
    \end{center}
  \end{frame}%
}

% Four images: two on top, two below (2x2 grid)
\newcommand{\fourimages}[6]{%
  \begin{frame}{#1}
    \begin{center}
      \begin{minipage}[t]{0.47\textwidth}
        \centering
        \includegraphics[width=\linewidth, height=0.27\paperheight, keepaspectratio]{#2}
      \end{minipage}\hfill
      \begin{minipage}[t]{0.47\textwidth}
        \centering
        \includegraphics[width=\linewidth, height=0.27\paperheight, keepaspectratio]{#3}
      \end{minipage}
      \par\vspace{0.2cm}
      \begin{minipage}[t]{0.47\textwidth}
        \centering
        \includegraphics[width=\linewidth, height=0.27\paperheight, keepaspectratio]{#4}
      \end{minipage}\hfill
      \begin{minipage}[t]{0.47\textwidth}
        \centering
        \includegraphics[width=\linewidth, height=0.27\paperheight, keepaspectratio]{#5}
      \end{minipage}
      \imagecaption{#6}
    \end{center}
  \end{frame}%
}

\endinput
