Our Computer Notes

Recent site activity

Latex‎ > ‎

Using Makefile to compile your .tex documents

Organize your latex projects may be not easy if you are not using a complex latex editor, so I search for some solutions at the internet and create a makefile should be a good way.

With a makefile you can use all of the advantages of that and organize your latex project.

I created a Makefile and now I'm using it with great results.

If you want to use a Makefile with your latex project, in the Makefile that is presented bellow, you will just need to modify the value of the MAIN_TEX_NAME.

Source of Makefile:
-------
LATEX    = latex
BIBTEX    = bibtex
PS2PDF = ps2pdf
DVIPS    = dvips

DVI_VIEWER = xdvi
PS_VIEWER = evince
PDF_VIEWER = evince

WORK_DIR = tmp

PS2PDF_OPTIONS = -sPAPERSIZE=a4
LATEX_OPTIONS = -output-directory=$(WORK_DIR) -halt-on-error

MAIN_TEX_NAME = curriculum

all: dvi   

dvi: $(MAIN_TEX_NAME)

$(MAIN_TEX_NAME):
    mkdir -p $(WORK_DIR)   
    $(LATEX) $(LATEX_OPTIONS) $(MAIN_TEX_NAME).tex
    $(LATEX) $(LATEX_OPTIONS) $(MAIN_TEX_NAME).tex
    mv $(WORK_DIR)/$(MAIN_TEX_NAME).dvi .

bib:
    $(BIBTEX) $(WORK_DIR)/$(MAIN_TEX_NAME)
   
pdf: ps
    $(PS2PDF) $(PS2PDF_OPTIONS) $(MAIN_TEX_NAME).ps $(MAIN_TEX_NAME).pdf

ps: dvi
    $(DVIPS) $(MAIN_TEX_NAME).dvi

viewdvi: dvi
    $(DVI_VIEWER) $(MAIN_TEX_NAME).dvi

viewps: ps
    $(PS_VIEWER) $(MAIN_TEX_NAME).ps

viewpdf: pdf
    $(PDF_VIEWER) $(MAIN_TEX_NAME).pdf

clean:
    rm -rf $(WORK_DIR)
    rm -rf $(MAIN_TEX_NAME).dvi
    rm -rf $(MAIN_TEX_NAME).ps
    rm -rf $(MAIN_TEX_NAME).pdf
-----

Comments (1)

Cristian Thiago Moecke - Jun 9, 2008 7:36 AM

Note: you need to replace the spaces in the indented lines with TABs. Unfortunately google sites replaces tabs with spaces.