Amusing exercise – ouroboros file – Output of TeX includes itself recursively ad infinitum

Here is a possible start: (code streamlined in edit)

The idea is to use the box model of TeX. In a vbox we construct the page. Then the vbox self-includes itself with a scale of .7 thanks to scalebox of package graphicx. The box includes an hyperref link, and all reduced copies up to the tiniest work.

documentclass[a4paper]{article}
usepackage[margin=0pt]{geometry}
usepackage{graphicx}
usepackage{picture}
usepackage{hyperref}% tous les liens marchent même le plus petit!
usepackage{url}
parindent0pt
topskip0pt
parskip0pt
newboxouroboros
begin{document}

setboxouroboros 
vbox{hsizedimexprpaperwidth-1cmrelax
begin{picture}(paperwidth-1cm,paperheight-1cm)
put(0,0){framebox(paperwidth-1cm,paperheight-1cm){}}
end{picture}}


% Loop
count255 15
loop
setboxouroboros
vbox{hsizedimexprpaperwidth-1cmrelax
begin{picture}(paperwidth-1cm,paperheight-1cm)
% frame
put(0,0){framebox(paperwidth-1cm,paperheight-1cm){}}% or dashbox
% top
put(0,.85paperheight){makebox(paperwidth-1cm,3cm){hugebfseries  HERE IS
    THE SOLUTION TO ALL MYSTERIES:}}
put(.5paperwidth-.5cm,.85paperheight){makebox(0,0){parbox{.9paperwidth}
{The ouroboros often symbolizes self-reflexivity or cyclicality, especially in
the sense of something constantly re-creating itself, the eternal return, and
other things such as the phoenix which operate in cycles that begin anew as
soon as they end.}}}
% SELF INCLUSION:
put(.5paperwidth-.5cm,.5paperheight-.5cm){makebox(0,0){scalebox{.7}{boxouroboros}}}
% bottom
put(.5paperwidth-.5cm,.1paperheight){makebox(0,0){parbox{.9paperwidth}
{It can also represent the idea of primordial unity related to something
existing in or persisting from the beginning with such force or qualities it
cannot be extinguished. While first emerging in Ancient Egypt, the ouroboros
has been important in religious and mythological symbolism, but has also been
frequently used in alchemical illustrations, where it symbolizes the circular
nature of the alchemist's opus. It is also often associated with Gnosticism,
and Hermeticism.

url{http://en.wikipedia.org/wiki/Ouroboros}}}}
end{picture}}
ifnumcount255 > 1
advancecount255 - 1
repeat

hrule height 0pt
kern0.5cm
noindentkern.5cmboxouroboros
end{document}

ouroboros

and with 15 iterations:

ouroboros15

EDIT

… include a more sinister version…

One File To Rule Them All...

I’m not sure if this is what you want. Strictly speaking, this file does not include itself. It includes its own output. This is what your images suggest you want but your description is ambiguous.

Anyway, since you mention using this with bashful, I thought I might as well use bashful. This needs to be compiled with shell escape for obvious reasons. But, if you are using bashful, then you obviously have to compile in a way which bashful requires and will therefore be using shell escape anyway.

A simple example:

documentclass{article}
usepackage{graphicx,bashful}
pagestyle{empty}
begin{document}

bash
[[ -f "prawf3.pdf" ]] && mv -f prawf3.pdf ouroboros.pdf
END

centering This Is The File To End All Files

IfFileExists{ouroboros.pdf}{frame{includegraphics[width=.9textwidth]{ouroboros}}}{relax}

end{document}

A more sinister example using TiKZ:

documentclass[a4paper]{article}
usepackage{tikz,graphicx,bashful}
usepackage[scale=.95]{geometry}
usetikzlibrary{decorations.text,calc}
pagestyle{empty}
begin{document}
bash
[[ -f "prawf3.pdf" ]] && mv -f prawf3.pdf ouroboros.pdf
END
noindent
centering
vfill
begin{tikzpicture}
  path (.05textwidth,.05textheight) coordinate (o) rectangle +(.95textwidth,.95textheight) coordinate (f);
  node [outer sep=0pt, inner sep=0pt, anchor=center] at (current page.center) {%
    IfFileExists{ouroboros.pdf}{%
      includegraphics[scale=.9]{ouroboros}%
    }{}};
  path [decorate, decoration={text effects along path, text={One File To Rule Them Alldots }, text effects/.cd, repeat text, characters={text along path, anchor=center}}] (o |- f) [out=0, in=180] to (f) [out=-90, in=90] to (o -| f) [out=-180, in=0] to (o) [out=90, in=-90] to cycle;
end{tikzpicture}
vfill
clearpage
end{document}

Apologies to David Gilmour

documentclass[tikz,border=4mm]{standalone}
begin{document}
defdsotm{node[scale around={x:(0,-1)},
                 draw=white,ultra thin] 
                 at(0,0){includegraphics[height=4cm]{dsotm}};}
tikz{foreachx in{2,1.75,...,0.25}{dsotm}}
end{document}

enter image description here

Leave a Comment