2

My book structure is like:

book.tex
chapter/ch1.tex
       /ch2.tex
ref/ch1.bib
   /ch2.bib

As each chapter of my book is required to has its own reference thus I used chapterbib package and fed each chapter tex file with corresponding bib file. Finally I could manage to compile the book as following bash commands:

xelatex book
bibtex chapter/ch1
bibtex chapter/ch2
xelatex book
xelatex book

Now my question is that, how could I compile the book by writing the Makefile? My current script does no work at all.

TEXFILE := book
CHAPTERDIR := chapter
CHAPTERS := $(wildcard $(CHAPTERDIR)/*.tex)
TEXENGINE=xelatex
BIBTEX=bibtex
BUILDTEX=$(TEXENGINE) $(TEXFILE)

all:
    $(BUILDTEX)
    $(shell for chapterSrc in $(CHAPTERS); do \
        chapterSrcName=$(shell basename $(chapterSrc) .tex); \
        $(BIBTEX) $(CHAPTERDIR)/$(chapterSrcName); \
    done)
    $(BUILDTEX)
    $(BUILDTEX)

Thank you.

1

Warning: untested code. Should work in GNU Make.

TEXFILE := book
CHAPTERDIR := chapter
CHAPTERS := $(wildcard $(CHAPTERDIR)/*.tex)
BIBS := $(patsubst %.tex,%,$(CHAPTERS))
TEXENGINE=xelatex
BIBTEX=bibtex
BUILDTEX=$(TEXENGINE) $(TEXFILE)

all:
    $(BUILDTEX)
    for c in $(BIBS); do \
        $(BIBTEX) $$c; \
        done;
    $(BUILDTEX)
    $(BUILDTEX)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.