# Coffee (and wine (and nicotine)) stains on an entire document

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

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

\documentclass{article}
\usepackage[a5paper]{geometry}
\usepackage{lipsum}
%\setlipsumdefault{1-145}
\usepackage{coffee4}
\usepackage{everypage}
\def\randomAngle{\pdfuniformdeviate{360}}
\begin{document}
\lipsum
\end{document}

• 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
• 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
• why have you left out chocolate smears from inadequately licked fingers? – barbara beeton Apr 8 '15 at 17:35
• 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
• – Werner Apr 8 '15 at 17:55

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

\input random
\input fun-coffee

\newcount\picnum
\newcount\tmpnum

\setrannum\tmpnum{0}{50}\kern\the\tmpnum mm
\setrannum\tmpnum{40}{99}\edef\coffeescale{.\the\tmpnum}%
\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.

\documentclass{article}

\usepackage[a5paper]{geometry}
\usepackage{lipsum}
\usepackage{coffee4}
\usepackage{everypage}
\usepackage{pgf}

\pgfmathsetseed{\pdfuniformdeviate 10000000}

\pgfmathdeclarerandomlist{scales}{{0.5}{0.7}{1.0}{1.4}}
\pgfmathdeclarerandomlist{stains}{{\cofeAm}{\cofeBm}}

\pgfmathrandominteger{\angle}{15}{350}%
\pgfmathparse{rand/2.4}\xdef\xoffset{\pgfmathresult}%
\pgfmathparse{rand/2.4}\xdef\yoffset{\pgfmathresult}%
\pgfmathparse{(0.1 + rnd/3)}\xdef\trans{\pgfmathresult}%
\pgfmathrandomitem{\scale}{scales}%
\pgfmathrandomitem{\stain}{stains}%
\stain{\trans}\scale\angle{\xoffset\textwidth}{\yoffset\textheight}%
}

\begin{document}
\lipsum[1-150]
\end{document}


Limitations:

• 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.

• 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