forked from ntu-student-congress/tortue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen.js
63 lines (58 loc) · 1.94 KB
/
gen.js
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
var fs = require('fs');
var generator = require('./generator');
var templates = {
front: fs.readFileSync('front.tex', 'utf-8'),
cover: fs.readFileSync('cover.tex', 'utf-8'),
back: fs.readFileSync('back.tex', 'utf-8'),
cleardoublepage: "\\cleardoublepage "
};
var params = {};
if(process.argv[process.argv.length - 1] == '1') {
params.combined = 1;
}
if(process.argv[process.argv.length - 2] == '-v') {
params.print = 1;
}
fs.readdir("laws", function(err, law_cats) {
if(!params.combined && !fs.existsSync("laws_tex")) {
fs.mkdirSync("laws_tex");
}
var cats_latex = law_cats.map(function(law_cat) {
var stat = fs.statSync("laws/" + law_cat);
if(!stat || !stat.isDirectory()) return;
if(!params.combined && !fs.existsSync("laws_tex/" + law_cat)) {
fs.mkdirSync("laws_tex/" + law_cat);
}
var cat_latex = templates.cleardoublepage + '\\vspace*{\\fill}\\begin{center} \\fontsize{80pt}{100pt} \\fontheiti ' + law_cat.split('_')[1] + '\\end{center}\\vspace*{\\fill}\n';
var laws_fn = fs.readdirSync("laws/" + law_cat);
var laws = [];
laws_fn.forEach(function(law_in_cat) {
laws.push(law_cat + "/" + law_in_cat);
});
var laws_latex = laws.map(function(law_fn) {
if(!params.combined) {
fs.writeFileSync("laws_tex/" + law_fn.split('.')[0] + ".tex", [templates.front, "\\begin{document}", "\\pagestyle{empty}", generator(law_fn), "\\end{document}"].join("\n"));
} else {
return [templates.cleardoublepage, generator(law_fn)].join("");
}
});
if(!params.combined) {
return;
} else {
cat_latex += laws_latex.join("\n");
return cat_latex;
}
});
if(!params.combined) {
return 0;
}
var latex_final = templates.front;
latex_final += templates.cover;
latex_final += cats_latex.join("\n\n");
latex_final += templates.back;
if(!params.print) {
fs.writeFileSync('final.tex', latex_final);
} else {
console.log(latex_final);
}
});