XUtils

Literate

A literate programming tool for any language


Literate

What is Literate programming?

Literate programming is a style of programming invented by Donald Knuth, where the main idea is that a program’s source code is made primarily to be read and understood by other people, and secondarily to be executed by the computer.

This frees the programmer from the structure of a program imposed by the computer and means that the programmer can develop programs in the order of the flow of their thoughts.

A Literate program generally consists of explanation of the code in a natural language such as English, interspersed with snippets of code to be executed. This means that Literate programs are very easy to understand and share, as all the code is well explained.


Literate is a tool for creating literate programs.

The goal of this project is to create a literate programming tool which keeps most, if not all of the features of Knuth and Levy’s original CWEB system, but simplifies the system and adds even more features.

You can view the main website about Literate here including a manual on how to use Literate.

Example

Here is a trivial example of a literate program saved in the file hello.lit.

For a full example of a literate program, please see examples/wc.lit which is a literate implementation of the wc (word count) program found on Unix systems. You can find the compiled html here.

@title Hello world in C

@s Introduction

This is an example hello world C program.
We can define codeblocks with `---`

--- hello.c
@{Includes}

int main() {
    @{Print a string}
    return 0;
}
---

Now we can define the `Includes` codeblock:

--- Includes
#include <stdio.h>
---

Finally, our program needs to print "hello world"

--- Print a string
printf("hello world\n");
---

To compile this code simply run

$ lit hello.lit

Which generates hello.c and hello.html.

You can also find this program in examples/hello.lit.

Prebuilt binaries

Download
Mac OS X
64 bit Linux
32 bit Linux
Arm Linux

Building from Source

Mac

On Mac you can use brew to build Literate from source:

$ brew tap zyedidia/literate
$ brew install --HEAD literate

For now, Literate is head only.


Literate is made with the D programming language so you must install dmd (D compiler) and dub (D package manager). Then you should download the zip or clone the repository and run the following commands:

$ cd Literate
$ make

You can find the binary in path/to/Literate/bin (you may want to add this to your path or move it to /usr/local/bin).

Editors


Articles

  • coming soon...