[Tex/LaTex] How to prolong compilation time while engaging in leisure activities

compilingfun

I thought of that old joke today, where a programmer can make an undeniable excuse for his leisure activities while in work on the basis that he is just waiting for his code to compile.

Although I am a workaholic and a fair player, such an excuse comes in handy now and then, so what is the best way to achieve a long compilation time with as little additional code as possible?

Additional imaginary points shall be awarded for any cunning additional value such as making it hard for a LaTeX advanced user or even an expert to identify the cause straight away (the longer it takes, the better) or exceptionally creative ways of doing so.

All solutions must eventually compile, so indefinite loops and such are prohibited. The ideal solution should not produce written output to the built document, mask itself from the console output log, load as few packages as possible, and be difficult to detect.

Use this as a basic template and use e.g. UNIX time to find how long the compilation took (should any solutions come, I shall time them under the same conditions and post the results) (this is unnecessary since there are virtually infinite solutions).

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\title{Title}
\author{Author}
\date{Today}
\maketitle
\lipsum
\end{document}

Hopefully it is worth some time and a laugh and not just one of my idiomatic (and perhaps idiotic) creations.

Best Answer

With pdfTeX, add

\everypar{\ifnum\pdfelapsedtime<\maxdimen
  \the\expandafter\everypar\else\pdfresettimer\fi}

(after the \begin{document} if you are using pdfLaTeX). This will wait four hours and a half (\maxdimen scaled seconds, that is, 2^{30-16} seconds) before starting each paragraph. Replace \maxdimen by 65536 (and a space) to get a one second delay at each paragraph. Compiling a book with, say, 1000 paragraphs takes about six months. Not bad for a 90 characters addition.

With a bit more code (184 characters), an engine-agnostic implementation of the Ackermann function lets us get pretty much any delay by changing the arguments of \A just a little bit (I am not sure at what point TeX's limits are exceeded). With

\def\A#1#2{\the\numexpr\B{#1}{#2+1}\empty
  {\A{#1-1}{\B{#2}1\empty{\A{#1}{#2-1}}.}}.\relax}
\def\B#1{\ifnum\numexpr#1=0 \C\else\C\fi}
\def\C#1#2#3#4#5.{#1#3#4}
\everypar{{\count0=\A{3}{1}}}

I add about 6 minutes per paragraph to the compilation time on my machine. An additional benefit of this answer is that the definitions can easily be scattered in the preamble to avoid detection. Using xint lets us manipulate larger numbers, hence give larger arguments to \A:

\usepackage{xint}
\def\C#1#2#3#4#5.{#1#3#4}
\def\b#1{\if0\s{#1}\C\else\C\fi}
\let\s\xintSgn
\let\d\romannumeral
\let\x\xintAdd
\def\a#1#2{\b{#1}{\x{#2}1}\empty{%
    \a{\x{#1}{-1}}
    {\d-`-\b{#2}1\empty{\a{#1}{\d-`-\x{#2}{-1}}}.}}.}
\everypar{\d-\xintSgn{\A{3}{1}} }

This last code is not tested: xint puts an overhead on TeX's arithmetic, which makes the whole thing way too slow. Slower, even, would be to use the bigintcalc package, which predates xint and is not as optimized.

Related Question