-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbin.js
More file actions
executable file
·48 lines (43 loc) · 1.75 KB
/
Copy pathbin.js
File metadata and controls
executable file
·48 lines (43 loc) · 1.75 KB
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
#!/usr/bin/env node
const { program } = require('commander');
const latexToImage = require('./index');
const path = require('path');
const fs = require('fs');
program
.version('1.0.0')
.description('Convert text with LaTeX to an image')
.argument('<input>', 'Input text or path to a text file')
.option('-o, --output <path>', 'Output image path', 'output.png')
.option('-s, --font-size <number>', 'Font size', parseInt, 24)
.option('-p, --padding <number>', 'Padding', parseInt, 20)
.option('-w, --width <number>', 'Fixed width in pixels', parseInt)
.option('-b, --background <color>', 'Background color')
.option('-t, --theme <string>', 'Theme (modern, handwritten, chalkboard)', 'modern')
.option('-g, --grounded [level]', 'Export bounding boxes to JSON (char, equation)')
.option('-d, --debug [level]', 'Draw bounding boxes for debugging (char, equation)')
.option('-n, --noise <number>', 'Noise level for artifact synthesis (0.0 to 1.0)', parseFloat, 0)
.action(async (input, options) => {
let text = input;
if (fs.existsSync(input)) {
text = fs.readFileSync(input, 'utf-8');
}
const outputPath = path.resolve(process.cwd(), options.output);
console.log(`Rendering to ${outputPath}...`);
try {
await latexToImage(text, outputPath, {
fontSize: options.fontSize,
padding: options.padding,
backgroundColor: options.background,
width: options.width,
theme: options.theme,
grounded: options.grounded,
debug: options.debug,
noise: options.noise
});
console.log('Done!');
} catch (err) {
console.error('Error:', err.message);
process.exit(1);
}
});
program.parse(process.argv);