-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxhtml-html_latex.make
100 lines (74 loc) · 2.27 KB
/
xhtml-html_latex.make
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
#!/usr/bin/env make
#
# Generate HTML and PDF (via LaTeX) output from XHTML input with some custom
# extensions for bibliography, etc.
#
# Andrew Cashner, 2023/09/25
#
# Generate html: `make html`
# Generate pdf: `make pdf`
# Generate both: `make all` or `make`
# View html: `make view`
# View pdf: `make view-pdf`
# Reset, start fresh: `make clean`
# Requirements
# - Installed and available on path: saxon, biber, latexmk & TeXLive
# - In project directory:
# - BibLaTeX bibliography file or symlink to one, *.bib
# - The stylesheets in this directory (check the xsl_dir path below)
# TODO
# find and copy css
# copy media files
# make xsl_dir configurable
dirs = aux build
xhtml_in = $(wildcard *.xhtml)
xhtml_include = $(wildcard include/*.xhtml)
bib = $(wildcard *.bib)
bibxml = $(addprefix aux/,$(bib:%.bib=%.bltxml))
biber_log = $(bibxml:%.bltxml=%.blg)
tex = $(addprefix aux/,$(xhtml_in:%.xhtml=%.tex))
html_out = $(addprefix build/,$(xhtml_in:%.xhtml=%.html))
pdf_out = $(html_out:%.html=%.pdf)
xsl_dir = $(HOME)/lib/xsl
saxon-html = saxon -xi:on -xsl:$(xsl_dir)/xhtml-html/main.xsl
saxon-latex = saxon -xi:on -xsl:$(xsl_dir)/xhtml-latex/main.xsl
biber-xml = biber --tool --output-format=biblatexml \
--output-resolve-crossrefs --no-bltxml-schema \
--logfile $(biber_log)
# Define variable TEX to change latex engine
# - On command line: `make TEX=xe` or `TEX=lua`
# - For pdflatex, leave blank (`TEX=""` to reset)
# - In Makefile: `TEX=xe; include $(this_makefile)`
latexmk = latexmk -outdir=aux
ifeq ($(TEX),xe)
makelatex = $(latexmk) -pdfxe
else ifeq ($(TEX),lua)
makelatex = $(latexmk) -pdflua
else
makelatex = $(latexmk) -pdf
endif
.PHONY: all html pdf view view-pdf clean
.SECONDARY : $(tex)
all : html pdf
html : $(html_out)
pdf : $(pdf_out)
$(dirs) :
mkdir -p $(dirs)
aux/%.bltxml : %.bib | $(dirs)
$(biber-xml) -O $@ $<
# xhtml -> html
build/%.html : %.xhtml $(xhtml_include) $(bibxml) | $(dirs)
$(saxon-html) -s:$< -o:$@
# xhtml -> latex -> pdf
build/%.pdf : aux/%.pdf
cp -u $< $@
aux/%.pdf : aux/%.tex $(bib)
$(makelatex) $<
aux/%.tex : %.xhtml $(xhtml_include) $(bibxml) | $(dirs)
$(saxon-latex) -s:$< -o:$@
view : $(html_out)
xdg-open $^ &
view-pdf : $(pdf_out)
xdg-open $^ &
clean :
rm -rf $(dirs)