LaTeX: Makefile

Post by Nico Brailovsky @ 2009-07-02 | Permalink | Leave a comment

Remember I said that being a programmer would make you a lot more comfortable around LaTeX? The reason is quite simple, tex is just source code for a document. As with any source code in Linux (Windows too, but that is besides the point) you can use a Makefile to compile it and make your life easier.

I have already posted this Makefile in another entry but it's time to explain how it works.


all: main.pdf
main.pdf: code_frames .tex
  pdflatex main.tex && pdflatex main.tex
.PHONY: run clean edit
edit:
  gvim -S vim.sess
run: main.pdf
 evince main.pdf &
clean:
 @# for each .tex file, remove the extension
 @#    and delete its generated files
 @for PART in $(shell ls .tex| sed 's:.tex::g'); do
   echo ".out .nav .aux .toc .log .snm .pdf .vrb" | \
      sed "s:*:$$PART:g" | xargs rm -f;
 done

It's rather easy, let's check it target by target:

Short entry this time - next: using source code from within LaTeX.