beamer add tag
samcarter (imported from SE)
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}
    \setbeamertemplate{navigation symbols}{}

    \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}
    \setbeamertemplate{navigation symbols}{}
    \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
                     3\StrLeft{.141592653589793238462643383279502884197169399375105820974944592307816406286 208998628034825342117067982148086513282306647093844609550582231725359408128481}{\arabic{framenumber}}
    	     	\end{minipage}
            }
    	\end{picture}
    }
    
    \begin{document}
        \begin{frame}
        \end{frame}
        
        \begin{frame}
        \end{frame}
    \end{document} 

  
Top Answer
egreg (imported from SE)
Here's a way with LaTeX3 macros:


    \documentclass[t]{beamer}
    \usepackage{xparse}
    
    \setbeamertemplate{navigation symbols}{}

     % just add the frame numbers
    \setbeamertemplate{footline}{\hfill\Large\strut\pagepi{\arabic{framenumber}}\hspace*{1pc}}
    
    \ExplSyntaxOn
    \tl_const:Nn \c_pidigits_tl {1415926535897932384626433832795028842}
    \DeclareExpandableDocumentCommand{\pagepi}{m}
     {
      \int_compare:nTF { #1 < 2 }
        { 3 }
        {
         3.
         \int_step_function:nnnN { 1 } { 1 } { #1-1 } \my_print_digits:n
        }
     }
    \cs_new:Npn \my_print_digits:n #1
     {
      \tl_item:Nn { \c_pidigits_tl } { #1 }
     }
    \ExplSyntaxOff
    \begin{document}
    
    \begin{frame}
    a\pause
    b
    \end{frame}
    \begin{frame}
    a\pause
    b
    \end{frame}
    \begin{frame}
    a\pause
    b
    \end{frame}
    
    \end{document}

![enter image description here][1]

---

A different implementation using a property list; here 250 digits are available, much more than a presentation should need.

    \documentclass[t]{beamer}
    \usepackage{xparse}
    
    \setbeamertemplate{navigation symbols}{}
    \setbeamertemplate{footline}{\hfill\Large\strut\pagepi{\arabic{framenumber}}\hspace*{1pc}}
    
    \ExplSyntaxOn
    \tl_const:Nn \c_pidigits_tl 
     {3%. % source: http://www.eveandersson.com/pi/digits
      1415926535897932384626433
      8327950288419716939937510
      5820974944592307816406286
      2089986280348253421170679
      8214808651328230664709384
      4609550582231725359408128
      4811174502841027019385211
      0555964462294895493038196
      4428810975665933446128475
      6482337867831652712019091
     }
    \tl_new:N \l__pidigits_cumulate_tl
    \tl_set:Nn \l__pidigits_cumulate_tl { 3. }
    \prop_new:N \g_pidigits_prop
    \prop_gput:Nnn \g_pidigits_prop { 1 } { 3 }
    \int_step_inline:nnnn { 2 } { 1 } { \tl_count:N \c_pidigits_tl }
     {
      \tl_set:Nx \l__pidigits_cumulate_tl
       { \l__pidigits_cumulate_tl \tl_item:Nn \c_pidigits_tl { #1 } }
      \prop_gput:NnV \g_pidigits_prop { #1 } \l__pidigits_cumulate_tl 
     }
    \prop_show:N \g_pidigits_prop
    \DeclareExpandableDocumentCommand{\pagepi}{m}
     {
      \prop_get:Nf \g_pidigits_prop { #1 } % #1 is \arabic{framenumber}
     }
    \cs_generate_variant:Nn \prop_get:Nn { Nf }
    \ExplSyntaxOff
    
    \begin{document}
    
    \begin{frame}
    a\pause
    b
    \end{frame}
    \begin{frame}
    a\pause
    b
    \end{frame}
    \begin{frame}
    a\pause
    b
    \end{frame}
    
    \end{document}

  [1]: https://i.stack.imgur.com/CZcnJ.png
Answer #2
erik (imported from SE)
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}{%
    	\usebeamerfont{page number in head/foot}
    	\pgfkeys{/pgf/number format/.cd,fixed,precision=\thepage}
    	\pgfmathprintnumber{\pgfmathresult}
    	\vskip.5ex %
    }
    % Define pi to as many digits as you need
    \pgfmathparse{3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067}
    \setcounter{page}{0}
    
    \begin{document}
    \frame{}\frame{}\frame{}\frame{}\frame{}\frame{}
    \end{document}
Answer #3
Marco (imported from SE)
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)'")
        context( f:read("*a") )
      \stopluacode}

    \setupheadertexts [\PrintPi]

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

Page 69:

![screenshot][1]


  [1]: https://i.stack.imgur.com/gCw46.png
Answer #4
Steven B. Segletes (imported from SE)
Here's an approach using `stringstrings` package.

    \documentclass[t]{beamer}
    \usepackage{stringstrings}
    \usepackage[absolute,overlay]{textpos}
    \setbeamertemplate{navigation symbols}{}
    \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}
Answer #5
Dror (imported from SE)
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.

    \documentclass[t]{beamer}
    
    \usepackage[absolute,overlay]{textpos}
    \setbeamertemplate{navigation symbols}{}
    
    \usepackage{luatextra}
    
    \newcommand{\pifoot}{
      \begin{textblock*}{120mm}(0mm,84.3mm)
        \raggedleft $\luaexec{
          slidenumber = \insertframenumber
          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`.
Answer #6
user36411 (imported from SE)
A slight modification to your code using the [`xstring`][1] package can do the trick. You have to enter `Pi` as a string, though:

    \documentclass[t]{beamer}
    \usepackage{xstring}
    \usepackage[absolute,overlay]{textpos}
    \setbeamertemplate{navigation symbols}{}

    \newcounter{Pi}

    \newcommand{\pifoot}{
        \begin{textblock*}{120mm}(0mm,84.3mm)
            \raggedleft \StrChar{3141592653589793238462643383279502884197169}{\arabic{Pi}}
        \end{textblock*}
        \stepcounter{Pi}
    }


    \begin{document}

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

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

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

    \end{document}


  [1]: http://www.ctan.org/pkg/xstring
Answer #7
David Carlisle (imported from SE)
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.

    \documentclass[t]{beamer}
    
    \usepackage[absolute,overlay]{textpos}
    \setbeamertemplate{navigation symbols}{}
    
    \setbeamertemplate{footline}[frame number]
    
    \newcommand{\pifoot}[1]{
        \begin{textblock*}{120mm}(0mm,84.3mm)
            \raggedleft #1
        \end{textblock*}
    }
    \def\pilist{3{.1}4159265.....}
    \makeatletter
    \def\insertframenumber{\csname pi-\the\c@framenumber\endcsname}
    \@namedef{pi-1}{3}
    \@namedef{pi-2}{3.1}
    \@namedef{pi-3}{3.14}
    \@namedef{pi-4}{3.141}
    \@namedef{pi-5}{3.1415}
    \makeatother
    
    
    % this doesn't work:-)
    \def\inserttotalframenumber{pi}
    
    \begin{document}
    
        \begin{frame}
            \pifoot{3}
        \end{frame}
    
        \begin{frame}
            \pifoot{3.1}
        \end{frame}
    
        \begin{frame}
            \pifoot{3.14}
        \end{frame}
    
    \end{document}
Answer #8
kiss my armpit (imported from SE)
Without PSTricks. Only up to 19 slides!

    \documentclass{beamer}
    \usepackage[nomessages]{fp}
    \usepackage{multido}
    
    \begin{document}
    \multido{\i=0+1}{19}{%
    \FPtrunc{\x}{\FPpi}{\i}%
    \begin{frame}{\x}
    \end{frame}}
    \end{document}


![enter image description here][1]


  [1]: https://i.stack.imgur.com/6leIU.gif
Answer #9
Red (imported from SE)
## 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}}
        \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.

    \documentclass[t]{beamer}
    \usepackage{xstring,ifthen,catchfile,forloop}
    \usepackage[absolute,overlay]{textpos}
    \setbeamertemplate{navigation symbols}{}
    
    \CatchFileDef{\PiG}{pi.txt}
    \newcounter{Pi}
    \setcounter{Pi}{1}
    \newcommand{\pifoot}{
    	\ifthenelse{\arabic{Pi}=2}{\stepcounter{Pi}}{}
        \begin{textblock*}{120mm}(0mm,84.3mm)
            \raggedleft \StrLeft{\PiG}{\arabic{Pi}}
        \end{textblock*}
        \stepcounter{Pi}
    }
    
    
    \begin{document}
    \newcounter{framenum}
    \forloop{framenum}{1}{\value{framenumber} < 50}{
        \begin{frame}
            \pifoot
        \end{frame}
    }
    \end{document}

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.