Since TeX and LaTeX can print out any text, it should be possible to write a self-replicating document, i.e., a document that is typeset as a PDF/DVI of itself. Have you seen something like that?
|
A long time ago, in a country far far away, under the influence of Hoefstader's Godel, Escher, Bach, I spent a merry few minutes playing with programs that would print out themselves. One goal was to make a minimal such program in a particular language, another was to have a general scheme that could be added to make any program (in that language) do this (in addition to what the program was supposed to do). In pursuit of that latter goal I figured out some general ingredients that could be used to do this. These were:
With these, the scheme is as follows. Create a list containing the code converted into some integer representation of the symbols it contains. Insert into that list a special character (usually Here's a TeX version of that:
This produces:
|
|||
|
|
|
Save as
It is due to Péter Szabó and has been published on TUGboat, vol. 29 (2008), p. 207 as part of the TeX Pearls section at EuroBachoTeX 2007. Here's the output:
|
||||
|
|
|
Here is a simple example:
The result looks as the original:
But if you want to be able to copy from the PDF, you must use this code:
The result:
|
|||||||||||||||||||||
|
|
If inputting the file itself is allowed, here's a shorter version (Plain TeX):
Alternative version:
|
|||||||||
|
|
Much impressed and motivated by Update: I am adding another shorter method. It is less analogous to LaTeX Update: I am adding a LaTeX solution, in the same spirit. I could have spared a few braces in the Plain TeX Update: one more incarnation in Plain TeX.
|
|||||||||||||
|










.dtxfile is a variant of the above concept (textdoc docstrip). – Yiannis Lazarides Jan 14 at 13:05