1

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

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

3 Comments

Is it possible to tell make that it must use files in pictures folder? I don't see it in your makefile.
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?
I'm not that familiar with tex, there should be an option to change the working and/or include directory though.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.