5

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}}
\AddEverypageHook{\cofeAm{1}{1.0}{\protect\randomAngle}{5.5cm}{3cm}}
\begin{document}
\lipsum
\end{document}
Yossi Gil
  • 15,951
  • 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 08 '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 08 '15 at 17:22
  • 2
    why have you left out chocolate smears from inadequately licked fingers? – barbara beeton Apr 08 '15 at 17:35
  • Arggh.... Would you like me to fix this, or would you be interested using your own licked fingers to edit my question? – Yossi Gil Apr 08 '15 at 17:40
  • @barbara beeton Well my method is certainly amenable to adding additional stains with new indices. All that is required for each new stain is a default horizontal offset from the invoked location, an image scale factor, and an image file. – Steven B. Segletes Apr 08 '15 at 17:40
  • 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 08 '15 at 17:50
  • 1
  • 1
    And muddy paw prints. :) – Thérèse Apr 08 '15 at 19:02
  • 1
    Another application, when grading math homework with both the tex and pdf submitted you could definitely make the graded version more interesting. This means some random red ink blotches and spills:) – R. Schumacher Apr 08 '15 at 19:08
  • 1
    I converted the Hanno Rein's data (original for PStricks) to the direct \pdfliteral language. No TikZ, no PStricks, no packages are needed. And I rounded the numbers during conversion, so the data is more compact. We needn't such accuracy for stains. You can compare 480 kB of coffeee4.sty with 128 kB in my result. Note that the body of all four macros of coffee.sty have to be stored in TeX memory. But the positioning macros is not solved here (for simplicity) and user can add these if he/she want. See http://petr.olsak.net/ftp/olsak/makra/fun-coffee.tex – wipet Apr 08 '15 at 20:16

2 Answers2

7

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

\headline{\setrannum\picnum{0}{3}%
   \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.

Yossi Gil
  • 15,951
wipet
  • 74,238
  • 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 09 '15 at 04:29
  • Should you be interested, I applied this to the course notes of my programming languages course. See here: https://www.dropbox.com/sh/gwbaa1axw4mx300/AABS86SAKMv7AIvUNx_j0_2va?dl=0 – Yossi Gil Apr 09 '15 at 09:11
1

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

\AddEverypageHook{%
  \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.

Yossi Gil
  • 15,951
  • 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 09 '15 at 03:05