Home > Python, Tech > Using waf to build LaTeX Documents

Using waf to build LaTeX Documents

I’ve finally made the migration away from make and the horrible system of autofoo and Makefiles.  A few years ago I discovered a build system called waf that does everything make can do, only better!

Waf is a Python based build system (or more generally a task execution system).  Directly from the site:

Waf is a Python-based framework for configuring, compiling and installing applications. It derives from the concepts of other build tools such as Scons, Autotools, CMake or Ant.

Just like make, waf is a quasi-declarative build system.  You define the tasks and results you require, and waf determines dependences and executes the tasks (in a valid order) necessary to produce the desired output.  However, waf differs from make in that waf actually uses a real programming language for declaring tasks and developing the build system (in case it wasn’t obvious, the language I’m referring to is Python).  This single fact alone is enough for me to want to move away from make completely.  However, waf also offers a whole slew of other extremely nice features that make it very powerful. See the project site for more details.

Until now I’ve been using make to build my LaTeX documents.  However, I’ve finally taken the time to discover how to do this with waf.  The following script (really just two functions), named wscript in the directory with the LaTeX source, is the result:

1
2
3
4
5
6
7
8
9
10
srcdir='.'
blddir='build'
 
def configure(conf):
   conf.check_tool('tex')
 
def build(bld):
   obj=bld.new_task_gen(features='tex')
   obj.source='source_tex_file.tex'
   bld.install_files('${PREFIX}','output_pdf_file.pdf')

The first two lines define the source directory (the current directory is denoted by the ‘.’) and the name of the build directory (where all the temporary files will be stored).  The configure function simply tells waf, using the check_tool call, to ensure that the tools necessary for building LaTeX documents are present on the system.  The build function defines that we want to create a PDF document from the file source_tex_file.tex using the tex waf tool.  And that’s it… seriously.

My workflow with this setup is basically edit LaTeX file, call ./waf build install, check the output PDF, repeat.  Easy as pie.

So, if you’re looking for a fabulous alternative to make, check out waf, I’m sure you’ll be impressed.

  1. No comments yet.
  1. No trackbacks yet.