2009-01-09

Using Makefile to ease the repeated compilaton of LaTeX source

I like LaTeX, but it can be tedious if you want "instant" check of the produced output. Usually, there is no need to check the output very often - basically you can write the whole article/report, ... and then compile the LaTeX source. However, when I create a presentation, I often check what does it look like. LyX can also be very handy with "instant" checking! Two days ago I gave a LaTeX Beamer package a try and I use the following Makefile for the process of several compilations of the Sweave source file (fusing LaTeX for the creation of the presentation and R for doing the computations and plotting) - here are the PDF and the source file.
You need to be carefull with formatting of the Makefile, i.e., the lines bellow the target (say line two) needs to start with a TAB and not with spaces!
all:
Sweave.sh --latex2pdf talk.Rnw; make rm

tex: # Sweave --> LaTeX
Sweave.sh talk.Rnw; make rm

rm: # Remove some other files
rm -f .pdf Rplots.pdf *.out *.nav *.snm *.log *.tex *.aux *.toc
Using this Makefile I only needed to type make or better pressing the "up" key to repeat the previous (make) command in the terminal to compile the Sweave source file.

2 comments:

Mario Pineda-Krch said...

...good idea, and if you need BibTeX'ification you can add that to the Makefile as well (+a few more re-runs of LaTeX to make sure all the cross-referencing is up to speed). As instantaneous as it gets, or? Well, if you are running OS X you can be using TeXShop which basically does all of this on the fly with a simple click on a button + it updates the pdf in the previewer. Of course you first need to hack the TeXShop config files to make it do Sweave'ification..., but you already knew that.

Gorjanc Gregor said...

Actually, I use texi2dvi as called by --latex2pdf switch of Sweave.sh! In this way I get the complete compilation from LaTeX to PDF including BibTeX, Makeindex, ...