-
Notifications
You must be signed in to change notification settings - Fork 2
/
makefile
166 lines (143 loc) · 5.62 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Makefile for latex compilation.
# © Yiannis Hadjimichael, 11 May 2021
#
# This makefile gives the option to complile the same LaTeX document with
# "pdflatex + biber (or bibtex) + pdflatex (x2)" command when two (or more) pdf outputs are desired.
#
# At the beginning of the .tex file a boolean variable (ifpaper) is set to "journaltrue"
# for the default latex configuration or "journalfalse" for the alternative one.
# This is useful when two different latex configurations are used to produce pdf outputs
# out of a single .tex file; for example, a pdf output based on a journal's template and a pdf
# output output for a pre-print or arXiv version.
#
# By default both compilations do not crop pdf and/or eps figures, however this is possible
# by running the corresponding make commands, e.g., make journal-crop.
# The "pdfcrop" package is used for removing the unnecessary white space before running
# latex/pdflatex commands. The package is contained in Tex Live and Mik Tex distributions and
# can be also downloaded from https://www.ctan.org/pkg/pdfcrop?lang=en
#
# LATEX warnings in .log file are shown after compilations.
#
# make journal: journal configuration
# make journal-crop: journal configuration with cropping figures before latex compilation
# make wias: WIAS configuration
# make wias-crop: WIAS configuration with cropping figures before latex compilation
#
# Keyword explanations:
# @ : avoid displaying the command displayed by make
# $< : the first item in the dependency list
# $@ : the name of the target
# $(word #,$^) : the name of the #th dependency
# dvips -Ppdf -G1 $@ -o : -Ppdf option to include Type 1 (scalable) fonts in the PS file
# -G1 (or -G0) option to fix a bug in versions of dvips earlier than 5.90
# (see http://www-rohan.sdsu.edu/~aty/bibliog/latex/LaTeXtoPDF.html)
# grep -A N --color : output N lines in color after the line containing the string found by grep
# pdfcrop [file.pdf] : cropping pdf file
# pdftops -eps [file.pdf] [file.eps] : converts file to .eps
### Below are the only variables that need to be set ###
# FILE: the main tex file to compile
# FIGURES folder containing all figures
# TEMPLATES: the different templates used to produced pdf outputs
# BIBENGINES: the corresponding bibliography compiler for each template
# FLAGS: the corresponding change of flags in the .tex file to enable switching from one template to another
FILE = positivity
FIGURES = figures
TEMPLATES = journal wias arxiv
BIBENGINES = bibtex bibtex biber
FLAGS1 = journalfalse/journaltrue journaltrue/journalfalse journaltrue/journalfalse
FLAGS2 = wiastrue/wiasfalse wiasfalse/wiastrue wiastrue/wiasfalse
FLAGS3 = arxivtrue/arxivfalse arxivtrue/arxivfalse arxivfalse/arxivtrue
### Code part of Makefile ###
### No need to edit anything after this line ###
PDF = $(FIGURES)/*.pdf
EPS = $(FIGURES)/*.eps
TEMPLATE_INFO = .latex_template
ifneq ("$(wildcard $(TEMPLATE_INFO))","")
PREV_TEMPLATE = $(shell cat $(TEMPLATE_INFO))
else
PREV_TEMPLATE =
endif
# code from https://stackoverflow.com/questions/62337774/using-word-function-in-makefile-with-variable
# $1 - list to check
# $2 - element to find
# returns - index of element
define get_index
$(sort $(eval index_count :=) \
$(foreach word,$(1), \
$(eval index_count := $(index_count) x) \
$(if $(findstring $(word),$(2)),$(words $(index_count)))) \
)
endef
$(foreach template,$(TEMPLATES), \
$(eval index = $(call get_index,$(TEMPLATES),$(template)) ) \
$(eval $(word $(index),$(TEMPLATES))_BIBENGINE := $(word $(index),$(BIBENGINES))) \
$(eval $(word $(index),$(TEMPLATES))_FLAG1 := $(word $(index),$(FLAGS1))) \
$(eval $(word $(index),$(TEMPLATES))_FLAG2 := $(word $(index),$(FLAGS2))) \
$(eval $(word $(index),$(TEMPLATES))_FLAG3 := $(word $(index),$(FLAGS3))) \
)
# Make recipes:
.PHONY: $(TEMPLATES) compile croppdf pdf2eps clean-eps clean
$(TEMPLATES):
@$(MAKE) TEMPLATE=$@ BIBENGINE=$($@_BIBENGINE) FLAG1=$($@_FLAG1) FLAG2=$($@_FLAG2) FLAG3=$($@_FLAG3) compile
@echo "$@" > $(TEMPLATE_INFO) # update TEMPLATE_INFO
compile:
@if [ "$(PREV_TEMPLATE)" != "$(TEMPLATE)" ]; then \
echo "Change template $(FLAG1) in $(FILE).tex ...\n" ; \
sed -i.bak s/$(FLAG1)/ $(FILE).tex ; \
echo "Change template $(FLAG2) in $(FILE).tex ...\n" ; \
sed -i.bak s/$(FLAG2)/ $(FILE).tex ; \
echo "Change template $(FLAG3) in $(FILE).tex ...\n" ; \
sed -i.bak s/$(FLAG3)/ $(FILE).tex ; \
$(RM) $(FILE).aux ; \
fi
@echo "LaTex compilation ..."
@$(MAKE) $(FILE).aux
$(FILE).aux: $(FILE).tex
@echo "Removing bib auxiliary files to enable biber/bibtex compilation ..."
@$(RM) $(FILE).bbl
@$(RM) $(FILE).blg
pdflatex $<
$(BIBENGINE) $(FILE) || true
pdflatex $<
pdflatex $<
pdflatex $<
@echo "\nChecking for errors or warnings ...\n"
@grep -A 1 --color 'Error\|Warning\|Overfull\|Underfull\|Badbox' $(FILE).log || true
croppdf:
@for file in $(PDF) ; do \
pdfcrop $$file ; \
mv $${file%.*}-crop.pdf $${file%.*}.pdf; \
done
pdf2eps:
@for file in $(PDF) ; do \
pdfcrop $$file ; \
pdftops -eps $${file%.*}-crop.pdf $${file%.*}.eps ; \
rm $${file%.*}-crop.pdf ; \
done
clean-eps:
@$(RM) $(EPS)
clean:
@echo "Removing latex auxiliary files."
@$(RM) $(FILE).aux*
@$(RM) $(FILE).bbl
@$(RM) $(FILE).bcf
@$(RM) $(FILE).blg
@$(RM) $(FILE)-blx.bib
@$(RM) $(FILE).dvi
@$(RM) $(FILE).idx
@$(RM) $(FILE).ilg
@$(RM) $(FILE).ind
@$(RM) $(FILE).log
@$(RM) $(FILE).lof
@$(RM) $(FILE).lot
@$(RM) $(FILE).nav
@$(RM) $(FILE).out
@$(RM) $(FILE).ps
@$(RM) $(FILE).run.xml
@$(RM) $(FILE).spl
@$(RM) $(FILE).synctex.gz
@$(RM) $(FILE).tex.bak
@$(RM) $(FILE).thm
@$(RM) $(FILE).toc
@$(RM) .latex_template
clean-all: clean clean-eps