Automatic LaTeX Processing

I have put together a Makefile that automates most of the steps involved in processing LaTeX documents.  Included, of course, is the ability to run latex the correct number of times, but the algorithm will also run bibtex and makeindex as needed.  A very nice feature of this Makefile is the ability to automatically process xfig .fig files for inclusion in your LaTeX documents.

To get started, place this LaTeX.Rules file in a directory somewhere (it doesn't matter where).  Then, in the directory where your LaTeX document is located, create a file called Makefile containing the following:

DOCUMENT := filename
include /path/to/LaTeX.Rules

where "filename" is the name of your LaTeX document without the .tex extension.  Then, in that directory just type "make" at the command prompt, and you should get a .dvi file.  Typing "make ps" will generate a .ps file.

If you would prefer to use pdflatex to process your document directly to PDF format, add the line

LATEX := pdflatex

to the Makefile somewhere before the include line.  Typing "make" will then produce a .pdf file instead of a .dvi.

If your LaTeX document includes any graphics files, for example EPS or PDF images, indicate this by adding lines like

GRAPHIC_FILES := image1.eps image2.eps
GRAPHIC_FILES += image3.eps image4.eps

and so on.  More information can be found in the LaTeX.Rules file itself.

And now a word for the technically-minded.  LaTeX has cyclic file dependancies, meaning some files ultimately depend on themselves.  The best example is the .aux file, which needs to be considered out of date, and thus rebuilt, every time its own contents change!  The make utility can only handle acyclic file dependancies, and thus cannot process LaTeX documents "out of the box".  To work around this problem, I play games with file modification time stamps and recursive calls to make in order to produce the correct behaviour.  The resulting algorithm seems to be very robust.  It is able to process very complex documents, such as my PhD thesis which requires five LaTeX passes and two bibTeX passes before the output stabilizes.

Please let me know if you have trouble using this system with your own LaTeX documents.  My ultimate goal is for this to do it all!  I am particularly interested in information on documents that require metapost steps.  I have never used metapost, so I do not know the commands and file dependancies involved.