~ubuntu-branches/ubuntu/wily/steam/wily

« back to all changes in this revision

Viewing changes to services/tex.pike

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2013-10-29 19:51:18 UTC
  • mfrom: (1.1.4) (0.1.4 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131029195118-b9bxciz5hwx5z459
Tags: 1:1.0.0.39-2ubuntu1
Add an epoch to the version number as there was an unrelated steam package
in the archive with a higher version number.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
inherit Service.Service;
2
 
 
3
 
void call_service(object user, mixed args, int|void id)
4
 
{
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";
6
 
 
7
 
    string formula = args->formula;
8
 
    if ( stringp(formula) ) {
9
 
        texcode += "$" + String.trim_all_whites(formula) + "$\n";
10
 
    }
11
 
    texcode += "\\end{document}\n";
12
 
    
13
 
    // run tex
14
 
    rm("in.dvi");
15
 
    werror("running process tex...\n");
16
 
    Stdio.File texfile = Stdio.File("in.tex", "wct");
17
 
    texfile->write(texcode);
18
 
    texfile->close();
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();
30
 
    psFile->close();
31
 
    Process.create_process( convArr, ([ "env": getenv(), "cwd": getcwd(), 
32
 
                                       "stdout":errFile, "stderr": errFile, ]) )->wait();
33
 
    errFile->close();
34
 
    rm("in.tex");
35
 
    rm("in.log");
36
 
    rm("in.ps");
37
 
    rm("in.dvi");
38
 
    string res;
39
 
    res = Stdio.read_file("formula.png");
40
 
    async_result(id, res);
41
 
}
42
 
 
43
 
static void run() {
44
 
}
45
 
 
46
 
static private void got_kill(int sig) {
47
 
        _exit(1);
48
 
}
49
 
 
50
 
int main(int argc, array argv)
51
 
{
52
 
        signal(signum("QUIT"), got_kill);
53
 
        init( "tex", argv );
54
 
        start();
55
 
        return -17;
56
 
}
57