# 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][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}%
}

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

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

begin{tikzpicture}
useasboundingbox (0pt, 0pt) rectangle ++ (paperwidth, [email protected]t);
begin{scope}
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][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}%
}

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

begin{tikzpicture}
useasboundingbox (0pt, 0pt) rectangle (paperwidth, [email protected]);
% you can use pgfmath expressions directly in coordinate specifications
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

## Related Questions

### Reading Lines Verbatim into a Sequence Variable

1  Asked on September 29, 2021

### Change the color of the chapter number (Oxford Thesis Template)

2  Asked on September 28, 2021 by user98131

### How to convert datatypes?

3  Asked on September 28, 2021 by alex-dinovitser

### How do I use the MagicPython syntax highlighting with latex?

0  Asked on September 28, 2021 by xetrev

### How to get alteration of biblatex-apa for online source

1  Asked on September 28, 2021

### Creating triangle commutative diagram with tikz-cd

1  Asked on September 28, 2021 by jaia

### latexindent: Can’t locate Log/Log4perl.pm in @INC (you may need to install the Log::Log4perl module)

4  Asked on September 28, 2021

### Latex Warning After Update Miktex: Font shape T1/lmr/m/scit’ undefined (Font) using T1/lmr/m/scsl’ instead

1  Asked on September 28, 2021

### How to tell one package where another package is located?

0  Asked on September 28, 2021

### 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

### How do I add a dot inside the zeros on the date?

0  Asked on September 27, 2021

### How can I produce s separate PDFs for each one of my floats, when their code isn’t self-contained

3  Asked on September 27, 2021

### Inserting and centering figures inside of a cell in a table (NiceTabular environment, nicematrix package)

1  Asked on September 27, 2021

### Coloring combining characters without changing color of a base character

5  Asked on September 27, 2021 by ojs

### Combine title page and contents on one page

0  Asked on September 27, 2021

### pstricks is not work properly

2  Asked on September 27, 2021