1
inherit Service.Service;
3
void call_service(object user, mixed args, int|void id)
5
string texcode ="\\documentclass[10pt]{article}\n\\pagestyle{empty}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{pst-plot}\n\\usepackage{color}\n\\usepackage{pstricks}\n\\parindent=0pt\n\\begin{document}\n";
7
string formula = args->formula;
8
if ( stringp(formula) ) {
9
texcode += "$" + String.trim_all_whites(formula) + "$\n";
11
texcode += "\\end{document}\n";
15
werror("running process tex...\n");
16
Stdio.File texfile = Stdio.File("in.tex", "wct");
17
texfile->write(texcode);
19
array runArr = ({ "latex", "-interaction=nonstopmode", "in.tex" });
20
array psArr = ({ "dvips", "-R", "-E", "in.dvi", "-f" });
21
array convArr = ({ "convert", "-quality", "100", "-density","120", "in.ps", "formula.png" });
22
object errFile = Stdio.File("in.log", "wct");
23
Stdio.File ipc = Stdio.File();
24
werror(texcode + "\n");
25
Process.create_process( runArr, ([ "env": getenv(), "cwd": getcwd(),
26
"stdout": errFile, "stderr": errFile, ]) )->wait();
27
Stdio.File psFile = Stdio.File("in.ps", "wct");
28
Process.create_process( psArr, ([ "env": getenv(), "cwd": getcwd(),
29
"stdout": psFile, "stderr": errFile, ]) )->wait();
31
Process.create_process( convArr, ([ "env": getenv(), "cwd": getcwd(),
32
"stdout":errFile, "stderr": errFile, ]) )->wait();
39
res = Stdio.read_file("formula.png");
40
async_result(id, res);
46
static private void got_kill(int sig) {
50
int main(int argc, array argv)
52
signal(signum("QUIT"), got_kill);