Hello, everybody. I've posted a few examples of my very long-running project the Platonic Music Engine here before demonstrating my use of LaTeX to algorithmically recreate various artifacts of human culture like art, poetry and so on. Today's is by far the most elaborate and also the most TeX-like of all of them. It is called the Infinite Library.
The inspiration comes the terrific short story Library of Babel by Jorge Borges. In it is a library that contains every book that could ever be written. Each book is a random collection of letters. Think infinite monkeys typing at infinite typewriters.
A more proximate inspiration comes from this online realization of the short story that comes with a really interesting twist.
My version takes advantage of some of TeX/LaTeX's capabilities by making the resulting texts look more like real books. My software randomly adds various features like chapters, epigraphs, poetry, indices and so on. The books are still random nonsense but they look more like actual books than what Borges indicated.
The software has four methods of generation:
Random letters: Borges stated that each book is made up of a random collection of 22 letters. We don't know which 22 letters. Some scholarship says it was the 26 letters of the English alphabet minus the letters "k", "q", "w" and "x". Other scholars think he meant the 22 letters of the Hebrew alphabet (Borges was into Jewish mysticism). I include both possibilities and add a third that uses all 26 letters of the English alphabet. The one linked here uses the Hebrew alphabet and is right-to-left (in appearance -- it is still just random letters).
Random words: This one is just words taken at random. Punctuation, paragraphs, chapters, etc, are determined at random.
Stochastic unbounded recursive generative grammar: This is my favorite. In this one a subject and verb are chosen at random. Then, randomly, other parts of speech are added like adjectives, possessives, prepositional phrases, adverbs, and so on. And then randomly more nouns and/or verbs are added. The process is recursive which, in linguistic terms, means, basically, stringing together parts of speech. So you might have a phrase like "The dog". Adding one adjective you get, "The big dog". Recursion takes place when you string more adjectives together that modify the same noun like "The big red dog" or "The big red smelly ugly tall confused flabbergasted dog". The odds that any part of speech will recurse are small but sometimes you get some pretty crazy sentences. Ideally the resulting sentences make sense syntactically but the grammar often fails (eg, no subject-verb agreement is forced) and the sentences are still nonsense.
Random sentences from public domain books: Here we take sentences at random from randomly selected books in the public domain.
The last two are interesting because they also include "styles". That is, randomly, a book will be about a certain domain. The generative book above is a poetry book meaning it has randomly generated poetry. Some use the verse environment (using indentation) and the others use shapepar. It also just happens to have some "ancient fonts" in it. This happened randomly and is not part of the poetry style.
The random sentence book uses the cartography style and has randomly generated maps in a couple of different styles. Other styles include music, math, linguistics and many more.
And then we have two books that are demos:
Paratextual demo: This one has things like a half-title page, preface, index, glossary, epigraphs, drop caps and so on.
Graphical demo: Here we have a frontispiece, hand-drawn annotations, charts, graphs, sheet music snippets, a bookmark, a book ribbon and many more graphical items. It also includes two "inserted" documents one being a map of where you and your selected book are and the other is one of 10 possible (so far) lore documents. This one is a short story written by one of the many librarians who live in the Infinite Library.
I had to do things like work out the physical layout of the library which is documented in some of the lore. One thing that happens is that each of the methods listed above exists in its own spatial dimension within the library. The random letter books are in the first dimension meaning all the books are either north or south of your starting point. Words and the generative grammar are the second (East and West) and third (Up and Down) dimensions respectively. The random sentence books exist in the fourth dimension (Ana and Kata). The title page of each book tells you where exactly your book is located.
Finally, the dedication at the top of the very first page of each document is what determines all the data in the book. A hash is taken of the dedication which becomes the seed for a prng included in the software. This means that it feels like there is a specific book for each different dedication.
Thanks for reading all of this and if anyone has any questions or comments please share! And if you have ideas for other features to add to the books let me know. I have to be careful because I'm not much of a programmer and things have to be pretty simple for me to do.
Also finally, I've been working on the larger project for around 15 years. So for most of that no AI was used. These days I use a little AI to help create the algorithms for some of the TikZ stuff. I have to fix all of it to make it fit my overall project but given there are things I just don't know how to do (like fractal trees), AI is helpful for that. Of the 40+k lines of code in the project, maybe 200 lines are directly from AI. I hope that's not too off-putting.
And the title of the post should be: Creating an Infinite Library (from Borges's "Library of Babel") using LuaLaTeX