Diff for /loncom/interface/lonprintout.pm between versions 1.486 and 1.500

version 1.486, 2006/10/16 10:32:46 version 1.500, 2007/04/26 09:32:23
Line 38  use Apache::grades; Line 38  use Apache::grades;
 use Apache::edit;  use Apache::edit;
 use Apache::File();  use Apache::File();
 use Apache::lonnavmaps;  use Apache::lonnavmaps;
 use Apache::lonratedt;  use LONCAPA::map();
 use POSIX qw(strftime);  use POSIX qw(strftime);
 use Apache::lonlocal;  use Apache::lonlocal;
 use Carp;  use Carp;
 use lib '/home/httpd/lib/perl/';  
 use LONCAPA;  use LONCAPA;
   
 my %perm;  my %perm;
 my %parmhash;  my %parmhash;
 my $resources_printed;  my $resources_printed;
   
   # Fetch the contents of a resource, uninterpreted.
   # This is used here to fetch a latex file to be included
   # verbatim into the printout<
   # NOTE: Ask Guy if there is a lonnet function similar to this?
   #
   # Parameters:
   #   URL of the file
   #
   sub fetch_raw_resource {
       my ($url) = @_;
   
       my $filename  = &Apache::lonnet::filelocation("", $url);
       my $contents  = &Apache::lonnet::getfile($filename);
   
       if ($contents == -1) {
    return "File open failed for $filename";      # This will bomb the print.
       }
       return $contents;
   
       
   }
   
 #  #
 #   printf_style_subst  item format_string repl  #   printf_style_subst  item format_string repl
 #    #  
Line 61  my $resources_printed; Line 82  my $resources_printed;
 #  #
 sub printf_style_subst {  sub printf_style_subst {
     my ($item, $format_string, $repl) = @_;      my ($item, $format_string, $repl) = @_;
       my $result = "";
     while ($format_string =~ /%\d*$item/) {      while ($format_string =~ /(%)(\d*)\Q$item\E/g ) {
  my $start = $-[0];   my $fmt = $1;
  my $end   = $+[0];   my $size = $2;
  my $len   = $end - $start;  
   
  # see if we need to truncate:  
   
  my $subst = $repl;   my $subst = $repl;
  my $fmt   = substr($format_string, $start, $len);  
  my $size  = $fmt;  
  $size     =~ s/%(\d*)$item/$1/;  
  if ($size ne "") {   if ($size ne "") {
     $subst = substr($subst, 0, $size);      $subst = substr($subst, 0, $size);
  }      
  $format_string =~ s/%(\d*)$item/$subst/;      #  Here's a nice edge case.. supose the end of the
       #  substring is a \.  In that case may have  just
       #  chopped off a TeX escape... in that case, we append
       #   " " for the trailing character, and let the field 
       #  spill over a bit (sigh).
       #  We don't just chop off the last character in order to deal
       #  with one last pathology, and that would be if substr had
       #  trimmed us to e.g. \\\  
   
   
       if ($subst =~ /\\$/) {
    $subst .= " ";
       }
    }
    my $item_pos = pos($format_string);
    $result .= substr($format_string, 0, $item_pos - length($size) -2) . $subst;
           $format_string = substr($format_string, pos($format_string));
     }      }
   
     return $format_string;      # Put the residual format string into the result:
   
       $result .= $format_string;
   
       return $result;
 }  }
   
   
Line 135  sub format_page_header { Line 168  sub format_page_header {
  $format =  &printf_style_subst("a", $format, $assignment);   $format =  &printf_style_subst("a", $format, $assignment);
  $format =  &printf_style_subst("c", $format, $course);   $format =  &printf_style_subst("c", $format, $course);
  $format =  &printf_style_subst("n", $format, $student);   $format =  &printf_style_subst("n", $format, $student);
   
    # If the user put %'s in the format string, they  must be escaped
    # to \% else LaTeX will think they are comments and terminate
    # the line.. which is bad!!!
   
   
     }      }
           
   
Line 158  sub num_to_letters { Line 197  sub num_to_letters {
 sub letters_to_num {  sub letters_to_num {
     my ($letters) = @_;      my ($letters) = @_;
     my @letters = split('', uc($letters));      my @letters = split('', uc($letters));
     my %substitution;     my %substitution;
     my $digit = 0;      my $digit = 0;
     foreach my $letter ('A'..'J') {      foreach my $letter ('A'..'J') {
  $substitution{$letter} = $digit;   $substitution{$letter} = $digit;
Line 473  sub character_chart { Line 512  sub character_chart {
     $result =~ s/&\#147;/\`\`/g;      $result =~ s/&\#147;/\`\`/g;
     $result =~ s/&\#148;/\'\'/g;      $result =~ s/&\#148;/\'\'/g;
     $result =~ s/&\#149;/\\ensuremath\{\\bullet\}/g;      $result =~ s/&\#149;/\\ensuremath\{\\bullet\}/g;
     $result =~ s/&\#150;/--/g;      $result =~ s/&(\#150|\#8211);/--/g;
     $result =~ s/&\#151;/---/g;      $result =~ s/&\#151;/---/g;
     $result =~ s/&\#152;/\\ensuremath\{\\sim\}/g;      $result =~ s/&\#152;/\\ensuremath\{\\sim\}/g;
     $result =~ s/&\#153;/\\texttrademark /g;      $result =~ s/&\#153;/\\texttrademark /g;
Line 680  sub character_chart { Line 719  sub character_chart {
     $result =~ s/&(clubs|\#9827);/\\ensuremath\{\\clubsuit\}/g;      $result =~ s/&(clubs|\#9827);/\\ensuremath\{\\clubsuit\}/g;
     $result =~ s/&(hearts|\#9829);/\\ensuremath\{\\heartsuit\}/g;      $result =~ s/&(hearts|\#9829);/\\ensuremath\{\\heartsuit\}/g;
     $result =~ s/&(diams|\#9830);/\\ensuremath\{\\diamondsuit\}/g;      $result =~ s/&(diams|\#9830);/\\ensuremath\{\\diamondsuit\}/g;
   #   Chemically useful 'things' contributed by Hon Kie (bug 4652).
       $result =~ s/&\#8636;/\\ensuremath\{\\leftharpoonup\}/g;
       $result =~ s/&\#8637;/\\ensuremath\{\\leftharpoondown\}/g;
       $result =~ s/&\#8640;/\\ensuremath\{\\rightharpoonup\}/g;
       $result =~ s/&\#8641;/\\ensuremath\{\\rightharpoondown\}/g;
       $result =~ s/&\#8652;/\\ensuremath\{\\rightleftharpoons\}/g;
       $result =~ s/&\#8605;/\\ensuremath\{\\leadsto\}/g;
       $result =~ s/&\#8617;/\\ensuremath\{\\hookleftarrow\}/g;
       $result =~ s/&\#8618;/\\ensuremath\{\\hookrightarrow\}/g;
       $result =~ s/&\#8614;/\\ensuremath\{\\mapsto\}/g;
       $result =~ s/&\#8599;/\\ensuremath\{\\nearrow\}/g;
       $result =~ s/&\#8600;/\\ensuremath\{\\searrow\}/g;
       $result =~ s/&\#8601;/\\ensuremath\{\\swarrow\}/g;
       $result =~ s/&\#8598;/\\ensuremath\{\\nwarrow\}/g;
     return $result;      return $result;
 }  }
   
Line 688  sub character_chart { Line 741  sub character_chart {
 my %page_formats=  my %page_formats=
     ('letter' => {      ('letter' => {
  'book' => {   'book' => {
      '1' => [ '7.1 in','9.8 in', '-0.57 in','-0.57 in','0.7 cm'],       '1' => [ '7.1 in','9.8 in', '-0.57 in','-0.57 in','0.275 in'],
      '2' => ['3.66 in','9.8 in', '-0.57 in','-0.57 in','0.7 cm']       '2' => ['3.66 in','9.8 in', '-0.57 in','-0.57 in','0.275 in']
  },   },
  'album' => {   'album' => {
      '1' => [ '8.8 in', '6.8 in','-0.55 in',  '-0.55 in','1 cm'],       '1' => [ '8.8 in', '6.8 in','-0.55 in',  '-0.55 in','0.394 in'],
      '2' => [ '4.8 in', '6.8 in','-0.5 in', '-1.0 in','3.5 in']       '2' => [ '4.8 in', '6.8 in','-0.5 in', '-1.0 in','3.5 in']
  },   },
      },       },
Line 748  my %page_formats= Line 801  my %page_formats=
      },       },
      'a4' => {       'a4' => {
  'book' => {   'book' => {
      '1' => ['17.6 cm','27.2 cm','-0.55  in','-0.83 in','-0.5 in'],       '1' => ['17.6 cm','27.2 cm','-1.397 cm','-2.11 cm','-1.27 cm'],
      '2' => [ '9.1 cm','27.2 cm','-0.55  in','-0.83 in','-0.5 in']       '2' => [ '9.1 cm','27.2 cm','-1.397 cm','-2.11 cm','-1.27 cm']
  },   },
  'album' => {   'album' => {
      '1' => ['8.5 in','7.7 in','-0.55 in','-0.83 in','0 in'],       '1' => ['21.59 cm','19.558 cm','-1.397cm','-2.11 cm','0 cm'],
      '2' => ['3.9 in','7.7 in','-0.55 in','-0.83 in','0 in']       '2' => ['9.91 cm','19.558 cm','-1.397 cm','-2.11 cm','0 cm']
  },   },
      },       },
      'a5' => {       'a5' => {
Line 1148  sub print_construction_sequence { Line 1201  sub print_construction_sequence {
     if ($helper->{'VARS'}->{'curseed'}) {      if ($helper->{'VARS'}->{'curseed'}) {
  $rndseed=$helper->{'VARS'}->{'curseed'};   $rndseed=$helper->{'VARS'}->{'curseed'};
     }      }
     my $errtext=&Apache::lonratedt::mapread($currentURL);      my $errtext=&LONCAPA::map::mapread($currentURL);
     #       # 
     #  These make this all support recursing for subsequences.      #  These make this all support recursing for subsequences.
     #      #
     my @order    = @Apache::lonratedt::order;      my @order    = @LONCAPA::map::order;
     my @resources = @Apache::lonratedt::resources;       my @resources = @LONCAPA::map::resources; 
     for (my $member=0;$member<=$#order;$member++) {      for (my $member=0;$member<=$#order;$member++) {
  $resources[$order[$member]]=~/^([^:]*):([^:]*):/;   $resources[$order[$member]]=~/^([^:]*):([^:]*):/;
  my $urlp=$2;   my $urlp=$2;
Line 1234  sub output_data { Line 1287  sub output_data {
     my ($r,$helper,$rparmhash) = @_;      my ($r,$helper,$rparmhash) = @_;
     my %parmhash = %$rparmhash;      my %parmhash = %$rparmhash;
     $resources_printed = '';      $resources_printed = '';
       my $do_postprocessing = 1;
     my $js = <<ENDPART;      my $js = <<ENDPART;
 <script type="text/javascript">  <script type="text/javascript">
     var editbrowser;      var editbrowser;
Line 1424  ENDPART Line 1478  ENDPART
  $resources_printed .= $currentURL.':';   $resources_printed .= $currentURL.':';
  my $texversion=&Apache::lonnet::ssi($currentURL,%form);   my $texversion=&Apache::lonnet::ssi($currentURL,%form);
  $result .= $texversion;   $result .= $texversion;
    } elsif ($cleanURL =~/.tex$/) {
       # For this sort of print of a single LaTeX file,
       # We can just print the LaTeX file as it is uninterpreted in any way:
       #
   
       $result = &fetch_raw_resource($currentURL);
       $do_postprocessing = 0; # Don't massage the result.
   
  } else {   } else {
     $result.=&unsupported($currentURL,$helper->{'VARS'}->{'LATEX_TYPE'},      $result.=&unsupported($currentURL,$helper->{'VARS'}->{'LATEX_TYPE'},
   $helper->{'VARS'}->{'symb'});    $helper->{'VARS'}->{'symb'});
Line 1828  ENDPART Line 1890  ENDPART
  $result .= '\end{document}';         $result .= '\end{document}';      
     }      }
 #-------------------------------------------------------- corrections for the different page formats  #-------------------------------------------------------- corrections for the different page formats
     $result = &page_format_transformation($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'},$helper->{'VARS'}->{'TABLE_CONTENTS'},$helper->{'VARS'}->{'TABLE_INDEX'},$selectionmade);  
     $result = &latex_corrections($number_of_columns,$result,$selectionmade,      # Only post process if that has not been turned off e.g. by a raw latex resource.
  $helper->{'VARS'}->{'ANSWER_TYPE'});  
     #if ($numberofcolumns == 1) {      if ($do_postprocessing) {
    $result = &page_format_transformation($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'},$helper->{'VARS'}->{'TABLE_CONTENTS'},$helper->{'VARS'}->{'TABLE_INDEX'},$selectionmade);
    $result = &latex_corrections($number_of_columns,$result,$selectionmade,
        $helper->{'VARS'}->{'ANSWER_TYPE'});
    #if ($numberofcolumns == 1) {
  $result =~ s/\\textwidth\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\textwidth= $helper->{'VARS'}->{'pagesize.width'} $helper->{'VARS'}->{'pagesize.widthunit'} /;   $result =~ s/\\textwidth\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\textwidth= $helper->{'VARS'}->{'pagesize.width'} $helper->{'VARS'}->{'pagesize.widthunit'} /;
  $result =~ s/\\textheight\s*=?\s*-?\d*\.?\d*\s*(cm|mm|in)/\\textheight $helper->{'VARS'}->{'pagesize.height'} $helper->{'VARS'}->{'pagesize.heightunit'} /;   $result =~ s/\\textheight\s*=?\s*-?\d*\.?\d*\s*(cm|mm|in)/\\textheight $helper->{'VARS'}->{'pagesize.height'} $helper->{'VARS'}->{'pagesize.heightunit'} /;
  $result =~ s/\\evensidemargin\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\evensidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;   $result =~ s/\\evensidemargin\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\evensidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
  $result =~ s/\\oddsidemargin\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\oddsidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;   $result =~ s/\\oddsidemargin\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\oddsidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
     #}   #}
       }
   
 #-- writing .tex file in prtspool   #-- writing .tex file in prtspool 
     my $temp_file;      my $temp_file;
Line 1962  sub print_resources { Line 2029  sub print_resources {
     my $printed = '';      my $printed = '';
     my ($username,$userdomain,$usersection) = split /:/,$person;      my ($username,$userdomain,$usersection) = split /:/,$person;
     my $fullname = &get_name($username,$userdomain);      my $fullname = &get_name($username,$userdomain);
     my $namepostfix;      my $namepostfix = "\\\\"; # Both anon and not anon should get the same vspace.
     if ($person =~ 'anon') {      if ($person =~ 'anon') {
  $namepostfix="\\\\Name: ";   $namepostfix .="Name: ";
  $fullname = "CODE - ".$moreenv->{'CODE'};   $fullname = "CODE - ".$moreenv->{'CODE'};
     }      }
     #  Fullname may have special latex characters that need \ prefixing:      #  Fullname may have special latex characters that need \ prefixing:
Line 2767  CHOOSE_FROM_ANY_SEQUENCE Line 2834  CHOOSE_FROM_ANY_SEQUENCE
   
     if (($perm{'pav'} and &Apache::lonnet::allowed('vgr',$env{'request.course.id'})) or       if (($perm{'pav'} and &Apache::lonnet::allowed('vgr',$env{'request.course.id'})) or 
  ($helper->{VARS}->{'construction'} eq '1')) {   ($helper->{VARS}->{'construction'} eq '1')) {
  addMessage("<hr width='33%' /><table><tr><td align='right'>Print: </td><td>");   addMessage("<hr width='33%' /><table><tr><td align='right'>".
                      '<label for="ANSWER_TYPE_forminput">'.
                      &mt('Print').
                      "</label>: </td><td>");
         $paramHash = Apache::lonhelper::getParamHash();          $paramHash = Apache::lonhelper::getParamHash();
  $paramHash->{'variable'} = 'ANSWER_TYPE';      $paramHash->{'variable'} = 'ANSWER_TYPE';   
  $helper->declareVar('ANSWER_TYPE');            $helper->declareVar('ANSWER_TYPE');         
Line 2783  CHOOSE_FROM_ANY_SEQUENCE Line 2853  CHOOSE_FROM_ANY_SEQUENCE
   
     if ($perm{'pav'}) {      if ($perm{'pav'}) {
  if (!$startedTable) {   if (!$startedTable) {
     addMessage("<hr width='33%' /><table><tr><td align='right'>LaTeX mode: </td><td>");      addMessage("<hr width='33%' /><table><tr><td align='right'>".
                          '<label for="LATEX_TYPE_forminput">'.
                          &mt('LaTeX mode').
                          "</label>: </td><td>");
     $startedTable = 1;      $startedTable = 1;
  } else {   } else {
     addMessage("<tr><td align='right'>LaTeX mode: </td><td>");      addMessage("<tr><td align='right'>".
                          '<label for="LATEX_TYPE_forminput">'.
                           &mt('LaTeX mode').
                          "</label>: </td><td>");
  }   }
         $paramHash = Apache::lonhelper::getParamHash();          $paramHash = Apache::lonhelper::getParamHash();
  $paramHash->{'variable'} = 'LATEX_TYPE';      $paramHash->{'variable'} = 'LATEX_TYPE';   
Line 2802  CHOOSE_FROM_ANY_SEQUENCE Line 2878  CHOOSE_FROM_ANY_SEQUENCE
  }   }
         Apache::lonhelper::dropdown->new();          Apache::lonhelper::dropdown->new();
     
  addMessage("</td></tr><tr><td align='right'>Print Table of Contents: </td><td>");   addMessage("</td></tr><tr><td align='right'>".
                      '<label="TABLE_CONTENTS_forminput">'.
                      &mt('Print Table of Contents').
                      "</label>: </td><td>");
         $paramHash = Apache::lonhelper::getParamHash();          $paramHash = Apache::lonhelper::getParamHash();
  $paramHash->{'variable'} = 'TABLE_CONTENTS';      $paramHash->{'variable'} = 'TABLE_CONTENTS';   
  $helper->declareVar('TABLE_CONTENTS');            $helper->declareVar('TABLE_CONTENTS');         
Line 2813  CHOOSE_FROM_ANY_SEQUENCE Line 2892  CHOOSE_FROM_ANY_SEQUENCE
  addMessage("</td></tr>");   addMessage("</td></tr>");
                   
  if (not $helper->{VARS}->{'construction'}) {   if (not $helper->{VARS}->{'construction'}) {
     addMessage("<tr><td align='right'>Print Index: </td><td>");      addMessage("<tr><td align='right'>".
                          '<label for="TABLE_INDEX_forminput">'.
                          &mt('Print Index').
                          "</label>: </td><td>");
     $paramHash = Apache::lonhelper::getParamHash();      $paramHash = Apache::lonhelper::getParamHash();
     $paramHash->{'variable'} = 'TABLE_INDEX';         $paramHash->{'variable'} = 'TABLE_INDEX';   
     $helper->declareVar('TABLE_INDEX');               $helper->declareVar('TABLE_INDEX');         
Line 2822  CHOOSE_FROM_ANY_SEQUENCE Line 2904  CHOOSE_FROM_ANY_SEQUENCE
      ['Yes', 'yes'] ];       ['Yes', 'yes'] ];
     Apache::lonhelper::dropdown->new();      Apache::lonhelper::dropdown->new();
     addMessage("</td></tr>");      addMessage("</td></tr>");
     addMessage("<tr><td align='right'>Print Discussions: </td><td>");      addMessage("<tr><td align='right'>".
                          '<label for="PRINT_DISCUSSIONS_forminput">'.
                          &mt('Print Discussions').
                          "</label>: </td><td>");
     $paramHash = Apache::lonhelper::getParamHash();      $paramHash = Apache::lonhelper::getParamHash();
     $paramHash->{'variable'} = 'PRINT_DISCUSSIONS';         $paramHash->{'variable'} = 'PRINT_DISCUSSIONS';   
     $helper->declareVar('PRINT_DISCUSSIONS');               $helper->declareVar('PRINT_DISCUSSIONS');         
Line 2844  CHOOSE_FROM_ANY_SEQUENCE Line 2929  CHOOSE_FROM_ANY_SEQUENCE
   
  if ($helper->{'VARS'}->{'construction'}) {    if ($helper->{'VARS'}->{'construction'}) { 
     my $stylevalue=$env{'construct.style'};      my $stylevalue=$env{'construct.style'};
               my $randseedtext=&mt("Use random seed");
               my $stylefiletext=&mt("Use style file");
   
     my $xmlfrag .= <<"RNDSEED";      my $xmlfrag .= <<"RNDSEED";
     <message><tr><td align='right'>Use random seed:  </td><td></message>      <message><tr><td align='right'>
               <label for="curseed_forminput">$randseedtext</label>:
               </td><td></message>
     <string variable="curseed" size="15" maxlength="15">      <string variable="curseed" size="15" maxlength="15">
  <defaultvalue>   <defaultvalue>
             return $helper->{VARS}->{'curseed'};              return $helper->{VARS}->{'curseed'};
         </defaultvalue>          </defaultvalue>
     </string>      </string>
      <message></td></tr><tr><td align="right">Use style file:</td><td></message>       <message></td></tr><tr><td align="right">
                <label for="style_file_value">$stylefiletext</label>:
                </td><td></message>
              <message><input type="text" size="40" name="style_file_value" value="$stylevalue"  />&nbsp; <a href="javascript:openbrowser('helpform','style_file_value','sty')">Select style file</a> </td><tr><td></message>               <message><input type="text" size="40" name="style_file_value" value="$stylevalue"  />&nbsp; <a href="javascript:openbrowser('helpform','style_file_value','sty')">Select style file</a> </td><tr><td></message>
      <choices allowempty="1" multichoice="true" variable="showallfoils">       <choices allowempty="1" multichoice="true" variable="showallfoils">
                 <choice computer="1">Show all foils?</choice>                  <choice computer="1">Show all foils?</choice>

Removed from v.1.486  
changed lines
  Added in v.1.500


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>