How to number frames with an increasing number of digits of pi? Illustrative, I want the frame numbers to be like
-
3 (on the first slide)
-
3.1 (on the second slide)
-
3.14 (on the third slide)
… and so on.
This is a question, which occupies me for quite some time; actually since a talk I gave on March 14th (also known as pi-day 😃.
My present workaround is, to insert the frame numbers by hand – which is of course quite annoying when changing the order of slides.
EDIT:
Based on Reds great answer I compiled an unpretentious solution. It abstains new counters in favour of the current page number.
This can also be done by returning \pgfmathresult
of pi with the precision determined by the frame number. I kinda like that \pgfmathprintnumber
rounds the output, so the fourth frame will be 3.142, the fifth will be 3.1416, the sixth 3.14159, and so on.
Here I present a ConTeXt solution which admittedly cheats a little and resorts to Perl, instead of using Lua to calculate Pi. The idea can easily be ported to LaTeX as well.
First the TeX macro \PrintPi
is created, which generates one more
digit with every consecutive call. It only keeps track of the page
number and calls Perl. This macro is then placed in the header of
every page.
The performance should be sufficient for presentations with less than 400 slides.
Page 69:
Here’s an approach using stringstrings
package.
Here is a solution using lua
. With this solution you don’t have to bother about which slide is it, or whether you have given enough digits at the beginning. Obviously, it can be easily integrated into one of the themes of beamer
, so you can typeset it in a fancy way as well.
Has to be processed using lualatex
.
A slight modification to your code using the xstring
package can do the trick. You have to enter Pi
as a string, though:
I tried to make the total be pi or \pi
as well but beamer
didn’t want to play, this does the digit counting though.
EDIT
I did not success in using an algorithm to calculate the pi digits but I can get them by the web using the \write18
command of LaTeX
(require --shell-enabled
) and the shell command wget
and sed
.
All you need to do is substitute the row
xxxxxxxxxx
\CatchFileDef{\PiG}{pi.txt}
in the code below with:
xxxxxxxxxx
\IfFileExists{./digits.txt}{}
{
\immediate\write18{\detokenize{wget http://www.geom.uiuc.edu/~huberty/math5337/groupe/digits.html -O digits.txt}}
\immediate\write18{sed -i '/[0-9]$/!d' digits.txt}
\immediate\write18{sed -i '1,13!d' digits.txt}
\immediate\write18{sed -i 's/ //g' digits.txt}
}
\CatchFileDef{\PiG}{digits.txt}
This is the correct modification to @user36411 answer. Just create a file pi.txt
with the number of pi digits you need.