% \iffalse meta-comment
%
% File: beamertheme-westlake.dtx
% -----------------------------------------------------------------------
%   Copyright (C) 2026 by Mingyu Xia <myhsia@outlook.com>               *
% -----------------------------------------------------------------------
%   This work may be distributed and/or modified under the conditions   *
%   of the LaTeX Project Public License (LPPL), either version 1.3c of  *
%   this license or (at your option) any later version.                 *
%   The latest version of this license is in                            *
%                                                                       *
%       http://www.latex-project.org/lppl.txt                           *
%                                                                       *
%   and version 1.3c or later is part of all distributions of LaTeX     *
%   version 2008 or later.                                              *
%                                                                       *
%   This work has the LPPL maintenance status `maintained'.             *
%                                                                       *
%   The Current Maintainer of this work is Mingyu Xia.                  *
% -----------------------------------------------------------------------
%   This work consists of the files beamertheme-westlake.dtx,           *
%                                   beamertheme-westlake.ins,           *
%                 the derived files beamerthemewestlake.sty,            *
%           the documentation files beamertheme-westlake.pdf,           *
%                               and README.md.                          *
% -----------------------------------------------------------------------
%                                                                       *
%   Any modification of this file should ensure that the copyright and  *
%   license information is placed in the derived files.                 *
%                                                                       *
% -----------------------------------------------------------------------
%
%<*internal>
\iffalse
%</internal>
%
%<*readme>
[![CTAN Version](https://img.shields.io/ctan/v/beamertheme-westlake)](https://ctan.org/pkg/beamertheme-westlake)
[![GitHub Release](https://img.shields.io/github/v/release/myhsia/beamertheme-westlake)](https://github.com/myhsia/beamertheme-westlake/releases/latest)
[![GitHub Last Commit](https://img.shields.io/github/last-commit/myhsia/beamertheme-westlake)](https://github.com/myhsia/beamertheme-westlake/commits)
[![Actions Status](https://github.com/myhsia/beamertheme-westlake/actions/workflows/main.yaml/badge.svg?branch=main)](https://github.com/myhsia/beamertheme-westlake/actions)
[![GitHub Repo stars](https://img.shields.io/github/stars/myhsia/beamertheme-westlake)](https://github.com/myhsia/beamertheme-westlake)

The `Westlake` Beamer Theme
===========================

The `Westlake` Beamer theme is inspired by West Lake, a famous freshwater lake
in Hangzhou, China, and also inspired by Westlake University.

Overview
--------

To load this theme under the `beamer` class, write the lines

    \usetheme[logo = <file>, badge = <file>, mainbg = <file>, basebg = <file>]{westlake}

to set the theme color and graphics.

See `beamertheme-westlake.pdf` for more. Happy TeXing!

Issues
------

The issue tracker for `beamertheme-westlake` is currently located
[on GitHub](https://github.com/myhsia/pbeamertheme-westlake).

Build status
------------

This project uses [GitHub Actions](https://github.com/features/actions)
as a hosted continuous integration service. For each commit, the build status
is tested using the current release of TeX Live.

_Current build status:_ ![build status](https://github.com/myhsia/beamertheme-westlake/actions/workflows/main.yaml/badge.svg?branch=main)

Copyright and License
---------------------

Copyright (C) 2026 by Mingyu Xia \<myhsia@outlook.com\>

This work may be distributed and/or modified under the conditions
of the LaTeX Project Public License (LPPL), either version 1.3c of
this license or (at your option) any later version.
The latest version of this license is in

    http://www.latex-project.org/lppl.txt

and version 1.3c or later is part of all distributions of LaTeX
version 2008 or later.

This work has the LPPL maintenance status `maintained'.

The Current Maintainer of this work is **Mingyu Xia**.
%</readme>
%
%<*internal>
\fi
%</internal>
%
%<*driver>
\documentclass[11pt, letterpaper, cs-break = true]{l3doc}
\usepackage[osf, mono = false]{libertine}
\usepackage{pdfpages}
\newcommand \mail[1]{\href{mailto:#1}{\ttfamily #1}}
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \begin{documentation}
%
% \title{The \pkg{Westlake} Beamer Theme\thanks{\parbox[t]{.8\linewidth}{^^A
%   \url{https://github.com/myhsia/beamertheme-westlake},\\
%   \url{https://ctan.org/pkg/beamertheme-westlake}}}^^A
% }
%
% \author{Mingyu Xia\thanks{\mail{xiamingyu@westlake.edu.cn}}}
% \makeatletter
% \date{Released 2026-03-02\quad \texttt{v0.1A}}
% \makeatother
% \maketitle
%
% \begin{abstract}
%   The \pkg{Westlake} Beamer Theme is inspired by West Lake,
%   a famous freshwater lake in Hangzhou, China,
%   and also inspired by Westlake University.
% \end{abstract}
%
% \section{Introduction \& Usage}
%
% The introduction and usage instructions for the \pkg{Westlake} Beamer Theme
% are included in \file{\jobname-demo.pdf}, which is also attached in the
% following 3 pages.
%
% The demo loads the theme with the following lines
% \begin{quote}
%   \cs{usetheme}"[logo   = "\file{westlake-logo.pdf}","\\
%       "          badge  = "\file{westlake-badge.pdf}","\\
%       "          mainbg = "\file{westlake-paint.png}","\\
%       "          basebg = "\file{plain.png}"]{westlake}"
% \end{quote}
% The code of the theme is implemented after the demo pages.
%
% \includepdf[nup = 1x2, pages = -, frame, delta = 0 .125in]{\jobname-demo.pdf}
%
% \end{documentation}
% \appendix
% \begin{implementation}
% \section{The Source Code}
% Start the optionlist package for \pkg{l3docstrip}.
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
% Declare the package information.
%    \begin{macrocode}
\def \westlake@date    {2026-03-02}
\def \westlake@version {v0.1A}
\ProvidesPackage{beamerthemewestlake}%
  [\westlake@date\ \westlake@version Westlake beamer theme]
%    \end{macrocode}
% Switch to presentation mode.
%    \begin{macrocode}
\mode<presentation>
%    \end{macrocode}
% Set up the options.
%    \begin{macrocode}
\DeclareOptionBeamer{themergb}{\definecolor{westlake}{rgb}{#1}}
\DeclareOptionBeamer{logo}    {\gdef \westlake@logo       {#1}}
\DeclareOptionBeamer{badge}   {\gdef \westlake@badge      {#1}}
\DeclareOptionBeamer{mainbg}  {\gdef \westlake@mainbg     {#1}}
\DeclareOptionBeamer{basebg}  {\gdef \westlake@basebg     {#1}}
\ExecuteOptionsBeamer{themergb = {.132, .324, .570}}
\ProcessOptionsBeamer
%    \end{macrocode}
% Configure the theme color and the inner theme.
%    \begin{macrocode}
\usecolortheme[named = westlake]{structure}
\useinnertheme{rounded}
%    \end{macrocode}
% Load the \pkg{tikz} package with the \pkg{fadings} library.
%    \begin{macrocode}
\RequirePackage{tikz}
\usetikzlibrary{fadings}
%    \end{macrocode}
% \begin{variable}[int]{\ifsection}
% A boolean variable to indicate whether the current page is a section page.
%    \begin{macrocode}
\newif \ifsection
%    \end{macrocode}
% \end{variable}
% Configure the section page.
%    \begin{macrocode}
\AtBeginSection[]{%
  \sectiontrue
  \begin{frame}
    \tikz [remember picture, overlay]
      \node [below right, shift = {(.5ex,-1em)}]
        at (current page.north west)
        {\includegraphics
          [height = \dimeval{2\paperheight/15}]{\westlake@badge}};
    \vfill
    \usebeamerfont{title}\bfseries \color{westlake}%
    \insertsectionhead \par
    \tikz{%
      \draw [ultra thick, line cap = round, westlake!20]
        (0,0) --++ (2\linewidth/3,0);
      \filldraw [ultra thick, line cap = round, westlake!60, path fading = west]
        (0,0) --++
        (\fpeval{\insertpagenumber/\insertdocumentendpage * 2/3}\linewidth,0);
    }
    \vfill
  \end{frame}
  \sectionfalse
}
%    \end{macrocode}
% Configure the background.
%    \begin{macrocode}
\usebackgroundtemplate{%
  \tikz [remember picture, overlay] {%
    \ifnum \insertpagenumber=1
      \ifcsname westlake@mainbg\endcsname
        \node [above, inner sep = 0pt, opacity = .2]
          at (current page.south)
          {\includegraphics
            [width = \paperwidth, height = \paperwidth]{\westlake@mainbg}};
      \fi
      \fill [westlake!90]
        (current page.south west) --++ ({-pi/6*\paperwidth},.4)
        cos + ({(1/18+pi/12)*\paperwidth},+.4)
        sin + ({(1/18+pi/12)*\paperwidth},+.4)
        cos + ({(1/18+pi/12)*\paperwidth},-.4)
        sin + ({(1/18+pi/12)*\paperwidth},-.4)
        cos + ({(1/18+pi/12)*\paperwidth},+.4) --
        (current page.south east) -- cycle;
      \fill [westlake!90, opacity = .5]
        (current page.south east) --++ (-.75\paperwidth, 0)
        to[bend left = 6] ([yshift = 1.4cm]current page.south east) -- cycle;
    \else
      \ifsection \ifcsname westlake@mainbg\endcsname
        \node [above, inner sep = 0pt, opacity = .2]
          at (current page.south)
          {\includegraphics
            [width = \paperwidth, height = \paperwidth]{\westlake@mainbg}};
        \fi
      \else \ifcsname westlake@basebg\endcsname
        \node [above, inner sep = 0pt, opacity = .8]
          at (current page.south)
          {\includegraphics
            [width = \paperwidth, height = \paperwidth]{\westlake@basebg}};
        \fi
      \fi
      \node [inner sep = 0pt, opacity = .1, xshift = -2em]
        at (current page.east)
        {\includegraphics[height = .75\paperheight]{\westlake@logo}};
    \fi
  }
}
%    \end{macrocode}
% Configure the badge at the north west corners.
%    \begin{macrocode}
\titlegraphic{%
  \tikz [remember picture, overlay]
    \node [below right, shift = {(.5ex,-.5em)}] at (current page.north west)
      {\includegraphics[height = \dimeval{2\paperheight/15}]{\westlake@badge}};
}
%    \end{macrocode}
% Configure the title page, remove the footline and headline
% and set the title font.
%    \begin{macrocode}
\let \@maketitle \maketitle
\renewcommand \maketitle {\begingroup
  \setbeamertemplate{footline}{}
  \setbeamertemplate{headline}{}
  \setbeamerfont{title}{series = \bfseries \Large}
  \@maketitle \endgroup
}
%    \end{macrocode}
% Configure the blocks, including the colors and the opacity.
%    \begin{macrocode}
\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}{%
  use = block title, parent = normal text,
  bg  = block title.bg!50!bg
}
\setbeamercolor{block body alerted}{%
  use = block title alerted, parent = normal text,
  bg  = block title alerted.bg!50!bg
}
\setbeamercolor{block body example}{%
  use = block title example, parent = normal text,
  bg  = block title example.bg!50!bg
}
\addtobeamertemplate{block begin}
  {\pgfsetfillopacity{.8}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block alerted begin}
  {\pgfsetfillopacity{.8}}{\pgfsetfillopacity{1}}
\addtobeamertemplate{block example begin}
  {\pgfsetfillopacity{.8}}{\pgfsetfillopacity{1}}
%    \end{macrocode}
% Configure the footer, remove navigation buttons, and set the color series.
%    \begin{macrocode}
\useoutertheme{infolines}
\setbeamertemplate{navigation symbols}{}
\setbeamercolor{title}{parent = author in head/foot}
\setbeamercolor*{palette primary}
  {use = structure, fg = black, bg = structure.fg!30!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}
%    \end{macrocode}
% Configure the header, draw the progress bar.
%    \begin{macrocode}
\addtobeamertemplate{headline}{}{%
  \tikz [remember picture, overlay]{%
    \ifnum \inteval{2*\insertpagenumber}>\insertdocumentendpage
      \filldraw [westlake!60]
        (current page.north) --++ (0,-4ex) [rounded corners = 1ex] --++
        (\fpeval
          {\insertpagenumber/\insertdocumentendpage/2}\paperwidth,0)
        [rounded corners = 0pt] --++ (4ex,4ex)
       node [left = 2ex, midway, white, font = \bfseries \small]
        {\inteval{100*\insertpagenumber/\insertdocumentendpage}\%} -- cycle;
    \else
      \filldraw [westlake!60]
        (current page.north) --++ (0,-4ex) [rounded corners = 1ex] --++
        (\fpeval
          {\insertpagenumber/\insertdocumentendpage/2}\paperwidth,0)
        [rounded corners = 0pt] --++ (4ex,4ex)
       node [right = 2ex, midway, westlake, font = \bfseries \small]
        {\inteval{100*\insertpagenumber/\insertdocumentendpage}\%} -- cycle;
    \fi
  }
}
%    \end{macrocode}
%    \begin{macrocode}
\RequirePackage{ragged2e}
\justifying
\let\raggedright=\justifying
%    \end{macrocode}
% Configure the bibliography list format.
%    \begin{macrocode}
\setbeamertemplate{bibliography item}[text]
%    \end{macrocode}
% Switch to all mode.
%    \begin{macrocode}
\mode<all>
%    \end{macrocode}
%    \begin{macrocode}
\endinput
%    \end{macrocode}
% End the optionlist package for \pkg{l3docstrip}.
%    \begin{macrocode}
%</package>
%    \end{macrocode}
% \end{implementation}
% \appendix
% \PrintIndex