Latex makefile
From MohidWiki
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.
Contents
Installing
- Copy/paste the makefile snippets below and create a dependency file.
- Make sure you have tabulations in the makefile's rules.
- Chmod the file (linux only):
> chmod 755 makefile
Syntax
- Build target pdf or postscript files with either one of the following commands:
> make -ri > make -ri main > make -ri main.pdf > make -ri main.ps
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
#--make_all.mk--------------------------------------- MAIN = main .PHONY: all clean all : $(MAIN).pdf $(MAIN).ps @echo Done building $^ rm *.aux clean : rm $(MAIN).pdf $(MAIN).ps #-------------------------------------------
Svn
#---make_svn.mk--------------------------------------- REPO = https://preopmodel.googlecode.com/svn/trunk/latexsample USER = guillaume.riflet PASS = ******* .PHONY = checkout commit checkout: svn $@ $(REPO) . --username $(USER) commit: svn $@ --force-log . #-------------------------------------------
Makefile
#!/usr/bin/make -ri SHELL = /bin/sh include make_all.mk include make_svn.mk #---makefile--------------------------------------- % : %.pdf %.ps @echo Done building $^ %.pdf : %.dvi dvipdf $< %.ps : %.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! #------------------------------------------- include make_dependencies.mk
Dependencies
#--make_dependencies.mk------------------------------ Z = tex $(MAIN).$(Z) : \ introduction.$(Z) \ contents.$(Z) \ conclusion.$(Z) \ annex.$(Z) touch $@ #-------------------------------------------
Latex DAG diagram