InsideDarkWeb.com

Why is there an arithmetic overflow in the progress bar with more than 44 frames?

I am trying to implement a progress bar into my beamer theme, but as soon as I hit 45 frames, I get the error message

! Arithmetic overflow.
[email protected] [email protected] 
divide [email protected]

Here is my MWE:

documentclass{beamer}

usepackage{tikz}

makeatletter
[email protected]{} % the progress bar
[email protected]% auxiliary counter
[email protected]% auxiliary counter
[email protected] %progressbar height
[email protected] %progressbar width
[email protected] % auxiliary dimension

[email protected]=paperwidth
[email protected]=1cm

% the progress bar
[email protected]{%
    
    [email protected]=insertframenumber
    [email protected]=inserttotalframenumber
    [email protected][email protected]
    [email protected] by [email protected]
    [email protected] by [email protected]
    
    begin{tikzpicture}
    useasboundingbox (0pt, 0pt) rectangle ++ ([email protected], [email protected]);
    begin{scope}
    clip ([email protected], 0pt) rectangle ([email protected], [email protected]);
    node[anchor=south west,inner sep=0pt,outer sep=0pt,minimum height=1cm,minimum width=paperwidth,fill=green] at (0pt,0pt) {};
    end{scope}
    end{tikzpicture}%
}

addtobeamertemplate{footline}{}{vspace*{-1cm}[email protected]}
makeatother

begin{document}
foreach x in {1,2,...,45} {begin{frame}[label=test]{My frame}
    Test x
end{frame}}

end{document}

What is the reason behind and how can I avoid it?

TeX - LaTeX Asked on November 12, 2021

2 Answers

2 Answers

A more simplified approach that I am now using might be a bit easier to read, but of course not as flexible as before, but it makes use of the fact that for PGF you don't need to convert the macros to counters before, hence this works to produce a progress bar that is variable in height and is inverted. It also takes into account muzimuzhi's comment regarding the use of pgfmathsetmacro:

documentclass{beamer}

usepackage{tikz}

makeatletter
[email protected]
[email protected]
[email protected]=1cm

addtobeamertemplate{footline}{}{%
begin{tikzpicture}
useasboundingbox (0pt, 0pt) rectangle ++ (paperwidth, [email protected]t);
begin{scope}
[email protected]{insertframenumber/inserttotalframenumber}
clip ([email protected] * paperwidth, 0pt) rectangle (paperwidth, [email protected]);
node[anchor=south west,inner sep=0pt,outer sep=0pt,minimum height=1cm,minimum width=paperwidth,fill=green] at (0pt,0pt) {};
end{scope}
end{tikzpicture}%
}
makeatother

begin{document}
    foreach x in {1,2,...,50} {begin{frame}{My frame}
        Test x
end{frame}}

end{document}

Answered by TobiBS on November 12, 2021

TeX has a maxdimen (16383.99999pt), which represents the largest dimension you can use in an dimension expression. See discussions among maxdimen on this site, including my answer.

When x == 45,

  • [email protected] == 364.19536pt and [email protected] == 45,
  • their multiplication 364.19536pt * 45 = 16,388.7912pt, is slightly larger than maxdimen, hence raises "arithmetic overflow" and the result of multiplication is truncated.

Since the final result @tmpdim * @tmpcounta / @tmpcountb is smaller than maxdimen, we can firstly compute @tmpcounta / @tmpcountb, then compute @tmpdim * <ratio>. Here is a try making use of pgfmathparse from pgfmath, which is an autoloaded sub-package of tikz:

documentclass{beamer}

usepackage{tikz}

makeatletter
[email protected]{} % the progress bar
[email protected]% auxiliary counter
[email protected]% auxiliary counter
[email protected] %progressbar height
[email protected] %progressbar width
[email protected] % auxiliary dimension

[email protected]=paperwidth
[email protected]=1cm

% the progress bar
[email protected]{%
    [email protected]=insertframenumber
    [email protected]=inserttotalframenumber
    [email protected][email protected]
    % to show current values
    rlap{[email protected], [email protected]}%
    pgfmathparse{[email protected]/[email protected]}%
    [email protected][email protected]
    begin{tikzpicture}
    useasboundingbox (0pt, 0pt) rectangle ++ ([email protected], [email protected]);
    begin{scope}
      clip ([email protected], 0pt) rectangle ([email protected], [email protected]);
      node[anchor=south west,inner sep=0pt,outer sep=0pt,minimum height=1cm,minimum width=paperwidth,fill=green] at (0pt,0pt) {};
    end{scope}
    end{tikzpicture}%
}

addtobeamertemplate{footline}{}{vspace*{-1cm}[email protected]}
makeatother

begin{document}
foreach x in {1,2,...,45} {begin{frame}[label=test]{My frame}
    Test x
end{frame}}

end{document}

Update

Sorry, I paid too much attention to the error message "arithmetic overflow" yesterday, but not the whole picture of drawing a progress bar. Inspired by @TobiBS's answer, I find the implementation can be further simplified to

documentclass{beamer}
usepackage{tikz}

makeatletter
[email protected]
[email protected]=1cm

addtobeamertemplate{footline}{}{%
  begin{tikzpicture}
    useasboundingbox (0pt, 0pt) rectangle (paperwidth, [email protected]);
    % you can use pgfmath expressions directly in coordinate specifications
    fill[green] (insertframenumber/inserttotalframenumber*paperwidth, 0)
       rectangle (paperwidth, [email protected]);
  end{tikzpicture}%
}
makeatother

begin{document}
foreach x in {1,2,...,50} {
  begin{frame}{My frame}
    Test x
  end{frame}
}
end{document}

Answered by muzimuzhi Z on November 12, 2021

Add your own answers!

Related Questions

Reading Lines Verbatim into a Sequence Variable

1  Asked on September 29, 2021

 

How to convert datatypes?

3  Asked on September 28, 2021 by alex-dinovitser

     

Why is my longtable being treated like a figure?

0  Asked on September 28, 2021 by julia-s

     

Remove blank line in moderncv

1  Asked on September 28, 2021

   

Unable to get break lines in URLs for bibliography

1  Asked on September 28, 2021 by jinzu

     

how to go from emacs to xdvi

0  Asked on September 28, 2021 by pgc

     

pstricks is not work properly

2  Asked on September 27, 2021

 

Ask a Question

Get help from others!

© 2021 InsideDarkWeb.com. All rights reserved.