Personal tools

Latex makefile

From MohidWiki

Jump to: navigation, search

Hard-core latex users may want to compile their postscript and pdf files from the command line and edit their tex files with vim. However, they'll be obliged to call several commands before they can get a final pdf file. This is because latex has a pretty complex dependency diagram. For this type of advanced users, a bash script or a makefile may come in handy. In this article, we'll discuss a generic makefile solution.


  1. Copy/paste the makefile snippets below and create a dependency file.
  2. Make sure you have tabulations in the makefile's rules.
  3. Chmod the file (linux only):
> chmod 755 makefile


  • Build target pdf or postscript files with either one of the following commands:
> make -ri
> make -ri main
> make -ri main.pdf
> make -ri

The first couple of lines will produce, each, both a pdf and a ps; whereas the last two lines will produce, each, only one of a kind. So, choose your weapon :)

  • Clean pdf or ps files:
> make clean
  • Checkout from subversion repository
> make checkout
  • Commit to subversion repository
> make commit

The makefile

The dependencies in the dependencies file are from latex template's.

NOTE: Make sure you get tabulations(\t) in your makefile's rules when you copy/paste.

NOTE2: Make sure you disable all internal rules and ignore errors (make -ri) when calling the makefile.

Main rules

MAIN = main

.PHONY: all clean

all : $(MAIN).pdf $(MAIN).ps
       @echo Done building $^
       rm *.aux

clean : 
       rm $(MAIN).pdf $(MAIN).ps



USER = guillaume.riflet
PASS = *******

.PHONY = checkout commit

       svn $@ $(REPO) . --username $(USER)

       svn $@ --force-log . 



#!/usr/bin/make -ri
SHELL = /bin/sh



% : %.pdf
       @echo Done building $^

%.pdf : %.dvi
       dvipdf $< : %.dvi
       dvips $<

#Warning: must duplicate the command for cross-references
%.dvi : %.blg
       latex $(<:.blg=.tex)
       latex $(<:.blg=.tex)

%.blg : %.bbl
       @echo Warning: $@ doesn't exists yet!

%.bbl : %.log
       bibtex $(<:.log=)

%.log : %.toc
       @echo Warning: $@ doesn't exists yet!

%.toc : %.aux
       @echo Warning: $@ doesn't exists yet!

%.aux : %.tex
       latex $<

%.tex :
       @echo Warning: $@ doesn't exists yet!




Z = tex

$(MAIN).$(Z) : \
  introduction.$(Z) \
  contents.$(Z) \
  conclusion.$(Z) \
       touch $@


Latex DAG diagram

See also