I’ve started using LaTeX when I started my degree at uni a bit more than 5 years ago. When I first heard about it I thought it was a software like Microsoft Office, just not as horrible with the formatting. That has all changed and LaTeX has become my language of choice for writing papers, reports, coursework or anything closely related. I found it quite handy that there are so many different editors available until I have recently discovered the best of them all: Emacs + make.
I was looking for something new because I became more and more fed up with so and so often having to reach to the mouse and click on buttons to compile my bib and tex files. The solution: using a Makefile for the compilation process. I had always told myself I should really learn how to write Makefiles, but I never really got round to it. The one for LaTeX documents is a very neat one, though, since it doesn’t require much knowledge and is very short:
# LaTeX Makefile
\rm *.aux *.blg *.out *.bbl *.log
So let’s examine this in a bit more detail. At the beginning I just define a variable called
FILE, which will hold the filename of the tex file. By using a variable here I made sure I will only ever have to change this one single line when I use different tex files. A Makefile command looks generally like this:
The target all defines what happens when you just type
make in the terminal. Here, all has the finished pdf file as a dependency. It will then check the dependencies for the pdf file (target
$(FILE).pdf) and if none of the source files have changed and the pdf file exists already it will do nothing. So make will only take action if it has to, which is a handy feature, as it minimises the work to be done by ruling out things that don’t have to be done. If the pdf file doesn’t exist or any of the dependencies for it (tex or bib files in this case) have changed, it will run all the dependencies. You could also run
make report.pdf and with that call the target
$(FILE).pdf explicitly. I have added one more target called
clean, which deletes all files that are generated during the compilation process, except for the pdf file. You can call this command by typing
make clean in the terminal.
There are many more options of what could be included in the Makefile, but here I only want to outline the bare essentials of it. My new LaTeX “editor” setup in the office is shown in the image below. One screen holds the terminal and Emacs and the other one has been set upright because in my opinion that makes for a better reading experience on the screen. I find this setup quite a lot more useful than having both screens in the normal setting.
Update: Rob has pointed out that you should apply the phony rule for targets that aren’t files. I’ve added that to the makefile