Nicolás Brailovsky


A modern blog

LaTeX: Makefile

author Posted by: nico on date Jul 2nd, 2009 | filed Filed under: LaTeX

latexmk

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.

  1. all: main.pdf
  2.  
  3. main.pdf: code_frames *.tex
  4.         pdflatex main.tex && pdflatex main.tex
  5.  
  6. .PHONY: run clean edit
  7. edit:
  8.         gvim -S vim.sess
  9.  
  10. run: main.pdf
  11.         evince main.pdf &
  12.  
  13. clean:
  14.         @# for each .tex file, remove the extension
  15.         @#              and delete its generated files
  16.         @for PART in $(shell ls *.tex| sed ‘s:.tex::g’); do
  17.                 echo "*.out *.nav *.aux *.toc *.log *.snm *.pdf *.vrb" |
  18.                         sed "s:*:$$PART:g" | xargs rm -f;
  19.         done

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

  • all: create the main document – used as default target
  • main.pdf: document’s target – no need to call it main.pdf, I just do it because the entry point in C programs is called “main” so I’m used to it. Also, it looks better than foo.pdf. As a side note, it runs twice “pdflatex” because it first creates the document and the second time updates the document’s index.
  • edit: I usually have a single document split in many files, so keeping a line to quickly open up your editor with all this files is handy. I just keep it as a Vim session, no need for more
  • run: target to open up the document in a pdf viewer. I call it run so I can use it with my default mapping in Vim
  • clean: clean up the files created while compiling a document. Some times it’s needed if there’s an error you can track – it may be a corrupted .aux file

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

     Add A Comment

trackback Trackback URI | rsscomment Comments RSS