%% sidebars -- (sidebars.sty) style file
%% A style package for the talk class
%% Author: Martin Wiebusch
%%
%% This file 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/lppl-1-3/
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2003/12/01 or later.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{talk-sidebars}

\newif\if@compress\@compressfalse
\DeclareOption{compress}{\@compresstrue}

\ProcessOptions\relax

\RequirePackage{cmbright}
\RequirePackage[hidelinks]{hyperref}

\newlength{\sb@unit}
\setlength{\sb@unit}{1in}
\@slidesize{8\sb@unit}{4.5\sb@unit}
\slidesmag{1.2}

\newcommand{\backgroundcolor}[1]{\definecolor{sb@bg}{rgb}{#1}}
\newcommand{\sidebarcolor}[1]{\definecolor{sb@sb}{rgb}{#1}}
\newcommand{\highlightcolor}[1]{\definecolor{sb@hl}{rgb}{#1}}
\newcommand{\titlecolor}[1]{\definecolor{sb@title}{rgb}{#1}}
\newcommand{\sidebartitlecolor}[1]{\definecolor{sb@sbt}{rgb}{#1}}

\backgroundcolor{1,1,1}
\sidebarcolor{0.85,0.85,0.85}
\highlightcolor{0,0,0.7}
\titlecolor{0,0,0.7}
\sidebartitlecolor{0,0,0.7}

\@newlayout{default}{%
  \renewcommand{\@makeslide}{%
    % Draw the background, including the sidebar. We use pgf here, but any other
    % graphics package will work, too. You can also use \includegraphics if you
    % have an image in a separate file.
    \shiftbox[tl]\z@\z@{%
      \begin{pgfpicture}
        \color{sb@bg}
        \pgfrect[fill]{\pgfpoint{\z@}{-\slideheight}}{\pgfpoint\slidewidth\slideheight}%
        \color{sb@sb}%
        \pgfrect[fill]{\pgfpoint{6.8\sb@unit}{-\slideheight}}{\pgfpoint{1.2\sb@unit}\slideheight}%
        \@ifscreen{}{%
          \color{black}%
          \pgfrect[stroke]{\pgfpoint{\z@}{-\slideheight}}{\pgfpoint\slidewidth\slideheight}%
        }%
      \end{pgfpicture}
    }%
    % Fill the sidebar with table-of-contents information.
    \shiftbox[tl]{6.9\sb@unit}{-0.2\sb@unit}{%
      \begin{minipage}[t][4.1\sb@unit]{1\sb@unit}%
        \tiny%
        {\centering\tiny\textcolor{sb@sbt}{\@shorttitle}\par%
         \vspace{1em}\@shortauthor\par\vspace{2em}}%
        {\parskip=0.8em\@tableofcontents}%
        {\vfill\hspace*{\fill}p. \theslidelabel\hspace*{\fill}}%
      \end{minipage}%
    }%
    % Typeset the slide title and body.
    \shiftbox[tl]{0.2\sb@unit}{-0.2\sb@unit}{%
      \begin{minipage}[t][4.1\sb@unit][s]{6.4\sb@unit}%
        {\color{sb@title}\LARGE\@slidetitle\par}%
        \vspace*{1.5em plus 1fil}%
        \@slidebody%
        \vspace*{0pt plus 1fil}%
      \end{minipage}%
    }%
  }%
  % Define the \@maketocsection and \@maketocsubsection commands so that
  % the current (sub)section is highlighted.
  \renewcommand{\@maketocsection}[3]{%
    \raggedright\noindent%
    \@ifcurrentsection{##1}{%
      \@ifcurrentsubsection{0}{%
        \hyperlink{section.##1}{\textcolor{sb@hl}{##2}}\par%
      }{%
        \hyperlink{section.##1}{##2}\par%
      }%
    }{%
      \hyperlink{section.##1}{##2}\par%
    }%
  }%
  \renewcommand{\@maketocsubsection}[4]{%
    \raggedright\noindent%
    \@ifcurrentsection{##1}{%
      \@ifcurrentsubsection{##2}{%
        {%
          \leftskip=1.5em\textcolor{sb@hl}{%
            \hyperlink{subsection.##1.##2}{##3}}\par%
        }%
      }{%
        {\leftskip=1.5em \hyperlink{subsection.##1.##2}{##3}\par}%
      }%
    }{%
      \if@compress%
      \else%
        {\leftskip=1.5em\hyperlink{subsection.##1.##2}{##3}\par}%
      \fi%
    }%
  }%
}

% Same as before, but now we don't have a sidebar.
\@newlayout{nosidebar}{%
  \renewcommand{\@makeslide}{%
    \shiftbox[tl]\z@\z@{%
      \begin{pgfpicture}%
        \color{sb@bg}%
        \pgfrect[fill]{\pgfpoint\z@\z@}{\pgfpoint\slidewidth\slideheight}%
        \@ifscreen{}{%
          \color{black}%
          \pgfrect[stroke]{\pgfpoint\z@\z@}{\pgfpoint\slidewidth\slideheight}%
        }%
      \end{pgfpicture}%
    }%
    \shiftbox[tl]{0.2\sb@unit}{-0.2\sb@unit}{%
      \begin{minipage}[t][4.1\sb@unit][s]{7.6\sb@unit}%
        {\color{sb@title}\LARGE\@slidetitle\par}%
        \vspace*{1.5em plus 1fil}%
        \@slidebody%
        \vspace*{0pt plus 1fil}%
      \end{minipage}%
    }%
  }%
}

% Same as before, but now we remove the title as well.
\@newlayout{notitle}{%
  \renewcommand{\@makeslide}{%
    \shiftbox[tl]\z@\z@{%
      \begin{pgfpicture}%
        \color{sb@bg}%
        \pgfrect[fill]{\pgfpoint\z@\z@}{\pgfpoint\slidewidth\slideheight}%
        \@ifscreen{}{%
          \color{black}%
          \pgfrect[stroke]{\pgfpoint\z@\z@}{\pgfpoint\slidewidth\slideheight}%
        }%
      \end{pgfpicture}%
    }%
    \shiftbox[tl]{0.2\sb@unit}{-0.2\sb@unit}{%
      \begin{minipage}[t][4.1\sb@unit][s]{7.6\sb@unit}%
        \vspace*{0pt plus 1fil}\@slidebody\vspace*{0pt plus 1fil}%
      \end{minipage}%
    }%
  }%
}

% A layout with a centered title and thin bars on both sides of the slide.
% No table-of-contents information is displayed automatically since this
% should be included explicitly in the body (e.g. via the \tableofcontents
% command).
\@newlayout{outline}{%
  \renewcommand{\@makeslide}{%
    \shiftbox[tl]\z@\z@{%
      \begin{pgfpicture}
        \color{sb@bg}
        \pgfrect[fill]{\pgfpoint\z@\z@}{\pgfpoint\slidewidth\slideheight}%
        \color{sb@sb}
        \pgfrect[fill]{\pgfpoint\z@\z@}{\pgfpoint{0.6\sb@unit}\slideheight}%
        \pgfrect[fill]{\pgfpoint{7.4\sb@unit}\z@}{\pgfpoint{0.6\sb@unit}\slideheight}%
        \@ifscreen{}{%
          \color{black}%
          \pgfrect[stroke]{\pgfpoint\z@\z@}{\pgfpoint\slidewidth\slideheight}%
        }%
      \end{pgfpicture}%
    }%
    \shiftbox[tl]{0.8\sb@unit}{-0.2\sb@unit}{%
      \begin{minipage}[b][4.1\sb@unit][t]{6.4\sb@unit}%
        {\centering\LARGE\color{sb@title}\@slidetitle\par}%
        \vspace*{1.5em plus 1fil}%
        \@slidebody%
        \vspace*{0pt plus 1fil}%
      \end{minipage}%
    }%
  }%
}

\newcommand{\maketitleslide}{%
  \begin{slide}[notitle]{}%
    {\centering%
      {\color{sb@sbt}\LARGE\@title\par}\vspace{3em}%
      {\large\@author\par}\vspace{1.5em}%
      {\large\@date\par}%
    }%
  \end{slide}%
}
\renewcommand{\tableofcontents}[1][0.0-99.99]{%
  \bgroup\parskip=0.4em\hangafter=1%
  \def\@maketocsection##1##2##3{%
    \@ifinrange{##1}{0}{#1}{{
      \hangindent=2.5em%
      \hspace{2em}\makebox[\z@][r]{##1.}\hspace{0.5em}%
      \hyperlink{section.##1}{##3}\par%
    }}{}%
  }
  \def\@maketocsubsection##1##2##3##4{%
    \@ifinrange{##1}{##2}{#1}{{%
      \hangindent=3.5em
      \hspace{2.5em}\makebox[\z@][l]{$\bullet$}\hspace{1em}%
      \hyperlink{subsection.##1.##2}{##3}\par%
    }}{}%
  }
  \@tableofcontents
  \egroup
}

\renewcommand{\@makenotesslide}{%
  \par\hspace*{\fill}%
  \scalebox{0.7}{\@slidebox}%
  \hspace*{\fill}\par\bigskip%
}
\@ifnotes{%
  \addtolength{\textwidth}{1in}
  \addtolength{\oddsidemargin}{-0.5in}
}{}

\setlength{\parindent}{\z@}
\setparskip{1.5ex plus0.5ex minus0.5ex}
\layout{default}
\sloppy
