[Tex/LaTex] How to display pi in LaTeX like Don

fontsizemath-modetypography

Way back in 1979, Donald Knuth, tried to give the feeling that π is irrational using the idea of infinite sequence of smaller and smaller font sizes like what I have tried to do here using HTML and CSS. How do I do the same using LaTeX?

Now to the very difficult part, how do I some how create the feeling using typesetting that π is transcendental (not a solution of any finite polynomial having integer coefficients).

.pi sub { vertical-align: baseline; font-size: 96%; }

π = 3.14159265358979323846264338327950288419716939937510

Best Answer

EDITED to allow repeat invocations without having to reset parameters, using the syntax

\diminish[scale-down-ratio]{string}

The value of \defaultstartht sets the strut height of the first letter (default is set to \baselineskip), and the scale-down ratio defaults to 0.98, but may be supplied as an optional parameter.

Beware that arithmetic underflows are possible, if things get teeny enough.

See addendum for pseudo 3-D effect:

\documentclass{article}
\usepackage{scalerel}
\newlength\curht
\def\defaultdimfrac{.98}
\def\defaultstartht{\baselineskip}
\newcommand\diminish[2][\defaultdimfrac]{%
  \curht=\defaultstartht\relax
  \def\dimfrac{#1}%
  \diminishhelpA{#2}%
}
\newcommand\diminishhelpA[1]{%
  \expandafter\diminishhelpB#1\relax%
}
\def\diminishhelpB#1#2\relax{%
  \scaleto{\strut#1}{\curht}%
  \curht=\dimfrac\curht\relax%
  \ifx\relax#2\relax\else\diminishhelpA{#2}\fi%
}
\begin{document}
\def\defaultstartht{14pt}
\def\pinum{3.14159265358979323846264338327950288419716939937510}
\diminish{\pinum}\par
\diminish[0.96]{\pinum}\par
\diminish[0.94]{\pinum}\par
\def\defaultstartht{38pt}
\diminish[0.92]{\pinum}
\end{document}

enter image description here

ADDENDUM

Based on Yori's desire to see something more "3-D", I have EDITED to incorporate Bruno's \slantbox at Shear transform a "box". Combining that with a \raisebox allows the effect which some may find more 3-D. The additional user parameters to control it are \slantvalue which is Bruno's model parameter and \zshft, which is an added vertical shift per letter.

\documentclass{article}
\usepackage{scalerel}
\newlength\curht
\newlength\zshft
\newcounter{letcount}
\def\defaultdimfrac{.98}
\def\slantvalue{0}
\zshft=0pt\relax
\def\defaultstartht{\baselineskip}
\newcommand\diminish[2][\defaultdimfrac]{%
  \curht=\defaultstartht\relax
  \def\dimfrac{#1}%
  \setcounter{letcount}{0}
  \diminishhelpA{#2}%
}
\newcommand\diminishhelpA[1]{%
  \expandafter\diminishhelpB#1\relax%
}
\def\diminishhelpB#1#2\relax{%
  \raisebox{\value{letcount}\zshft}{\scaleto{\strut\slantbox{#1}}{\curht}}%
  \stepcounter{letcount}%
  \curht=\dimfrac\curht\relax%
  \ifx\relax#2\relax\else\diminishhelpA{#2}\fi%
}
\newsavebox{\foobox}
\newcommand{\slantbox}[2][\slantvalue]{\mbox{%
        \sbox{\foobox}{#2}%
        \hskip\wd\foobox
        \pdfsave
        \pdfsetmatrix{1 0 #1 1}%
        \llap{\usebox{\foobox}}%
        \pdfrestore
}}
\begin{document}
\def\pinum{3.14159265358979323846264338327950288419716939937510}
\def\defaultstartht{14pt}
  \diminish{\pinum}\par
\def\slantvalue{.15}
\zshft=.1pt\relax
  \diminish[0.96]{\pinum}\par
  \diminish[0.94]{\pinum}\par
\def\slantvalue{.35}
\zshft=.4pt\relax
\def\defaultstartht{38pt}
  \diminish[0.92]{\pinum}
\end{document}

enter image description here

While the curvy tail gives a certain stylistic fading, it might be preferable to follow the rules of perspective and have the numbers vanish along a linear path to the vanishing point. What this means is that rather than an additional \zshft added for each letter, the \zshft should also get smaller with each letter, so that the total shift (dZ) on the nth letter (after the 1st) should be

dZ = dz + k dz + k^2 dz + ... + k^(n-1) dz

where dz is the specified \zshft, and k is the scale-down parameter given by \dimfrac. Simple manipulation reveals that the shift for the nth letter (after the 1st) is:

dZ = dz (1 - k^n)/(1-k)

This can be calculated in LaTeX, but requires the much more computationally intensive fp package. So, at the expense of compilation time, we can achieve the following:

\documentclass{article}
\usepackage{scalerel,fp}
\newlength\curht
\newlength\zshft
\newcounter{letcount}
\def\defaultdimfrac{.98}
\def\slantvalue{0}
\zshft=0pt\relax
\def\defaultstartht{\baselineskip}
\newcommand\diminish[2][\defaultdimfrac]{%
  \curht=\defaultstartht\relax
  \def\dimfrac{#1}%
  \setcounter{letcount}{0}
  \diminishhelpA{#2}%
}
\newcommand\diminishhelpA[1]{%
  \expandafter\diminishhelpB#1\relax%
}
\def\diminishhelpB#1#2\relax{%
  \FPpow\localshift{\dimfrac}{\theletcount}\unskip%
  \FPsub\localshift{1}{\localshift}%
  \FPsub\localdenom{1}{\dimfrac}%
  \FPdiv\localshift{\localshift}{\localdenom}%
  \raisebox{\localshift\zshft}{\scaleto{\strut\slantbox{#1}}{\curht}}%
  \stepcounter{letcount}%
  \curht=\dimfrac\curht\relax%
  \ifx\relax#2\relax\else\diminishhelpA{#2}\fi%
}
\newsavebox{\foobox}
\newcommand{\slantbox}[2][\slantvalue]{\mbox{%
        \sbox{\foobox}{#2}%
        \hskip\wd\foobox
        \pdfsave
        \pdfsetmatrix{1 0 #1 1}%
        \llap{\usebox{\foobox}}%
        \pdfrestore
}}
\begin{document}
\def\pinum{3.14159265358979323846264338327950288419716939937510}
\def\defaultstartht{14pt}
  \diminish{\pinum}\par
\def\slantvalue{.15}
\zshft=.3pt\relax
  \diminish[0.96]{\pinum}\par
  \diminish[0.94]{\pinum}\par
\def\slantvalue{.35}
\zshft=1.7pt\relax
\def\defaultstartht{38pt}
  \diminish[0.92]{\pinum}
\end{document}

enter image description here

Oops!! Spill in aisle 1! (coding left to the student)

enter image description here