I am creating a theme for a progressbar that shows for all slides except the first slide. I place the progressbar in the footline as I want it to show up at the bottom.
What I don't understand is why this doesn't work (actually it shows a very tiny progressbar if you use zoom in a lot)
\ifnum\insertframenumber>1\relax%
%progress bar code
\fi
and this works
\ifnum\insertframenumber=1\relax%
\else
%progress bar code
\fi
Another issue is that if I dont add \ifnum\inserttotalframenumber>1
, it will fail on first run but works in subsequent runs. It seems that latex compiles the code twice in the first run with the first compilation having \inserttotalframenumber equal to 1 (causing division by 0). Is this correct?
I put the code below. There is a comment for working code and not working code. It is compiled with Luatex. I am not sure if pdflatex will work.
% filename: beamerouterthemetest.sty
\mode<presentation>
\RequirePackage{tikz}
\newcount\progressbar@current
\newcount\progressbar@total
\newdimen\progressbar@curwidth
\newdimen\progressbar@width
\newdimen\progressbar@height
\progressbar@width=\paperwidth
\progressbar@height=1mm
% the progress bar
\def\progressbar@progressbar{%
\progressbar@current=\insertframenumber
\progressbar@total=\inserttotalframenumber
\advance\progressbar@current-1
\advance\progressbar@total-1
\progressbar@curwidth=\progressbar@width
\multiply\progressbar@curwidth by \progressbar@current
\divide\progressbar@curwidth by \progressbar@total
\begin{tikzpicture}[]
\draw[fill=fg] %
(0pt, 0pt) rectangle ++ (\progressbar@curwidth, \progressbar@height);
\end{tikzpicture}%
}
% THIS WORKS!!!!!!!!!!!!!!!!!!!
% Footline
\defbeamertemplate*{footline}{test}[1][] {
\ifnum\insertframenumber=1\relax%
\else
% Added next ifnum to avoid division by 0 crash in first run
\ifnum\inserttotalframenumber>1\relax%
\begin{beamercolorbox}[wd=\paperwidth]{progressbar}%
\progressbar@progressbar%
\end{beamercolorbox}%
\fi
\fi
}
% THIS DOESNT WORK!!!!!!!!!!!!!!!!!!!
% % Footline
% \defbeamertemplate*{footline}{test}[1][] {
% \ifnum\insertframenumber>1\relax%
% % Added next ifnum to avoid division by 0 crash in first run
% \ifnum\inserttotalframenumber>1\relax%
% \begin{beamercolorbox}[wd=\paperwidth]{progressbar}%
% \progressbar@progressbar%
% \end{beamercolorbox}%
% \fi
% \fi
% }
\mode<all>
% filename: test-example.tex
\documentclass[aspectratio=169]{beamer}
\useoutertheme{test}
\begin{document}
\begin{frame}{Slide 1}
\end{frame}
\begin{frame}{Slide 2}
\end{frame}
\begin{frame}{Slide 3}
\end{frame}
\begin{frame}{Slide 4}
\end{frame}
\begin{frame}{Slide 5}
\end{frame}
\begin{frame}{Slide 6}
\end{frame}
\begin{frame}{Slide 7}
\end{frame}
\end{document}