Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
6  
For a random turn and perhaps some inspiration on random typesetting, see Are there any (La)TeX Easter Eggs? and my answer to How do I make my document look like it was written by an Cthulhu worshipping madman?. You'll have to change the code to be applied to every letter, which I don't know how to do. –  doncherry Dec 17 '11 at 12:17

2 Answers 2

up vote 47 down vote accepted

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

share|improve this answer
20  
Man, that kerning is TERRIBLE. –  fluffy Dec 17 '11 at 20:58
    
I believe Diomidis Spinellis as the author of the PostScript code is actually a member of this community. –  Christian Lindig Dec 18 '11 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 ... –  Frank Mittelbach Dec 20 '11 at 17:47
3  
Fluffy, is that a joke? The kerning should be terrible to meet the OP's needs... –  dfc Jan 28 '12 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.

\documentclass{article}
\usepackage{xcolor,graphicx}
\usepackage{expl3,l3rand,xparse}
\usepackage{bbold}
\ExplSyntaxOn
\cs_generate_variant:Nn \clist_item:Nn { Nf }
\clist_const:Nn \c_anon_fonts_clist
  {
    \fontfamily{antt}\selectfont\bfseries,
    \fontfamily{antt}\selectfont\itshape,
    \fontfamily{antt}\selectfont,
    \bfseries,
    \bbfamily,
    \itshape,
    \scshape,
    \rmfamily
  }
\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
  {
    \anon_random_box:n
      {
        \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_font:
            \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:
        \rand_clean:
      }
  }
\ExplSyntaxOff
\begin{document}
\raggedright\pagestyle{empty}

\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!}

\end{document}

\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

share|improve this answer
2  
Awesome, Bruno! :) –  Paulo Cereda Dec 17 '11 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 Dec 18 '11 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 Dec 18 '11 at 7:03
    
@Canageek: thanks. I added that font, and \bbfamily. –  Bruno Le Floch Dec 19 '11 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 Dec 19 '11 at 2:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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