forked from pandoc-scholar/pandoc-scholar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
133 lines (115 loc) · 5.21 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
## The path to the directory in which this file resides. This allows users to
## include this Makefile into theirs and to reuse all rules, given that they set
## this variable to the correct value.
PANDOC_SCHOLAR_PATH ?= $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
# include local makefile to allow easy overwriting of variables
-include local.mk
include $(PANDOC_SCHOLAR_PATH)/pandoc-options.inc.mk
LUA_FILTERS_PATH ?= $(PANDOC_SCHOLAR_PATH)/lua-filters
PANDOC ?= pandoc
# Configuration (overwrite using Makefile.local.in if necessary)
ARTICLE_FILE ?= example/article.md
OUTFILE_PREFIX ?= outfile
DEFAULT_EXTENSIONS ?= latex pdf docx odt epub html
ADDITIONAL_EXTENSIONS ?= xml jats jsonld txt
JSON_FILE ?= $(OUTFILE_PREFIX).enriched.json
FLATTENED_JSON_FILE ?= $(OUTFILE_PREFIX).flattened.json
LUA_FILTERS ?= $(LUA_FILTERS_PATH)/cito/cito.lua \
$(LUA_FILTERS_PATH)/abstract-to-meta/abstract-to-meta.lua \
$(LUA_FILTERS_PATH)/scholarly-metadata/scholarly-metadata.lua
default: $(addprefix $(OUTFILE_PREFIX).,$(DEFAULT_EXTENSIONS))
all: $(addprefix $(OUTFILE_PREFIX).,$(DEFAULT_EXTENSIONS)) \
$(addprefix $(OUTFILE_PREFIX).,$(ADDITIONAL_EXTENSIONS))
$(JSON_FILE): $(ARTICLE_FILE) $(LUA_FILTERS)
$(PANDOC) $(PANDOC_READER_OPTIONS) \
$(foreach filter, $(LUA_FILTERS), --lua-filter=$(filter)) \
--to=json \
--output=$@ $<
$(OUTFILE_PREFIX).pdf $(OUTFILE_PREFIX).latex: \
$(JSON_FILE) \
$(TEMPLATE_FILE_LATEX) \
$(PANDOC_SCHOLAR_PATH)/scholar-filters/template-helper.lua
$(PANDOC) $(PANDOC_WRITER_OPTIONS) \
$(PANDOC_LATEX_OPTIONS) \
--lua-filter=$(PANDOC_SCHOLAR_PATH)/scholar-filters/template-helper.lua \
--output $@ $<
$(OUTFILE_PREFIX).docx: $(JSON_FILE) \
$(DOCX_REFERENCE_FILE) \
$(LUA_FILTERS_PATH)/author-info-blocks/author-info-blocks.lua
$(PANDOC) $(PANDOC_WRITER_OPTIONS) \
$(PANDOC_DOCX_OPTIONS) \
--lua-filter=$(LUA_FILTERS_PATH)/author-info-blocks/author-info-blocks.lua \
--output $@ $<
$(OUTFILE_PREFIX).odt: $(JSON_FILE) \
$(ODT_REFERENCE_FILE) \
$(LUA_FILTERS_PATH)/author-info-blocks/author-info-blocks.lua
$(PANDOC) $(PANDOC_WRITER_OPTIONS) \
$(PANDOC_ODT_OPTIONS) \
--lua-filter=$(LUA_FILTERS_PATH)/author-info-blocks/author-info-blocks.lua \
--output $@ $<
$(OUTFILE_PREFIX).epub: $(JSON_FILE) \
$(TEMPLATE_FILE_EPUB) \
$(LUA_FILTERS_PATH)/author-info-blocks/author-info-blocks.lua
$(PANDOC) $(PANDOC_WRITER_OPTIONS) \
$(PANDOC_EPUB_OPTIONS) \
--lua-filter=$(LUA_FILTERS_PATH)/author-info-blocks/author-info-blocks.lua \
--output $@ $<
$(OUTFILE_PREFIX).html: $(JSON_FILE) \
$(TEMPLATE_FILE_HTML) \
$(TEMPLATE_STYLE_HTML) \
$(PANDOC_SCHOLAR_PATH)/scholar-filters/template-helper.lua
$(PANDOC) $(PANDOC_WRITER_OPTIONS) \
$(PANDOC_HTML_OPTIONS) \
--lua-filter=$(PANDOC_SCHOLAR_PATH)/scholar-filters/template-helper.lua \
--css=$(TEMPLATE_STYLE_HTML) \
--self-contained \
--mathjax \
--output $@ $<
$(OUTFILE_PREFIX).jsonld: $(JSON_FILE) \
$(BIBLIOGRAPHY_FILE) \
$(PANDOC_SCHOLAR_PATH)/scholar-filters/json-ld.lua \
$(PANDOC_SCHOLAR_PATH)/writers/jsonld.lua
$(PANDOC) --to $(PANDOC_SCHOLAR_PATH)/writers/jsonld.lua \
--lua-filter=$(PANDOC_SCHOLAR_PATH)/scholar-filters/json-ld.lua \
--output=$@ $<
$(OUTFILE_PREFIX).txt: $(ARTICLE_FILE)
$(PANDOC) $(PANDOC_WRITER_OPTIONS) \
--output $@ $<
## Process the original ARTICLE_FILE instead of the pre-processed
## JSON file, as we need full control over bibliography handling
## to get acceptable JATS output. All PANDOC_WRITER_OPTIONS are
## omitted for the same reason.
##
## The JSON file is required only for metadata (csl) extraction
## by the jats-fixes.lua script, as pandoc overrides the CSL
## field when converting to JATS.
$(OUTFILE_PREFIX).jats $(OUTFILE_PREFIX).xml: $(ARTICLE_FILE) \
$(JSON_FILE) \
$(PANDOC_SCHOLAR_PATH)/templates/pandoc-scholar.jats \
$(PANDOC_SCHOLAR_PATH)/scholar-filters/jats-fixes.lua \
$(PANDOC_SCHOLAR_PATH)/scholar-filters/template-helper.lua \
$(PANDOC_SCHOLAR_PATH)/csl/chicago-author-date.csl \
$(PANDOC_SCHOLAR_PATH)/csl/jats.csl
$(PANDOC) \
$(PANDOC_READER_OPTIONS) \
$(PANDOC_JATS_OPTIONS) \
$(foreach filter, $(LUA_FILTERS), --lua-filter=$(filter)) \
--lua-filter=$(PANDOC_SCHOLAR_PATH)/scholar-filters/template-helper.lua \
--lua-filter=$(PANDOC_SCHOLAR_PATH)/scholar-filters/jats-fixes.lua \
--metadata=jats-csl=$(PANDOC_SCHOLAR_PATH)/csl/jats.csl \
--metadata=pandoc-scholar-json=$(JSON_FILE) \
--metadata=csl-path=$(PANDOC_SCHOLAR_PATH)/csl \
--to=jats \
--output $@ $<
clean:
@# Explicitly iterate over known extensions instead of using a wildcard.
@# This lets us avoid to accidentally delete any other files, e.g. if the
@# ARTICLE_FILE happens to begin with OUTFILE_PREFIX.
for ext in $(DEFAULT_EXTENSIONS) $(ADDITIONAL_EXTENSIONS); do\
rm -f $(OUTFILE_PREFIX).$$ext;\
done
rm -f $(JSON_FILE) $(FLATTENED_JSON_FILE)
.PHONY: all clean
# Include archive-generating targets. This makefile is not included in the
# distributed archives
-include archives.inc.mk