tex._pike
Go to the documentation of this file.
1 /*0*/
2 inherit Service.Service;
3 class tex {
4 public:
5 
6 void call_service(object user, mixed args, int|void id)
7 {
8  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";
9 
10  string formula = args->formula;
11  if ( stringp(formula) ) {
12  texcode += "$" + String.trim_all_whites(formula) + "$\n";
13  }
14  texcode += "\\end{document}\n";
15 
16  // run tex
17  rm("in.dvi");
18  werror("running process tex...\n");
19  Stdio.File texfile = Stdio.File("in.tex", "wct");
20  texfile->write(texcode);
21  texfile->close();
22  array runArr = ({ "latex", "-interaction=nonstopmode", "in.tex" });
23  array psArr = ({ "dvips", "-R", "-E", "in.dvi", "-f" });
24  array convArr = ({ "convert", "-quality", "100", "-density","120", "-transparent", "white", "in.ps", "formula.png" });
25  object errFile = Stdio.File("in.log", "wct");
26  Stdio.File ipc = Stdio.File();
27  werror(texcode + "\n");
28  Process.create_process( runArr, ([ "env": getenv(), "cwd": getcwd(),
29  "stdout": errFile, "stderr": errFile, ]) )->wait();
30  Stdio.File psFile = Stdio.File("in.ps", "wct");
31  Process.create_process( psArr, ([ "env": getenv(), "cwd": getcwd(),
32  "stdout": psFile, "stderr": errFile, ]) )->wait();
33  psFile->close();
34  Process.create_process( convArr, ([ "env": getenv(), "cwd": getcwd(),
35  "stdout":errFile, "stderr": errFile, ]) )->wait();
36  errFile->close();
37  rm("in.tex");
38  rm("in.log");
39  rm("in.ps");
40  rm("in.dvi");
41  string res;
42  res = Stdio.read_file("formula.png");
43  async_result(id, res);
44 }
45 
46 protected:
47  void run() {
48 }
49 
50 public:
51 
52 private:
53  private void got_kill(int sig) {
54  _exit(1);
55 }
56 
57 public:
58 
59 int main(int argc, array argv)
60 {
61  signal(signum("QUIT"), got_kill);
62  init( "tex", argv );
63  start();
64  return -17;
65 }
66 
67 
68 
69 };