66

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%; }

&pi; = 3.14159<sub>2<sub>6<sub>5<sub>3<sub>5<sub>8<sub>9<sub>7<sub>9<sub>3<sub>2<sub>3<sub>8<sub>4<sub>6<sub>2<sub>6<sub>4<sub>3<sub>3<sub>8<sub>3<sub>2<sub>7<sub>9<sub>5<sub>0<sub>2<sub>88419716939937510</sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub></sub>
Sukii
  • 1,051
  • Thanks for all those interesting answers. I am humbled by all your answers. – Sukii Oct 23 '14 at 17:23
  • 1
    856142 repeats, so they usually indicate this repeat by $1/7=0.142\overline{856142}$. I think any rational number has these repeats. – Sukii Oct 24 '14 at 13:01
  • You could think of transcendence as lack of rootedness. – Sukii Oct 24 '14 at 14:00
  • Blabbering along the same vein, since polynomials with rational coefficients are countable, these rootless transcendental numbers are what fills the real line. Looks more like our modern society? – Sukii Oct 25 '14 at 07:45
  • I know that the decimal representation of any rational number ultimately repeats (and of irrationals it doesn't ultimately repeat). However there is no way one can see from an initial segment whether it ultimately repeats. Which is why I needed to indicate that what I wrote was supposed to be the (repeating) representation of 1/7. – Marc van Leeuwen Oct 25 '14 at 07:49
  • 1
    @Sukii: Or More directly as $1/7=0.\overline{142856}$. And yes, any rational number is of that form (if you count a repeating 0 the same way, although it would be highly unusual to set $1/4=0.25\overline{0}$). The same way, the continued fraction of any algebraic of degree 2 is eventually repeating. – Christopher Creutzig Oct 25 '14 at 13:07
  • One way transcendence can be indicated subtly using .pi sub { vertical-align: top; font-size: 96%; } showing that it is not rooted to baseline. Can you do that in LaTeX? – Sukii Oct 26 '14 at 15:41
  • @Maesumi: Yes I knew that; I can't figure out why I wrote that or even what I meant at the time. I guess I'll just delete the silly comment. – Marc van Leeuwen Nov 23 '15 at 21:00

5 Answers5

98

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

  • 8
    In some sense the "right" value for scale-down-ratio would be 0.1. – Nate Eldredge Oct 22 '14 at 21:57
  • 1
    I wonder if there is a way to make this look more "3D", i.e., making it look like an infinite row of numbers vanishing at the horizon? – yori Oct 23 '14 at 01:25
  • @NateEldredge A factor of 0.1 in each numeral's area, perhaps, so a factor of 0.3 in character height. Cute. – rob Oct 23 '14 at 02:09
  • 2
    @Yori Does the addendum achieve what you desire? – Steven B. Segletes Oct 23 '14 at 10:43
  • @StevenB.Segletes: Haha, pretty cool!! – yori Oct 24 '14 at 07:22
  • @NateEldredge Like reals on the number line, I am dense. While 6 people liked your comment about the right value for scale-down parameter being 0.1, I still don't understand the comment at all. I couldn't even say whether there is a joke hidden it it or some greater mathematical truth? – Steven B. Segletes Oct 24 '14 at 14:18
  • 1
    @StevenB.Segletes: Since we're working in base 10, the value of each successive decimal place is 1/10 the value of the one before it. So maybe one should make the heights diminish in the same proportion. (Or, as rob, suggests, the areas.) – Nate Eldredge Oct 24 '14 at 18:22
  • 2
    @NateEldredge D'oh! So your comment contained both a joke and a greater mathematic truth! – Steven B. Segletes Oct 24 '14 at 19:38
28

Mark Wibrow enhanced the text decoration library of TikZ greatly and you can do all kinds of stuff based on formulas regarding the character number and total count of words and so on.

Here is a wacky take on it, (thus a simple monotone scaling along a path is very simple and is possible just by playing with the formula with scale instead of yscale)

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.text}
\tikzset{pi decoration/.style={
decoration={text effects along path,
text={3.14159265358979323846264338327950288419716939937510},
text align=center,
text effects/.cd,
character total=\n,character count=\i,
path from text,
characters={yscale=10*sin(deg(5*\i/\n))-\i/\n,inner sep=0,anchor=base}
}}}
\begin{document}
\begin{tikzpicture}
\path[pi decoration,decorate] (0,0);
\end{tikzpicture}
\end{document}

enter image description here

percusse
  • 157,807
24

A recursive macro:

\documentclass[border=2]{standalone}
\usepackage{mathptmx} % a scalable font is needed

\makeatletter \def\makesmaller#1#2{% \dimen0=\dimexpr\dimen0-.08pt\relax \ifx#2\relax \expandafter@gobble \else {\fontsize{\dimen0}{0}\selectfont#1}% \expandafter@firstofone \fi {\makesmaller{#2}}% } \def\decreasingpi{% {\dimen0=16pt\fontsize{\dimen0}{0}\selectfont 3.\makesmaller1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253 \relax} } \makeatletter

\begin{document} \decreasingpi \end{document}

enter image description here

One might first count the number of digits and decide the minimum size, so as to adjust the decrease step. I leave this as an exercise.


UPDATE

A different version:

\documentclass{article}
\usepackage{graphicx}

\ExplSyntaxOn

\NewDocumentCommand{\vanishing}{O{1}m} { \seq_set_split:Nnn \l_tmpa_seq { . } { #2 } \seq_item:Nn \l_tmpa_seq { 1 } . \seq_set_split:Nnx \l_tmpb_seq { } { \seq_item:Nn \l_tmpa_seq { 2 } } \fp_set:Nn \l_tmpa_fp { \seq_count:N \l_tmpb_seq } \seq_map_indexed_inline:Nn \l_tmpb_seq { \scalebox{\fp_eval:n { 1 - ##1/(\seq_count:N \l_tmpb_seq + #1) } } { ##2 } } }

\cs_generate_variant:Nn \seq_set_split:Nnn { Nnx }

\ExplSyntaxOff

\begin{document}

$e=\vanishing[10]{2.71828 18284 59045 23536 02874 71352 66249 77572 47093 69995}$

$e=\vanishing{2.71828 18284 59045 23536 02874 71352 66249 77572 47093 69995}$

\end{document}

The optional argument (default 1) is for avoiding the last digit becomes too small.

enter image description here

egreg
  • 1,121,712
13

Just another way...

\documentclass[varwidth,border=5]{standalone}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\newdimen\dx
\def\dm#1#2{\dx=1em\relax\def\rt{#1}{\Dm#2\dm}}
\def\Dm#1{\ifx#1\dm\else\fontsize\dx\dx\selectfont#1\dx=\rt\dx\expandafter\Dm\fi}
\begin{document}
\dm{0.95}{3.14159265358979323846264338327950288419716939937510}
\end{document}

enter image description here

Mark Wibrow
  • 70,437
3

For example, in plain TeX:

\input apnum

\apFRAC=80

\evaldef\Pi{\PI} \evaldef\E{\EXP{1}}

\def\printsmaller#1{\ifx\end#1\else #1\pdfsetmatrix{.97 0 0 .97}% \expandafter\printsmaller\fi}

\noindent\pdfsave\rlap{\expandafter\printsmaller\E\end}\pdfrestore \bigskip \noindent\pdfsave\rlap{\expandafter\printsmaller\Pi\end}\pdfrestore

\bye

wipet
  • 74,238