Penguin
Blame: LatexMakefiles
EditPageHistoryDiffInfoLikePages
Annotated edit history of LatexMakefiles version 13, including all changes. View license author blame.
Rev Author # Line
8 AristotlePagaltzis 1 In the process of writing 420 final reports, SamJansen and Tom Young worked to create some [MakeFile]s useful for [LaTeX] projects. [LaTeX] and Bibtex have some strange properties which makes writing [MakeFile]s for them an interesting challenge. This page is currently a work in progress.
5 SamJansen 2
8 AristotlePagaltzis 3 !! A Basic Makefile
5 SamJansen 4
5 (remember that the indented lines need tabs, not spaces)
6
7 A very basic makefile that does not support Bibtex, images, or multiple input files looks something like the following:
8
9 <verbatim>
10 # vim: tabstop=8 shiftwidth=8 noexpandtab
11 # A very basic Latex makefile by Sam Jansen.
12 # See http://www.wlug.org.nz/LatexMakefiles for more information
13 # Change the following to whatever you like. Target will have '.ps' or '.pdf'
14 # appended as need be. Tex should be the tex file WITHOUT the '.tex' suffix.
15 TEX=report
16 TARGET=report
17
18 # You probably don't need to change anything below the following line:
19 .PHONY: clean debug gvshow pdfshow acroshow dvishow
20 LATEX_ARGS=--interaction batchmode
21 LATEX=latex
22
23 $(TARGET).ps: $(TARGET).dvi
24 dvips $(TARGET) -o $(TARGET).ps
25
26 $(TARGET).pdf: $(TEX).tex
27 pdflatex $(LATEX_ARGS) $(TEX)
28
29 $(TARGET).dvi: $(TEX).tex
30 $(LATEX) $(LATEX_ARGS) $(TEX)
31 @mv $(TEX).dvi $(TARGET).dvi
32
33 clean:
11 WildernessChild 34 rm *.toc *.aux *.pdf *.ps *.eps *.log *.lof *.bib *.bbl *.blg *.dvi
5 SamJansen 35
36 debug:
37 latex $(TEX)
38
39 gvshow: $(TARGET).ps
40 gv $(TARGET).ps
41
42 pdfshow: $(TARGET).pdf
43 xpdf $(TARGET).pdf
44
45 acroshow: $(TARGET).pdf
46 acroread $(TARGET).pdf
47
48 dvishow: $(TARGET).dvi
49 xdvi $(TARGET).dvi
50 </verbatim>
51
52 Probably the most interesting thing about the above makefile is that it uses __--interaction batchmode__ as an argument to Latex. The rest is a fairly standard makefile. Things get a little more complex when Bibtex and automatic image conversion is added to the makefiles.
13 ChrisRae 53
54 Note that this is a really dangerous Makefile to use as is: this clean stanza will delete ALL pdf, eps, and ps files in the current directory. Be sure you have backups elsewhere of all your letters-of-support.pdf and all the figures.eps for your proposal, because when you run make clean with this makefile they are also going to be rm'ed. There is also a .bib extension being deleted! .bib usually contains your raw bibliography database, so it is input, just like your .tex file. Delete it and you can't ever generate your document again without a lot of pain. The clean stanza should have something more like
55 rm $(TARGET).{toc,aux,pdf,ps,eps,log,lof,bbl,blg,dvi}
56 to restrict it to relevant and output files only ( -- ChrisRae).
5 SamJansen 57
58 ----
8 AristotlePagaltzis 59
60 !! A Simple Latex and Bibtex Makefile
61
5 SamJansen 62 Serious people use bibtex to manage their references. Here is a makefile that should run bibtex and latex the appropriate number of times.
8 AristotlePagaltzis 63
5 SamJansen 64 (I've removed the extra targets and steps I had in here to run musixtex as well... -- JohnMcPherson)
65
66 <verbatim>
6 JohnMcPherson 67 TARGET=proposal
68
5 SamJansen 69 # make pdf by default
10 KristjanOnu 70 all: ${TARGET}.pdf
5 SamJansen 71
72 # it doesn't really need the .dvi, but this way all the refs are right
73 %.pdf : %.dvi
74 pdflatex $*
75
76 ${TARGET}.bbl: ../bib/music.bib
6 JohnMcPherson 77 # in case we don't already have a .aux file listing citations
78 # this should probably be a separate makefile target/dependency instead
79 # of doing it every time... but *shrug*
80 latex ${TARGET}.tex
81 # get the citations out of the bibliography
5 SamJansen 82 bibtex ${TARGET}
6 JohnMcPherson 83 # do it again in case there are out-of-order cross-references
5 SamJansen 84 @latex ${TARGET}.tex
85
86 ${TARGET}.dvi: ${TARGET}.bbl ${TARGET}.tex
87 @latex ${TARGET}.tex
88
89 # shortcut, so we can say "make ps"
90 ps: ${TARGET}.ps
91
92 ${TARGET}.ps: ${TARGET}.dvi
93 @dvips -t a4 ${TARGET}.dvi
94
95 clean:
96 rm -f ${TARGET}.{log,aux,ps,dvi,bbl,blg,log}
97
98 reallyclean: clean
99 rm -f ${TARGET}.{ps,pdf}
100
101
102 PHONY : ps all clean reallyclean
103
104 </verbatim>
105
106 ----
9 JohnMcPherson 107 !! Useful Variables
108 [LaTeX] has some [EnvironmentVariable]s that control where it looks for various
109 files. Note that just setting these in the Makefile isn't enough; you need to set
110 them for the actual call to latex/pdflatex/bibtex etc. These allow you to run
111 latex from different directories but still have relative paths work, which is
112 useful if you have a very large document split up into smaller files and use the
113 "\input" latex tag.
8 AristotlePagaltzis 114
9 JohnMcPherson 115 !TEXINPUTS
116 A colon-separated list of paths of where to look for files named in \input and
117 \usepackage (etc) tags. End with ":" so that it also checks the default system
118 directories for class/style files. Eg
119 TEXINPUTS=".:..:~/mylatexfiles:" latex foo
120 !BIBINPUTS
121 ":"-separated path to look for bibliography files
122 !TEXFORMATS
123 ":"-separated path to look for .fmt files - for example if you have pdflatex installed in a non-standard place, you can set this to tell it where to find the pdflatex.fmt file.
124 !TEXMF
125 The base directory for the latex installation.
126
127 ----
8 AristotlePagaltzis 128 !! More Powerful Makefiles
5 SamJansen 129
7 MattBrown 130 Because of all the crap that Latex and Bibtex outputs, SamJansen decided to create a directory structure for the report that kept all the "work" files away from the main directory. There are a few additions by MattBrown below to allow images to be generated from .fig files and to spellcheck the report before generating it.
5 SamJansen 131
132 * ''images/'' contains all images and figures used in the report. All such images are converted to appropriate formats by the makefile in this directory.
133 * ''work/'' is used when Latex and Bibtex is run. Therefore all the extraneous files like .toc and .aux and so on are put in here.
134 * The root directory holds all .tex files and the main makefile.
135
8 AristotlePagaltzis 136 ! Usage
5 SamJansen 137
7 MattBrown 138 Place .tex file in the root directory, a .bib file in the root directory, and .eps, .png, .jpg, .fig and .dia images/figures in the ''images/'' directory. There are various targets used, just typing 'make' will just build a pdf file. The only editing of files needed is the top of the root makefile.
5 SamJansen 139
140 Here is what the current version looks like:
141
8 AristotlePagaltzis 142 ! Makefile in the root directory
5 SamJansen 143
144 <verbatim>
145 # vim: ts=8 noexpandtab
146 # $Id: Makefile,v 1.11 2003/10/11 04:12:43 stj2 Exp $
147
148 # Edit the below:
149 TEXFILES=$(wildcard *.tex)
150 BIBFILE=report.bib
151 TARGET=report
152
153 # The following should not need editing:
154 export TEXFILES BIBFILE TARGET
155
7 MattBrown 156 $(TARGET).pdf: spellcheck $(TEXFILES) $(BIBFILE)
5 SamJansen 157 $(MAKE) -C images pdf
158 $(MAKE) -C work pdf
159
7 MattBrown 160 $(TARGET).ps: spellcheck $(TEXFILES) $(BIBFILE)
5 SamJansen 161 $(MAKE) -C images ps
162 $(MAKE) -C work ps
163
164 $(TARGET).dvi:
165 $(MAKE) $(TARGET).ps
166
7 MattBrown 167 spellcheck:
168 ispell -t $(TEXFILES)
5 SamJansen 169
7 MattBrown 170 .PHONY: show showx clean wordcount images debug spellcheck
5 SamJansen 171
172 debug:
173 $(MAKE) -C images
174 $(MAKE) -C work debug
175
176 pdfdebug:
177 $(MAKE) -C images pdf
178 $(MAKE) -C work pdfdebug
179
180 gvshow: $(TARGET).ps
181 gv $(TARGET).ps
182
183 pdfshow: $(TARGET).pdf
184 xpdf $(TARGET).pdf
185
186 acroshow: $(TARGET).pdf
187 acroread $(TARGET).pdf
188
189 dvishow: $(TARGET).dvi
190 xdvi work/$(TARGET).dvi
191
192 clean:
12 GlynWebster 193 @rm $(TARGET).pdf 2>/dev/null; true
194 @rm $(TARGET).ps 2>/dev/null; true
5 SamJansen 195 $(MAKE) -C work clean
196 $(MAKE) -C images clean
197
198 wordcount:
199 @echo Approximate word count: `grep -v '^\\\\' $(TEXFILES)|grep -v '^%'|wc -w`
200 </verbatim>
201
202 !Makefile in the ''work/'' directory
203
204 <verbatim>
205 # vim: noexpandtab ts=8
206 # $Id: Makefile,v 1.10 2003/10/11 12:09:37 stj2 Exp $
207 .PHONY: pdf ps clean
208
209 TEXS=$(foreach i,$(TEXFILES),$(addprefix ../,$i))
210 BIB=$(addprefix ../,$(BIBFILE))
211
7 MattBrown 212 $(TARGET).aux: $(TEXS)
213 @cp -l $(TEXS) . 2>/dev/null; true
214 @cp -l ../images/*.eps . 2>/dev/null; true
215 latex --interaction batchmode $(TARGET)
216
217 $(TARGET).bbl: $(BIB) $(TARGET).aux
5 SamJansen 218 @cp -l $(BIB) . 2>/dev/null; true
7 MattBrown 219 @cp -l ../images/*.eps . 2>/dev/null; true
5 SamJansen 220 bibtex -terse $(TARGET)
221 latex --interaction batchmode $(TARGET)
222
223 $(TARGET).dvi: $(TEXS) $(TARGET).bbl
224 @cp -l $(TEXS) . 2>/dev/null; true
225 @cp -l ../images/*.eps . 2>/dev/null; true
226 latex --interaction batchmode $(TARGET)
227
228 pdf: $(TARGET).dvi
229 @cp -l ../images/*.pdf . 2>/dev/null; true
230 pdflatex --interaction batchmode $(TARGET)
231 @cp $(TARGET).pdf ..
232
233 ps: $(TARGET).dvi
234 latex --interaction batchmode $(TARGET)
235 dvips -q $(TARGET) -o $(TARGET).ps
236 @cp $(TARGET).ps ..
237
238 debug:
239 @cp -l $(TEXS) . 2>/dev/null; true
240 @cp -l $(BIB) . 2>/dev/null; true
241 @cp -l ../images/*.{pdf,eps} . 2>/dev/null; true
242 latex $(TARGET)
243
244 pdfdebug:
245 @cp -l $(TEXS) . 2>/dev/null; true
246 @cp -l $(BIB) . 2>/dev/null; true
247 @cp -l ../images/*.{pdf,eps} . 2>/dev/null; true
248 pdflatex $(TARGET)
249
250 clean:
251 rm -f *.toc *.aux *.pdf *.ps *.eps *.log *.tex *.lof *.bib *.bbl *.blg *.dvi
252 </verbatim>
253
254 !Makefile in the ''images/'' directory
255
256 <verbatim>
257 # vim: noexpandtab ts=8
258 # $Id: Makefile,v 1.6 2003/10/02 21:21:20 stj2 Exp $
259
260 .PHONY: pdf ps clean
261
262 PNGS=$(wildcard *.png)
263 DIAS=$(wildcard *.dia)
7 MattBrown 264 FIGS=$(wildcard *.fig)
5 SamJansen 265 EPSS=$(wildcard *.eps)
266
7 MattBrown 267 OUTPUT_EPS=$(PNGS:png=eps) $(DIAS:dia=eps) $(FIGS:fig=eps) $(EPSS)
5 SamJansen 268 OUTPUT_PDF=$(OUTPUT_EPS:eps=pdf)
269
270 pdf: $(OUTPUT_PDF)
271
272 ps: $(OUTPUT_EPS)
273
274 clean:
275 rm $(OUTPUT_PDF) $(DIAS:dia=eps) $(PNGS:png=eps) 2>/dev/null; true
7 MattBrown 276 rm $(FIGS:fig=eps) 2>/dev/null; true
5 SamJansen 277
278 # Bitmap images -> EPS: PNG and JPG are covered at the moment, using
279 # ImageMagick's 'convert' utility
280 %.eps: %.png
281 convert $< $@
282
283 %.eps: %.jpg
284 convert $< $@
285
286 # EPS -> PDF
287 # epstopdf is much better than ps2pdf... it preserves bounding box
288 %.pdf: %.eps
289 epstopdf $<
290
291 # DIA -> EPS
292 %.eps: %.dia
293 dia --nosplash -e $@ $<
7 MattBrown 294
295 # FIG -> EPS
296 %.eps: %.fig
297 fig2dev -L eps $< $@
298
5 SamJansen 299 </verbatim>

PHP Warning

lib/blame.php:177: Warning: Invalid argument supplied for foreach()