--- loncom/xml/londefdef.pm 2005/11/27 23:54:00 1.294 +++ loncom/xml/londefdef.pm 2005/12/05 23:22:49 1.300 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.294 2005/11/27 23:54:00 foxr Exp $ +# $Id: londefdef.pm,v 1.300 2005/12/05 23:22:49 foxr Exp $ # # # Copyright Michigan State University Board of Trustees @@ -48,7 +48,7 @@ use Apache::lonmenu(); use Apache::lonmeta(); use Apache::Constants qw(:common); use File::Basename; -use Data::Dumper; +#use Data::Dumper; BEGIN { @@ -61,16 +61,16 @@ BEGIN { # 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 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 { $Apache::londefdef::TD_redirection=0; @@ -145,10 +145,11 @@ sub end_m { } sub start_tthoption { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; my $result; if ($target eq 'web') { - my $inside = &Apache::lonxml::get_all_text("/tthoption",$parser); + my $inside = &Apache::lonxml::get_all_text("/tthoption",$parser, + $style); $inside=~s/^\s*//; if ($env{'browser.mathml'}) { &tth::ttmoptions($inside); @@ -385,13 +386,13 @@ sub end_title { #-- tag (end tag forbidden) sub start_meta { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; my $currentstring = ''; if ($target eq 'web') { my $args=''; if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; } if ($args eq '') { - &Apache::lonxml::get_all_text("/meta",$parser); + &Apache::lonxml::get_all_text("/meta",$parser,$style); } else { $currentstring = $token->[4]; } @@ -454,7 +455,7 @@ sub end_meta { # accessrule sub start_accessrule { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; my $currentstring = ''; my $eff=&Apache::lonxml::get_param ('effect',$parstack,$safeeval,undef,1); @@ -473,7 +474,7 @@ sub start_accessrule { my $args=''; if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; } if ($args eq '') { - &Apache::lonxml::get_all_text("/accessrule",$parser); + &Apache::lonxml::get_all_text("/accessrule",$parser,$style); } else { $currentstring = $token->[4]; } @@ -1987,9 +1988,7 @@ sub start_table { $Apache::londefdef::table[-1]{'content'}=[]; $Apache::londefdef::table[-1]{'align'}=[]; $currentstring.='\keephidden{NEW TABLE ENTRY}'; - &Apache::lonnet::logthis("------ start-table------"); - &debug_dump_table; - &Apache::lonnet::logthis("-------start-table------"); + } return $currentstring; @@ -2005,8 +2004,6 @@ sub end_table { my $output = ''; my $WARNING=''; #width of columns from TeXwidth attributes - &Apache::lonnet::logthis("----------------end_table-----------------"); - &debug_dump_table; for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) { for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) { @@ -2213,7 +2210,6 @@ sub end_table { $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut'.'\\\\'."\n".'\strut '; if ($#Apache::londefdef::table > 0) { my $inmemory = $Apache::londefdef::table[-1]{'output'}; - &Apache::lonnet::logthis("--- popping nested table --"); # 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 @@ -2222,20 +2218,17 @@ sub end_table { 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; - &Apache::lonnet::logthis("Nested min: $min_nested_width"); - &Apache::lonnet::logthis("Nested max: $max_nested_width"); my $outer_column = $Apache::londefdef::table[-2]{'counter_columns'}; my $outer_row = $Apache::londefdef::table[-2]{'row_number'}; - &Apache::lonnet::logthis("Outer row/column: $outer_row : $outer_column"); 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; } @@ -2250,9 +2243,6 @@ sub end_table { pop @Apache::londefdef::table; undef @Apache::londefdef::table; } - &debug_dump_table; - &Apache::lonnet::logthis("---------end table------"); - } return $currentstring; } @@ -2264,7 +2254,6 @@ sub start_tr { if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - &Apache::lonnet::logthis("--------------start-tr----------"); $Apache::londefdef::table[-1]{'row_number'}++; my $alignchar=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); if ($alignchar ne '') { @@ -2273,14 +2262,16 @@ sub start_tr { push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l'; } push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'}); + # + # Need to save the number of table columns to preserve the max # columns. + # + $Apache::londefdef::table[-1]{'prior_columns'} = $Apache::londefdef::table[-1]{'counter_columns'}; $Apache::londefdef::table[-1]{'counter_columns'} = -1; push @ {$Apache::londefdef::table[-1]{'TeXlen'}}, []; push @ {$Apache::londefdef::table[-1]{'objectlen'}}, []; push @ {$Apache::londefdef::table[-1]{'minlen'}}, []; push @ {$Apache::londefdef::table[-1]{'maxlen'}}, []; push @ {$Apache::londefdef::table[-1]{'content'}}, []; - &debug_dump_table; - &Apache::lonnet::logthis("------------start-tr-----------"); } return $currentstring; } @@ -2291,12 +2282,16 @@ sub end_tr { if ($target eq 'web') { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { - &Apache::lonnet::logthis("-------end-tr-----"); if ($Apache::londefdef::TD_redirection) { &end_td_tex($parstack,$parser,$safeeval); } - &debug_dump_table; - &Apache::lonnet::logthis("------end-tr------"); + # Counter columns must be the maximum number of columns seen + # in the table so far so: + if ($Apache::londefdef::table[-1]{'prior_columns'} > $Apache::londefdef::table[-1]{'counter_columns'}) { + $Apache::londefdef::table[-1]{'counter_columns'} = $Apache::londefdef::table[-1]{'prior_columns'}; + } + + } return $currentstring; @@ -2309,11 +2304,8 @@ sub start_td { if ($target eq 'web') { $currentstring = $token->[4]; } elsif ($target eq 'tex') { - &Apache::lonnet::logthis("------start-td----"); $Apache::londefdef::TD_redirection = 1; &tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval); - &debug_dump_table; - &Apache::lonnet::logthis("-----start-td-----"); } return $currentstring; } @@ -2433,8 +2425,11 @@ sub end_td_tex { 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] \&/; + for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) { + my $nested = $Apache::londefdef::table[-1]{'include'}[$in]; + $nested =~ s/\\end\{tabular\}\\strut\\\\/\\end\{tabular\}/; + # $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/; + $data =~ s/\\keephidden\{NEW TABLE ENTRY\}/$nested/; } push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data; return''; @@ -2446,11 +2441,8 @@ sub end_td { if ($target eq 'web') { $currentstring = $token->[2]; } elsif ($target eq 'tex') { - &Apache::lonnet::logthis("--------end_td-----"); $Apache::londefdef::TD_redirection =0; &end_td_tex($parstack,$parser,$safeeval); - &debug_dump_table; - &Apache::lonnet::logthis("--------end-td----"); } return $currentstring; } @@ -2596,11 +2588,11 @@ sub end_th { # (Note there seems to also be support for this as a % of page size) # sub start_img { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval, undef,1); if (not $src and ($target eq 'web' or $target eq 'tex')) { - my $inside = &Apache::lonxml::get_all_text("/img",$parser); + my $inside = &Apache::lonxml::get_all_text("/img",$parser,$style); return ''; } &Apache::lonxml::extlink($src);