
\usepackage{ifthen}

\usepackage{tikz}

\usetikzlibrary{trees, arrows, shapes, automata, petri}
\usetikzlibrary{fit, calc, decorations}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{positioning}
\usetikzlibrary{shadings, fadings, patterns}
\usetikzlibrary{overlay-beamer-styles}
%\usepackage{pgfbaselayers}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\input{colors}

\usepackage{beamerthemesplit}
\usepackage{wasysym}

\usetheme{Copenhagen}
%\usecolortheme{crane}
%\useoutertheme{infolines}
\input{colors}

\setbeamertemplate{headline}{}
\setbeamertemplate{navigation symbols}{}

\newcommand\applyToFrameNumbers[1]{#1}

\newlength\footlineprogressbar

\newcommand\totalmeaningfulframenumber{23}%\inserttotalframenumber

\setbeamertemplate{footline}{
	\parbox{0pt}{%
		\ifthenelse{\insertframenumber>\totalmeaningfulframenumber}{%
			\setlength\footlineprogressbar{\textwidth}%
		}{%
		%\applyToFrameNumbers{%
			\setlength\footlineprogressbar%
				{\dimexpr\textwidth*\insertframenumber/\totalmeaningfulframenumber\relax}%
		%}%
		}%
		\textcolor{LightPlum}{\rule[-3pt]{\footlineprogressbar}{1mm}}
	}%
	\parbox{1cm}{
		\vspace{-2em}\normalfont\hspace{1em}
    %\insertdocnavigationsymbol
    \ifnum\theframenumber=0\relax\else%
				\normalsize\textcolor{DarkPlum}{\applyToFrameNumbers{\insertframenumber}}%/\inserttotalframenumber}
    \fi%
    %\quad
		}
		\hfill
}

\makeatletter
%\sectionframe[]{}
% no star: section name (facultative, if not specified, it is the second argument), the huge text written on the slide.
% one star: no section defined, the argument is the huge text.
% two stars: no section defined, the arguments are the huge text and some text to be written afterwards.
% I guess {\sectionframe}*: a if no stars, but with an additional argument, with is the text written afterwards.
\newcommand\sectionframe@star@add[2]{
    \begin{frame}
        \begin{center}
            \Huge \textcolor{Plum}{#1}
        \end{center}
        #2
    \end{frame}
}
\newcommand\sectionframe@unstar@add[3][]{
    \ifempty{#1}{\section{#2}}{\section{#1}}
    \sectionframe@star@add{#2}{#3}
}
\newcommand\sectionframe@star@base[1]{\sectionframe@star@add{#1}{}}
\newcommand\sectionframe@unstar@base[2][]{\sectionframe@unstar@add[#1]{#2}{}}
\newcommand\sectionframe@star{\@ifstar\sectionframe@star@add\sectionframe@star@base}
\newcommand\sectionframe@unstar{\@ifstar\sectionframe@unstar@add\sectionframe@unstar@base}
\newcommand\sectionframe{\@ifstar\sectionframe@star\sectionframe@unstar}
\makeatother

% Source: https://tex.stackexchange.com/questions/13793/beamer-alt-command-like-visible-instead-of-like-only
\makeatletter
% Detect mode. mathpalette is used to detect the used math style
\newcommand<>\Alt[2]{%
    \begingroup
    \ifmmode
        \expandafter\mathpalette
        \expandafter\math@Alt
    \else
        \expandafter\make@Alt
    \fi
    {{#1}{#2}{#3}}%
    \endgroup
}

% Un-brace the second argument (required because \mathpalette reads the three arguments as one
\newcommand\math@Alt[2]{\math@@Alt{#1}#2}

% Set the two arguments in boxes. The math style is given by #1. \m@th sets \mathsurround to 0.
\newcommand\math@@Alt[3]{%
    \setbox\z@ \hbox{$\m@th #1{#2}$}%
    \setbox\@ne\hbox{$\m@th #1{#3}$}%
    \@Alt
}

% Un-brace the argument
\newcommand\make@Alt[1]{\make@@Alt#1}

% Set the two arguments into normal boxes
\newcommand\make@@Alt[2]{%
    \sbox\z@ {#1}%
    \sbox\@ne{#2}%
    \@Alt
}

% Place one of the two boxes using \rlap and place a \phantom box with the maximum of the two boxes
\newcommand\@Alt[1]{%
    \alt#1%
        {\rlap{\usebox0}}%
        {\rlap{\usebox1}}%
    \setbox\tw@\null
    \ht\tw@\ifnum\ht\z@>\ht\@ne\ht\z@\else\ht\@ne\fi
    \dp\tw@\ifnum\dp\z@>\dp\@ne\dp\z@\else\dp\@ne\fi
    \wd\tw@\ifnum\wd\z@>\wd\@ne\wd\z@\else\wd\@ne\fi
    \box\tw@
}

\makeatother

\makeatletter
\newcommand\bsphere[2][-.65ex]{%
    \raisebox{#1}{%
    \begin{pgfpicture}[-1ex]{-.65ex}{1ex}{1ex}%
       \usebeamercolor[fg]{item projected}%
       {\pgftransformscale{1.75}\pgftext{\normalsize\pgfuseshading{bigsphere}}}%
       {\pgftransformshift{\pgfpoint{0pt}{.5pt}}%
           \pgftext{\usebeamerfont*{item projected}%
               \usebeamercolor[fg]{item projected}%
               #2%
           }%
       }%
    \end{pgfpicture}%
   }%
}
\makeatother

\newcommand\minicoqlogo{\includegraphics[height = 5mm]{images/CoqLogo.png}}

\newcommand\provedincoq[1]{%
  \hfill%
  \parbox[b][0pt][b]{5mm}{%
    \hfill%
    \raisebox{0mm}{%
        \ifempty{#1}{%
						\minicoqlogo{}%
        }{%
            ~\vspace{-2mm}%
            \anchor{#1}{%
								\minicoqlogo{}%
            }%
            \hspace{-4mm}%
        }%
        \hspace{1mm}~%
    }%
  }%
}

\newenvironment{variableblock}[3]{%
    \setbeamercolor{block body}{#2}
    \setbeamercolor{block title}{#3}
          \begin{block}{#1}}{\end{block}}

\newenvironment{innertikz}[1][]{%
    \begin{tikzpicture}[baseline={([yshift=-.5ex]current bounding box.center)}, #1]
}{
    \end{tikzpicture}%
}

\newenvironment{centertikz}[1][]{%
    \begin{center}%
    \begin{tikzpicture}[#1]
}{
    \end{tikzpicture}%
    \end{center}
}

\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist 

\newenvironment{widemargin}{
    \begin{changemargin}{-1cm}{-1cm}}{
    \end{changemargin}}

\newcommand\anchor[3][]{%
    \begin{innertikz}[remember picture, #1]%
        \node (#2) {#3} ;%
    \end{innertikz}%
}

\newcommand*\anchorm[3][]{%
    \anchor[#1]{#2}{\!\!\(#3\)\!\!}%
}


% Source: https://tex.stackexchange.com/questions/4684/longrightarrow-doesnt-look-good-in-12pt
\makeatletter
\newcommand{\myRelbar}{%
    {\Rightarrow}%
    \llap{\textcolor{white}{\rule[-0.2ex]{1.1ex}{2ex}}}%
    \kern-1.5ex}
\let\saveLongrightarrow\Longrightarrow
\renewcommand{\Longrightarrow}{%
    \mathrel{\rlap{$\m@th\myRelbar\myRelbar$}%
    \phantom{{\saveLongrightarrow}}%
    \llap{$\m@th\Rightarrow$}}}
\makeatother

% Source: https://tex.stackexchange.com/questions/84921/href-not-working-with-image-but-ok-with-text/85103#85103
% \ifxetex
% 	\usepackage{letltxmacro}
% 	\setlength{\XeTeXLinkMargin}{1pt}
% 	\LetLtxMacro\SavedIncludeGraphics\includegraphics
% 	\def\includegraphics#1#{% #1 catches optional stuff (star/opt. arg.)
% 		\IncludeGraphicsAux{#1}%
% 	}%
% 	\newcommand*{\IncludeGraphicsAux}[2]{%
% 		\XeTeXLinkBox{%
% 			\SavedIncludeGraphics#1{#2}%
% 		}%
% 	}%
% \fi

\newcommand\danger{{\fontencoding{U}\fontfamily{futs}\selectfont\char 66\relax}}

