File:
[LON-CAPA] /
loncom /
interface /
printout.pl
Revision
1.22:
download - view:
text,
annotated -
select for diffs
Wed Mar 5 16:28:04 2003 UTC (21 years, 4 months ago) by
sakharuk
Branches:
MAIN
CVS tags:
HEAD
Exact (or more correctly almost exact) "pointer" to the problem where LaTeX error was occured is shows up on the screen. Added one more LaTeX error indication (one of the most frequent errors).
1: #!/usr/bin/perl
2: use IO::File;
3: use Image::Magick;
4: print "Content-type: text/html\n\n";
5: print "<body bgcolor=\"#FFFFFF\">\n";
6: my ($texfile,$laystyle,$numberofcolumns,$selectionmade) = split(/&/,$ENV{'QUERY_STRING'});
7: my $figfile = $texfile;
8: $figfile =~ s/^([^\.]+printout)[^t]+\.tex/$1\.dat/;
9: my $duefile = $texfile;
10: $duefile =~ s/^([^\.]+printout)[^t]+\.tex/$1\.due/;
11: #do we have figures?
12: if (-e $figfile) {
13: my $temporary_file=IO::File->new($figfile) || die "Couldn't open file for reading: $!\n";
14: my @content_of_file = <$temporary_file>;
15: close $temporary_file;
16: my $noteps;
17: foreach $not_eps (@content_of_file) {
18: if ($not_eps ne '') {
19: my $eps_f = $not_eps;
20: $eps_f =~ s/\.[^.]*$/\.eps/i;
21: $_ = $eps_f;
22: m/\/([^\/]+)$/;
23: $eps_f = '/home/httpd/prtspool/'.$1;
24: my $image = Image::Magick->new;
25: $not_eps =~ s/^\s+//;
26: $not_eps =~ s/\s+$//;
27: $status = $image->Read($not_eps);
28: if ($status) {print " $status ";}
29: $image->Set(page => '+100+200');
30: $status = $image->Write($eps_f);
31: if ($status) {print " $status ";}
32: #check is eps exist in prtspool
33: if(not -e $eps_f) {
34: for (my $i=0;$i<10000;$i++) {
35: if (-e $eps_f.'.'.$i) {
36: rename $eps_f.'.'.$i, $eps_f;
37: last;
38: }
39: }
40: }
41: }
42: }
43: unlink $figfile;
44: }
45: #print "$texfile\n"; #name of the tex file for debugging only
46: $texfile =~ m/^(.*)\/([^\/]+)$/;
47: my $name_file = $2;
48: my $path_file = $1.'/';
49: chdir $path_file;
50: system("latex $name_file 1>/dev/null 2>/dev/null");
51: #Do we have a latex error in the log file?
52: my $logfilename = $texfile;
53: $logfilename =~ s/\.tex$/\.log/;
54: my $temporary_file=IO::File->new($logfilename) || die "Couldn't open file for reading: $!\n";
55: my @content_of_file = <$temporary_file>;
56: close $temporary_file;
57: my $body_log_file = join(' ',@content_of_file);
58: if ($body_log_file=~m/!\s+Emergency stop/) {
59: #LaTeX failed to parse tex file
60: print "<h2>LaTeX could not successfully parse your tex file.</h2>";
61: print "It probably has errors in it.<br />";
62: my $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART';
63: my $whereitends = rindex $body_log_file,'STAMPOFPASSEDRESOURCEEND';
64: if ($whereitbegins!=-1 and $whereitends!=-1) {
65: print "With very high probability this error occured in ".substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26)."<br /><br />";
66: }
67: print "Here are the error messages in the LaTeX log file</br><br />";
68: my $sygnal = 0;
69: for (my $i=0;$i<=$#content_of_file;$i++) {
70: if ($content_of_file[$i]=~m/^Runaway argument?/ or $content_of_file[$i]=~m/^!/) {
71: $sygnal = 1;
72: }
73: if ($content_of_file[$i]=~m/Here is how much of/) {
74: $sygnal = 0;
75: }
76: if ($sygnal) {
77: print "$content_of_file[$i]<br />";
78: }
79: }
80: } else {
81: #LaTeX successfully parsed tex file
82: $name_file =~ s/\.tex/\.dvi/;
83: my $new_name_file = $name_file;
84: $new_name_file =~ s/\.dvi/\.ps/;
85: my $comma = "dvips -o $new_name_file";
86: system("$comma $name_file");
87: if (-e $new_name_file) {
88: print "<h1>OUTPUT is in the PDF FILE (see link below)</h1>\n";
89: $new_name_file =~ m/^(.*)\./;
90: my $tempo_file = $1.'temporar.ps';
91: my $name_file = $1.'.pdf';
92: if ($laystyle eq 'album' and $numberofcolumns eq '2') {
93: $comma = "psnup -2 -s1.0 $new_name_file";
94: system("$comma $tempo_file");
95: system("ps2pdf $tempo_file $name_file");
96: } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
97: $comma = 'pstops -pletter "2:0+1(0.48w,0)"';
98: system("$comma $new_name_file $tempo_file");
99: system("ps2pdf $tempo_file $name_file");
100: } else {
101: system("ps2pdf $new_name_file $name_file");
102: }
103: my $texlog = $texfile;
104: my $texaux = $texfile;
105: my $texdvi = $texfile;
106: my $texps = $texfile;
107: $texlog =~ s/\.tex/\.log/;
108: $texaux =~ s/\.tex/\.aux/;
109: $texdvi =~ s/\.tex/\.dvi/;
110: $texps =~ s/\.tex/\.ps/;
111: my @garb = ($texlog,$texaux,$texdvi,$texps);
112: # unlink @garb;
113: unlink $duefile;
114: print "<a href=\"/prtspool/$name_file\">Your PDF document</a>";
115: print "\n";
116: }
117: }
118:
119:
120:
121:
122:
123:
124:
125:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>