# How to number slides with an increasing number of digits of pi?

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.

\documentclass[t]{beamer}

\usepackage[absolute,overlay]{textpos}

\newcommand{\pifoot}[1]{
\begin{textblock*}{120mm}(0mm,84.3mm)
\raggedleft #1
\end{textblock*}
}

\begin{document}

\begin{frame}
\pifoot{3}
\end{frame}

\begin{frame}
\pifoot{3.1}
\end{frame}

\begin{frame}
\pifoot{3.14}
\end{frame}

\end{document}


EDIT:

Based on Reds great answer I compiled an unpretentious solution. It abstains new counters in favour of the current page number.

\documentclass[t]{beamer}

\usepackage[absolute,overlay]{textpos}
\usepackage{xstring}

\setbeamertemplate{footline}{%
\begin{picture}(54,12.5)(0,0)
\put(0.9,0.52){%
\begin{minipage}[b][12.5mm][c]{112.5mm}
\raggedleft
\end{minipage}
}
\end{picture}
}

\begin{document}
\begin{frame}
\end{frame}

\begin{frame}
\end{frame}
\end{document}

• Which template are you using? And is it the frame or slide numbers you want pi to appear? – percusse Sep 9 '13 at 10:13
• I use a custom-made template, therefore it is really nice that the answers below work independently of any template – samcarter_is_at_topanswers.xyz Sep 9 '13 at 11:05

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

\CatchFileDef{\PiG}{pi.txt}


in the code below with:

\IfFileExists{./digits.txt}{}
{
\immediate\write18{\detokenize{wget  http://www.geom.uiuc.edu/~huberty/math5337/groupe/digits.html -O digits.txt}}
if tonumber(slidenumber) == 1 then
numbertoinsert = tostring(3)
else
numbertoinsert = "\%." .. tostring(slidenumber-1) .. "f"
end
tex.sprint(string.format(numbertoinsert,math.pi))
}\$
\end{textblock*}
}

\begin{document}

\begin{frame}
\pifoot
\end{frame}

\begin{frame}
\pifoot
\end{frame}

\begin{frame}
\pifoot
\end{frame}

\end{document}


Has to be processed using lualatex.

• The numbers are wrong from slide #17 upwards. – Marco Sep 9 '13 at 13:06
• True indeed :( I don't know where the problem is coming from, but if I were to guess then I'd say due the bad representation of pi in lua. – Dror Sep 9 '13 at 13:37
• If someone has an idea how to solve the problem mentioned by @Marco, I would be delighted :) – Dror Sep 9 '13 at 13:47
• LuaTeX is compiled with the double precision floating point format, which is used in Lua for all numeric calculations. By default it does not offer a higher precision without implementing a custom number format or using an external library. – Marco Sep 9 '13 at 13:49
• Yes, this is what I figured out. There goes one of my first attempts with lua(TeX). – Dror Sep 9 '13 at 13:52

Here's an approach using stringstrings package.

\documentclass[t]{beamer}
\usepackage{stringstrings}
\usepackage[absolute,overlay]{textpos}
\def\PI{3.141592653589793238462643383279502884197169}
\newcounter{sigdigits}
\setcounter{sigdigits}{0}
\newcommand{\pifoot}{%
\if1\thesigdigits\stepcounter{sigdigits}\fi%
\stepcounter{sigdigits}%
\begin{textblock*}{120mm}(0mm,84.3mm)
\raggedleft \substring{\PI}{1}{\thesigdigits}%
\end{textblock*}
}

\begin{document}

\begin{frame}
\pifoot
\end{frame}

\begin{frame}
\pifoot
\end{frame}

\begin{frame}
\pifoot
\end{frame}

\end{document}

• fwiw, we once had a ctan package author who numbered versions 1, 1.1, 1.11, 1.111, etc (iirc, he got up to 1.111111111). i persuaded him that this didn't help people who wanted to know if they had the latest version. is pi any better in this regard? -- or does it not patter, since it's "only" a slide show? – wasteofspace Sep 9 '13 at 11:15
• @wasteofspace With a name like yours, is that not the pot calling the kettle black :^) I figured the OP's question was not for his general use, but as a gimmick on a particular presentation, perhaps one entitled "The nature of irrational numbers" or something. – Steven B. Segletes Sep 9 '13 at 11:40
• @wasteofspace As indicated in the original question, this page-numbering scheme was used for a special occasion (pi-day). And working in a rather nerdy environment my colleges found it quite funny. – samcarter_is_at_topanswers.xyz Sep 9 '13 at 12:24

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.

\setuppapersize [S6]  %% screen size for slides

\define\PrintPi
{\startluacode
userdata     = userdata or {}
userdata.num = userdata.num or 1
userdata.num = userdata.num + 1

f = io.popen("perl -Mbignum=bpi -wle 'print 0+substr(bpi("..userdata.num.."),0,-1)'")
\stopluacode}

\starttext
\dorecurse{80}
{\input ward\page}
\stoptext


Page 69:

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.

\documentclass{beamer}
\setbeamertemplate{footline}{%