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)


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


with LaTeX instead of plain TeX:



\newcount\cntm \cntm=1
  \scalebox{\Scale}{#1}\ifnum\the\cntm=1 \kern-10pt\fi%
  \advance\cntm by \@ne%



alt text


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


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

% Here are the macros to parse the string character-by-character:

% This macro will be called on each character of the string:


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


An eTeX based solution

\currentStep = 1

% Do not increment step at 2nd iteration
  {\ifnum\currentStep = 2 
    \else \increment\currentStep


\handletokens 3{\kern-0,2em.\kern-0.1em}1415926535897932384626 \with\Show

alt text

  • You mean a ConTeXt-based solution? – Will Robertson Jan 23 '11 at 0: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 1:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.