La Vita è Bella

Sunday, October 02, 2005

Makefile for LATEX

Update:TeXLive doesn't have it, but it have a tool texi2dvi with the same function (at least it also support -b and -p parameters).

You don't know how many times you should run the command latex, so it's hard to write a Makefile for LATEX

But I've found texify today. It can automatically calls the commands needed including latex/pdflatex, bibtex, etc., with needed times, and ships with almost all tex distributions.

Here's an example for my "Makefile" file (Note: don't forget to define RMRF, ACROREAD & PREVIEW for your environment):

LATEX = texify
PARAMS = -b
DVIPDF = dvipdfmx
MAINNAME = myarticle
SRCS = $(MAINNAME).tex \
	   chapter1.tex \
	   chapter2.tex
DVIFILE = $(MAINNAME).dvi
PDFFILE = $(MAINNAME).pdf

all: $(PDFFILE)

$(PDFFILE): $(DVIFILE)
	$(DVIPDF) $(DVIFILE)

$(DVIFILE): $(SRCS)
	$(LATEX) $(PARAMS) $(MAINNAME).tex

preview: $(DVIFILE)
	$(PREVIEW) $(DVIFILE)

read: $(PDFFILE)
	$(ACROREAD) $(PDFFILE)

clean:
	$(RMRF) *.toc *.out *.aux *.log *.bak

cleanall: clean
	$(RMRF) $(PDFFILE) $(DVIFILE)
	
.PHONY: clean cleanall all

For pdflatex files, beamer slides for example, use texify -p, here's the Makefile:

LATEX = texify -p
PARAMS = -b
MAINNAME = myarticle
SRCS = $(MAINNAME).tex \
	   chapter1.tex \
	   chapter2.tex
PDFFILE = $(MAINNAME).pdf

all: $(PDFFILE)

$(PDFFILE): $(SRCS)
	$(LATEX) $(PARAMS) $(MAINNAME).tex

read: $(PDFFILE)
	$(ACROREAD) $(PDFFILE)

clean:
	$(RMRF) *.toc *.out *.aux *.log *.bak

cleanall: clean
	$(RMRF) $(PDFFILE) $(DVIFILE)
	
.PHONY: clean cleanall all

If you need gbk2uni for Chinese support, change the line

	$(LATEX) $(PARAMS) $(MAINNAME).tex

into (Note: don't forget to define GBK2UNI):

	$(LATEX) $(PARAMS) $(MAINNAME).tex
	$(GBK2UNI) $(MAINNAME).out
	$(LATEX) $(PARAMS) $(MAINNAME).tex

That's it!



tags: , ,

06:09:36 by fishy - latex - Permanent Link

Revision: 1.0/1.0, last modified on 2005-10- 2 @ 21:09.

Karma: -6 (47.50% out of 120 were positive) [+/-]

You can subscribe to RSS 2.0 feed for comments and trackbacks

Trackbacks:
There are currently no trackbacks for this item.
Use this TrackBack url to ping this item (right-click, copy link target). If your blog does not support Trackbacks you can manually add your trackback by using this form.

No comments yet

Add Comment



A blog about open source, patches, thoughts and geeks