forked from cagix/pandoc-thesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
236 lines (192 loc) · 6.71 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
####################
## Setup (public) ##
####################
## pandoc-thesis official image
## Verify its signature before run `make container` ;)
OCI ?= ghcr.io/andros21/pandoc-thesis:latest
## Container name (from working dir)
CN := $(shell basename $$PWD)
## User id and group id using id command
## In case this doesn't work, set your UID and GID
UID ?= $(shell id -u)
GID ?= $(shell id -g)
## Container engine to use
## Choose between docker or podman (rootless)
## (Defaults to docker)
CE ?= $(shell basename `which docker 2>/dev/null ||\
which podman 2>/dev/null || echo docker`)
## Check podman version
ifeq ($(CE), podman)
PODMAN_VERSION = $(shell podman --version | cut -d' ' -f 3 | cut -d'.' -f 1)
endif
# User container as current user
docker_flags = --user $(UID):$(GID)
# Map current user as container user
podman_flags_4 = --userns keep-id:uid=65532,gid=65532
podman_flags = $(docker_flags) --userns keep-id
ifeq ($(CE), podman)
ifeq ($(PODMAN_VERSION), 4)
optional_flags=$(podman_flags_4)
else
optional_flags=$(podman_flags)
endif
else
optional_flags=$(docker_flags)
endif
## Working directory
## In case this doesn't work, set the path manually (use absolute paths).
WORKDIR = $(CURDIR)
## Check OS (supported Linux, Darwin aka Mac)
## Disable selinux volume mount remap on Mac
UNAME := $(shell uname -s)
default_remap =
selinux_remap = :Z
ifeq ($(UNAME), Linux)
remap=$(selinux_remap)
else
remap=$(default_remap)
endif
## Pandoc
## (Defaults to docker/podman. To use pandoc and TeX-Live directly, create an
## environment variable `PANDOC` pointing to the location of your
## pandoc installation.)
PANDOC ?= $(CE) exec $(CN) pandoc
## Source files
## (Adjust to your needs. Order of markdown files in $(SRC) matters!)
META = metadata.yaml
SRC = md/introduction.md \
md/relatedwork.md \
md/concept.md \
md/realisation.md \
md/conclusion.md
BIBFILE = md/references.bib
APPENDIX = md/appendix.md
TARGET = thesis.pdf
####################
## Internal setup ##
####################
## Auxiliary files
TITLEPAGE = titlepage.tex
FRONTMATTER = frontmatter.tex
BACKMATTER = backmatter.tex
REFERENCES = tex/references.tex
TMP1 = tex/$(TITLEPAGE:%.tex=__%.filled.tex)
TMP2 = tex/$(FRONTMATTER:%.tex=__%.filled.tex)
TMP3 = tex/$(BACKMATTER:%.tex=__%.filled.tex)
TMP = $(TMP1) $(TMP2) $(TMP3)
## Pandoc options
AUX_OPTS = --wrap=preserve
OPTIONS = -f markdown
OPTIONS += --pdf-engine=latexmk
OPTIONS += --pdf-engine-opt=-outdir=build
OPTIONS += --pdf-engine-opt=--shell-escape
OPTIONS += --standalone
OPTIONS += -M lang=en-EN
OPTIONS += --metadata-file=$(META)
OPTIONS += --filter pandoc-imagine
OPTIONS += --include-in-header=$(TMP1)
OPTIONS += --include-before-body=$(TMP2)
OPTIONS += --include-after-body=$(TMP3)
OPTIONS += --citeproc
OPTIONS += -M bibliography=$(BIBFILE)
OPTIONS += -M link-citations=true
## download from https://www.zotero.org/styles
## cf. https://pandoc.org/MANUAL.html#citations
#OPTIONS += --csl=chicago-author-date-de.csl
#OPTIONS += --csl=chicago-note-bibliography.csl
#OPTIONS += --csl=ieee.csl
#OPTIONS += --csl=oxford-university-press-note.csl
OPTIONS += --listings
OPTIONS += -V documentclass=book
OPTIONS += -V papersize=a4
OPTIONS += -V fontsize=11pt
## uncomment and edit to change line stretch
#OPTIONS += -V linestretch=1.5
OPTIONS += -V classoption:open=right
OPTIONS += -V classoption:twoside=true
OPTIONS += -V classoption:cleardoublepage=empty
OPTIONS += -V classoption:clearpage=empty
OPTIONS += -V geometry:top=30mm
OPTIONS += -V geometry:left=25mm
OPTIONS += -V geometry:bottom=30mm
OPTIONS += -V geometry:width=150mm
OPTIONS += -V geometry:bindingoffset=6mm
OPTIONS += --toc
OPTIONS += --toc-depth=3
OPTIONS += --number-sections
## default links color
## set new colors inside `tex/extra.tex`
## and change with your
OPTIONS += -V citecolor=darkred
OPTIONS += -V linkcolor=darkred
OPTIONS += -V urlcolor=darkblue
OPTIONS += -V book=true
OPTIONS += -V titlepage=true
OPTIONS += -V toc-own-page=true
##################
## Main targets ##
##################
## Simple book layout
simple: containerstart $(TARGET)
## Open thesis after build it
thesis: simple
xdg-open ${TARGET} > /dev/null 2>&1 &
example: containerstart example.pdf
## Create "pandoc-thesis" container with pandoc and TeX-Live
container:
$(CE) run \
--detach \
--env HOME="/pandoc_thesis" \
--interactive \
--name $(CN) \
$(optional_flags) \
--volume "$(WORKDIR)":/pandoc_thesis$(remap) $(OCI)
$(CE) exec -u 0 -w /tmp $(CN) sh -c 'curl -sSf $$TEXLIVE_TRIGGER_URL | sh'
$(CE) exec -u 0 -w /tmp $(CN) sh -c 'curl -sSf $$JAVA_TRIGGER_URL | sh'
$(CE) exec -u 0 -w /tmp $(CN) dot -c
$(CE) exec -u 0 -w /tmp $(CN) python3 -m venv --system-site-packages /opt/imagine
$(CE) exec -u 0 -w /tmp $(CN) sh -c '/opt/imagine/bin/pip install \
--no-cache-dir --disable-pip-version-check \
git+$$PANDOC_IMAGINE_REPO@$$PANDOC_IMAGINE_VERSION'
#######################
## Auxiliary targets ##
#######################
## Build thesis
${TARGET}: $(SRC) $(REFERENCES) $(APPENDIX) $(META) $(BIBFILE) $(TMP)
$(PANDOC) ${OPTIONS} -o $@ $(SRC) $(REFERENCES) $(APPENDIX)
## Build example
SRC_EXAMPLE = example/introduction.md \
example/relatedwork.md \
example/concept.md \
example/realisation.md \
example/conclusion.md
BIBFILE_EXAMPLE = example/references.bib
APPENDIX_EXAMPLE = example/appendix.md
example.pdf: $(SRC_EXAMPLE) $(REFERENCES_EXAMPLE) $(APPENDIX_EXAMPLE) $(META) $(BIBFILE_EXAMPLE) $(TMP)
$(PANDOC) ${OPTIONS} -M bibliography=$(BIBFILE_EXAMPLE) -o $@ $(SRC_EXAMPLE) $(REFERENCES) $(APPENDIX_EXAMPLE)
## Build auxiliary files (title page, frontmatter, backmatter, references)
$(TMP): tex/__%.filled.tex: tex/%.tex $(META)
$(PANDOC) $(AUX_OPTS) --template=$< --metadata-file=$(META) -o $@ $<
## Start container or advice to setup it
containerstart:
@$(CE) start $(CN) \
|| (printf 'Error: no container `%s` found, run `make container` before\n' $(CN) && exit 1)
## Upgrade "pandoc-thesis" image and setup new container
containerupgrade: containerclean imageclean container
## Clean-up: Remove temporary (generated) files
clean:
rm -rf $(TMP) \?/ .cache/ pd-images/ .java/
## Clean-up: Remove also generated thesis
distclean: clean
rm -fr $(TARGET) build/
## Clean-up: Stop and remove "pandoc-thesis" container
containerclean:
$(CE) stop $(CN) || exit 0
$(CE) rm $(CN) || exit 0
## Clean-up: Remove "pandoc-thesis" image
imageclean:
$(CE) rmi $(OCI) || exit 0
##################################
## Declaration of phony targets ##
##################################
.PHONY: simple container containerstart containerupgrade clean distclean containerclean imageclean