Diff for /loncom/xml/londefdef.pm between versions 1.286 and 1.296

version 1.286, 2005/09/19 10:59:08 version 1.296, 2005/11/28 21:58:24
Line 48  use Apache::lonmenu(); Line 48  use Apache::lonmenu();
 use Apache::lonmeta();  use Apache::lonmeta();
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use File::Basename;  use File::Basename;
   #use Data::Dumper;
   
 BEGIN {  BEGIN {
   
Line 55  BEGIN { Line 56  BEGIN {
   
 }  }
   
   #
   #   Dumps all elements of the table structure.
   #   Need this 'cause evidently when given an array, Data::Dumper only seems
   #   to dump element 0.
   #
   sub debug_dump_table {
       my $lastrow = $#Apache::londefdef::table;
       &Apache::lonnet::logthis("Dumping table:  Last row index: $lastrow");
       my $row;
       for ($row =0; $row <= $lastrow; $row++ ) {
    my $text = Dumper($Apache::londefdef::table[$row]);
    &Apache::lonnet::logthis("table [ $row ]".$text);
   
       }
   }
   
 sub initialize_londefdef {  sub initialize_londefdef {
     $Apache::londefdef::TD_redirection=0;      $Apache::londefdef::TD_redirection=0;
     @Apache::londefdef::table = ();      @Apache::londefdef::table = ();
Line 109  sub start_m { Line 126  sub start_m {
  # detect simple math mode entry exits, and convert them   # detect simple math mode entry exits, and convert them
         # to use \ensuremath          # to use \ensuremath
  if ($currentstring=~/^\s*\$[^\$].*[^\$]\$\s*$/) {   if ($currentstring=~/^\s*\$[^\$].*[^\$]\$\s*$/) {
     $currentstring=~s/^\$//;      $currentstring=~s/^(\s*)\$/$1/;
     $currentstring=~s/\$$//;      $currentstring=~s/\$(\s*)$/$1/;
     $currentstring='\ensuremath{'.$currentstring.'}';      $currentstring='\ensuremath{'.$currentstring.'}';
  }   }
  $Apache::lonxml::post_evaluate=0;   $Apache::lonxml::post_evaluate=0;
Line 1206  sub start_br { Line 1223  sub start_br {
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  my @tempo=@$tagstack;   my @tempo=@$tagstack;
  my $signal=0;   my $signal=0;
    #  Not going to factor this to is_inside_of since that would require
           #  multiple stack traversals.
    #
  for (my $i=$#tempo;$i>=0;$i--) {   for (my $i=$#tempo;$i>=0;$i--) {
     if (($tempo[$i] eq 'b') || ($tempo[$i] eq 'strong') ||      if (($tempo[$i] eq 'b') || ($tempo[$i] eq 'strong') ||
                 ($tempo[$i] eq 'ol') || ($tempo[$i] eq 'ul') ||                  ($tempo[$i] eq 'ol') || ($tempo[$i] eq 'ul') ||
Line 1921  sub start_table { Line 1941  sub start_table {
  }   }
     }      }
  }   }
   
    # width either comes forced from the TeXwidth or the width parameters.
    # in either case it can be a percentage or absolute width.
   
  my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);   my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
  if (not defined $TeXwidth) {   if (not defined $TeXwidth) {
     my $htmlwidth = &Apache::lonxml::get_param('width',$parstack,$safeeval,undef,1);      $TeXwidth = &Apache::lonxml::get_param('width',$parstack,$safeeval,undef,1);
     if ($htmlwidth=~/%/) {  
                 $Apache::londefdef::table[-1]{'percent'}=1;   } else {
  $htmlwidth=~/(\d+)/;      $Apache::londefdef::table[-1]{'forcedtablewidth'} = 1;
  $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;;   }
     } else {   if ($TeXwidth=~/%/) {
  $Apache::londefdef::table[-1]{'width'}=$textwidth;  
     }  
  } elsif ($TeXwidth=~/%/) {  
     $Apache::londefdef::table[-1]{'percent'}=1;      $Apache::londefdef::table[-1]{'percent'}=1;
     $TeXwidth=~/(\d+)/;      $TeXwidth=~/(\d+)/;
             $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;              $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;
  } else {   } else {
     $Apache::londefdef::table[-1]{'forcetablewidth'}=1;  
     $Apache::londefdef::table[-1]{'width'}=$TeXwidth;      $Apache::londefdef::table[-1]{'width'}=$TeXwidth;
  }           }        
   
         #table's border          #table's border
  my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval);    my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval); 
         my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);          my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
Line 1966  sub start_table { Line 1987  sub start_table {
         $Apache::londefdef::table[-1]{'content'}=[];          $Apache::londefdef::table[-1]{'content'}=[];
         $Apache::londefdef::table[-1]{'align'}=[];          $Apache::londefdef::table[-1]{'align'}=[];
         $currentstring.='\keephidden{NEW TABLE ENTRY}';          $currentstring.='\keephidden{NEW TABLE ENTRY}';
    }  
   
       }
     return $currentstring;      return $currentstring;
 }  }
     
Line 1980  sub end_table { Line 2003  sub end_table {
  my $output = '';   my $output = '';
  my $WARNING='';   my $WARNING='';
         #width of columns from TeXwidth attributes          #width of columns from TeXwidth attributes
   
  for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {   for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
     for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {      for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
  if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]<$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn]) {   if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]<$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn]) {
Line 2164  sub end_table { Line 2188  sub end_table {
  for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {   for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
     for (my $jn=0;$jn<=$#fwidth;$jn++) {      for (my $jn=0;$jn<=$#fwidth;$jn++) {
  if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {   if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
     $output.='\vspace*{-6 mm}\begin{center}';      # $output.='\vspace*{-6 mm}\begin{center}';
       $output.='\begin{center}';
  } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {   } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
     $output.=' \hfill \llap{'      $output.=' \hfill \llap{'
  }   }
  $output.=$Apache::londefdef::table[-1]{'content'}[$in][$jn];   $output.=$Apache::londefdef::table[-1]{'content'}[$in][$jn];
  if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {   if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
     $output.='\end{center}\vspace*{-6 mm}';      # $output.='\end{center}\vspace*{-6 mm}';
       $output.='\end{center}';
  } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {   } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
     $output.='} ';      $output.='} ';
  }   }
Line 2183  sub end_table { Line 2209  sub end_table {
  $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut'.'\\\\'."\n".'\strut ';   $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut'.'\\\\'."\n".'\strut ';
  if ($#Apache::londefdef::table > 0) {       if ($#Apache::londefdef::table > 0) {    
     my $inmemory = $Apache::londefdef::table[-1]{'output'};      my $inmemory = $Apache::londefdef::table[-1]{'output'};
       # Figure out max/and min width  by summing us and then
       # apply that to the current column of the table we nest in
       # if it's larger than the current width or the current width
       # is undefined.
       #
       my $min_nested_width = 0;
       my $max_nested_width = 0;
       for (my $col = 0; $col <= $Apache::londefdef::table[-1]{'counter_columns'}; $col++) {
   
    $min_nested_width +=  $min_len[$col];
    $max_nested_width +=  $max_len[$col];
       }
       # Fudge in an extra 5 mm for borders etc:
       
       $min_nested_width += 5;
       $max_nested_width += 5;
   
       my $outer_column = $Apache::londefdef::table[-2]{'counter_columns'};
       my $outer_row    = $Apache::londefdef::table[-2]{'row_number'};
       if ($min_nested_width > $Apache::londefdef::table[-2]{'minlen'}[$outer_row][$outer_column]) {
    $Apache::londefdef::table[-2]{'minlen'}[$outer_row][$outer_column] = $min_nested_width;
       }
       if ($max_nested_width > $Apache::londefdef::table[-2]{'maxlen'}[$outer_row][$outer_column]) {
    $Apache::londefdef::table[-2]{'maxlen'}[$outer_row][$outer_column] = $max_nested_width;
       }
   
     pop @Apache::londefdef::table;      pop @Apache::londefdef::table;
     push @{$Apache::londefdef::table[-1]{'include'}}, $inmemory;      push @{$Apache::londefdef::table[-1]{'include'}}, $inmemory;
  } else {   } else {
Line 2228  sub end_tr { Line 2280  sub end_tr {
  if ($Apache::londefdef::TD_redirection) {   if ($Apache::londefdef::TD_redirection) {
     &end_td_tex($parstack,$parser,$safeeval);          &end_td_tex($parstack,$parser,$safeeval);    
  }   }
   
   
   
     }      }
     return $currentstring;      return $currentstring;
 }  }
Line 2361  sub end_td_tex { Line 2416  sub end_td_tex {
  }           }        
     }      }
  for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {            for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {         
     $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;      $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in] \&/;
  }   }
     push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;      push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
     return'';      return'';
Line 2527  sub start_img { Line 2582  sub start_img {
  my $inside = &Apache::lonxml::get_all_text("/img",$parser);   my $inside = &Apache::lonxml::get_all_text("/img",$parser);
  return '';   return '';
     }      }
     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;      &Apache::lonxml::extlink($src);
     my $currentstring = '';      my $currentstring = '';
     my $scaling = .3;      my $scaling = .3;
   
Line 2560  sub start_img { Line 2615  sub start_img {
   $safeeval,    $safeeval,
   undef,1));    undef,1));
  if(!$align) {   if(!$align) {
     $align = "bottom"; # This is html's default so it's ours too.      if (&is_inside_of($tagstack, "table")) {
    $align = "right";      # Force wraptext use. 
       } else {
    $align = "bottom"; # This is html's default so it's ours too.
       }
  }   }
  #   #
  &Apache::lonxml::debug("Alignemnt = $align");   &Apache::lonxml::debug("Alignemnt = $align");
Line 2577  sub start_img { Line 2636  sub start_img {
     undef,0);      undef,0);
  &Apache::lonxml::debug("LaTeX rendering = $latex_rendering");   &Apache::lonxml::debug("LaTeX rendering = $latex_rendering");
  if(!$latex_rendering) {   if(!$latex_rendering) {
     $latex_rendering = "parbox";      $latex_rendering = "texwrap";
  }   }
  &Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src");   &Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src");
   
Line 2733  sub start_applet { Line 2792  sub start_applet {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
           
     my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,undef,1);      my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,undef,1);
     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$code;      &Apache::lonxml::extlink($code);
       
     my $archive=&Apache::lonxml::get_param('archive',$parstack,$safeeval,      my $archive=&Apache::lonxml::get_param('archive',$parstack,$safeeval,
    undef,1);     undef,1);
     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$archive;      &Apache::lonxml::extlink($archive);
       
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  if ($env{'browser.appletsuppress'} ne 'on') {   if ($env{'browser.appletsuppress'} ne 'on') {
Line 2784  sub end_applet { Line 2841  sub end_applet {
 sub start_embed {      sub start_embed {    
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);      my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;      &Apache::lonxml::extlink($src);
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  if ($env{'browser.embedsuppress'} ne 'on') {   if ($env{'browser.embedsuppress'} ne 'on') {
Line 2815  sub end_embed { Line 2872  sub end_embed {
 #-- <param> tag (end tag forbidden)  #-- <param> tag (end tag forbidden)
 sub start_param {  sub start_param {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     if (&Apache::lonxml::get_param      if (&Apache::lonxml::get_param('name',$parstack,
  ('name',$parstack,$safeeval,undef,1)=~/^cabbase$/i) {     $safeeval,undef,1)=~/^cabbase$/i) {
  $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=   my $value=&Apache::lonxml::get_param('value',$parstack,
     &Apache::lonxml::get_param('value',$parstack,$safeeval,undef,1);       $safeeval,undef,1);
     }      &Apache::lonxml::extlink($value);
     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=         } 
  &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);    
       my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
       &Apache::lonxml::extlink($src);
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  my %toconvert;   my %toconvert;
Line 2853  sub end_param { Line 2912  sub end_param {
 sub start_allow {  sub start_allow {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);      my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
     $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);      &Apache::lonxml::extlink($src);
     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=  
  &Apache::lonnet::clutter($src);  
     if ($target eq 'tex') { &image_replication($src); }      if ($target eq 'tex') { &image_replication($src); }
     my $result;      my $result;
     if ($target eq 'edit') {      if ($target eq 'edit') {
Line 3449  sub end_legend { Line 3507  sub end_legend {
   
 #-- <link> tag (end tag forbidden)  #-- <link> tag (end tag forbidden)
 sub start_link {  sub start_link {
     my ($target,$token) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
    my $href=&Apache::lonxml::get_param('href',$parstack,$safeeval,
       undef,1);
    &Apache::lonxml::extlink($href);
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     }       } 
     return $currentstring;      return $currentstring;
Line 4046  sub file_path { Line 4107  sub file_path {
     }       } 
     return $file,$path;      return $file,$path;
 }  }
   #  Converts a measurement in to mm from any of 
   #  the other valid LaTeX units of measure.
   #  If the units of measure are missing from the 
   #  parameter, it is assumed to be in and returned
   #  with mm units of measure
 sub recalc {  sub recalc {
     my $argument = shift;      my $argument = shift;
     if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}      if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}
Line 4091  sub LATEX_length { Line 4156  sub LATEX_length {
 }  }
   
   
   # is_inside_of $tagstack $tag
   #    This sub returns true if the current state of Xml processing
   #    is inside of the tag.   
   # Parameters:
   #     tagstack   - The tagstack from the parser.
   #     tag        - The tag (without the <>'s.).
   # Sample usage:
   #     if (is_inside_of($tagstack "table")) {
   #          # I'm in a table....
   #      }
   sub is_inside_of {
       my ($tagstack, $tag) = @_;
       my @stack = @$tagstack;
       for (my $i = ($#stack - 1); $i >= 0; $i--) {
    if ($stack[$i] eq $tag) {
       return 1;
    }
       }
       return 0;
   }
   
   
 1;  1;

Removed from v.1.286  
changed lines
  Added in v.1.296


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