-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild.lua
167 lines (149 loc) · 5.26 KB
/
build.lua
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env texlua
module = "latex-talk"
docfiledir = "."
typesetfiles = {"latex-talk.tex"}
typesetopts = "-interaction=nonstopmode -shell-escape"
-- Package for Overleaf
sourcedir = "."
sourcefiles = {"*.sty","vi/","contrib/","support/"}
-- Select the typesetting engine for different platforms.
if os.type == "windows" then
typesetexe = "pdflatex"
etypesetexe = "etex"
else
typesetexe = "xelatex"
etypesetexe = "xetex"
end
supportdir = "support"
-- Compile on latexmk,
-- for a custom compiling environment typesetdir.
-- And copy the output pdf into outputdir.
function latexmk_typeset(file, typesetdir, outputdir)
local latexmkexe = "latexmk"
local latexmkopt = "-xelatex -interaction=nonstopmode -shell-escape -outdir=. -quiet"
local errorlevel = os.execute("cd " .. typesetdir .. " && "
.. latexmkexe .. " " .. file .. " " .. latexmkopt)
local pdffile = file:gsub("%.tex$", ".pdf")
cp(pdffile, typesetdir, outputdir)
return errorlevel
end
-- typeset all the tex files in dir.
function typesetdirtex(dir)
for _, file in ipairs(filelist(dir, "*.tex")) do
-- if fileexists(dir .. "/" .. file:gsub("%.tex$", ".pdf")) == false then
errorlevel = latexmk_typeset(file, dir, dir)
if errorlevel ~= 0 then
print("! latexmk " .. file .. " failed")
return errorlevel
end
-- end
end
return 0
end
-- typseset_demo_tasks() start after support file copying
-- and before the main document is typeset.
function typeset_demo_tasks()
local errorlevel = 0
-- Refresh dependencies: SJTUBeamer, SJTUThesis, SJTUTeX
local beamerdepdir = "SJTUBeamer"
local thesisdepdir = "SJTUThesis"
local thesisv2depdir = "SJTUTeX"
for _, dir in ipairs({beamerdepdir, thesisdepdir, thesisv2depdir}) do
if direxists(dir) == false then
-- Clone the dependencies first.
errorlevel = os.execute("git clone https://mirror.sjtu.edu.cn/git/" .. dir .. ".git/")
if (errorlevel ~= 0) then
print("! git clone " .. dir .. " failed")
return errorlevel
end
else
-- Update the dependencies from the master branch
-- and reset to the current state forcely.
os.execute("cd " .. dir ..
" && git fetch && git reset --hard && git pull")
end
end
-- Required files in SJTUBeamer.
local beamerdepreq = {"*.sty","contrib/","vi/",".vscode/"}
-- Move the required dependencies to the current folder
-- for compatibility with overleaf version.
-- and to the doc build directory for l3build typesetting.
for _, file in pairs(beamerdepreq) do
cp(file, beamerdepdir, docfiledir)
cp(file, beamerdepdir, typesetdir)
end
-- Remember, although previous "git pull"
-- refreshed the tex file to default state,
-- here we move the unchanged support files
-- to the dependency directory again
-- to overwrite the default files.
local suppthesisdir = supportdir .. "/thesis"
cp("*", suppthesisdir, thesisdepdir)
-- Compile the SJTUThesis first.
for _, file in ipairs(filelist(suppthesisdir, "*.tex")) do
errorlevel = latexmk_typeset(file, thesisdepdir, suppthesisdir)
if errorlevel ~= 0 then
print("! latexmk " .. file .. " failed")
return errorlevel
end
end
-- Compile the SJTUTeX.
-- Generate the samples.
os.execute("cd " .. thesisv2depdir)
os.execute(
"cd " .. thesisv2depdir .. "/sjtutex"
.. " && " .. "l3build doc")
local suppbeamerdir = supportdir .. "/beamer"
cp("*", suppbeamerdir, beamerdepdir)
for _, file in ipairs(filelist(suppbeamerdir, "*.tex")) do
errorlevel = latexmk_typeset(file, beamerdepdir, suppbeamerdir)
if errorlevel ~= 0 then
print("! latexmk " .. file .. " failed")
return errorlevel
end
end
-- typeset auxiliary pdfs and cache them.
local auxdirs = {
supportdir .. "/examples",
supportdir .. "/figures",
supportdir .. "/pgfplots"
}
for _, dir in ipairs(auxdirs) do
errorlevel = typesetdirtex(dir)
if errorlevel ~= 0 then
return errorlevel
end
end
-- clean up the auxiliary files.
cleandirs = {
supportdir .. "/contents",
supportdir .. "/examples",
supportdir .. "/figures",
supportdir .. "/thesis",
supportdir .. "/pgfplots",
supportdir .. "/beamer",
}
cleansuffixs = {
".aux",
".fdb_latexmk",
".fls",
".log",
".synctex.gz",
".nav",
".snm",
".toc",
".out",
".xdv",
".vrb"
}
for _, dir in ipairs(cleandirs) do
for _, suffix in ipairs(cleansuffixs) do
rm(dir, "*" .. suffix)
end
end
-- Rerun the support file copying,
-- because the typesetsuppfiles is set to none
-- in the first place and doesn't trigger the process.
cp(supportdir, ".", typesetdir)
return errorlevel
end