--- loncom/interface/printout.pl 2008/03/26 09:50:21 1.135
+++ loncom/interface/printout.pl 2009/09/27 03:13:06 1.142.6.1
@@ -1,7 +1,7 @@
#!/usr/bin/perl
# CGI-script to run LaTeX, dvips, ps2ps, ps2pdf etc.
#
-# $Id: printout.pl,v 1.135 2008/03/26 09:50:21 foxr Exp $
+# $Id: printout.pl,v 1.142.6.1 2009/09/27 03:13:06 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -45,9 +45,14 @@ use strict;
my $busy_wait_timeout = 30;
+
+my $debugging = 0;
+
sub debug {
- my ($text) = @_;
- print "$text
\n";
+ if ($debugging) {
+ my ($text) = @_;
+ print "$text
\n";
+ }
}
# Determine if a user is operating as a student for this course/domain.
@@ -118,7 +123,7 @@ sub send_error_mail {
if (&is_student()) {
# build the subject and message body:
- # print "sending message to course coordinators.
";
+ &debug("sending message to course coordinators.");
# Todo: Convert badurl into a url from file path:
@@ -137,9 +142,9 @@ sub send_error_mail {
}
my (undef, %receivers) = &Apache::lonmsg::decide_receiver(undef, 0,
1,1,1);
- # print "
sending...section: $env{'request.course.sec'}";
+ &debug("sending...section: $env{'request.course.sec'}");
foreach my $dest (keys %receivers) {
- # print "
dest is $dest";
+ &debug("dest is $dest");
my @destinfo = split(/:/,$dest);
my $user = $destinfo[0];
my $dom = $destinfo[1];
@@ -211,8 +216,11 @@ $duefile =~ s/^(.*_printout)_\d+_\d+_\d+
# it contains the names of the files that need to be converted, one per line.
#
+&debug("Figure file is $figfile");
+
if (-e $figfile) {
- # print "$figfile exists\n";
+ &debug( "Figure file exists");
+ &debug("$figfile exists");
my %done_conversion;
my $temporary_file=IO::File->new($figfile) || die "Couldn't open fig file $figfile for reading: $!\n";
my @content_of_file = <$temporary_file>;
@@ -223,6 +231,7 @@ if (-e $figfile) {
print('
');
foreach my $not_eps (@content_of_file) {
chomp($not_eps);
+ &debug( "Being asked to convert $not_eps");
if ($not_eps ne '') {
$not_eps=~s|\/\.\/|\/|g;
if (!$done_conversion{$not_eps}) { # Only convert multiple includes once.
@@ -264,7 +273,7 @@ my $ind=-1;
my %prog_state;
if ($advanced_role) {
- %prog_state=&Apache::lonhtmlcommon::Create_PrgWin('','Print Status','Class Print Status',$number_of_files,'inline','80');
+ %prog_state=&Apache::lonhtmlcommon::Create_PrgWin('','Print Status',&mt('Class Print Status'),$number_of_files,'inline','80');
}
print "
";
my $num_files = @texfile; # How does this differ from $number_of_files , can that be 0?
@@ -403,7 +412,8 @@ foreach $texfile (@texfile) {
my $papera=$paper;
if ($papera eq 'letter') {$papera='';}
if ($papera ne '') {$papera='-t'.$papera;}
- my $comma = "dvips $papera -Ppdf -G0 -o $new_name_file";
+ my $extra_ps_header = $perlvar{'lonLib'} .'/includepsheader.ps';
+ my $comma = "dvips $papera -h $extra_ps_header -Ppdf -G0 -o $new_name_file";
&busy_wait_command("$comma $name_file 1>/dev/null 2>/dev/null",
"for $status_statement now Converting to PS",
\%prog_state,$new_name_file);
@@ -457,14 +467,21 @@ foreach $texfile (@texfile) {
my $ps_file = my $tempo_file = $1.'temporar.ps';
my $pdf_file = $1.'.pdf';
$papera=~s/t/p/;
+ $comma = "fixps --force $new_name_file";
+ &debug("FIXPS command: $comma");
+ &busy_wait_command("$comma 1>/dev/null 2>/dev/null",
+ "for $status_statement now validating PS",
+ \%prog_state,$tempo_file);
if ($laystyle eq 'album' and $numberofcolumns eq '2') {
$comma = "psnup $papera -2 -s1.0 $new_name_file";
+ &debug("PSNUP command: $comma");
&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') {
- $comma = 'pstops '.$papera.' "2:0+1(0.48w,0)"';
- &busy_wait_command("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null",
+ $comma = 'pstops '.$papera.' "2:0+1(0.48w,0)" '.$new_name_file;
+ &debug("PSTOPS command: $comma ");
+ &busy_wait_command("$comma $tempo_file 1>/dev/null 2>/dev/null",
"for $status_statement now Modifying PS layout",
\%prog_state,$tempo_file);
} else {
@@ -491,7 +508,7 @@ foreach $texfile (@texfile) {
close(FFHS);
$ps_file=$new_ps_file;
}
- &busy_wait_command("ps2pdf $ps_file $pdf_file 1>/dev/null 2>/dev/null",
+ &busy_wait_command("ps2pdf13 $ps_file $pdf_file 1>/dev/null 2>/dev/null",
"for $status_statement now Converting PS to PDF",
\%prog_state,$pdf_file);
@@ -594,7 +611,7 @@ sub busy_wait_command {
# various bits and pieces that control how the latex file is processed:
# LaTeX is run as many times a needed to make this all happen... this may
# result in several runs of LaTeX that just are errors if the LaTeX is
-# bad, butthe printing subsystem is _supposed_ to not do that.
+# bad, but the printing subsystem is _supposed_ to not do that.
#
# Parameters:
# name_file - Name of the LaTeX file to process.
@@ -845,6 +862,7 @@ sub create_missing_fonts {
#
sub convert_figure {
my ($not_eps) = @_;
+ &debug("in convert_figure");
my $status_statement='EPS picture for '.$not_eps;
my $eps_f = $not_eps;
@@ -888,7 +906,24 @@ sub convert_figure {
&Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,
'Converting to EPS '.$prettyname);
}
- system("convert $not_eps $eps_f");
+ #
+ # If the file is a PDF, need to use pdftops to convert it to a ps file.
+ # otherwise use imagemagik:
+ #
+ if($not_eps =~/\.(pdf|PDF)$/) {
+
+ #
+ # For whatever reason, pure postscript conversions have to be
+ # in the same dir as the base file:
+ #
+ $eps_f = &basename($eps_f);
+ $eps_f = $perlvar{'lonPrtDir'}.'/'.$eps_f;
+
+ &debug("Converting pdf $not_eps to postscript: $eps_f");
+ system("pdftops $not_eps $eps_f");
+ } else {
+ system("convert $not_eps $eps_f");
+ }
if (not -e $eps_f) {
# converting an animated gif creates either:
@@ -966,16 +1001,20 @@ sub analyze_logfile {
length($badtext) - $whereitbegins - 48);
# print "
failing resourcename: $badresource
";
}
- }
+ }
# Guys with privileged roles get a more detailed error output:
if ($advanced_role) {
#LaTeX failed to parse tex file
- print "
"; + print "".&mt('LaTeX could not successfully parse your TeX file.')."
"; + print &mt('It probably has errors in it.')."
"; + if ($badtext) { + print &mt('With very high probability this error occured in [_1].',$badtext) + ."
"; + } + print &mt('Here are the error messages in the LaTeX log file:') + .""; my $sygnal = 0; for (my $i=0;$i<=$#content_of_file;$i++) { @@ -991,10 +1030,10 @@ sub analyze_logfile { } print "\n"; # print "
Advanced role
"; - print "The link to "; $logfilename=~s{^\Q$perlvar{'lonPrtDir'}\E}{/prtspool}; - print "Your log file "; - print "\n"; + print "" + .&mt('The link to [_1]Your log file[_2]','','') + ."\n"; #link to original LaTeX file 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>; @@ -1004,11 +1043,11 @@ sub analyze_logfile { $tex_temporary_file = IO::File->new('>'.$texfile); print $tex_temporary_file 'LOGFILE '.$body_tex_file.''."\n"; print "
"; - print "The link to "; $texfile=~s{^\Q$perlvar{'lonPrtDir'}\E}{/prtspool}; - print "Your original LaTeX file "; - print "\n"; - my $help_text = &Apache::loncommon::help_open_topic("Print_Resource", "Help on printing"); + print "" + .&mt('The link to [_1]Your original LaTeX file[_2]','','') + ."
\n"; + my $help_text = &Apache::loncommon::help_open_topic("Print_Resource", &mt('Help on printing')); print ("$help_text"); # Students on the other hand get a minimal error message, since they won't @@ -1021,13 +1060,22 @@ sub analyze_logfile { # $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"; + print ''; + if ($badtext) { + print &mt('There are errors in [_1].',$badtext); + } else { + print &mt('There are errors.'); + } + print '
' + .&mt('These errors prevent this resource from printing correctly.'); + my $tex_handle = IO::File->new($texfile); 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
"; - my $help_text = &Apache::loncommon::help_open_topic("Print_Resource", "Help on printing"); + print "" + .&mt('A message has been sent to the instructor describing this failure.') + ."
"; + my $help_text = &Apache::loncommon::help_open_topic("Print_Resource", &mt('Help on printing')); print ("$help_text"); } @@ -1044,22 +1092,24 @@ sub analyze_logfile { } elsif ($body_log_file=~m//) { my $whereitbegins = index $body_log_file,' '; - print "You are running LaTeX in batch mode."; + print &mt('You are running LaTeX in [_1]batch mode[_2].','',''); while ($whereitbegins != -1) { my $tempobegin=$whereitbegins; $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART',$whereitbegins; my $whereitends = index $body_log_file,'STAMPOFPASSEDRESOURCEEND',$whereitbegins; - print "
It has found an error in".substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26)."
and corrected it.\n"; - print "Usually this correction is valid but you probably need to check the indicated resource one more time and implement neccessary corrections by yourself.\n"; + print "
" + .&mt('It has found an error in [_1][_2]and corrected it.',substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26),"
")."\n"; + print &mt('Usually this correction is valid but you probably need to check the indicated resource one more time and implement neccessary corrections by yourself.')."\n"; $whereitbegins = index $body_log_file,'',$tempobegin+10; } if ($advanced_role) { print "
"; - print "The link to "; $logfilename=~s{^\Q$perlvar{'lonPrtDir'}\E}{/prtspool}; - print "Your log file "; - print "\n"; + print "" + .&mt('The link to [_1]Your log file[_2]' + ,'','') + ."\n"; #link to original LaTeX file 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>; @@ -1069,10 +1119,10 @@ sub analyze_logfile { $tex_temporary_file = IO::File->new('>'.$texfile); print $tex_temporary_file 'LOGFILE '.$body_tex_file.''."\n"; print "
"; - print "The link to "; $texfile=~s{^\Q$perlvar{'lonPrtDir'}\E}{/prtspool}; - print "Your original LaTeX file "; - print "\n"; + print "" + .&mt('The link to [_1]Your original LaTeX file[_2]','',''); + print "\n"; } return 1; }