Scons and noweb

Literate Programming

Enrico Spinielli


June 14, 2009

I was curious to see how I could integrate noweb and Scons.

You can download my little Sconstruct for this, Sconstruct.example. It defines two builders. NoWeave is used to produce TeX or LaTeX documents, while NoTangle extracts the non-document artefacts, i.e. programs, config files, scripts … It also includes productions for generating a sample program about Ackermann function:

    ackdoc  = env.NoWeave('ack.tex', 'ack.nw')
    ackcode = env.NoTangle('', 'ack.nw')
    acktest = env.NoTangle('', 'ack.nw')

The noweb source is ack.nw and the companion BibTeX file is ack.bib

It contains the doc chunks describing the function, the source code chunck for the relevant Python code and the code chunk for the unit test.

You can try it out executing

    $ scons -f Sconstruct.example

You will get the following artefacts,, ack.tex, and ack.pdf

Remember to run BibTeX first…