% Beamer sTeX slide theme;
% Copyright (c) 20 Michael Kohlhase <michael.kohlhase@fau.de>.
\ProvidesPackage{beamerthemesTeX}
\typeout{Beamer sTeX theme}
\RequirePackage{xspace}
\RequirePackage{xcolor}
\RequirePackage{stex}

\ExplSyntaxOn
\protected\def\stexbeamerthm#1#2#3#4#5#6#7#8{
  \newcounter{#1}
  \tl_if_empty:nF{#4}{
    \tl_set:cn{the#1}{
      \use:c{the#4}.\arabic{#1}
    }
  }
  \tl_set:cn{#1autorefname}{#6}

  \newenvironment{#1}{
    \ifhmode\par\fi

    \tl_if_empty:nF{#5}{
      \setcounter{#1}{\value{#5}}
      \stepcounter{#5}
    }
    \refstepcounter{#1}
    \noindent#7{
      #6~\use:c{the#1}
      \tl_if_empty:cF{s#2title}{
        {}~(\csname s#2title\endcsname)
      }.
    }
    #8
  }{\par}
  \csname stexpatch#2\endcsname[#3]{\begin{#1}}{\end{#1}}
}
\ExplSyntaxOff

\stexbeamerthm{theorem}{assertion}{theorem}{section}{}{Theorem}\textbf\itshape
\stexbeamerthm{observation}{assertion}{observation}{section}{theorem}{Observation}\textbf\itshape
\stexbeamerthm{corollary}{assertion}{corollary}{section}{theorem}{Corollary}\textbf\itshape
\stexbeamerthm{lemma}{assertion}{lemma}{section}{theorem}{Lemma}\textbf\itshape
\stexbeamerthm{axiom}{assertion}{axiom}{section}{theorem}{Axiom}\textbf\itshape
\stexbeamerthm{remark}{assertion}{remark}{section}{theorem}{Remark}\emph{}
\stexpatchparagraph[remark]{\begin{remark}}{\end{remark}}
\stexbeamerthm{example}{example}{}{section}{theorem}{Example}\textbf{}
\stexbeamerthm{definition}{definition}{}{section}{theorem}{Definition}\textbf{}


% THEME
\mode
<presentation>

\sffamily

\ifcsname slidelogo\endcsname\else
  \newsavebox\slidelogo
  \sbox\slidelogo{\sTeX}
\fi

%% Logo images
\pgfdeclareimage[height=2ex]{instlogo}{sTeX-logo}
\pgfdeclareimage[height=2ex]{cclogo}{stex-cc_somerights}

%% A simple frame title with a long rule under it. 
\setbeamertemplate{frametitle}{%
    \usebeamerfont{frametitle}\insertframetitle\strut%
    \vskip-.1\baselineskip%
    \leaders\vrule width \paperwidth\vskip0.4pt%
    \vskip0pt%
    \nointerlineskip
}

%% A Footer line with a Institution and CC logos
\setbeamertemplate{footline}[text line]{%
  \usebeamercolor[fg]{titlelike}
  \usebox\slidelogo\hspace*{1cm}\insertshortauthor: \insertshorttitle\hfill{}%
  \insertframenumber\hfill\insertshortdate\hspace*{1cm}\pgfuseimage{cclogo}%
  }

%% Turn off the navigation symbols
\setbeamertemplate{navigation symbols}{}

%% Inner theme
\useinnertheme{default}
%\setbeamertemplate{enumerate item}{(\alph{enumi})}
%\setbeamertemplate{enumerate subitem}{(\roman{enumii})}

\mode
<all>

%% Redefine various margin sizes 
\setbeamersize{text margin left=3mm}
\setbeamersize{text margin right=3mm}
\setbeamersize{description width=0.57cm}
\setlength\leftmargini{1em}
\setlength\leftmarginii{1em}
\setlength\leftmarginiii{1em}
\providecommand{\vstretch}[1]{\vspace*{\stretch{#1}}}

%% set the colors for sTeX content highlighting

\def\compemph#1{\ifcsname textcolor\endcsname\textcolor{SteelBlue}{#1}\else#1\fi}
\def\symrefemph#1{\ifcsname textcolor\endcsname\textcolor{SteelBlue}{#1}\else#1\fi}
\def\defemph#1{\ifcsname textcolor\endcsname\textcolor{magenta}{#1}\else\textbf{#1}\fi}
\def\varemph#1{\ifcsname textcolor\endcsname\textcolor{gray}{#1}\else#1\fi}
\def\titleemph#1{\ifcsname textcolor\endcsname\textcolor{blue}{#1}\else\textbf{#1}\fi}

%% set PDF tooltips
\RequirePackage{pdfcomment}
\protected\def\compemph@uri#1#2{%
  \pdftooltip{%
    \srefsymuri{#2}{\compemph{#1}}%
  }{%
    URI:~\detokenize{#2}%
  }%
}
\protected\def\symrefemph@uri#1#2{%
  \pdftooltip{%
    \srefsymuri{#2}{\symrefemph{#1}}%
  }{%
    URI:~\detokenize{#2}%
  }%
}
\protected\def\defemph@uri#1#2{%
  \pdftooltip{%
    \defemph{#1}%
  }{%
    URI:~\detokenize{#2}%
  }%
}
\protected\def\varemph@uri#1#2{%
  \pdftooltip{%
    \varemph{#1}%
  }{%
    Variable~\detokenize{#2}%
  }%
}