Just to remind everyone of the amazing coffee stains package - coffee by Hanno Rein. This package makes it possible to add coffee stains to your document.

This question is for a generalization of coffee which would drain coffee on each and every page of your document. The stains should be random, and different on every page. Even further generalization is to add wine, ketchup, mustard stains. More difficult I think are nicotine (little burns?) and oil stains (which make the page a bit greasy and transparent).

A basic answer is easy I think: combine \everypage with pgf randomization and the coffee4.

Why would this be useful to anyone? I think heaps. Consider the common case by which an author makes an electronic version of his book available through the net, but is still interested in selling the printed and bound book. Adding stains to the electronic version would add teeny incentive to buying the printed copy.


EDIT Here is a minimal, but non-working answer:

  • 4
    I just yesterday sent Dr. Rein pdfcoffee.sty that uses png overlays (either directly called in the text, or with an everypage interface that allows arbitrary x,y placement.). However, I still only use his original 4 stains, and so doing it every page would get old, I think. I made two versions, with regular images and with transparant background images. While latter is preferable, I seemed to detect anti-aliasing artifacts. His reply: "Oh wow. That's amazing. I'm surprised you even found this after all those years. I think I might have to put this in a github repository after all." – Steven B. Segletes Apr 8 '15 at 17:21
  • 1
    I should add that his original package does not work with pdflatex, and so that was my motivation. When placed inline, the syntax is \coffee[<x-shift>]{<1-4>}, where <xshift> is applied atop the default horizontal shift. Alternately, I can use \atXY{<x>}{<y>}{\coffee{<1-4>} which does a ThisPageHook of the stain at the designated coordinate (upper left of stain). – Steven B. Segletes Apr 8 '15 at 17:22
  • 2
    why have you left out chocolate smears from inadequately licked fingers? – barbara beeton Apr 8 '15 at 17:35
  • 1
    The reason I wanted to use the feature (not on every page, but just the first few) was to identify to the reader that the version he is reading is a draft version. (I also use DRAFT header/footer, but coffee was a nice added touch) – Steven B. Segletes Apr 8 '15 at 17:50
  • 1

I can show how to do this in my favorite format, i.e. in plain TeX.

\input random
\input fun-coffee


   \setrannum\tmpnum{0}{50}\kern\the\tmpnum mm
   \setrannum\tmpnum{10}{150}\coffeepic\picnum \hfil
\def\coffeepic#1{\vbox to0pt{\kern\the\tmpnum mm
   \ifcase#1\coffeeA \or \coffeeB \or \coffeeC \or \coffeeD \fi\vss  

The four pictures are printed in random sizes (from the factor 0.4 to 0.99) and at random places. The fun-coffee.tex macro file is available here.

  • Thanks for this great answer. I could not get it to work as is on LateX since it does not recognize the \headline command. A fix is to employ \usepackage{everypage} and then \AddEverypageHook{\setrannum\picnum{0}{3}... Doing so, the overhead is infinitesimally small. Wonderful. – Yossi Gil Apr 9 '15 at 4:29
  • Should you be interested, I applied this to the course notes of my programming languages course. See here: dropbox.com/sh/gwbaa1axw4mx300/AABS86SAKMv7AIvUNx_j0_2va?dl=0 – Yossi Gil Apr 9 '15 at 9:11

Here is something that works.



\pgfmathsetseed{\pdfuniformdeviate 10000000}


  \pgfmathparse{(0.1 + rnd/3)}\xdef\trans{\pgfmathresult}%



  • Does not work in twocolumn mode
  • It is real slow; my compile time is 20sec, but without the stains, it is only 0.4 sec.

Would it be faster with lualatex? I don't know.

  • 1
    Try to change \usepackage{coffee4} to\input fun-coffee (see my answer) and replace the line \pgfmathdeclarerandomlist{stains}{{\cofeAm}{\cofeBm}} by \pgfmathdeclarerandomlist{stains}{{\coffeeA}{\coffeeB}{\coffeeC}{\coffeeD}} and line \stain{\trans}... by \edef\coffeescale{\trans}\stain. Then the speed is normal. – wipet Apr 9 '15 at 3:05

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.