! Dimension too large error in beamer with more than 34 slides

beamer

The following code, when added to a beamer template generates the ! Dimension too large error, when the number of slides is above 34. I am not quite finding which of these macros is the culprit:

% Progression bar at the bottom
%--------------------------------------------------
\makeatletter
\addtobeamertemplate{footline}{%
  \color{cidacsred}% to color the progressbar
  \hspace*{-\beamer@leftmargin}%
  \rule{\beamer@leftmargin}{2pt}%
  \rlap{\rule{\dimexpr
      \beamer@startpageofframe\dimexpr
      \beamer@rightmargin+\textwidth\relax/\beamer@endpageofdocument}{1pt}}
  {}
}
  • What am I doing wrong?

Best Answer

This is due to the way \dimexpr parses dimension expressions. During any step, the intermediate dimension must not exceed 16383.99999pt (with one exception). In your case, if you have more than 34 slides, then the following will overflow:

\beamer@startpageofframe\dimexpr\beamer@rightmargin+\textwidth\relax

which, on the 35th slide, means 35*<about the width of slide>.

We can get around this overflow, by doing a “scaling operation” instead of “first multiplying then dividing”. This is the one exception when the intermediate dimension can be as large as a 64-bit integer representation (the result has to be less than 16383.99999pt in absolute value, of course). So you can change the first argument of \rule to

\dimexpr(\beamer@rightmargin+\textwidth)
  *\beamer@startpageofframe/\beamer@endpageofdocument\relax

so that the multiplication and division are done as one “scaling” step.