-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMakefile
106 lines (78 loc) · 3.42 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
SHELL := /bin/bash
# use bash for <( ) syntax
.PHONY : publish upload all slides hws
all : README.html syllabus.html schedule.html slides hws
slides :
$(MAKE) -C slides
hws :
$(MAKE) -C hws
# change this to the location of your local MathJax.js library
LOCAL_MATHJAX = /dont/use/local/mathjax/for/webpages
ifeq ($(wildcard $(LOCAL_MATHJAX)),)
MATHJAX = https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js
else
MATHJAX = $(LOCAL_MATHJAX)
endif
# may want to add "--self-contained" to the following
PANDOC_OPTS = --mathjax=$(MATHJAX)?config=TeX-AMS-MML_HTMLorMML --standalone --self-contained
# optionally add in a latex file with macros
LATEX_MACROS = macros.tex
ifeq ($(wildcard $(LATEX_MACROS)),)
# macros file isn't there
else
PANDOC_OPTS += -H .pandoc.$(LATEX_MACROS)
endif
.pandoc.$(LATEX_MACROS) : $(LATEX_MACROS)
(echo '<div style="display: none">'; echo '\['; cat $(LATEX_MACROS); echo '\]'; echo '</div>') > $@
# knitr by default tries to interpret ANY code chunk; I only want it to do the ones beginning with ```r.
KNITR_PATTERNS = list( chunk.begin="^```+\\s*\\{[.]?(r[a-zA-Z]*.*)\\}\\s*$$", chunk.end="^```+\\s*$$", inline.code="`r +([^`]+)\\s*`")
# or, uncomment for OSX:
# KNITR_PATTERNS = list( chunk.begin="^```+\\\\s*\\\\{[.]?(r[a-zA-Z]*.*)\\\\}\\\\s*$$", chunk.end="^```+\\\\s*$$", inline.code="`r +([^`]+)\\\\s*`")
%.html : %.Rmd
# cd $$(dirname $<); Rscript -e 'knitr::knit2html(basename("$<"),output=basename("$@"))'
# cd $$(dirname $<); Rscript -e 'rmarkdown::render(basename("$<"),output_file=basename("$@"))'
# Rscript -e 'templater::render_template("$<", output="$@", change.rootdir=TRUE)'
Rscript -e 'knitr::knit_patterns[["set"]]($(KNITR_PATTERNS)); templater::render_template("$<", output="$@", change.rootdir=TRUE, clean=FALSE)'
%.html : %.md .pandoc.$(LATEX_MACROS)
pandoc -o $@ $(PANDOC_OPTS) $<
%.md : %.Rmd
# cd $$(dirname $<); Rscript -e 'knitr::knit_patterns[["set"]]($(KNITR_PATTERNS)); knitr::knit(basename("$<"),output=basename("$@"))'
Rscript -e 'knitr::knit_patterns[["set"]]($(KNITR_PATTERNS)); templater::render_template("$<", output="$@", change.rootdir=TRUE)'
%.pdf : %.md
pandoc -o $@ -t latex $<
## VARIOUS SLIDE METHODS
REVEALJS_OPTS = -t revealjs -V theme=simple -V slideNumber=true -V transition=none -H resources/adjust-revealjs.style --slide-level 2
SLIDES_OPTS = $(REVEALJS_OPTS)
%.slides.html : %.md .pandoc.$(LATEX_MACROS)
pandoc -o $@ $(SLIDES_OPTS) $(PANDOC_OPTS) $<
%.revealjs.html : %.md .pandoc.$(LATEX_MACROS)
pandoc -o $@ $(REVEALJS_OPTS) $(PANDOC_OPTS) $<
# hope their head isn't detached
GITBRANCH := $(shell git symbolic-ref -q --short HEAD)
# upload to github
upload :
git push origin --all
# update the gh-pages branch
publish :
@if ! git diff-index --quiet HEAD --; then echo "Commit changes first."; exit 1; fi
git checkout gh-pages
git merge master
git diff --quiet || git commit -a -m 'automatic update of html'
git checkout $(GITBRANCH)
@echo ""
@echo ""
@echo "Now on branch $$(git rev-parse --abbrev-ref HEAD)"
##
# Graphics whatnot
# save inkscape svg files as .ink.svg and this'll do the right thing
$(DISPLAYDIR)/%.svg : %.ink.svg
inkscape $< --export-plain-svg=$@
$(DISPLAYDIR)/%.pdf : %.ink.svg
inkscape $< --export-pdf=$@
$(DISPLAYDIR)/%.svg : %.pdf
inkscape $< --export-plain-svg=$@
$(DISPLAYDIR)/%.png : %.pdf
convert -density 300 $< -flatten $@
## things without mathjax
syllabus.html : syllabus.md
pandoc -o $@ --standalone --self-contained $<