Diff for /loncom/xml/londefdef.pm between versions 1.415.4.6 and 1.416

version 1.415.4.6, 2011/11/15 17:34:19 version 1.416, 2010/05/04 19:40:47
Line 48  use Image::Magick; Line 48  use Image::Magick;
 use Apache::lonmenu();  use Apache::lonmenu();
 use Apache::lonmeta();  use Apache::lonmeta();
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::loncommon();  
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use File::Basename;  use File::Basename;
 use LONCAPA();  use LONCAPA();
Line 590  sub start_body { Line 589  sub start_body {
 sub edit_controls {  sub edit_controls {
     my ($nochgview) = @_;      my ($nochgview) = @_;
     my $result .= '      my $result .= '
 <form method="post" action="">  <form method="post">
 <div class="LC_edit_problem_header">';  <div class="LC_edit_problem_header">';
     unless ($nochgview) {      unless ($nochgview) {
         $result .= '          $result .= '
Line 602  sub edit_controls { Line 601  sub edit_controls {
     $result .= '      $result .= '
 <div><input type="submit" name="editmode" accesskey="e" value="'.&mt('Edit').'" />';  <div><input type="submit" name="editmode" accesskey="e" value="'.&mt('Edit').'" />';
     if (($env{'request.course.id'}) && ($env{'form.forceedit'})) {      if (($env{'request.course.id'}) && ($env{'form.forceedit'})) {
         my $viewtext = &mt('Course View');          $result .= ('&nbsp;' x 3).'<input type="button" value="'.&mt('Course View').'" onclick="javascript:location.href=currentURL" />';
         if (&Apache::loncommon::course_type() eq 'Community') {  
             $viewtext = &mt('Community View');  
         }  
         $result .= ('&nbsp;' x 3).'<input type="button" value="'.  
                    $viewtext.'" onclick="javascript:location.href=currentURL" />';  
     }      }
     $result .= '</div>      $result .= '</div>
 </div>  </div>
Line 2045  sub start_table { Line 2039  sub start_table {
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  &disable_para(); # Can't have paras in a table.   &disable_para(); # Can't have paras in a table.
   
   
    #  New table code:
   
  #  Get the parameters that we can do something about:   #  Get the parameters that we can do something about:
   
  my $border = &Apache::lonxml::get_param('border', $parstack, $safeeval, undef, 0);   my $border = &Apache::lonxml::get_param('border', $parstack, $safeeval, undef, 0);
  my $width  = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval, undef, 0);   my $width  = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval, undef, 0);
  my $theme  = &Apache::lonxml::get_param('TeXtheme', $parstack, $safeeval, undef, 0);   my $theme  = &Apache::lonxml::get_param('TeXtheme', $parstack, $safeeval, undef, 0);
  my $align  = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 0);   my $align  = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 0);
         my $cell_border = &Apache::lonxml::get_param('rules', $parstack, $safeeval, undef, 0);  
   
  # The only thing that needs any figuring out is the width.. and then only if it is   # The only thing that needs any figuring out is the width.. and then only if it is
  # a percent. If not it's assumed to be some valid TeX measurement unit e.g. 3.0cm   # a percent. If not it's assumed to be some valid TeX measurement unit e.g. 3.0cm
  #   #
   
  my $table = new Apache::lontable();   my $table = new Apache::lontable();
         if ((defined $border) && ($border > 0)) {   if ($border ne '') {
         #    &Apache::lonnet::logthis("Turning on table borders: $border");      $table->table_border(1);
             $table->table_border(1);      $table->cell_border(1);
             if (!defined $cell_border) {   }
                 $table->cell_border(1); # Default for rules is all if rules not defined.   if ($theme ne '') {
             }  
         }  
   
         if ((defined $cell_border)) {  
             if ($cell_border eq 'all') {  
                 $table->cell_border(1);  
             } elsif ($cell_border eq 'rows') {  
                 $table->cell_border(2);  
             } elsif ($cell_border eq 'cols') {  
                 $table->cell_border(3);  
             } elsif($cell_border eq 'groups') {  
                 $table->cell_border(4);  
             } else {  
                 $table->cell_border(0);  
             }  
         }  
         if (defined $theme) {  
     $table->theme($theme);      $table->theme($theme);
  }   }
  if (defined $align) {   if ($align ne '') {
     $table->alignment($align);      $table->alignment($align);
  }   }
   
  # Missing width is most of page width   # Missing width is most of page width
   
  if (!(defined $width)) {   if ($width eq "") {
     $width = '70%';      $width = '70%';
  }   }
   
Line 2106  sub start_table { Line 2085  sub start_table {
  push(@Apache::londefdef::table, $table);   push(@Apache::londefdef::table, $table);
         $currentstring.=' \keephidden{NEW TABLE ENTRY}';          $currentstring.=' \keephidden{NEW TABLE ENTRY}';
   
    #--------------------------------------------------------
    #  Old table code here.
    #--------------------------------------------------------
   
   
    if (0) {
    push(@Apache::londefdef::table, {}); 
    $Apache::londefdef::table[-1]{'row_number'} = -1;
           #maximum table's width (default coincides with text line length)
    if ($#Apache::londefdef::table==0) {
       $textwidth=&recalc($env{'form.textwidth'}); #result is always in mm
       $textwidth=~/(\d+\.?\d*)/;
       $textwidth=0.85*$1; #accounts "internal" LaTeX space for table frame
    } else {
       if ($Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]=~/\d/) {
    #the maximum width of nested table is determined by LATeX width of parent cell
    $textwidth=$Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]; 
       } else {
                 #try to use all space not used before (minus 5% for LaTeX table internal) - rather silly
    $textwidth=$Apache::londefdef::table[-2]{'width'};
    for (my $i=0;$i<$Apache::londefdef::table[-2]{'counter_columns'};$i++) {
       $textwidth=$textwidth-$Apache::londefdef::table[-2]{'TeXlen'}[0][$i];
    }
       }
    }
   
    # width either comes forced from the TeXwidth or the width parameters.
    # in either case it can be a percentage or absolute width.
    # in the width case we ignore absolute width 
    my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
    if (!defined($TeXwidth)) {
       my $htmlwidth = &Apache::lonxml::get_param('width',$parstack,
          $safeeval,undef,1);
       if ($htmlwidth =~ /%/) {
    $TeXwidth = $htmlwidth;
       } else { 
    $TeXwidth = $textwidth;
       }
    }
    # if the width is specified as a % it is converted to an absolute width.
    # otherwise.. just plugged right in the hash
   
    if ($TeXwidth=~/%/) {
       $TeXwidth=~/(\d+)/;
               $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;
    } else {
       $Apache::londefdef::table[-1]{'width'}=$TeXwidth;
    }
           #  In the end, however the table width cannot be wider than $textwidth...
   
    if ($Apache::londefdef::table[-1]{'width'} > $textwidth) {
       $Apache::londefdef::table[-1]{'width'} = $textwidth;
    }
           #table's border
    my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval); 
           my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
    unless (defined $border) { $border = 0; }
    if ($border) { 
       $Apache::londefdef::table[-1]{'hinc'} = '\hline '; 
       $Apache::londefdef::table[-1]{'vinc'} = '&'; 
       $Apache::londefdef::table[-1]{'vvinc'} = '|';
    } else {
       $Apache::londefdef::table[-1]{'hinc'} = ''; 
       $Apache::londefdef::table[-1]{'vinc'} = '&'; 
       $Apache::londefdef::table[-1]{'vvinc'} = '';
    }
    if ($#Apache::londefdef::table==0) {
       #    Note that \newline seems to destroy the alignment envs.
       # $Apache::londefdef::table[-1]{'output'}='\strut\newline\strut\setlength{\tabcolsep}{1 mm}';
       $Apache::londefdef::table[-1]{'output'}='\strut'.'\\\\'."\n".'\strut\setlength{\tabcolsep}{1 mm}';
    }
    $Apache::londefdef::table[-1]{'output'}.=' \noindent \begin{tabular} ';
           $Apache::londefdef::table[-1]{'TeXlen'}=[];
           $Apache::londefdef::table[-1]{'objectlen'}=[];
           $Apache::londefdef::table[-1]{'objectsignal'}=[];
           $Apache::londefdef::table[-1]{'maxlen'}=[];
           $Apache::londefdef::table[-1]{'minlen'}=[];
           $Apache::londefdef::table[-1]{'content'}=[];
           $Apache::londefdef::table[-1]{'align'}=[];
           $currentstring.=' \keephidden{NEW TABLE ENTRY}';
       }
   
     }      }
     return $currentstring;      return $currentstring;
 }  }
Line 2118  sub end_table { Line 2179  sub end_table {
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
   
   
    #  New table code:
   
  my $table = pop(@Apache::londefdef::table);   my $table = pop(@Apache::londefdef::table);
  my $t     = $table->generate();   my $t     = $table->generate();
  $currentstring = $t->generate_string();   $currentstring = $t->generate_string();
Line 2659  sub tag_check { Line 2722  sub tag_check {
 #  #
   
 sub cell_config_hash {  sub cell_config_hash {
     my ($align, $rowspan, $colspan, $width) = @_;      my ($align, $rowspan, $colspan) = @_;
     if ($rowspan ne '') {  
         $rowspan =~ s/^\s+|\s+$//g;  
     }  
     if ($colspan ne '') {  
         $colspan =~ s/^\s+|\s+$//g;  
     }  
     my %config;      my %config;
     if ($align ne '') {      if ($align ne '') {
  $config{'halign'} = $align;   $config{'halign'} = $align;
     }      }
     if (($colspan =~ /^\d+$/) && ($colspan > 0)) {      if ($colspan ne "") {
  $config{'colspan'} = $colspan;   $config{'colspan'} = $colspan;
     }      }
     if (($rowspan =~ /^\d+$/) && ($rowspan > 0)) {      if ($rowspan ne '') {
  $config{'rowspan'} = $rowspan;   $config{'rowspan'} = $rowspan;
     }      }
     if ($width ne '') {  
         $config{'width'} = $width;  
     }  
     return \%config;      return \%config;
 }  }
     
Line 2690  sub start_td_tex { Line 2744  sub start_td_tex {
     # attributes, but empty of text.  end_td_tex will      # attributes, but empty of text.  end_td_tex will
     # fetch the contents from the recursive parse and      # fetch the contents from the recursive parse and
     # fill the cell with them:      # fill the cell with them:
     my $align   = &Apache::lonxml::get_param('align', $parstack, $safeeval);      my $align   = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 1);
     my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval);      my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval, undef, 1);
     my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval);      my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval, undef, 1);
     my $width   = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval);  
     my $config = &cell_config_hash($align, $rowspan, $colspan, $width);      my $config = &cell_config_hash($align, $rowspan, $colspan);
   
     my $table = $Apache::londefdef::table[-1];      my $table = $Apache::londefdef::table[-1];
     $table->add_cell('', $config);      $table->add_cell('', $config);
Line 3221  sub start_img { Line 3275  sub start_img {
    ['','bottom','middle','top','left','right'],$token,5);     ['','bottom','middle','top','left','right'],$token,5);
  $currentstring .=&Apache::edit::select_arg('TeXwrap:', 'TeXwrap',   $currentstring .=&Apache::edit::select_arg('TeXwrap:', 'TeXwrap',
    ['', 'none','parbox', 'parpic', 'wrapfigure'], $token, 2);     ['', 'none','parbox', 'parpic', 'wrapfigure'], $token, 2);
         my $alt=    &Apache::lonxml::get_param('alt',$parstack,$safeeval);  
         my $enc=    &Apache::lonxml::get_param('encrypturl',$parstack,$safeeval);  
   
  $currentstring .=&Apache::edit::select_arg('Encrypt URL:','encrypturl',   $currentstring .=&Apache::edit::select_arg('Encrypt URL:','encrypturl',
    ['no','yes'], $token, 2);     ['no','yes'], $token, 2);
         if (($alt=~/\S/) && (lc($enc) eq 'yes')) {  
            $currentstring.='<br /><span class="LC_warning">'.&mt('Warning: the description "[_1]" will be available, even for encrypted URL',$alt).'</span><br />';  
         }  
  $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();   $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  my $src=    &Apache::lonxml::get_param('src',$parstack,$safeeval);   my $src=    &Apache::lonxml::get_param('src',$parstack,$safeeval);
    my $alt=    &Apache::lonxml::get_param('alt',$parstack,$safeeval);
  my $width=  &Apache::lonxml::get_param('width',$parstack,$safeeval);   my $width=  &Apache::lonxml::get_param('width',$parstack,$safeeval);
  my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);   my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
   
         if ($token->[2]{'src'}=~/\$/) {          if ($token->[2]{'src'}=~/\$/) {
            $currentstring.=&mt('Variable image source');             $currentstring.='Variable image source';
         } elsif ($token->[2]{'src'}=~/\S/) {  
            $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';  
            if ($width) { $currentstring.=' width="'.$width.'" '; }  
            if ($height) { $currentstring.=' height="'.$height.'" '; }  
            $currentstring .= ' />';  
         } else {          } else {
            $currentstring.=&mt("No image source specified");     $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
      if ($width) { $currentstring.=' width="'.$width.'" '; }
      if ($height) { $currentstring.=' height="'.$height.'" '; }
      $currentstring .= ' />';
         }          }
     } elsif ($target eq 'modified') {      } elsif ($target eq 'modified') {
  my ($osrc,$owidth,$oheight)=   my ($osrc,$owidth,$oheight)=
Line 3312  sub start_applet { Line 3359  sub start_applet {
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {      if ($target eq 'web' || $target eq 'webgrade') {
  if ($env{'browser.appletsuppress'} ne 'on') {   if ($env{'browser.appletsuppress'} ne 'on') {
             $currentstring = $token->[4];      $currentstring = &Apache::lonenc::encrypt_ref($token,
     {'code'=>$code,
      'archive'=>$archive}
     );
  } else {   } else {
     my $alttag= &Apache::lonxml::get_param('alt',$parstack,      my $alttag= &Apache::lonxml::get_param('alt',$parstack,
    $safeeval,undef,1);     $safeeval,undef,1);
Line 3830  sub end_col { Line 3880  sub end_col {
   
 #-- <colgroup> tag (end tag optional)  #-- <colgroup> tag (end tag optional)
 sub start_colgroup {  sub start_colgroup {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {      if ($target eq 'web' || $target eq 'webgrade') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     }      } 
     if ($target eq 'tex') {  
         # TODO: Ensure this tag is in a table:  
   
         # Fetch the attributes and build the hash for the  
         # call to define_colgroup.  
   
         my $span    = &Apache::lonxml::get_param('span',   $parstack, $safeeval);  
         my $halign  = &Apache::lonxml::get_param('halign', $parstack, $safeeval);  
   
         my %colgroup_params;  
         if ($span ne '') {  
             $colgroup_params{'span'} = $span;  
         }  
         if ($halign ne '') {  
             $colgroup_params{'halign'} = $halign;  
         }  
   
         my $table = $Apache::londefdef::table[-1];  
         $table->define_colgroup(\%colgroup_params);  
   
     }  
     return $currentstring;      return $currentstring;
 }  }
   
Line 3868  sub end_colgroup { Line 3897  sub end_colgroup {
     return $currentstring;      return $currentstring;
 }  }
   
   
 #-- <del> tag (end tag required)  #-- <del> tag (end tag required)
 sub start_del {  sub start_del {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {      if ($target eq 'web' || $target eq 'webgrade') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
       } elsif ($target eq 'tex') {
    &disable_para();
    $currentstring .= '\st{';  
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 3882  sub end_del { Line 3915  sub end_del {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {      if ($target eq 'web' || $target eq 'webgrade') {
  $currentstring = $token->[2];       $currentstring = $token->[2];     
       } elsif ($target eq 'tex') {
    &enable_para();
    $currentstring = '}';
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 4341  sub start_tbody { Line 4377  sub start_tbody {
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {      if ($target eq 'web' || $target eq 'webgrade') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     }  
     if ($target eq 'tex') {  
         # TODO: Ensure this tag is within a table:  
   
         my $table = $Apache::londefdef::table[-1];  
         $table->start_body();  
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 4356  sub end_tbody { Line 4386  sub end_tbody {
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {      if ($target eq 'web' || $target eq 'webgrade') {
  $currentstring = $token->[2];       $currentstring = $token->[2];    
     }  
     if($target eq 'tex') {  
         # TODO: Ensure this tag is within a table:  
   
         my $table = $Apache::londefdef::table[-1];  
         $table->end_body();  
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 4372  sub start_tfoot { Line 4396  sub start_tfoot {
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {      if ($target eq 'web' || $target eq 'webgrade') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     }  
     if ($target eq 'tex') {  
         # TODO: ensure this is within a table tag.  
         my $table = $Apache::londefdef::table[-1];  
         $table->start_foot();  
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 4386  sub end_tfoot { Line 4405  sub end_tfoot {
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {      if ($target eq 'web' || $target eq 'webgrade') {
  $currentstring = $token->[2];       $currentstring = $token->[2];    
     }  
     if ($target eq 'tex') {  
         #  TODO: Ensure this is in side a table  
         my $table = $Apache::londefdef::table[-1];  
         $table->end_foot();  
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 4401  sub start_thead { Line 4415  sub start_thead {
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {      if ($target eq 'web' || $target eq 'webgrade') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     }  
     if ($target eq 'tex') {  
         # Assume we're in a table... TODO: Verify that and ignore tag if not.  
         my $table = $Apache::londefdef::table[-1];  
         $table->start_head();  
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 4415  sub end_thead { Line 4424  sub end_thead {
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {      if ($target eq 'web' || $target eq 'webgrade') {
  $currentstring = $token->[2];       $currentstring = $token->[2];    
     }  
     if ($target eq 'tex') {  
         # TODO: Verify we are in a table and ignore tag if not.  
   
         my $table = $Apache::londefdef::table[-1];  
         $table->end_head();  
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 4851  sub latex_header { Line 4854  sub latex_header {
  "\\usepackage{xcolor}\n".   "\\usepackage{xcolor}\n".
  '\usepackage{calc}'.   '\usepackage{calc}'.
  '\usepackage{amsmath}'.   '\usepackage{amsmath}'.
       '\usepackage{soul}',
  '\usepackage{amssymb}'.   '\usepackage{amssymb}'.
  '\usepackage{amsfonts}'.   '\usepackage{amsfonts}'.
  '\usepackage{amsthm}'.   '\usepackage{amsthm}'.

Removed from v.1.415.4.6  
changed lines
  Added in v.1.416


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