Literate Programming with XML

Literate Programming is a style of programming developed by Donald Knuth, which makes writing programs similar to writing essays - you write a program as part of an essay which explains how it works. In literate programming, readability and pedagogical purposes come first, and program structure come second. Literate Programming tools allow you to write your program in the structure that makes most sense to explain it, and then a program called tangle restructures it to the likings of whatever interpreter or compiler you are using. If you are not familiar with Literate Programming, you can check out the site or buy the book Literate Programming by Donald Knuth.

Literate Programming has been traditionally tied to specific languages and document types. The most common language is C, and the most common document type is TeX. With the birth of XML and XML publishing it follows that there should be tools to facilitate Literate Programming in XML, where you can simply use the traditional XML stylesheet mechanisms for the weave. However, all of the tools up until now have been DTD-specific. In fact, this tool suite originated in a small program I wrote to do this in DocBook ( However, I discovered that there was no reason to do this. XML has this amazing feature that is terribly underused - processing instructions. Thus, I decided to create literate programming tools that could be used by any DTD, and the information I needed for doing literate programming would be discovered through processing instructions.

The first program here is xmltangle. It is not as feature-rich as I would desire, but it has a ways until it hits version 1.0. Please feel free to use it and let me know how I could modify it to make it more useful. Feel free to email me at

Project Page Documentation (PDF version) Example Literate Program Example woven program (PDF version) Example tangled program