-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
101 lines (81 loc) · 2.38 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/make -f
# Set the projects (top-level .tex files) you want to compile.
PROJECTS ?= presentation poster
# The main project (where the metadata is loaded from).
MAIN ?= presentation
# The presentation project.
PRESENTATION ?= presentation
# The resulting combined file.
COMBINED ?= combined
VIEWER ?= evince
ENGINE ?= pdflatex
LATEXMK ?= latexmk
ENGINE_OPTIONS ?= -shell-escape -synctex=1
# FIXME: Maybe a better way to detect dependencies somehow? TeX LSP? :'D
SOURCES=$(wildcard ./*.tex ./*.bib)
# paper.pdf presentation.pdf ...
OUTPUTS := $(foreach proj, $(PROJECTS), $(proj).pdf)
default: all
all: $(MAIN).pdf
.PHONY: $(PROJECTS)
$(PROJECTS): %:
$(MAKE) $*.pdf
%.pdf: %.tex $(SOURCES)
command -v texliveonfly && \
texliveonfly -c $(ENGINE) -a "$(ENGINE_OPTIONS) -interaction=nonstopmode" $<
$(LATEXMK) -$(ENGINE) $(ENGINE_OPTIONS) $<
%-gray.pdf: %.pdf
gs -sOUTPUTFILE=$@ -sDEVICE=pdfwrite \
-sColorConversionStrategy=Gray \
-dProcessColorModel=/DeviceGray \
-dCompatibilityLevel=1.4 \
-dNOPAUSE -dBATCH \
$< </dev/null
TEXTS := $(foreach proj, $(PROJECTS), $(proj).txt)
%.txt: %.pdf
pdftotext -nopgbrk $<
.PHONY: show
show: $(OUTPUTS)
$(VIEWER) $(OUTPUTS) &>/dev/null &
.PHONY: show-gray
GRAYS := $(foreach proj, $(PROJECTS), $(proj)-gray.pdf)
show-gray: $(GRAYS)
$(VIEWER) $(GRAYS) &>/dev/null &
# (Needed: pip install 'lpython pdfrw stapler')
$(COMBINED).pdf: $(OUTPUTS)
stapler --force cat $^ $@
# Rewrite the metadata in the combined file with the one in the main
# project. Sadly, 'stapler' by default clears the metadata portion.
lpython -t bare \
"from pdfrw import PdfReader, PdfWriter;; "\
"presData = PdfReader(ARGS[1]); "\
"outf = PdfReader(ARGS[2]); "\
"outf.Info = presData.Info; "\
"PdfWriter(ARGS[2], trailer=outf).write()" \
-X $(MAIN).pdf \
-X $@
.PHONY: show-combined
show-combined: combined.pdf
$(VIEWER) $^ &>/dev/null &
.PHONY: present
present: $(PRESENTATION).pdf
pdfpc $(PRESENTATION).pdf
.PHONY: clean
clean: --clean-extra
$(LATEXMK) -$(ENGINE) -c
.PHONY: distclean
distclean: clean
$(LATEXMK) -$(ENGINE) -C
$(RM) $(GRAYS)
$(RM) $(TEXTS)
$(RM) $(COMBINED).pdf
.PHONY: --clean-extra
--clean-extra:
$(RM) $(wildcard ./*.cut) \
$(wildcard ./*.bbl) \
$(wildcard ./*.nav) \
$(wildcard ./*.snm) \
$(wildcard ./*.vrb) \
$(wildcard ./*.synctex.gz) \
$(wildcard ./*.run.xml)
$(RM) -r $(wildcard ./_minted-*)