I have a lecture consisting of interconnected tex files. lecture.tex uses pictures in pdf format in /pictures/output folder. They are being produced from tex files in /pictures folder.
lecture.tex
makefile
/pictures
/output
01_picture.pdf
02_picture.pdf
01_picture.tex
02_picture.tex
makefile
I created a makefile for pictures (it works fine):
COMMAND = pdflatex
FLAGS = #-quiet
FILES = $(wildcard ./[0-9]*.tex)
.PHONY = all create_dir
OUTPUTDIR="output"
all: create_dir $(patsubst ./%.tex,./output/%.pdf,$(FILES))
create_dir:
@if [ ! -d $(OUTPUTDIR) ]; then \
mkdir $(OUTPUTDIR); \
fi
./output/%.pdf: %.tex
$(COMMAND) $(FLAGS) $*.tex
mv ./$*.pdf ./output
rm ./$*.aux ./$*.log
Now when compiling lecture, we need to do:
if(any pictures tex files were modified)
recompile picture pdf
recompile lecture.tex
I tried to do it with this main makefile:
COMMAND = pdflatex
FLAGS = #-quiet
.PHONY = pictures
all: lecture.pdf
lecture.pdf: pictures lecture.tex
$(COMMAND) $(FLAGS) lecture.tex
pictures:
make -C pictures
But it doesn't work. Or maybe, I need just 1 makefile for everything?
asked Aug 30, 2016 at 10:39
user4035
24k11 gold badges69 silver badges101 bronze badges
1 Answer 1
Just use one makefile, and express the dependencies correctly:
pictures := pictures
output := $(pictures)/output
PDFLATEX := pdflatex
PDFLATEXFLAGS := #-quiet
COMPILE.pdf := $(PDFLATEX) $(PDFLATEXFLAGS)
pictures_tex := $(wildcard $(pictures)/[0-9]*.tex)
pictures_pdf := $(pictures_tex:$(pictures)/%.tex=$(output)/%.pdf)
lecture.pdf: lecture.tex $(pictures_pdf)
$(COMPILE.pdf) $<
$(output)/%.pdf: $(pictures)/%.tex | $(output)
$(COMPILE.pdf) -output-directory $| $<
$(RM) $(output)/$*.aux $(output)/$*.log
$(output): ; mkdir -p $@
answered Aug 30, 2016 at 11:53
user657267
21.1k5 gold badges65 silver badges81 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
user4035
Is it possible to tell make that it must use files in pictures folder? I don't see it in your makefile.
user4035
There are some pictures, that use internal files located in
pictures folder. I tried cd pictures && $(COMPILE.pdf) -output-directory $(OUTPUT) $<, but it gives an error: pictures/01_picture.tex not found as we are inside pictures folder. Or maybe, accept your answer and write this as a separate question?user657267
I'm not that familiar with tex, there should be an option to change the working and/or include directory though.