forked from kisonecat/web2js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenTikzLibJSON.js
executable file
·37 lines (32 loc) · 1.43 KB
/
genTikzLibJSON.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
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const spawnSync = require('child_process').spawnSync;
const basePath = '/usr/share/texlive/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries';
fs.mkdirSync('tikz_libs', { recursive: true });
const processDir = (dir) => {
for (let file of fs.readdirSync(dir, { withFileTypes: true })) {
if (file.isDirectory()) {
processDir(path.resolve(basePath, file.name));
} else if (file.name.match(/^tikzlibrary.*\.code\.tex$/)) {
let tikzLibName = file.name.replace(/^tikzlibrary(.*)\.code\.tex$/, '$1');
console.log(`Processing ${tikzLibName}`);
let texFile = `tikz_libs/${tikzLibName}.tex`;
if (!fs.existsSync(texFile)) {
console.log(`Creating ${texFile}`);
fs.writeFileSync(
texFile,
//'\\documentclass[margin=0pt]{standalone}\n\\usepackage{tikz}\n' +
`\\usetikzlibrary{${tikzLibName}}\n\\begin{document}\n\\end{document}\n`
);
}
console.log(`Running TeX on ${texFile}`);
fs.writeFileSync(
`tikz_libs/${tikzLibName}.output.log`,
spawnSync('node', ['tex.js', texFile, 'y']).stdout.toString()
);
console.log(`TeX output saved to tikz_libs/${tikzLibName}.output.log`);
}
}
};
processDir(basePath);