forked from kisonecat/web2js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinitex.js
executable file
·45 lines (34 loc) · 1.38 KB
/
initex.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
#!/usr/bin/env node
const fs = require('fs');
const library = require('./library');
const { pages } = require('./commonMemory');
const binary = fs.readFileSync('tex.wasm');
const code = new WebAssembly.Module(binary);
const initexMemory = new WebAssembly.Memory({ initial: pages, maximum: pages });
library.setMemory(initexMemory.buffer);
library.setInput('\n*latex.ltx\n\\dump\n\n', () => {});
let wasm = new WebAssembly.Instance(code, { library, env: { memory: initexMemory } });
library.setWasmExports(wasm.exports);
wasm.exports.main();
const memory = new WebAssembly.Memory({ initial: pages, maximum: pages });
library.setMemory(memory.buffer);
library.setInput(
'\n&latex\n' +
'\\documentclass[margin=0pt]{standalone}\n' +
'\\def\\pgfsysdriver{pgfsys-ximera.def}\n' +
'\\usepackage[svgnames]{xcolor}\n' +
'\\usepackage{tikz}\n\n' +
'\\DeclareGraphicsExtensions{}\n',
() => {
library.tex_final_end();
const buffer = new Uint8Array(memory.buffer);
fs.writeFileSync('core.dump', buffer);
// Save the files used to a json file.
let filesystem = library.getUsedFiles();
fs.writeFileSync('initex-files.json', JSON.stringify(filesystem, null, '\t'));
process.exit();
}
);
wasm = new WebAssembly.Instance(code, { library, env: { memory } });
library.setWasmExports(wasm.exports);
wasm.exports.main();