This is the makefile I use to deal with LaTeX documents. It is flexible and very easy to use and extend.
To use this, you will need make, of course. It is designed to handle one target: one latex source file, one destination. However, it is very easly possible to use it even if you have more than one document.
Makefile.latex
:
#
# Makefile for LaTeX
#
# Date: 2002-06-25
# Written by Mario Konrad
#
### programs
LATEX=latex
DVIPS=dvips
DVIPDF=dvipdf
MAKEINDEX=makeindex
### targets
ps: $(TARGET).ps
pdf: $(TARGET).pdf
dvi: $(TARGET).dvi
### clean up
clean:
find . -maxdepth 1 -name $(TARGET).log -exec rm {} \;
find . -maxdepth 1 -name $(TARGET).aux -exec rm {} \;
find . -maxdepth 1 -name $(TARGET).toc -exec rm {} \;
find . -maxdepth 1 -name $(TARGET).lof -exec rm {} \;
find . -maxdepth 1 -name $(TARGET).lot -exec rm {} \;
clean-dvi:
find . -maxdepth 1 -name $(TARGET).dvi -exec rm {} \;
clean-ps:
find . -maxdepth 1 -name $(TARGET).ps -exec rm {} \;
clean-all: clean clean-dvi clean-ps
### implicit rules
.dvi.ps:
$(DVIPS) $< -o $@
.dvi.pdf:
$(DVIPDF) $< -o $@
.tex.dvi:
$(LATEX) $< # do this two times to generate the TOC
$(LATEX) $<
### misc
.SUFFIXES: .tex .aux .toc .lof .lot .log .dvi .ps .pdf
This is a list of the features of the current makefile:
compile the LaTeX source to a DVI file
table of contents awareness
create a Postscript file, using dvips
create a PDF file, using dvipdf
clean up all temporarly created files
clean up of all created files
The default setting is to create a postscript file. If you like to choose your target file format use the following parameters:
ps: Postscript
pdf: PDF
dvi: DVI (stop at the dvi stage)
First, we have a look at the most simple usage possible. Let’s assume that we have a single LaTeX document test.tex. If you like to build a postscript file file, just type:
This will create a postscript file per default. If you like a PDF file, use the following command:
If you like your own makefile instead of typing the command above every time you like to build your document, you may want to take advantage of the makefile provided on this site. Let’s assume the same situation as above: one simple LaTeX document test.tex. Your own makefile could have the following content (minimum, without the line numbers):
TARGET=test
include Makefile.latex
The invocation of the build is now easy:
of if you like to produce a PDF file:
Note: the include statemant has to be at the very bottom of your own makefile, otherwise make will try to build the first target it can find. Maybe at this time variable TARGET
is not set properly.
Sometimes it’s useful to build several documents at once (with the same target file format or different formats). In this case you need your own makefile. This could be like the following one: