/
Makefile
executable file
·349 lines (312 loc) · 12.7 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
.PHONY: all clean distclean
.SILENT: help all all-cover search-tex search-pdf
DOC := report
PUBS := publications
ifneq ($(OS),Windows_NT)
EXISTSBIBS := $(shell grep -rnw --include \*.tex '.' -e '\\bibliography{' --color=always --exclude-dir=bibliography-work-report > /dev/null && echo "true")
OUTBIBS := $(shell grep -rnw --include \*.tex '.' -e '%\\bibliography{' --color=always --exclude-dir=bibliography-work-report > /dev/null && echo "false")
SHELLBIBS := $(shell if [ "$(OUTBIBS)" = "false" ]; then echo "false"; else echo "true"; fi)
CHECKBIBS := $(shell if [ "$(EXISTSBIBS)" = "true" ]; then echo "$(SHELLBIBS)"; else echo "false"; fi)
CHECKPUBS := $(shell test -f $(PUBS).aux && echo "true")
CHECKREPORT := $(shell test -f $(DOC).pdf && echo "true")
EXISTSGLOSSARIES := $(shell grep -rnw --include \*.tex '.' -e 'makeglossaries' --color=always --exclude-dir=bibliography-work-report > /dev/null && echo "true")
OUTGLOSSARIES := $(shell grep -rnw --include \*.tex '.' -e '%\\makeglossaries' --color=always --exclude-dir=bibliography-work-report > /dev/null && echo "false")
CHECKGLOSSARIES := $(shell if [ "$(OUTGLOSSARIES)" = "false" ]; then echo "false"; else echo "true"; fi)
SHELLGLOSSARIES := $(shell if [ "$(EXISTSGLOSSARIES)" = "true" ]; then echo "$(CHECKGLOSSARIES)"; else echo "false"; fi)
OS_NAME := $(shell uname -s | tr A-Z a-z)
CHECK_DOCKER := $(shell which docker)
endif
# base compilation
base:
pdflatex -enable-write18 --shell-escape $(DOC).tex
# compile without bibliography
nobib:
pdflatex -draftmode -enable-write18 --shell-escape $(DOC).tex
ifeq ($(SHELLGLOSSARIES),false)
echo "" && \
sh -c 'echo "\033[33;1mGlossary not found !!!\033[0m"' && \
echo ""
else
makeglossaries $(DOC)
echo "" && \
sh -c 'echo "\033[33;1mGlossary found !!!\033[0m"' && \
echo ""
endif
pdflatex -draftmode -enable-write18 --shell-escape $(DOC).tex
pdflatex -enable-write18 --shell-escape $(DOC).tex
echo "" && \
sh -c 'echo "\033[33;1mPDFLaTex compilation finished !!!\033[0m"' && \
echo ""
# compile with index and bibliography
all:
ifeq ($(OS),Windows_NT)
compile-latex.bat $(DOC).tex
else
pdflatex -draftmode -enable-write18 --shell-escape $(DOC).tex
ifeq ($(SHELLGLOSSARIES),false)
echo "" && \
sh -c 'echo "\033[33;1mGlossary not found !!!\033[0m"' && \
echo ""
else
makeglossaries $(DOC)
echo "" && \
sh -c 'echo "\033[33;1mGlossary found !!!\033[0m"' && \
echo ""
endif
ifeq ($(CHECKBIBS),true)
bibtex $(DOC).aux
echo "" && \
sh -c 'echo "\033[33;1mBibliography found !!!\033[0m"' && \
echo ""
else
echo "" && \
sh -c 'echo "\033[33;1mBibliography not found !!!\033[0m"' && \
echo ""
endif
ifeq ($(CHECKPUBS),true)
bibtex $(PUBS).aux
endif
pdflatex -draftmode -enable-write18 --shell-escape $(DOC).tex
pdflatex -enable-write18 --shell-escape $(DOC).tex
echo "" && \
sh -c 'echo "\033[33;1mPDFLaTex compilation finished !!!\033[0m"' && \
echo ""
endif
# compile with index and without bibliography
simple: nobib
# clean compilation
distclean:
rm -f *.aux \
$(DOC).log \
$(DOC).blg \
$(DOC).bbl \
$(DOC).out \
$(DOC).dvi \
*.mw
# clean compilation
clean:
ifeq ($(OS),Windows_NT)
del /q *.aux $(DOC).log $(DOC).blg $(DOC).bbl $(DOC).out $(DOC).dvi $(DOC).pdf *.mw >nul 2>&1
else
rm -f *.aux \
$(DOC).log \
$(DOC).blg \
$(DOC).bbl \
$(DOC).out \
$(DOC).dvi \
$(DOC).pdf \
*.mw
endif
compile-grayscale:
pdflatex -draftmode -enable-write18 --shell-escape "\def\forceprint{}\input{${DOC}}" $(DOC).tex
ifeq ($(SHELLGLOSSARIES),false)
echo "" && \
sh -c 'echo "\033[33;1mGlossary not found !!!\033[0m"' && \
echo ""
else
makeglossaries $(DOC)
echo "" && \
sh -c 'echo "\033[33;1mGlossary found !!!\033[0m"' && \
echo ""
endif
ifeq ($(CHECKBIBS),true)
bibtex $(DOC).aux
echo "" && \
sh -c 'echo "\033[33;1mBibliography found !!!\033[0m"' && \
echo ""
else
echo "" && \
sh -c 'echo "\033[33;1mBibliography not found !!!\033[0m"' && \
echo ""
endif
ifeq ($(CHECKPUBS),true)
bibtex $(PUBS).aux
echo "" && \
sh -c 'echo "\033[33;1mBibliography not found !!!\033[0m"' && \
echo ""
endif
pdflatex -draftmode -enable-write18 --shell-escape "\def\forceprint{}\input{${DOC}}" $(DOC).tex
pdflatex -enable-write18 --shell-escape "\def\forceprint{}\input{${DOC}}" $(DOC).tex
echo "" && \
sh -c 'echo "\033[33;1mPDFLaTex compilation finished !!!\033[0m"' && \
echo ""
# compile black text but colourful images
compile-black:
pdflatex -draftmode -enable-write18 --shell-escape "\def\compileblack{}\input{${DOC}}" $(DOC).tex
ifeq ($(SHELLGLOSSARIES),false)
echo "" && \
sh -c 'echo "\033[33;1mGlossary not found !!!\033[0m"' && \
echo ""
else
makeglossaries $(DOC)
echo "" && \
sh -c 'echo "\033[33;1mGlossary found !!!\033[0m"' && \
echo ""
endif
ifeq ($(CHECKBIBS),true)
bibtex $(DOC).aux
echo "" && \
sh -c 'echo "\033[33;1mBibliography found !!!\033[0m"' && \
echo ""
else
echo "" && \
sh -c 'echo "\033[33;1mBibliography not found !!!\033[0m"' && \
echo ""
endif
ifeq ($(CHECKPUBS),true)
bibtex $(PUBS).aux
echo "" && \
sh -c 'echo "\033[33;1mBibliography not found !!!\033[0m"' && \
echo ""
endif
pdflatex -draftmode -enable-write18 --shell-escape "\def\compileblack{}\input{${DOC}}" $(DOC).tex
pdflatex -enable-write18 --shell-escape "\def\compileblack{}\input{${DOC}}" $(DOC).tex
echo "" && \
sh -c 'echo "\033[33;1mPDFLaTex compilation finished !!!\033[0m"' && \
echo ""
# convert images to black and white
print-images:
chmod +x utils/convert-grayscale.sh && ./utils/convert-grayscale.sh && echo ""
# compile pdf and convert images to black and white
print-force: print-images compile-grayscale
# check convert imagems to grayscale
convert-grayscale: $(eval SHELL:=/bin/bash)
@read -p $$'\e[33;1mDo you want to convert images to grayscale? [y/n]\e[0m ' -n 1 -r; \
echo ""; \
if [[ $$REPLY =~ ^[Yy] ]]; \
then \
echo "" && make print-images; \
fi
# force print style
print: convert-grayscale compile-grayscale
# compress final pdf
compress:
docker run --rm -v `pwd`:/pdf sergiomtzlosa/gsexiftool gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dNOPAUSE -dQUIET -dBATCH -dEmbedAllFonts=true -dPrinted=false -dSubsetFonts=true -dDetectDuplicateImages -dPDFSETTINGS=/prepress -sOutputFile=${DOC}-compress.pdf ${DOC}.pdf && \
docker run --rm -v `pwd`:/pdf sergiomtzlosa/gsexiftool exiftool -overwrite_original -all= -tagsFromFile ${DOC}.pdf ${DOC}-compress.pdf
# extra compress
compress-big:
docker run --rm -v `pwd`:/pdf sergiomtzlosa/gsexiftool gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dPrinted=false -dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages -dCompressFonts=true -r150 -sOutputFile=${DOC}-compress-big.pdf ${DOC}.pdf
docker run --rm -v `pwd`:/pdf sergiomtzlosa/gsexiftool exiftool -overwrite_original -all= -tagsFromFile ${DOC}.pdf ${DOC}-compress-big.pdf
# install dependencies to convert pdf to html
# install ImageMagick 7: https://www.tecmint.com/install-imagemagick-on-debian-ubuntu/
install: install-deps
pip install wordcloud
install-texlive:
sudo apt-get install texlive-full
install-deps:
ifeq ($(OS_NAME),linux)
sudo apt-get update && \
sudo apt-get install docker python3-pygments cm-super pdfgrep poppler-utils texlive-pstricks && \
sudo apt -y install texlive-science
endif
ifeq ($(OS_NAME),darwin)
brew install docker pygments pdf2htmlEX pdfgrep poppler
endif
# convert pdf to html
pdf-html:
mkdir -p html
ifeq ($(OS_NAME),linux)
docker run -ti --rm -v `pwd`:/pdf sergiomtzlosa/pdf2htmlex pdf2htmlEX --zoom 1.5 $(DOC).pdf html/$(DOC).html
endif
ifeq ($(OS_NAME),darwin)
pdf2htmlEX --zoom 1.5 $(DOC).pdf html/$(DOC).html
endif
zip html/$(DOC).zip html/$(DOC).html
rm html/$(DOC).html
# create word cloud
word-cloud:
ifeq ($(CHECKREPORT),true)
echo "" && \
sh -c 'echo "\033[33;1mCreating word cloud, please wait ... \033[0m"' && \
echo "" && \
pdftotext $(DOC).pdf - | wordcloud_cli --height 3000 --width 2000 --background white --imagefile images/wordcloud.png
endif
# compile, convert images to black and white and convert pdf to html
full-print: all print pdf-html
# compile book cover with pdflatex
cover-pdflatex:
cd book-cover/universal && \
pdflatex -enable-write18 --shell-escape book_cover.tex && \
cp book_cover.pdf ../../ && \
echo "" && \
sh -c 'echo "\033[33;1mPDFLATEX COVER COMPILATION DONE !!!\033[0m"' && \
echo ""
#compile cover with latex
cover-latex:
cd book-cover/universal && \
latex --shell-escape "\def\latexcompiler{}\input{book_cover}" book-cover/universal/book_cover.tex && \
dvipdf -dNOSAFER -dALLOWPSTRANSPARENCY book_cover.dvi book_cover.pdf && \
cp book_cover.pdf ../../ && \
echo "" && \
sh -c 'echo "\033[33;1mLATEX COVER COMPILATION DONE !!!\033[0m"' && \
echo ""
# merge main PDF file and cover
merge-cover:
ifneq ($(CHECK_DOCKER),'')
docker run --rm -v `pwd`:/pdf sergiomtzlosa/gsexiftool gs -dPrinted=false -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dNOPAUSE -dQUIET -dBATCH -dEmbedAllFonts=true -dDetectDuplicateImages -dPDFSETTINGS=/prepress -sDEVICE=pdfwrite -sOUTPUTFILE=$(DOC)-combine.pdf book_cover.pdf $(DOC).pdf && \
echo "" && \
sh -c 'echo "\033[33;1mPDF file + cover merged !!!\033[0m"' && \
echo ""
else
echo "" && \
sh -c 'echo "\033[33;1mDOCKER NOT INSTALLED !!!\033[0m"' && \
echo ""
endif
# reduce size main PDF
reduce-pdf:
ifneq ($(CHECK_DOCKER),'')
docker run --rm -v `pwd`:/pdf sergiomtzlosa/gsexiftool gs -dPrinted=false -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dNOPAUSE -dQUIET -dBATCH -dEmbedAllFonts=true -dDetectDuplicateImages -dPDFSETTINGS=/prepress -sDEVICE=pdfwrite -sOUTPUTFILE=$(DOC)-reduced.pdf $(DOC).pdf && \
echo "" && \
sh -c 'echo "\033[33;1mPDF file reduced !!!\033[0m"' && \
echo ""
else
echo "" && \
sh -c 'echo "\033[33;1mDOCKER NOT INSTALLED !!!\033[0m"' && \
echo ""
endif
# compile cover and merge with main document
mm-cover: cover-latex merge-cover
# compile all with cover
all-cover: all cover-latex reduce-pdf merge-cover
# compile all with cover and word cloud
all-cover-wc: word-cloud all cover-latex merge-cover
# reduce and merge pdf file
reduce-merge-pdf: cover-latex reduce-pdf merge-cover
# search in pdf file
# USAGE: make search-pdf SEARCH_TERM=Kittel
search-pdf:
pdfgrep -n -R "$(SEARCH_TERM)" $(DOC).pdf --exclude=bibliography-work-report | cat
# search in tex files
# USAGE: make search-tex SEARCH_TERM=Kittel
search-tex:
grep -rnw --include \*.tex '.' -e '$(SEARCH_TERM)' --color=always --exclude-dir=bibliography-work-report | cat
# Help command
help:
echo "" && \
echo "Compilation help" && \
echo "---------------------" && \
sh -c 'echo "\033[33;1mmake base\033[0m --> Base compilation (unused)"' && \
sh -c 'echo "\033[33;1mmake nobib\033[0m --> Full compilation without bibliography"' && \
sh -c 'echo "\033[33;1mmake all\033[0m --> Full compilation with all latex options"' && \
sh -c 'echo "\033[33;1mmake simple\033[0m --> Same as make nobib"' && \
sh -c 'echo "\033[33;1mmake distclean\033[0m --> Clean compilation files"' && \
sh -c 'echo "\033[33;1mmake clean\033[0m --> Clean compilation files and pdf file"' && \
sh -c 'echo "\033[33;1mmake print\033[0m --> Full compilation in grayscale for printing"' && \
sh -c 'echo "\033[33;1mmake print\033[0m --> Force full compilation in grayscale for printing"' && \
sh -c 'echo "\033[33;1mmake compress\033[0m --> Compress output pdf"' && \
sh -c 'echo "\033[33;1mmake compress-big\033[0m --> Strong compressing output pdf"' && \
sh -c 'echo "\033[33;1mmake install\033[0m --> Install dependencies"' && \
sh -c 'echo "\033[33;1mmake install-texlive\033[0m --> Install TeXLive"' && \
sh -c 'echo "\033[33;1mmake pdf-html\033[0m --> Convert output pdf file into beautiful HTML"' && \
sh -c 'echo "\033[33;1mmake word-cloud\033[0m --> Create a fancy word cloud image"' && \
sh -c 'echo "\033[33;1mmake full-print\033[0m --> Compile in grayscale for printing and convert output pdf into HTML"' && \
sh -c 'echo "\033[33;1mmake cover-pdflatex\033[0m --> Compile book cover with pdflatex"' && \
sh -c 'echo "\033[33;1mmake cover-latex\033[0m --> Compile book cover with latex"' && \
sh -c 'echo "\033[33;1mmake mm-cover\033[0m --> Compile book cover and merge it with output main pdf"' && \
sh -c 'echo "\033[33;1mmake all-cover\033[0m --> Full compilation with all options, reduce size of main pdf and merge cover"' && \
sh -c 'echo "\033[33;1mmake all-cover-wc\033[0m --> Full compilation with all options, reduce size of main pdf, merge cover and create word cloud image"' && \
sh -c 'echo "\033[33;1mmake search-pdf SEARCH_TERM=Kittel\033[0m --> Search string in output pdf"' && \
sh -c 'echo "\033[33;1mmake search-tex SEARCH_TERM=Kittel\033[0m --> Search string in TeX files"' && \
sh -c 'echo "\033[33;1mmake compile-black\033[0m --> compile black text but colourful images"' && \
sh -c 'echo "\033[33;1mmake reduce-merge-pdf\033[0m --> Reduce pdf file and merge cover in a new pdf file"' && \
echo ""