new($figfile) || die "Couldn't open fig file $figfile for reading: $!\n";
my @content_of_file = <$temporary_file>;
@@ -95,7 +205,9 @@ END
foreach my $not_eps (@content_of_file) {
chomp($not_eps);
if ($not_eps ne '') {
+ # print "Converting $not_eps"; # Debugging.
my $status_statement='EPS picture for '.$not_eps;
+ # print "$status_statement\n";
$not_eps=~s|\/\.\/|\/|g;
my $eps_f = $not_eps;
$eps_f =~ s/\.[^.]*$/\.eps/i;
@@ -109,26 +221,24 @@ END
$eps_f=~/$Apache::lonnet::perlvar{'lonUsersDir'}\/([^\/]+)\/\w\/\w\/\w\/(.+)/;
$eps_f = '/home/httpd/prtspool/'.$1.'/'.$2;
}
+ $eps_f =~ s/ /\_/g; # Spaces are problematic for system commands and LaTeX.
my $path=$eps_f;
- $path=~s/\/([^\/]+)\.eps$//;
+ $path =~ s/\/([^\/]+)\.eps$//;
+ # print "Final file path: $path "; # Debugging
File::Path::mkpath($path,0,0777);
- my $image = Image::Magick->new;
$not_eps =~ s/^\s+//;
$not_eps =~ s/\s+$//;
- if ( exists($done_conversion{$not_eps})) {
- next;
- }
+ $not_eps =~ s/ /\\ /g;
+ if ( exists($done_conversion{$not_eps})) { next; }
if ($adv) {
my $prettyname=$not_eps;
$prettyname=~s|/home/([^/]+)/public_html|/priv/$1|;
$prettyname=~s|$Apache::lonnet::perlvar{'lonDocRoot'}/|/|;
- &Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,'Converting to EPS '.$prettyname); }
+ &Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,'Converting to EPS '.$prettyname);
+ }
$done_conversion{$not_eps}=1;
- my $status = $image->Read($not_eps);
- if ($status) {print " $status ";}
- $image->Set(page => '+100+200');
- $status = $image->Write($eps_f);
- if ($status) {print " $status ";}
+ # print "Converting $not_eps -> $eps_f"; # Debugging
+ system("convert $not_eps $eps_f");
#check is eps exist in prtspool
if(not -e $eps_f) {
for (my $i=0;$i<10000;$i++) {
@@ -140,7 +250,9 @@ END
}
}
}
- if ($adv) { &Apache::lonhtmlcommon::Close_PrgWin('',\%prog_state); }
+ if ($adv) {
+ &Apache::lonhtmlcommon::Close_PrgWin('',\%prog_state);
+ }
unlink($figfile);
}
#print "$texfile\n"; #name of the tex file for debugging only
@@ -218,29 +330,41 @@ foreach $texfile (@texfile) {
$temporary_file = IO::File->new('>'.$logfilename);
print $temporary_file 'LOGFILE'.$body_log_file.'
'."\n";
if ($body_log_file=~m/!\s+Emergency stop/) {
- #LaTeX failed to parse tex file
- print "LaTeX could not successfully parse your tex file.
";
- print "It probably has errors in it.
";
my $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART';
my $whereitends = rindex $body_log_file,'STAMPOFPASSEDRESOURCEEND';
+ my $badresource;
+ my $badtext;
if ($whereitbegins!=-1 and $whereitends!=-1) {
- print "With very high probability this error occured in ".substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26)."
";
- }
- print "Here are the error messages in the LaTeX log file
";
- my $sygnal = 0;
- for (my $i=0;$i<=$#content_of_file;$i++) {
- if ($content_of_file[$i]=~m/^Runaway argument?/ or $content_of_file[$i]=~m/^!/) {
- $sygnal = 1;
- }
- if ($content_of_file[$i]=~m/Here is how much of/) {
- $sygnal = 0;
- }
- if ($sygnal) {
- print "$content_of_file[$i]";
- }
+ $badtext = substr($body_log_file,$whereitbegins+26, $whereitends-$whereitbegins-26);
+ $whereitbegins = rindex $badtext,'located in';
+ if ($whereitbegins != -1) {
+
+ $badresource = substr($badtext, $whereitbegins+27,
+ length($badtext) - $whereitbegins - 48);
+ # print "
failing resourcename: $badresource
";
+ }
}
- print "
\n";
- if ($advans_role) {
+
+ if ($advanced_role) {
+ #LaTeX failed to parse tex file
+ print "LaTeX could not successfully parse your tex file.
";
+ print "It probably has errors in it.
";
+ print "With very high probability this error occured in ".$badtext."
";
+ print "Here are the error messages in the LaTeX log file
";
+ my $sygnal = 0;
+ for (my $i=0;$i<=$#content_of_file;$i++) {
+ if ($content_of_file[$i]=~m/^Runaway argument?/ or $content_of_file[$i]=~m/^!/) {
+ $sygnal = 1;
+ }
+ if ($content_of_file[$i]=~m/Here is how much of/) {
+ $sygnal = 0;
+ }
+ if ($sygnal) {
+ print "$content_of_file[$i]";
+ }
+ }
+ print "
\n";
+ # print "
Advanced role
";
print "The link to ";
$logfilename=~s/\/home\/httpd//;
print "Your log file ";
@@ -258,6 +382,18 @@ foreach $texfile (@texfile) {
$texfile=~s/\/home\/httpd//;
print "Your original LaTeX file ";
print "\n";
+ } else { # Student role...
+ # at this point:
+ # $body_log_file - contains the log file.
+ # $name_file - is the name of the LaTeX file.
+ # $identifier - is the unique LaTeX identifier.l
+
+ print "
There are errors in $badtext";
+ print "
These errors prevent this resource from printing correctly";
+ my $tex_handle = IO::File->new($name_file);
+ my @tex_contents = <$tex_handle>;
+ &send_error_mail($identifier, $badresource, $body_log_file, \@tex_contents);
+ print "
A message has been sent to the instructor describing this failure
"
}
} elsif ($body_log_file=~m//) {
@@ -287,7 +423,10 @@ foreach $texfile (@texfile) {
my $ps_file = my $tempo_file = $1.'temporar.ps';
my $pdf_file = $1.'.pdf';
if ($laystyle eq 'album' and $numberofcolumns eq '2') {
- $comma = "psnup -2 -s1.0 $new_name_file";
+ my $papera=$paper;
+ if ($papera eq 'letter') {$papera='';}
+ if ($papera ne '') {$papera='-p'.$papera;}
+ $comma = "psnup $papera -2 -s1.0 $new_name_file";
&busy_wait_command("$comma $tempo_file 1>/dev/null 2>/dev/null",
"for $status_statement now Modifying PS layout",
\%prog_state,$tempo_file);
@@ -319,26 +458,26 @@ foreach $texfile (@texfile) {
# unlink @garb;
unlink $duefile;
print "Your PDF document";
- if ($advans_role) {
- print "
";
- print "The link to ";
- $logfilename=~s/\/home\/httpd//;
- print "Your log file ";
- print "\n";
- #link tooriginal LaTeX file (included according Michael Hamlin desire)
- my $tex_temporary_file=IO::File->new($texfile) || die "Couldn't open tex file $texfile for reading: $!\n";
- my @tex_content_of_file = <$tex_temporary_file>;
- close $tex_temporary_file;
- my $body_tex_file = join(' ',@tex_content_of_file);
- $texfile =~ s/\.tex$/aaaaa\.html/;
- $tex_temporary_file = IO::File->new('>'.$texfile);
- print $tex_temporary_file 'LOGFILE'.$body_tex_file.'
'."\n";
- print "
";
- print "The link to ";
- $texfile=~s/\/home\/httpd//;
- print "Your original LaTeX file ";
- print "\n";
- }
+ }
+ if ($advanced_role) {
+ print "
";
+ print "The link to ";
+ $logfilename=~s/\/home\/httpd//;
+ print "Your log file ";
+ print "\n";
+ #link tooriginal LaTeX file (included according Michael Hamlin desire)
+ my $tex_temporary_file=IO::File->new($texfile) || die "Couldn't open tex file $texfile for reading: $!\n";
+ my @tex_content_of_file = <$tex_temporary_file>;
+ close $tex_temporary_file;
+ my $body_tex_file = join(' ',@tex_content_of_file);
+ $texfile =~ s/\.tex$/aaaaa\.html/;
+ $tex_temporary_file = IO::File->new('>'.$texfile);
+ print $tex_temporary_file 'LOGFILE'.$body_tex_file.'
'."\n";
+ print "
";
+ print "The link to ";
+ $texfile=~s/\/home\/httpd//;
+ print "Your original LaTeX file ";
+ print "\n";
}
} else {
#LaTeX successfully parsed tex file
@@ -357,13 +496,13 @@ foreach $texfile (@texfile) {
$new_name_file =~ m/^(.*)\./;
my $ps_file = my $tempo_file = $1.'temporar.ps';
my $pdf_file = $1.'.pdf';
+ $papera=~s/t/p/;
if ($laystyle eq 'album' and $numberofcolumns eq '2') {
- $comma = "psnup -2 -s1.0 $new_name_file";
+ $comma = "psnup $papera -2 -s1.0 $new_name_file";
&busy_wait_command("$comma $tempo_file 1>/dev/null 2>/dev/null",
"for $status_statement now Modifying PS layout",
\%prog_state,$tempo_file);
} elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
- $papera=~s/t/p/;
$comma = 'pstops '.$papera.' "2:0+1(0.48w,0)"';
&busy_wait_command("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null",
"for $status_statement now Modifying PS layout",