forked from petrelharp/r-markdown-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
87 lines (66 loc) · 3.08 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
SHELL := /bin/bash
# use bash for <( ) syntax
.PHONY : all publish
all : using-rmarkdown.slides.html using-rmarkdown.html Readme.html technical-notes.html
# change this to the location of your local MathJax.js library
LOCAL_MATHJAX = /usr/share/javascript/mathjax/MathJax.js
ifeq ($(wildcard $(LOCAL_MATHJAX)),)
MATHJAX = https://cdn.mathjax.org/mathjax/latest/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
# optionally add in a latex file with macros
MACROS_FILE = macros.tex
ifeq ($(wildcard $(MACROS_FILE)),)
# macros file isn't there
else
PANDOC_OPTS += -H <(echo '\['; cat $(MACROS_FILE); echo '\]')
endif
# 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("$@"))'
%.html : %.md
pandoc -o $@ $(PANDOC_OPTS) $<
%.md : %.Rmd
cd $$(dirname $<); Rscript -e 'knitr::knit_patterns[["set"]]($(KNITR_PATTERNS)); knitr::knit(basename("$<"),output=basename("$@"))'
using-rmarkdown.html : using-rmarkdown.Rmd
cd $$(dirname $<); Rscript -e 'knitr::knit_patterns[["set"]]($(KNITR_PATTERNS)); knitr::knit(basename("$<"),output=basename("$@"))'
## VARIOUS SLIDE METHODS
REVEALJS_OPTS = -t revealjs -V theme=simple -V slideNumber=true -V transition=none -H resources/adjust-revealjs.style
SLIDY_OPTS = -t slidy
S5_OPTS = -t s5
SLIDES_OPTS = $(REVEALJS_OPTS)
%.slides.html : %.md
pandoc -o $@ $(SLIDES_OPTS) $(PANDOC_OPTS) $<
%.revealjs.html : %.md
pandoc -o $@ $(REVEALJS_OPTS) $(PANDOC_OPTS) $<
%.slidy.html : %.md
pandoc -o $@ $(SLIDY_OPTS) $(PANDOC_OPTS) $<
%.s5.html : %.md
pandoc -o $@ $(S5_OPTS) $(PANDOC_OPTS) $<
### VARIOUS METHODS USING R
%.rmarkdown.html : %.md
### rmarkdown::render()
cd $$(dirname $<); Rscript -e 'rmarkdown::render(basename("$<"),output_file=basename("$@"))'
%.markdown.html : %.md
### markdown::markdownToHTML()
cd $$(dirname $<); Rscript -e 'markdown::markdownToHTML(basename("$<"),output=basename("$@"))'
%.knitr.html : %.md
### knitr::knit2html()
cd $$(dirname $<); Rscript -e 'knitr::knit2html(basename("$<"),output=basename("$@"))'
%.pander.html : %.md
### pander::Pandoc.convert()
# note that pander silently modifies input markdown file
# AND doesn't provide a way to set the output file
# so this WON'T work with files with images in
cd $$(dirname $<) && \
TEMPFILE="$(addprefix _pander_,$(<F))" && \
cp $(<F) $$TEMPFILE && \
Rscript -e 'f.out <- pander::Pandoc.convert(f="'$${TEMPFILE}'",open=FALSE); file.copy(f.out,basename("$@")); unlink(f.out); cat("$@","\n")' && \
rm $$TEMPFILE