[LON-CAPA-cvs] cvs: loncom /interface lonprintout.pm rat lonpage.pm
raeburn
raeburn@source.lon-capa.org
Tue, 13 Jul 2010 00:16:28 -0000
This is a MIME encoded message
--raeburn1278980188
Content-Type: text/plain
raeburn Tue Jul 13 00:16:28 2010 EDT
Modified files:
/rat lonpage.pm
/loncom/interface lonprintout.pm
Log:
- Fix some issues with headers in TeX which caused begin{document} to be missing in some cases:
(a) generating printouts with answers only
(b) printing .page
- Fix some issue which caused HTML to be included in .tex files for resources within
a page. For now change target to "tex_answer" in lonpage.pm,
if $env{'form.answer_output_mode'} is 'tex' and $env{'form.grade_target'} is 'answer'
- answers for all resources in page appear after rendering of individual
resources in .page, when print type is "with answers" for a .page.
- Eliminate some cases where printing would fail.
--raeburn1278980188
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100713001628.txt"
Index: rat/lonpage.pm
diff -u rat/lonpage.pm:1.93 rat/lonpage.pm:1.94
--- rat/lonpage.pm:1.93 Tue Mar 16 19:56:02 2010
+++ rat/lonpage.pm Tue Jul 13 00:16:23 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Page Handler
#
-# $Id: lonpage.pm,v 1.93 2010/03/16 19:56:02 droeschl Exp $
+# $Id: lonpage.pm,v 1.94 2010/07/13 00:16:23 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -158,6 +158,19 @@
my $number_of_columns = 1;
my $requrl=$r->uri;
my $target = $env{'form.grade_target'};
+
+# Short term solution: define target as 'tex_answer' when retrieving answers
+# for resources in a .page when generating printouts.
+# A better long-term fix would be to modify the way problem rendering, and
+# answer rendering are retrieved for individual resources when printing a .page,
+# so rendered problem and answer are sequential for individual resources in
+# the .page
+#
+ if ($target eq 'answer') {
+ if ($env{'form.answer_output_mode'} eq 'tex') {
+ $target = 'tex_answer';
+ }
+ }
# &Apache::lonnet::logthis("Got a target of $target");
if ($target eq 'meta') {
&Apache::loncommon::content_type($r,'text/html');
@@ -242,12 +255,14 @@
my %posthash=('request.prefix' => $prefix,
'LONCAPA_INTERNAL_no_discussion' => 'true',
'symb' => $symb);
- if ($env{'form.grade_target'} eq 'tex') {
+ if (($env{'form.grade_target'} eq 'tex') ||
+ ($env{'form.answer_output_mode'} eq 'tex')) {
$posthash{'grade_target'}=$env{'form.grade_target'};
$posthash{'textwidth'}=$env{'form.textwidth'};
$posthash{'problem_split'}=$env{'form.problem_split'};
$posthash{'latex_type'}=$env{'form.latex_type'};
$posthash{'rndseed'}=$env{'form.rndseed'};
+ $posthash{'answer_output_mode'} = $env{'form.answer_output_mode'};
}
my $submitted=exists($env{'form.all_submit'});
if (!$submitted) {
@@ -271,7 +286,7 @@
}
my $output=Apache::lonnet::ssi($src,%posthash);
$output=~s|//(\s*<!--)? BEGIN LON-CAPA Internal.+?// END LON-CAPA Internal\s*(-->)?\s||gs;
- if ($target eq 'tex') {
+ if (($target eq 'tex') || ($target eq 'tex_answer')) {
$output =~ s/^([^&]+)\\begin{document}//;
$output =~ s/\\end{document}//;
# $output = '\parbox{\minipagewidth}{ '.$output.' }';
@@ -372,7 +387,7 @@
# ------------------------------------------------------------------ Build page
# ---------------------------------------------------------------- Send headers
- unless ($target eq 'tex') {
+ unless (($target eq 'tex') || ($target eq 'tex_answer')) {
if ($isxml) {
&Apache::loncommon::content_type($r,'text/xml');
} else {
@@ -396,7 +411,7 @@
&Apache::lonenc::check_encrypt($requrl)
.'">');
}
- } elsif ($target eq 'tex') {
+ } elsif (($target eq 'tex') || ($target eq 'tex_answer')) {
# I think this is not needed as the header
# will be put in for each of the page parts
# by the londefdef.pm now that we are opening up
@@ -410,7 +425,7 @@
# \begin{document}');
}
# ----------------------------------------------------------------- Start table
- if ($target eq 'tex') {
+ if (($target eq 'tex') || ($target eq 'tex_answer')) {
# # $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');
if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};
} else {
@@ -419,7 +434,7 @@
# generate rows
for ($i=0;$i<=$#rows;$i++) {
if ($rows[$i]) {
- unless ($target eq 'tex') {
+ unless (($target eq 'tex') || ($target eq 'tex_answer')) {
$r->print("\n<tr>");
}
my @colcont=split(/\&/,$rows[$i]);
@@ -428,11 +443,11 @@
my $rid=$colcont[$j];
my $metainfo =&get_buttons(\%hash,$rid).'<br />';
- unless ($target eq 'tex') {
+ unless (($target eq 'tex') || ($target eq 'tex_answer')) {
$r->print('<td colspan="'.$avespan.'"');
}
if ($cellemb{$rid} eq 'ssi') {
- unless ($target eq 'tex') {
+ unless (($target eq 'tex') || ($target eq 'tex_answer')) {
if ($ssibgcolor{$rid}) {
$r->print(' bgcolor="'.
$ssibgcolor{$rid}.'"');
@@ -454,13 +469,13 @@
$r->print('>');
}
$r->print($ssibody{$rid});
- unless ($target eq 'tex') {
+ unless (($target eq 'tex') || ($target eq 'tex_answer')) {
$r->print('</font>');
}
if ($env{'course.'.
$env{'request.course.id'}.
'.pageseparators'} eq 'yes') {
- unless($target eq 'tex') {
+ unless (($target eq 'tex') || ($target eq 'tex_answer')) {
$r->print('<hr />');
}
}
@@ -475,7 +490,7 @@
&mt('It is recommended that you use an up-to-date virus scanner before handling this file.').'</p><p><table>'.
&Apache::londocs::entryline(0,&mt("Click to download or use your browser's Save Link function"),'/'.&Apache::lonnet::declutter($hash{'src_'.$rid})).'</table></p><br />');
}
- unless ($target eq 'tex') {
+ unless (($target eq 'tex') || ($target eq 'tex_answer')) {
$r->print('</td>');
} else {
# for (my $incol=1;$incol<=$avespan;$incol++) {
@@ -483,14 +498,14 @@
# }
}
}
- unless ($target eq 'tex') {
+ unless (($target eq 'tex') || ($target eq 'tex_answer')) {
$r->print('</tr>');
} else {
# $r->print('REMOVETHEHEADOFLONGTABLE\\\\');
}
}
}
- unless ($target eq 'tex') {
+ unless (($target eq 'tex') || ($target eq 'tex_answer')) {
$r->print("\n</table>");
} else {
# $r->print('\end{longtable}\strut');
@@ -501,7 +516,7 @@
'<input name="all_submit" value="Submit All" type="'.
(($nforms>1)?'submit':'hidden').'"></input></form>');
}
- unless ($target eq 'tex') {
+ unless (($target eq 'tex') || ($target eq 'tex_answer')) {
$r->print(&Apache::loncommon::end_page({'discussion'
=> 1,}));
} else {
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.581 loncom/interface/lonprintout.pm:1.582
--- loncom/interface/lonprintout.pm:1.581 Thu Jun 10 16:14:34 2010
+++ loncom/interface/lonprintout.pm Tue Jul 13 00:16:28 2010
@@ -2,7 +2,7 @@
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.581 2010/06/10 16:14:34 bisitz Exp $
+# $Id: lonprintout.pm,v 1.582 2010/07/13 00:16:28 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1560,7 +1560,9 @@
my $title=&Apache::lonnet::gettitle($symb);
$title = &Apache::lonxml::latex_special_symbols($title);
} else {
- $result.=$currentURL;
+ my $esc_currentURL= $currentURL;
+ $esc_currentURL =~ s/_/\\_/g;
+ $result.=$esc_currentURL;
}
$result .= '\\\\';
@@ -1590,7 +1592,7 @@
}
# these resources go through the XML transformer:
- elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
+ elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) {
my $urlp = &Apache::lonnet::clutter($resource_src);
my %form;
my %moreenv;
@@ -2130,7 +2132,6 @@
&Apache::lonnet::delenv('construct.style');
}
-
if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'current_document') {
#-- single document - problem, page, html, xml, ...
my ($currentURL,$cleanURL);
@@ -2300,9 +2301,9 @@
($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') or
($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_resources') or # BUGBUG
($helper->{'VARS'}->{'PRINT_TYPE'} eq 'select_sequences')
- ) {
-
+ ) {
+
#-- produce an output string
if (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') or
($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_in_page') ) {
@@ -2365,7 +2366,13 @@
&Apache::lonxml::remember_problem_counter();
if ($flag_latex_header_remove eq 'NO') {
$texversion.=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); # RF
- $flag_latex_header_remove = 'YES';
+ unless (($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only') ||
+ (($i==0) &&
+ (($urlp=~/\.page$/) ||
+ ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_in_page') ||
+ ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_resources_in_page')))) {
+ $flag_latex_header_remove = 'YES';
+ }
}
$texversion.=&ssi_with_retries($urlp, $ssi_retry_count, %form);
if ($urlp=~/\.page$/) {
@@ -2373,7 +2380,7 @@
if ($number_of_columns_page > $number_of_columns) {$number_of_columns=$number_of_columns_page;}
$texversion =~ s/\\end{document}\d*/\\end{document}/;
$flag_page_in_sequence = 'YES';
- }
+ }
if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
@@ -2385,13 +2392,22 @@
&Apache::lonxml::restore_problem_counter();
my $answer=&ssi_with_retries($urlp, $ssi_retry_count, %answerform);
-
+ if ($urlp =~ /\.page$/) {
+ $answer =~ s/\\end{document}(\d*)$//;
+ }
if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
- $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
+ if ($urlp =~ /\.page$/) {
+ my @probs = split(/\\keephidden{ENDOFPROBLEM}/,$texversion);
+ my $lastprob = pop(@probs);
+ $texversion = join('\keephidden{ENDOFPROBLEM}',@probs).
+ $answer.'\keephidden{ENDOFPROBLEM}'.$lastprob;
+ } else {
+ $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
+ }
} else {
- if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {
+ if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page)$/) {
$texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
- $texversion =~ s/\\begin{document}//;
+# $texversion =~ s/\\begin{document}//; # FIXME
my $title = &Apache::lonnet::gettitle($master_seq[$i]);
$title = &Apache::lonxml::latex_special_symbols($title);
my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
@@ -2484,7 +2500,7 @@
}
$result .= $texversion;
$flag_latex_header_remove = 'YES';
- }
+ }
if (&Apache::loncommon::connection_aborted($r)) {
last;
}
@@ -2960,7 +2976,7 @@
$i++;
if ( !($type eq 'problems' &&
- ($curresline!~ m/\.(problem|exam|quiz|assess|survey|form|library)$/)) ) {
+ ($curresline!~ m/\.(problem|exam|quiz|assess|survey|form|library|page)$/)) ) {
my ($map,$id,$res_url) = &Apache::lonnet::decode_symb($curresline);
if (&Apache::lonnet::allowed('bre',$res_url)) {
if ($res_url!~m|^ext/|
@@ -2969,6 +2985,18 @@
&Apache::lonxml::remember_problem_counter();
my $rendered = &get_student_view_with_retries($curresline,$ssi_retry_count,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);
+ if ($res_url =~ /\.page$/) {
+ if ($remove_latex_header eq 'NO') {
+ if (!($rendered =~ /\\begin\{document\}/)) {
+ $rendered = &print_latex_header().$rendered;
+ }
+ }
+ if ($remove_latex_header eq 'YES') {
+ $rendered = &latex_header_footer_remove($rendered);
+ } else {
+ $rendered =~ s/\\end{document}\d*//;
+ }
+ }
if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
# Use a copy of the hash so we don't pervert it on future loop passes.
@@ -2986,7 +3014,9 @@
my $header =&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
- $header =~ s/\\begin{document}//; #<<<<<
+ unless ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only') {
+ $header =~ s/\\begin{document}//; #<<<<<
+ }
my $title = &Apache::lonnet::gettitle($curresline);
$title = &Apache::lonxml::latex_special_symbols($title);
my $body ='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
--raeburn1278980188--