I'm trying to create an effect as if the text is made up of letters cut from magazines and newspapers and even the same words had different style. It is necessary that each letter in the word had a random parameters (in a predetermined range):

  • fonts (from a few pre-selected)
  • font size
  • turn
  • above or below the baseline for a few pt

Of course, all this can be set manually, but it will take a long time. How can this be automated?


2 Answers 2


I only know about a non-LaTeX solution using PostScript. Because PostScript is a programming language it can randomly pick fonts while typesetting a text. A program ransom.ps using that effect was once published by Diomidis Spinellis on Usenet. The description reads:

This is a small postscript program you can use to create ransom notes. Enter the text you want between the brackets at the beginning of the script and send the whole file to a postscript printer. The text will be printed using many different fonts, sizes, orientations, and styles. You can modify the margins and the fonts used, by modifying the source.

Executing the PostScript code ransom.ps gave me the following result:

enter image description here

  • 22
    Man, that kerning is TERRIBLE.
    – fluffy
    Commented Dec 17, 2011 at 20:58
  • I believe Diomidis Spinellis as the author of the PostScript code is actually a member of this community. Commented Dec 18, 2011 at 20:55
  • Diomidis' solution is quite nice indeed (and it fits my image of him that it was done in PostScript :-) but it doesn't really answer to the question how to do this in TeX does it? Okay, the question doesn't explicitly asks for this but ... Commented Dec 20, 2011 at 17:47
  • 3
    Fluffy, is that a joke? The kerning should be terrible to meet the OP's needs...
    – dfc
    Commented Jan 28, 2012 at 8:45

EDIT: I changed the text to be the same as Christian Lindig, and added a couple of typefaces.

Here is a partial solution with the very experimental l3rand package for random numbers. It can be found in the l3trial directory of the LaTeX3 source code (see, e.g., the GitHub mirror).

I've never taken time to learn how to load other fonts, so you should probably customize the list of font changing commands given in \c_anon_fonts_clist.

\cs_generate_variant:Nn \clist_item:Nn { Nf }
\clist_const:Nn \c_anon_fonts_clist
\cs_new_protected:Npn \anon_random_font:
    \clist_item:Nf \c_anon_fonts_clist
      { \rand_range:nn { 0 } { \clist_length:N \c_anon_fonts_clist - 1 } }
\cs_new_protected:Npn \anon_random_box:n #1
    \rotatebox [origin=c] { \rand_range:nn {-15} {15} }
        \exp_args:Nx \scalebox
          { 1 . \rand_range:nn { 0 } { 99 } }
          { \rand_clean: #1 }
\cs_new_protected:Npn \anon_one_letter:n #1
        \int_if_odd:nF { \rand_range:nn {0}{1} }
          { \colorbox[gray]{ 0.\rand_range:nn {0}{99} } }
            \color[gray]{ 0.\rand_range:nn {0}{99} }
            \anon_random_box:n { \scalebox{.8}{#1} \rand_clean: }
\DeclareDocumentCommand { \AnonymousLetter } { o m }
    \IfValueT {#1} { \rand_seed:n { #1 } }
    \seq_set_split:Nnn \l_anon_seq { ~ } {#2}
    \seq_map_inline:Nn \l_anon_seq
        \tl_map_function:nN {##1} \anon_one_letter:n
        \hskip \rand_range:nn { 3 } { 10 } pt \scan_stop:
        \penalty 2000\scan_stop:

\AnonymousLetter{Mr. Diomidis Spinellis}

\AnonymousLetter{This is a message from an international terrorist group.
We have abducted your files and have hidden them away.
You must pay \$500 by Sunday afternoon in order to see them again.
You will receive further telephone instructions.
Do not notify the police or any authorities; you will endager their life.}

\AnonymousLetter{Remember: time flies!}


\AnonymousLetter loops over word in the input with \seq_map_inline:Nn, and for each letter in the word (\tl_map_function:nN) wraps this letter in a bunch of boxes with random parameters. The function \anon_random_box:n is defined to be a combination of \scalebox and \rotatebox. The method to produce floating point random numbers is somewhat kludgy since I haven't programmed floating point random numbers yet, I glue together the integer and decimal pieces.

The first, optional, argument of \AnonymousLetter is the seed for the RNG. You may want to play around with that, and other parameters to suit your use case. The output I get is:

Output of the code for an anonymous letter

  • 2
    Awesome, Bruno! :) Commented Dec 17, 2011 at 22:42
  • Could you add in random typefaces from a list to make it look more like it was taken from different documents? Some of the ones at tug.dk/FontCatalogue/otherfonts.html look like they would work quite well.
    – Canageek
    Commented Dec 18, 2011 at 7:00
  • Ah, Just saw your line that you'd never learned that: The line I found was \fontfamily{antt}\selectfont <text here> where antt is a four letter code for the font-- I found it by looking through the package and experimenting, though I bet there is a list somewhere.
    – Canageek
    Commented Dec 18, 2011 at 7:03
  • @Canageek: thanks. I added that font, and \bbfamily. Commented Dec 19, 2011 at 2:44
  • @BrunoLeFloch That looks cool. I'd love to see if with a few more fonts tossed in there. Good thing I picked a common one for that document I did way back!
    – Canageek
    Commented Dec 19, 2011 at 2:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .