[LON-CAPA-cvs] cvs: loncom /xml londefdef.pm

sakharuk lon-capa-cvs@mail.lon-capa.org
Thu, 15 Jul 2004 17:05:21 -0000


This is a MIME encoded message

--sakharuk1089911121
Content-Type: text/plain

sakharuk		Thu Jul 15 13:05:21 2004 EDT

  Modified files:              
    /loncom/xml	londefdef.pm 
  Log:
  Bug 3198 (<th>no workie) is fixed.
  
  
--sakharuk1089911121
Content-Type: text/plain
Content-Disposition: attachment; filename="sakharuk-20040715130521.txt"

Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.229 loncom/xml/londefdef.pm:1.230
--- loncom/xml/londefdef.pm:1.229	Thu Jul 15 11:13:52 2004
+++ loncom/xml/londefdef.pm	Thu Jul 15 13:05:20 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.229 2004/07/15 15:13:52 sakharuk Exp $
+# $Id: londefdef.pm,v 1.230 2004/07/15 17:05:20 sakharuk Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -1156,7 +1156,8 @@
 	my $signal=0;
 	for (my $i=$#tempo;$i>=0;$i--) {
 	    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') ||
+                ($tempo[$i] eq 'td') || ($tempo[$i] eq 'th'))  {
 		$signal=1;
 		last;
 	    }
@@ -2250,55 +2251,128 @@
     if ($target eq 'web') {
 	$currentstring = $token->[4];     
     } elsif ($target eq 'tex') {
-	my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
-	if ($what_to_push eq '') {
-	    $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);;
-	}
-	push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push;
-	$Apache::londefdef::table[-1]{'counter_columns'}++;
-	&Apache::lonxml::startredirection();
+	$Apache::londefdef::TD_redirection = 1;
+	&tagg_check('tr','th',$tagstack,$parstack,$parser,$safeeval);
     } 
     return $currentstring;
 }   
-     
+    
+sub tagg_check {
+    my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
+    my @ar=@$parstack; 
+    for (my $i=$#ar-1;$i>=0;$i--) {
+	if (lc($$tagstack[$i]) eq $good_tag) {
+	    &start_th_tex($parstack,$parser,$safeeval);
+	    last;
+	} elsif (lc($$tagstack[$i]) eq $bad_tag) {
+	    splice @ar, $i+1;
+	    &end_th_tex(\@ar,$parser,$safeeval);
+	    &start_th_tex($parstack,$parser,$safeeval);
+	    last;
+	}
+    }
+    return '';
+}
+ 
+sub start_th_tex {
+    my ($parstack,$parser,$safeeval) = @_;
+    my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
+    if ($alignchar eq '') {
+	$alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
+    }
+    push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
+    $Apache::londefdef::table[-1]{'counter_columns'}++;
+    my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
+    if (defined $TeXwidth) {		
+	my $current_length=&recalc($TeXwidth);
+	$current_length=~/(\d+\.?\d*)/;
+	push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
+    }
+    &Apache::lonxml::startredirection();
+    return '';
+}
+
+sub end_th_tex {
+    my ($parstack,$parser,$safeeval) = @_;
+    my $current_row = $Apache::londefdef::table[-1]{'row_number'};
+    my $data=&Apache::lonxml::endredirection();
+    my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
+    if (defined $TeXwidth) {		
+	push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
+	push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
+	push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
+    } else {
+	if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
+	    my $garbage_data=$data;
+	    my $fwidth=0;
+            while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
+		my $current_length=&recalc($1);
+		$current_length=~/(\d+\.?\d*)/;
+		if ($fwidth<$1) {$fwidth=$1;}
+		$garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
+	    }
+            while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
+		my $current_length=$1;
+		if ($fwidth<$current_length) {$fwidth=$current_length;}
+		$garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
+	    }
+	    push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
+	    push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
+	    push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
+	    push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
+	} else {  
+	    $data=~s/^\s+(\S.*)/$1/; 
+	    $data=~s/(.*\S)\s+$/$1/;
+	    $data=~s/(\s)+/$1/;
+	    my ($current_length,$min_length)=(0,0);
+	    if ($data=~/\\vskip/) {
+                my $newdata=$data;
+		$newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
+		my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
+		foreach my $elementdata (@newdata) {
+		    my $lengthnewdata=2.5*&LATEX_length($elementdata);
+		    if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
+                    my @words=split(/ /,$elementdata);
+		    foreach my $word (@words) {
+			my $lengthword=2.5*&LATEX_length($word);
+			if ($min_length<$lengthword) {$min_length=$lengthword;}
+		    }
+		}
+	    } else {
+		$current_length=2.5*&LATEX_length($data);
+                    my @words=split(/ /,$data);
+		    foreach my $word (@words) {
+			my $lengthword=2*&LATEX_length($word);
+			if ($min_length<$lengthword) {$min_length=$lengthword;}
+		    }
+	    }
+	    push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
+	    push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
+	    push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
+	    push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
+	}        
+    }
+	for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {         
+	    $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
+	}
+    #make data bold
+    $data='\textbf{'.$data.'}';
+    push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
+    return'';
+}
+
 sub end_th {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';
     if ($target eq 'web') {
 	$currentstring = $token->[2];     
     } elsif ($target eq 'tex') {
-	my $current_row = $Apache::londefdef::table[-1]{'row_number'};
-	my $data=&Apache::lonxml::endredirection();
-	my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
-	if (defined $TeXwidth) {		
-	    my $current_length=&recalc($TeXwidth);
-	    $current_length=~/(\d+)/;
-	    $Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
-	    $Apache::londefdef::table[-1]{'length'} .= '0,';
-	} else {
-	    if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
-		my $current_length=&recalc($1);
-		$current_length=~/(\d+)/;
-		$Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
-		$Apache::londefdef::table[-1]{'length'} .= '0,';
-	    } else {     
-		$data=~/^\s*(\S.*)/;
-		$data=$1;
-		$data=~/(.*\S)\s*$/;
-		$data=$1;
-		my $current_length=2*length($data);
-		$Apache::londefdef::table[-1]{'length'} .= $current_length.',';
-		$Apache::londefdef::table[-1]{'TeXlength'} .= '0,';
-	    }        
-	}
-	for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {                                
-	    $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
-	}
-	$data='\textbf{'.$data.'}';
-	@{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'};
+        $Apache::londefdef::TD_redirection =0;
+	&end_th_tex($parstack,$parser,$safeeval);
     }
     return $currentstring;
 }
+     
 #-- <img> tag (end tag forbidden)
 sub start_img {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;

--sakharuk1089911121--