10

How can I reproduce the figure below?

alt text

The figure is from an old Knuth paper, which you can get at http://www.math.lsa.umich.edu/~millerpd/docs/501_Winter08/Knuth79.pdf (page 364)

yannisl
  • 117,160

4 Answers4

15

with LaTeX instead of plain TeX:

\documentclass[landscape]{article}
\usepackage[T1]{fontenc}
\usepackage[a4paper]{geometry}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{fp}

\newcommand*\PIfrac{141592653589793238462643383279502884197169399375105820974!!}

\pagestyle{empty}
\makeatletter
\newcount\cntm \cntm=1
\def\printNum#1{\expandafter\printNum@i#1\@nil}
\def\printNum@i#1#2#3\@nil{%
  \FPdiv{\Scale}{1}{\the\cntm}%
  \typeout{==:\Scale}%
  \scalebox{\Scale}{#1}\ifnum\the\cntm=1 \kern-10pt\fi%
  \advance\cntm by \@ne%
  \ifx#2!\else\expandafter\printNum@i#2#3\@nil\fi}
\makeatother
\begin{document}

\fontsize{6cm}{5.2cm}\selectfont
\scalebox{1.5}{3\kern-15pt,}\kern-20pt\printNum{\PIfrac}

\end{document}

alt text

10

This code iterates over each token in a string and scales them according to a user-defined function:

\documentclass{minimal}

\usepackage{graphicx} % For \scalebox
\usepackage{pgf}      % For arithmetic calculations

% Here are the macros to parse the string character-by-character:
\newcounter{numcharacters}
\def\decreasing#1{\setcounter{numcharacters}{0}\decreasinginternal{#1}}
\def\decreasinginternal#1{\ifx#1\relax\else\decreasingchar#1\enddecreasing\fi}
\def\decreasingchar#1#2\enddecreasing{\addtocounter{numcharacters}{1}\scaleString{#1}{\thenumcharacters}\decreasinginternal{#2}}

% This macro will be called on each character of the string:
\def\scaleString#1#2{\pgfmathparse{6/(#2+2)}\scalebox{\pgfmathresult}{#1}}

\begin{document}
  \decreasing{3.1415926535897932384626}%
\end{document}

Here is the result such that token i is scaled by a factor of 6/(i+2): 3.1415926535897932384626

ESultanik
  • 4,410
7

http://www.tug.org/texshowcase/, search for "diminuendo.tex"

Jan Hlavacek
  • 19,242
6

An eTeX based solution

\newcount\currentStep
\currentStep = 1

% Do not increment step at 2nd iteration
\def\updateStep
  {\ifnum\currentStep = 2 
     \def\updateStep{\increment\currentStep}%
    \else \increment\currentStep
   \fi}

\def\Show#1%
  {\dontleavehmode\scale[width=\the\dimexpr\bodyfontsize/\currentStep\relax]{\hbox{#1}}%
   \updateStep}

\setupbodyfont[72pt]
\starttext
\startTEXpage
\handletokens 3{\kern-0,2em.\kern-0.1em}1415926535897932384626 \with\Show
\stopTEXpage
\stoptext

alt text

doncherry
  • 54,637
Aditya
  • 62,301
  • You mean a ConTeXt-based solution? – Will Robertson Jan 23 '11 at 00:46
  • No. It is essentially identical to Herbert's solution, but using \dimexpr instead of the fp package. I wrote the solution in ConTeXt, just because that is what I know better. It should be easily to replicate it in plain or LaTeX. Doesn't the graphics package have a macro to scale a box to a particular width? – Aditya Jan 23 '11 at 01:31