1 # Put this Makefile in your project directory---i.e., the directory containing
2 # the paper you are writing. You can use it to create .html, .docx, and .pdf
3 # output files (complete with bibliography, if present) from your Markdown
7 # * Change the paths at the top of the file as needed.
9 # * Using `make` without arguments will generate html, tex, pdf, docx,
10 # and odt output files from all of the files with the designated
11 # markdown extension. The default is `.md` but you can change this.
13 # * You can specify an output format with `make tex`, `make pdf`,
14 # `make html`, `make odt`, or `make docx`
16 # * Running `make clean` will only remove all, .html, .pdf, .odt,
17 # and .docx files in your working directory **that have the same name
18 # as your Markdown files**. Other files with these extensions will be safe.
20 # * If wanted, remove the automatic call to `clean` to rely on make's
21 # timestamp checking. However, if you do this, you'll need to add all the
22 # document's images, etc. as dependencies, which means it might be easier
23 # to just clean and delete everything every time you rebuild.
26 # ----------------------
27 # Modifiable variables
28 # ----------------------
29 # Markdown extension (e.g. md, markdown, mdown).
32 # Optional folder for manuscript
35 # Location of Pandoc support files.
36 PREFIX = /Users/andrew/.pandoc
38 # Word and HTML can choke on PDF images, so those targets use a helper script
39 # named replace_pdfs to replace all references to PDFs with PNGs and convert
40 # existing PDFs to PNG using sips. However, there are times when it's better to
41 # *not* convert to PNG on the fly, like when using high resolution PNGs exprted
42 # from R with ggsave+Cairo. To disable on-the-fly conversion and supply your
43 # own PNGs, uncomment PNG_CONVERT below. The script will still replace
44 # references to PDFs with PNGs, but will not convert the PDFs
45 # PNG_CONVERT = --no-convert
48 # Location of your working bibliography file
49 BIB_FILE = /Users/andrew/Dropbox/Readings/Papers.bib
51 # CSL stylesheet (located in the csl folder of the PREFIX directory).
53 # * american-political-science-association
54 # * chicago-fullnote-bibliography
55 # * chicago-fullnote-no-bib
56 # * chicago-syllabus-no-bib
59 CSL = american-political-science-association
61 # LaTeX doesn't use pandoc-citeproc + CSL and instead lets biblatex handle the
62 # heavy lifting. There are three possible styles built in to the template:
63 # * bibstyle-chicago-notes
64 # * bibstyle-chicago-authordate
66 TEX_REF = bibstyle-chicago-authordate
69 # Cross reference options
70 CROSSREF = --filter pandoc-crossref -M figPrefix:"Figure" -M eqnPrefix:"Equation" -M tblPrefix:"Table"
72 # To add version control footer support in PDFs:
73 # 1. Run vcinit in the directory
74 # 2. Place `./vc` at the front of the formula
75 # 3. Add `-V vc` to the pandoc command
76 # 4. Change pagestyle to athgit instead of ath
83 BOLD_COLOR = \x1b[37;01m
84 OK_COLOR = \x1b[32;01m
85 WARN_COLOR = \x1b[33;01m
86 ERROR_COLOR = \x1b[31;01m
89 # --------------------
91 # --------------------
92 # All markdown files in the working directory
93 SRC = $(wildcard $(MS_DIR)/*.$(MEXT))
94 BASE = $(basename $(SRC))
99 MS_DIR_FOR_TEX = "$(MS_DIR)/"
104 HTML=$(SRC:.md=.html)
107 DOCX=$(SRC:.md=.docx)
108 MS_ODT=$(SRC:.md=-manuscript.odt)
109 MS_DOCX=$(SRC:.md=-manuscript.docx)
112 all: clean $(PDF) $(HTML) $(ODT) $(DOCX) $(MS_ODT) $(MS_DOCX) $(TEX) $(BIB)
119 msdocx: clean $(MS_DOCX)
124 @echo "$(WARN_COLOR)Converting Markdown to HTML using standard template...$(NO_COLOR)"
125 replace_includes $< | replace_pdfs $(PNG_CONVERT) | \
126 pandoc -r markdown+simple_tables+table_captions+yaml_metadata_block -w html -S \
128 --default-image-extension=png \
129 --template=$(PREFIX)/templates/html.template \
130 --css=$(PREFIX)/styles/marked/kultiad-serif.css \
131 --filter pandoc-citeproc \
132 --csl=$(PREFIX)/csl/$(CSL).csl \
133 --bibliography=$(BIB_FILE) \
135 @echo "$(OK_COLOR)All done!$(NO_COLOR)"
138 @echo "$(WARN_COLOR)Converting Markdown to PDF using hikma-article template...$(NO_COLOR)"
139 replace_includes $< | replace_reference_title | \
140 pandoc -r markdown+simple_tables+table_captions+yaml_metadata_block -w latex -s -S \
142 --default-image-extension=pdf \
143 --latex-engine=xelatex \
144 --template=$(PREFIX)/templates/xelatex.template \
145 --filter pandoc-citeproc \
146 --csl=$(PREFIX)/csl/$(CSL).csl \
147 --bibliography=$(BIB_FILE) \
148 -V chapterstyle=hikma-article \
150 --base-header-level=2 \
152 @echo "$(OK_COLOR)All done!$(NO_COLOR)"
155 @echo "$(WARN_COLOR)Converting Markdown to TeX using hikma-article template...$(NO_COLOR)"
156 replace_includes $< | \
157 pandoc -r markdown+simple_tables+table_captions+yaml_metadata_block -w latex -s -S \
159 --default-image-extension=pdf \
160 --latex-engine=xelatex \
161 --template=$(PREFIX)/templates/xelatex.template \
164 --bibliography=$(BIB_FILE) \
165 -V chapterstyle=hikma-article \
167 --base-header-level=2 \
169 @echo "$(WARN_COLOR)...converting TeX to PDF with latexmk (prepare for lots of output)...$(NO_COLOR)"
170 latexmk -outdir=$(MS_DIR_FOR_TEX)$(TEX_DIR) -xelatex -quiet $@
171 @echo "$(OK_COLOR)All done!$(NO_COLOR)"
174 @echo "$(WARN_COLOR)Converting Markdown to .odt using standard template...$(NO_COLOR)"
175 replace_includes $< | replace_pdfs $(PNG_CONVERT) | \
176 pandoc -r markdown+simple_tables+table_captions+yaml_metadata_block -w odt -S \
178 --default-image-extension=png \
179 --template=$(PREFIX)/templates/odt.template \
180 --reference-odt=$(PREFIX)/styles/reference.odt \
181 --filter pandoc-citeproc \
182 --csl=$(PREFIX)/csl/$(CSL).csl \
183 --bibliography=$(BIB_FILE) \
185 @echo "$(OK_COLOR)All done!$(NO_COLOR)"
188 @echo "$(WARN_COLOR)Converting .odt to .docx...$(NO_COLOR)"
189 /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to docx --outdir $(MS_DIR) $<
190 @echo "$(WARN_COLOR)Removing .odt file...$(NO_COLOR)"
192 @echo "$(OK_COLOR)All done!$(NO_COLOR)"
194 %-manuscript.odt: %.md
195 @echo "$(WARN_COLOR)Converting Markdown to .odt using manuscript template...$(NO_COLOR)"
196 replace_includes $< | replace_pdfs $(PNG_CONVERT) | move_figs_tables_to_end | \
197 pandoc -r markdown+simple_tables+table_captions+yaml_metadata_block -w odt -S \
199 --default-image-extension=png \
200 --template=$(PREFIX)/templates/odt-manuscript.template \
201 --reference-odt=$(PREFIX)/styles/reference-manuscript.odt \
202 --filter pandoc-citeproc \
203 --csl=$(PREFIX)/csl/$(CSL).csl \
204 --bibliography=$(BIB_FILE) \
208 @echo "$(WARN_COLOR)Extracing all citations into a standalone .bib file...$(NO_COLOR)"
209 bib_extract --bibtex_file $(BIB_FILE) $< $@
212 @echo "$(WARN_COLOR)Deleting all existing targets...$(NO_COLOR)"
213 rm -f $(addsuffix .html, $(BASE)) $(addsuffix .pdf, $(BASE)) \
214 $(addsuffix .odt, $(BASE)) $(addsuffix .docx, $(BASE)) \
215 $(addsuffix -manuscript.odt, $(BASE)) $(addsuffix -manuscript.docx, $(BASE)) \
216 $(addsuffix .tex, $(BASE)) $(addsuffix .bib, $(BASE))