--- loncom/xml/londefdef.pm 2003/09/02 21:31:11 1.158.4.6 +++ loncom/xml/londefdef.pm 2003/08/07 20:12:40 1.159 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.158.4.6 2003/09/02 21:31:11 albertel Exp $ +# $Id: londefdef.pm,v 1.159 2003/08/07 20:12:40 sakharuk Exp $ # # # Copyright Michigan State University Board of Trustees @@ -319,7 +319,7 @@ sub start_title { if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - $currentstring .= '\keephidden{Title of the document: ' + $currentstring .= '\keephidden{' } if ($target eq 'meta') { $currentstring=''; @@ -394,7 +394,7 @@ sub start_meta { } sub end_meta { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$parser) = @_; my $currentstring = ''; if ($target eq 'web') { my $args=''; @@ -403,11 +403,8 @@ sub end_meta { $currentstring = $token->[4]; } } elsif ($target eq 'tex') { - my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval); - my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval); - if ((not defined $content) && (not defined $name)) { - &Apache::lonxml::endredirection(); - } + $currentstring=&Apache::lonxml::endredirection(); + $currentstring=''; } return $currentstring; } @@ -462,10 +459,6 @@ sub start_body { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { - if ($Apache::lonhomework::parsing_a_problem) { - &Apache::lonxml::warning("<body> tag found inside of <problem> tag this can cause problems."); - return ''; - } if (!$Apache::lonxml::registered) { $currentstring.='<head>'. &Apache::lonmenu::registerurl(undef,$target).'</head>'; @@ -1414,7 +1407,7 @@ sub start_a { } sub end_a { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring .= $token->[2]; @@ -1424,7 +1417,7 @@ sub end_a { #-- <li> tag sub start_li { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { $currentstring = $token->[4]; @@ -1788,7 +1781,7 @@ sub end_table { $needed=$#length_row_final-$needed+1; for (my $jn=0;$jn<=$#length_row_final;$jn++) { if ($length_row_final[$jn]==0) { - if ($length_raw_row[$jn]<$available_length) { + if ($length_raw_row[$jn]<$available_length/3) { $length_row_final[$jn]=$length_raw_row[$jn]; $available_length=$available_length-$length_raw_row[$jn]; $needed--; @@ -1824,7 +1817,7 @@ sub end_table { return $currentstring; } -#-- <tr> tag (end tag optional) +#-- <tr> tag sub start_tr { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -1858,76 +1851,102 @@ sub end_tr { return $currentstring; } -#-- <td> tag (end tag optional) +#-- <td> tag sub start_td { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; 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(); + &tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval); +# my @ar=@$parstack; +# for (my $i=$#ar-1;$i>=0;$i--) { +# if (lc($$tagstack[$i]) eq 'tr') { +# &start_td_tex($parstack,$parser,$safeeval); +# last; +# } elsif (lc($$tagstack[$i]) eq 'td') { +# splice @ar, $i+1; +# &end_td_tex(\@ar,$parser,$safeeval); +# &start_td_tex($parstack,$parser,$safeeval); +# last; +# } +# } } return $currentstring; } - + +sub tag_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_td_tex($parstack,$parser,$safeeval); + last; + } elsif (lc($$tagstack[$i]) eq $bad_tag) { + splice @ar, $i+1; + &end_td_tex(\@ar,$parser,$safeeval); + &start_td_tex($parstack,$parser,$safeeval); + last; + } + } + return ''; +} + +sub start_td_tex { + my ($parstack,$parser,$safeeval) = @_; + 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(); + return ''; +} + +sub end_td_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) { + 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+\.?\d*)/; + $Apache::londefdef::table[-1]{'TeXlength'} .= $1.','; + $Apache::londefdef::table[-1]{'length'} .= '0,'; + } else { + $data=~s/^\s+(\S.*)/$1/; + $data=~s/(.*\S)\s+$/$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]/; + } + @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'}; + return''; +} + sub end_td { 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+\.?\d*)/; - $Apache::londefdef::table[-1]{'TeXlength'} .= $1.','; - $Apache::londefdef::table[-1]{'length'} .= '0,'; - } else { - $data=~s/^\s+(\S.*)/$1/; - $data=~s/(.*\S)\s+$/$1/; - $data=~s/(\s)+/$1/; - my $current_length=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) { - $elementdata=~s/^\s+(\S.*)/$1/; - $elementdata=~s/(.*\S)\s+$/$1/; - $elementdata=~s/(\s)+/$1/; - my $lengthnewdata=1.8*length($elementdata); - if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;} - } - } else { - $current_length=1.8*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]/; - } - @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'}; + &end_td_tex($parstack,$parser,$safeeval); } return $currentstring; } -#-- <th> tag (end tag optional) +#-- <th> tag sub start_th { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; @@ -3058,7 +3077,7 @@ sub end_tbody { return $currentstring; } -#-- <tfoot> tag (end tag optional) +#-- <tfoot> tag sub start_tfoot { my ($target,$token) = @_; my $currentstring = ''; @@ -3077,7 +3096,7 @@ sub end_tfoot { return $currentstring; } -#-- <thead> tag (end tag optional) +#-- <thead> tag sub start_thead { my ($target,$token) = @_; my $currentstring = '';