forked from andrewheiss/Global-Pandoc-files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.master
218 lines (191 loc) · 7.22 KB
/
Makefile.master
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
# Put this Makefile in your project directory---i.e., the directory containing
# the paper you are writing. You can use it to create .html, .docx, and .pdf
# output files (complete with bibliography, if present) from your Markdown
# file.
#
# Additional notes:
# * Change the paths at the top of the file as needed.
#
# * Using `make` without arguments will generate html, tex, pdf, docx,
# and odt output files from all of the files with the designated
# markdown extension. The default is `.md` but you can change this.
#
# * You can specify an output format with `make tex`, `make pdf`,
# `make html`, `make odt`, or `make docx`
#
# * Running `make clean` will only remove all, .html, .pdf, .odt,
# and .docx files in your working directory **that have the same name
# as your Markdown files**. Other files with these extensions will be safe.
#
# * If wanted, remove the automatic call to `clean` to rely on make's
# timestamp checking. However, if you do this, you'll need to add all the
# document's images, etc. as dependencies, which means it might be easier
# to just clean and delete everything every time you rebuild.
# ----------------------
# Modifiable variables
# ----------------------
# Markdown extension (e.g. md, markdown, mdown).
MEXT = md
# Optional folder for manuscript
MS_DIR = .
# Location of Pandoc support files.
PREFIX = /Users/andrew/.pandoc
# Word and HTML can choke on PDF images, so those targets use a helper script
# named replace_pdfs to replace all references to PDFs with PNGs and convert
# existing PDFs to PNG using sips. However, there are times when it's better to
# *not* convert to PNG on the fly, like when using high resolution PNGs exprted
# from R with ggsave+Cairo. To disable on-the-fly conversion and supply your
# own PNGs, uncomment PNG_CONVERT below. The script will still replace
# references to PDFs with PNGs, but will not convert the PDFs
# PNG_CONVERT = --no-convert
# Location of your working bibliography file
BIB_FILE = /Users/andrew/Dropbox/Readings/Papers.bib
# CSL stylesheet (located in the csl folder of the PREFIX directory).
# Common CSLs:
# * american-political-science-association
# * chicago-author-date
# * chicago-fullnote-bibliography
# * chicago-fullnote-no-bib
# * chicago-syllabus-no-bib
# * apa
# * apsa-no-bib
CSL = chicago-author-date
# LaTeX doesn't use pandoc-citeproc + CSL and instead lets biblatex handle the
# heavy lifting. There are three possible styles built in to the template:
# * bibstyle-chicago-notes
# * bibstyle-chicago-authordate
# * bibstyle-apa
TEX_REF = bibstyle-chicago-authordate
TEX_DIR = tex_out
# Cross reference options
CROSSREF = --filter pandoc-crossref -M figPrefix:"Figure" -M eqnPrefix:"Equation" -M tblPrefix:"Table"
# To add version control footer support in PDFs:
# 1. Run vcinit in the directory
# 2. Place `./vc` at the front of the formula
# 3. Add `-V vc` to the pandoc command
# 4. Change pagestyle to athgit instead of ath
#--------------------
# Color definitions
#--------------------
NO_COLOR = \x1b[0m
BOLD_COLOR = \x1b[37;01m
OK_COLOR = \x1b[32;01m
WARN_COLOR = \x1b[33;01m
ERROR_COLOR = \x1b[31;01m
# --------------------
# Target definitions
# --------------------
# All markdown files in the working directory
SRC = $(wildcard $(MS_DIR)/*.$(MEXT))
BASE = $(basename $(SRC))
ifeq ($(MS_DIR), .)
MS_DIR_FOR_TEX =
else
MS_DIR_FOR_TEX = "$(MS_DIR)/"
endif
# Targets
PDF=$(SRC:.md=.pdf)
HTML=$(SRC:.md=.html)
TEX=$(SRC:.md=.tex)
ODT=$(SRC:.md=.odt)
DOCX=$(SRC:.md=.docx)
MS_ODT=$(SRC:.md=-manuscript.odt)
MS_DOCX=$(SRC:.md=-manuscript.docx)
BIB=$(SRC:.md=.bib)
all: clean $(PDF) $(HTML) $(ODT) $(DOCX) $(MS_ODT) $(MS_DOCX) $(TEX) $(BIB)
pdf: clean $(PDF)
html: clean $(HTML)
odt: clean $(ODT)
docx: clean $(DOCX)
ms: clean $(MS_ODT)
msdocx: clean $(MS_DOCX)
tex: clean $(TEX)
bib: $(BIB)
%.html: %.md
@echo "$(WARN_COLOR)Converting Markdown to HTML using standard template...$(NO_COLOR)"
replace_includes $< | replace_pdfs $(PNG_CONVERT) | \
pandoc -r markdown+autolink_bare_uris+ascii_identifiers+smart -s -w html \
$(CROSSREF) \
--default-image-extension=png \
--mathjax \
--template=$(PREFIX)/templates/html.template \
--css=$(PREFIX)/styles/ath-clean/ath-clean.css \
--filter pandoc-citeproc \
--csl=$(PREFIX)/csl/$(CSL).csl \
--bibliography=$(BIB_FILE) \
-o $@
@echo "$(OK_COLOR)All done!$(NO_COLOR)"
%.pdf: %.md
@echo "$(WARN_COLOR)Converting Markdown to PDF using hikma-article template...$(NO_COLOR)"
replace_includes $< | replace_reference_title | \
pandoc -r markdown+smart -w latex -s \
$(CROSSREF) \
--default-image-extension=pdf \
--pdf-engine=xelatex \
--template=$(PREFIX)/templates/xelatex.template \
--filter pandoc-citeproc \
--csl=$(PREFIX)/csl/$(CSL).csl \
--bibliography=$(BIB_FILE) \
-V chapterstyle=hikma-article \
-V pagestyle=ath \
--base-header-level=1 \
-o $@
@echo "$(OK_COLOR)All done!$(NO_COLOR)"
%.tex: %.md
@echo "$(WARN_COLOR)Converting Markdown to TeX using hikma-article template...$(NO_COLOR)"
replace_includes $< | \
pandoc -r markdown+smart+raw_tex -w latex -s \
$(CROSSREF) \
--default-image-extension=pdf \
--pdf-engine=xelatex \
--template=$(PREFIX)/templates/xelatex.template \
--biblatex \
-V $(TEX_REF) \
--bibliography=$(BIB_FILE) \
-V chapterstyle=hikma-article \
-V pagestyle=ath \
--base-header-level=1 \
-o $@
@echo "$(WARN_COLOR)...converting TeX to PDF with latexmk (prepare for lots of output)...$(NO_COLOR)"
latexmk -outdir=$(MS_DIR_FOR_TEX)$(TEX_DIR) -xelatex -quiet $@
@echo "$(OK_COLOR)All done!$(NO_COLOR)"
%.odt: %.md
@echo "$(WARN_COLOR)Converting Markdown to .odt using standard template...$(NO_COLOR)"
replace_includes $< | replace_pdfs $(PNG_CONVERT) | \
pandoc -r markdown+smart -w odt \
$(CROSSREF) \
--default-image-extension=png \
--template=$(PREFIX)/templates/odt.template \
--reference-doc=$(PREFIX)/styles/reference.odt \
--filter pandoc-citeproc \
--csl=$(PREFIX)/csl/$(CSL).csl \
--bibliography=$(BIB_FILE) \
-o $@;
@echo "$(OK_COLOR)All done!$(NO_COLOR)"
%.docx: %.odt
@echo "$(WARN_COLOR)Converting .odt to .docx...$(NO_COLOR)"
/Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to docx --outdir $(MS_DIR) $<
@echo "$(WARN_COLOR)Removing .odt file...$(NO_COLOR)"
rm $<
@echo "$(OK_COLOR)All done!$(NO_COLOR)"
%-manuscript.odt: %.md
@echo "$(WARN_COLOR)Converting Markdown to .odt using manuscript template...$(NO_COLOR)"
replace_includes $< | replace_pdfs $(PNG_CONVERT) | move_figs_tables_to_end | \
pandoc -r markdown+smart -w odt \
$(CROSSREF) \
--default-image-extension=png \
--template=$(PREFIX)/templates/odt-manuscript.template \
--reference-doc=$(PREFIX)/styles/reference-manuscript.odt \
--filter pandoc-citeproc \
--csl=$(PREFIX)/csl/$(CSL).csl \
--bibliography=$(BIB_FILE) \
-o $@
%.bib: %.md
@echo "$(WARN_COLOR)Extracing all citations into a standalone .bib file...$(NO_COLOR)"
bib_extract --bibtex_file $(BIB_FILE) $< $@
clean:
@echo "$(WARN_COLOR)Deleting all existing targets...$(NO_COLOR)"
rm -f $(addsuffix .html, $(BASE)) $(addsuffix .pdf, $(BASE)) \
$(addsuffix .odt, $(BASE)) $(addsuffix .docx, $(BASE)) \
$(addsuffix -manuscript.odt, $(BASE)) $(addsuffix -manuscript.docx, $(BASE)) \
$(addsuffix .tex, $(BASE)) $(addsuffix .bib, $(BASE))