Posts Tagged 'makefile'

Compiling LaTeX Documents using Makefiles

I usually don’t use a clumsy IDE for creating documents with LaTeX, but rather write them with a simple text editor like VIM or SciTe. To avoid typing the same commands for compiling a PDF file over and over again, I’ using a very simple and primitive Makefile:

PROJECT=
TEX=pdflatex
BIBTEX=bibtex
BUILDTEX=$(TEX) $(PROJECT).tex

all:
    $(BUILDTEX)
    $(BIBTEX) $(PROJECT)
    $(BUILDTEX)
    $(BUILDTEX)
clean-all:
    rm -f *.dvi *.log *.bak *.aux *.bbl *.blg *.idx *.ps *.eps *.pdf *.toc *.out *~

clean:
    rm -f *.log *.bak *.aux *.bbl *.blg *.idx *.toc *.out *~

To use this Makefile you need to define a project name, which should be the name of your LaTeX file (without the .tex suffix) containing the \begin{document} and end{document} tags. Just add this name to the first line of the make script. If you don’t use BibTeX, you’ll need to uncomment the line $(BIBTEX) $(PROJECT).
Now run the “make” command to create a PDF file and “make clean” to remove the temporary files created by pdflatex.