\ProvidesPackage{FABslides}%
  [2017/09/25 Addons and fixes for Beamer, Axel Berger]

\RequirePackage{etoolbox}
\RequirePackage{textpos}

\newif\ifFAB@bookframe \FAB@bookframefalse
\newif\ifFAB@aspect \FAB@aspecttrue
\newif\ifFAB@nav \FAB@navfalse
\ifcsundef{ifbeamer@sb@subsection}{%
	\newif\ifbeamer@sb@subsection \beamer@sb@subsectiontrue}{}
\ifcsundef{ifbeamer@FAB@footline}{%
	\newif\ifbeamer@FAB@footline \beamer@FAB@footlinefalse}{}

\DeclareOptionBeamer{bookframe}{\FAB@bookframetrue}
\DeclareOptionBeamer{nosub}{\beamer@sb@subsectionfalse}
\DeclareOptionBeamer{noaspect}{\FAB@aspectfalse}
\DeclareOptionBeamer{nav}{\FAB@navtrue}
\DeclareOptionBeamer{footline}{\beamer@FAB@footlinetrue}
\ProcessOptionsBeamer

\mode<presentation>{%
\ifFAB@aspect%
  \ifdim\beamer@paperwidth=16.00cm%
    \setlength{\beamer@paperwidth}{6.4in}%
    \ifdim\beamer@paperheight=10.00cm%
      \setlength{\beamer@paperheight}{4in}%
    \else\ifdim\beamer@paperheight=9.00cm%
      \setlength{\beamer@paperheight}{3.6in}%
    \fi\fi%
  \else\ifdim\beamer@paperwidth=14.00cm%
    \setlength{\beamer@paperwidth}{5.6in}%
    \setlength{\beamer@paperheight}{3.6in}%
  \else\ifdim\beamer@paperwidth=13.50cm%
    \setlength{\beamer@paperwidth}{5.4in}%
    \setlength{\beamer@paperheight}{3.6in}%
  \else\ifdim\beamer@paperwidth=12.80cm%
    \setlength{\beamer@paperwidth}{5.12in}%
    \setlength{\beamer@paperheight}{3.84in}%
  \else\ifdim\beamer@paperwidth=12.50cm%
    \setlength{\beamer@paperwidth}{5.6in}%
    \setlength{\beamer@paperheight}{4.48in}%
  \fi\fi\fi\fi\fi
  \geometry{papersize={\beamer@paperwidth,\beamer@paperheight}}
\fi}

\ifFAB@nav
\else
	\setbeamertemplate{navigation symbols}{}
\fi

\def\UrlTildeSpecial{%
	\do\~{\raise.2ex\hbox{\m@th$\scriptstyle\sim$}}}%
	\let\Url@force@Tilde\UrlTildeSpecial
\mode<presentation>{\hypersetup{final,
	pdfpagemode=UseOutlines,
	bookmarksopenlevel=4,
	bookmarksopen=true,
	hyperfootnotes=false,
	colorlinks=false,
	pdfborder={0 0 0},
	pdfpagelayout=SinglePage,
	pdfstartview=Fit}}
\mode<article>{\hypersetup{final,
	pdfpagemode=UseNone,
	pdfprintscaling=None,
	bookmarksopen=true,
	hyperfootnotes=false,
	colorlinks=false,
	pdfborder={0 0 1},
	pdfpagelayout=TwoColumnRight,
	pdfstartview=Fit}}

\mode<presentation>{%
\renewenvironment{alertenv}{\begin{altenv}%
  {\usebeamertemplate{alerted text begin}%
  \usebeamercolor[fg]{alerted text}\usebeamerfont{structure}}
  {\usebeamertemplate{alerted text end}}%
  {\color{.}}{}}{\end{altenv}}
\newenvironment{exampleenv}{\begin{altenv}%
  {\usebeamertemplate{example text begin}%
  \usebeamercolor[fg]{example text}\usebeamerfont{structure}}
 {\usebeamertemplate{example text end}}%
 {\color{.}}{}}{\end{altenv}}
\newcommand<>{\examp}[1]{\begin{exampleenv}#2#1\end{exampleenv}}
\ifdefined\fak%
	\newcommand*{\srcsize}{\scriptsize}%
\else%
	\newcommand*{\srcsize}{\normalsize}%
\fi
\ifbeamer@FAB@footline
	\newcommand{\src}[1]{\par
	\begin{textblock*}{\textwidth}[1,1](\paperwidth-8mm,\paperheight-3.5mm)
	\srcsize\hfill #1
	\end{textblock*}}
\else
	\newcommand{\src}[1]{\par
	\begin{textblock*}{\textwidth}[1,1](\paperwidth-2mm,\paperheight-2mm)
	\srcsize\hfill #1
	\end{textblock*}}
\fi
\newcommand{\notiz}[1]{}
}

\mode<article>{%
\newcommand<>{\examp}[1]{#1}
\newcommand{\src}[1]{\hspace*{\fill}#1}
\newcommand{\notiz}[1]{\par #1 \par}
% \newcommand{\notiz}[1]{#1 \par}
}

\providecommand*{\@tocrmarg}{2.55em}
\providecommand*{\newblock}{}
\providecommand*{\Kopfzeile}{}

\newcommand{\bcap}[3][1ex]{{\par \vspace{#1} #2 \footnotesize #3 \par}}
\newcommand{\rcap}[3][.1in]{\mbox{\hspace{#1}\parbox[b]
	{#2}{\footnotesize #3 \par\vspace{1.5\baselineskip}}}}
\newcommand{\lcap}[3][1mm]{\mbox{\parbox[b]
	{#2}{\footnotesize #3 \par\vspace{1.5\baselineskip}}\hspace{#1}}}

\setbeamercovered{transparent}
\setbeamertemplate{frametitle continuation}[from second]
\setbeamertemplate{bibliography item}[text]
\renewcommand*{\@cite}[2]{{#1\if@tempswa , #2\fi}}
\renewcommand*{\@biblabel}[1]{\hfill{#1}}


\mode<presentation>
\define@key{beamerframe}{c}[true]{% centered
  \beamer@frametopskip=0pt plus 1fill\relax%
  \beamer@framebottomskip=0pt plus 1fill\relax%
%%\beamer@framebottomskip=0pt plus 1.5fill\relax%
  \beamer@frametopskipautobreak=0pt plus .4\paperheight\relax%
  \beamer@framebottomskipautobreak=0pt plus .6\paperheight\relax%
  \def\beamer@initfirstlineunskip{}%
}
%%Bugfix from:
%%http://tex.stackexchange.com/questions/16447/beamer-top-aligning-columns-within-a-top-aligned-frame
\define@key{beamerframe}{t}[true]{% top
  \beamer@frametopskip=.2cm plus .5\paperheight\relax%
  \beamer@framebottomskip=0pt plus 1fill\relax%
  \beamer@frametopskipautobreak=\beamer@frametopskip\relax%
  \beamer@framebottomskipautobreak=\beamer@framebottomskip\relax%
  \def\beamer@initfirstlineunskip{}%
}

\newcommand{\FAB@miniframe}[4]{%
\hbox to 0pt{%
  \beamer@tempdim=-\beamer@vboxoffset%
  \advance\beamer@tempdim by-\beamer@boxsize%
  \multiply\beamer@tempdim by\beamer@ypos%
  \advance\beamer@tempdim by -.05cm%
  \raise\beamer@tempdim\hbox{%
    \beamer@tempdim=\beamer@boxsize%
    \multiply\beamer@tempdim by\beamer@xpos%
    \advance\beamer@tempdim by -\beamer@boxsize%
    \advance\beamer@tempdim by 1pt%
    \kern\beamer@tempdim\hbox{\beamer@link(#4){%
        \usebeamerfont{mini frame}%
        \ifnum\c@section=#1%
          \ifnum\c@subsection=#2%
            \usebeamercolor[fg]{mini frame}%
            \ifnum\c@subsectionslide=#3%
              \usebeamertemplate{mini frame}%\beamer@minislidehilight%
            \else%
              \usebeamertemplate{mini frame in current subsection}%\beamer@minisliderowhilight%
            \fi%
          \else%
            \usebeamercolor{mini frame}%
            %\color{fg!50!bg}%
            \usebeamertemplate{mini frame in other subsection}%\beamer@minislide%
          \fi%
        \else%
          \usebeamercolor{mini frame}%
          %\color{fg!50!bg}%
          \usebeamertemplate{mini frame in other subsection}%\beamer@minislide%
        \fi%
      }}}\hskip-10cm plus 1fil}}%

\def\slideentry#1#2#3#4#5#6{%
  %section number, subsection number, slide number, first/last frame, page number, part number
  \ifnum#6=\c@part% Part
  \ifnum#1>0\ifnum#3>0% Section, Frame
    \ifnum#2>0% Subsection
      \ifbeamer@sb@subsection%
        \ifbeamer@compress%
          \advance\beamer@xpos by1\relax%
          \ifnum#2>1%   nicht fuer die erste subsection
          \ifnum#3=1%   nur fuer den ersten frame
            \advance\beamer@xpos by1\relax%
          \fi\fi%
        \else% Compress
          \beamer@xpos=#3\relax%
          \beamer@ypos=#2\relax%
        \fi% Compress
        \FAB@miniframe{#1}{#2}{#3}{#4}%
      \else% No subsections, immer compress
        \advance\beamer@xpos by1\relax%
        \FAB@miniframe{#1}{#2}{#3}{#4}%
      \fi% Show Subsections
    \else% Subsection = 0
      \ifbeamer@sb@subsection% Do nothing
      \else% No subsections, Nummer egal
        \advance\beamer@xpos by1\relax%
        \FAB@miniframe{#1}{#2}{#3}{#4}%
      \fi%
    \fi% Subsection > 0
  \fi\fi% Section, Frame > 0
  \else% Part
  \fakeslideentry{#1}{#2}{#3}{#4}{#5}{#6}%
  \fi\ignorespaces}

\def\fakeslideentry#1#2#3#4#5#6{%
  \ifnum#1>0\ifnum#3>0% Frame
    \ifnum#2>0% Subsection
      \ifbeamer@sb@subsection%
        \ifbeamer@compress%
          \advance\beamer@xpos by1\relax%
          \ifnum#2>1%   nicht fuer die erste subsection
          \ifnum#3=1%   nur fuer den ersten frame
            \advance\beamer@xpos by1\relax%
          \fi\fi%
        \else% No Compress
          \beamer@xpos=#3\relax%
          \beamer@ypos=#2\relax%
        \fi% Compress
        \hbox to 0pt{\beamer@tempdim=-\beamer@vboxoffset%
          \advance\beamer@tempdim by -\beamer@boxsize%
          \multiply\beamer@tempdim by\beamer@ypos%
          \advance\beamer@tempdim by -.05cm%
          \raise\beamer@tempdim\hbox{}}%
      \else% No subsections, immer compress
        \advance\beamer@xpos by1\relax%
        \hbox to 0pt{\beamer@tempdim=-\beamer@vboxoffset%
          \advance\beamer@tempdim by -\beamer@boxsize%
          \multiply\beamer@tempdim by\beamer@ypos%
          \advance\beamer@tempdim by -.05cm%
          \raise\beamer@tempdim\hbox{}}%
      \fi% No subsections
    \else% Subsection = 0
      \ifbeamer@sb@subsection% Do nothing
      \else% No subsections, Nummer egal
        \advance\beamer@xpos by1\relax%
        \hbox to 0pt{\beamer@tempdim=-\beamer@vboxoffset%
          \advance\beamer@tempdim by -\beamer@boxsize%
          \multiply\beamer@tempdim by\beamer@ypos%
          \advance\beamer@tempdim by -.05cm%
          \raise\beamer@tempdim\hbox{}}%
      \fi% Subsections anzeigen
    \fi% Subsection
  \fi\fi% Section, Frame
  \ignorespaces}

\ifFAB@bookframe%
\let\OrgFrametitle\beamer@@frametitle%
\pretocmd{\beamer@@frametitle}{%
  \ifnumgreater{\thesection}{0}{%
    \ifnumgreater{\thesubsection}{0}{%
      {\only<1>{\belowpdfbookmark{#2}{F\insertframenumber}}}
    }{%
      \ifbeamer@sb@subsection\else%
      {\only<1>{\belowpdfbookmark{#2}{F\insertframenumber}}}%
    \fi}
    }{}}%
  {\message{** patching of \string\beamer@@frametitle succeeded **}}%
  {\errmessage{** patching of \string\beamer@@frametitle failed **}}%
\pretocmd{\beamer@checknoslide}{%
  % ensure the bookmark is not created if the slide is filtered out
  \let\beamer@@frametitle\OrgFrametitle}%
  {\message{** patching of \string\beamer@checknoslide succeeded **}}%
  {\errmessage{** patching of \string\beamer@checknoslide failed **}}%
\fi
\RerunFileCheck{\jobname.nav}{\immediate\closeout\tf@nav}{}
\RerunFileCheck{\jobname.toc}{\immediate\closeout\tf@toc}{}
\RerunFileCheck{\jobname.snm}{\immediate\closeout\tf@snm}{}

\mode
<all>
