sidenote

Using a makefile for large LaTeX projects is a real time saver if you don’t use LaTeX IDEs (e.g. Texmaker, TeXworks). For example some of my friends have to log in to a central server, which provides the same LaTeX setup for everyone in their institution, to compile their documents. In this particular case using make is a must do! thing if you don’t want to fiddle around keeping track of which was the last command you executed or whether your pdf is up to date.

So, what are these makefile and make things?

Make is a tool which controls the generation of executables and other non-source files of a program from the program’s source files.

Make gets its knowledge of how to build your program from a file called the makefile, which lists each of the non-source files and how to compute it from other files. When you write a program, you should write a makefile for it, so that it is possible to use Make to build and install the program.

[…]

Make figures out automatically which files it needs to update, based on which source files have changed. It also automatically determines the proper order for updating files, in case one non-source file depends on another non-source file.

GNU Make

Here is my standard makefile template for projects utilizing pdflatex and bibtex (also downloadable at the end of the post):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Makefile for my LaTeX project

# LaTeX
LC=pdflatex

# Bibtex
BC=bibtex

# The main tex file (without extension)
MAIN=main

# The tex files that are included in the project's main tex file
DEPS=./tex/chapter1.tex ./tex/chapter2.tex ./tex/chapter3.tex

MIDTARGET=$(MAIN).pdf

# The desired filename
TARGET=myprojectv01.pdf

.PHONY: clean show all

all: $(TARGET)

$(TARGET): $(MIDTARGET)
    cp $(MIDTARGET) $(TARGET)

$(MIDTARGET): $(MAIN).tex $(MAIN).aux
    $(BC) $(MAIN).aux
    $(LC) $(MAIN).tex
    $(LC) $(MAIN).tex

$(MAIN).aux: $(MAIN).tex $(DEPS)
    $(LC) $(MAIN).tex

show: $(TARGET)
    xdg-open $< &

clean:
    rm $(MAIN).out $(MAIN).aux $(MAIN).toc $(MAIN).lof $(MAIN).lot $(MAIN).log \
$(MAIN).bbl $(MAIN).blg $(MIDTARGET) $(TARGET)

I won’t go into the details, but if you want to complement this makefile for using latex instead of pdflatex then you’ll have to create another middle target for creating the dvi file. For those who’ll use this makefile in a non-X environment don’t use the show target beacuse xdg-open is meant to be used under X.

I think the GNU Make Manual is detailed enough to understand what I was talking about. But feel free to contact me if you have any questions.

Download: makefile.tar.gz

Megosztás, like stb.
0 komment
Komment írása