-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.js
47 lines (40 loc) · 2.16 KB
/
utils.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
/*=====================================================================*/
/* serrano/diffusion/talk/pliss23/utils.js */
/* ------------------------------------------------------------- */
/* Author : Manuel Serrano */
/* Creation : Thu May 26 16:19:55 2022 */
/* Last change : Thu Aug 24 08:03:36 2023 (serrano) */
/* Copyright : 2022-23 Manuel Serrano */
/* ------------------------------------------------------------- */
/* Utilities */
/*=====================================================================*/
/*---------------------------------------------------------------------*/
/* Module ... */
/*---------------------------------------------------------------------*/
import * as fs from "fs";
import * as path from "path";
import { system, systemSync } from "hop:system";
export { gnuplot, tikz };
/*---------------------------------------------------------------------*/
/* gnuplot ... */
/*---------------------------------------------------------------------*/
function gnuplot(file) {
const svg = file.replace(/[.]plot$/,".svg");
const dir = path.dirname(file);
if (!fs.existsSync(svg) || fs.statSync(file).ctime > fs.statSync(svg).ctime) {
console.log("Generating", svg, `[(cd ${dir}; gnuplot ${file} > ${svg})]`);
systemSync(`sh -c "(cd ${dir}; gnuplot ${file} > ${svg})"`);
}
return svg;
}
/*---------------------------------------------------------------------*/
/* tikz ... */
/*---------------------------------------------------------------------*/
function tikz(file) {
const svg = file.replace(/[.]tex$/,".svg");
if (!fs.existsSync(svg) || fs.statSync(file).ctime > fs.statSync(svg).ctime) {
console.log("Generating", svg, `[tikz2svg ${file} ${svg}]`);
systemSync(`tikz2svg ${file} ${svg}`);
}
return svg;
}