--- loncom/xml/londefdef.pm 2006/01/09 22:53:25 1.311 +++ loncom/xml/londefdef.pm 2006/02/05 18:32:40 1.319 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.311 2006/01/09 22:53:25 albertel Exp $ +# $Id: londefdef.pm,v 1.319 2006/02/05 18:32:40 albertel Exp $ # # # Copyright Michigan State University Board of Trustees @@ -105,11 +105,21 @@ sub start_m { $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]); #&Apache::lonxml::debug("M is evaulated to:$inside:"); } + my $tex = $inside; my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval); $currentstring = &Apache::lontexconvert::converted(\$inside,$display); if ($Apache::lontexconvert::errorstring) { - &Apache::lonxml::warning("tth error: ". - $Apache::lontexconvert::errorstring); + my $errormsg='
'.&HTML::Entities::encode($Apache::lontexconvert::errorstring,'<>&"').'
occured while attempting to convert this TeX:
';
+	    $tex = &HTML::Entities::encode($tex,'<>&"');
+	    my ($linenumber) =
+		($Apache::lontexconvert::errorstring =~ /Line (\d+)/);
+	    if (defined($linenumber)) {
+		my @tex=split("\n",$tex);
+		$tex[$linenumber]=''.
+		    $tex[$linenumber].'';
+		$tex=join("\n",@tex);
+	    }
+	    &Apache::lonxml::warning($errormsg.$tex.'
'); $Apache::lontexconvert::errorstring=''; } #&Apache::lonxml::debug("M is ends with:$currentstring:"); @@ -619,9 +629,6 @@ sub end_center { $currentstring = $token->[2]; } elsif ($target eq 'tex') { $currentstring = '\end{center}'; - if (&is_inside_of($tagstack, "table")) { - $currentstring .= ¢er_correction(); - } } return $currentstring; } @@ -1187,6 +1194,7 @@ sub start_p { $closing_string = '

'; # Deal correctly with

e.g. } } elsif ($target eq 'tex' && !$para_disabled) { + $currentstring .= &end_p(); # close off prior para if in progress. my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); if ($align eq 'center') { @@ -1194,7 +1202,6 @@ sub start_p { $closing_string = '\end{center}'; if (&is_inside_of($tagstack, "table")) { $currentstring = ¢er_correction().$currentstring; - $closing_string .= ¢er_correction(); } } elsif ($align eq 'right') { $currentstring.='\makebox['.$env{'form.textwidth'}.']{\hfill\llap{'; @@ -1204,7 +1211,11 @@ sub start_p { $closing_string = '}\hfill}'; } else { $currentstring.='\par '; - $closing_string = '\strut\\\\\strut '; + if (&is_inside_of($tagstack, 'table')) { + $closing_string = '\vskip 0pt'; # Seems to be consistent with

in tables. + } else { + $closing_string = '\strut\\\\\strut '; + } } } @@ -1539,7 +1550,6 @@ sub start_div { $endstring = '\end{center}'; if (&is_inside_of($tagstack, "table")) { $currentstring = ¢er_correction().$currentstring; - $endstring .= ¢er_correction(); } } elsif ($align eq 'right') { @@ -1980,7 +1990,12 @@ sub start_table { $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); @@ -2239,7 +2254,7 @@ sub end_table { } $output.=$Apache::londefdef::table[-1]{'content'}[$in][$jn]; if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') { - $output.='\end{center}'.¢er_correction(); + $output.='\end{center}'; } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') { $output.='} '; } @@ -2765,12 +2780,7 @@ sub start_img { $safeeval, undef,1)); if(!$align) { - # disabled for now see BUG#4535 - if (0 && &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"); @@ -2785,11 +2795,17 @@ sub start_img { $parstack, $safeeval, undef,0); - &Apache::lonxml::debug("LaTeX rendering = $latex_rendering"); + # &Apache::lonxml::debug("LaTeX rendering = $latex_rendering"); if(!$latex_rendering) { - $latex_rendering = "texwrap"; + $latex_rendering = "texwrap"; + } + # using texwrap inside a table does not work. So, if after all of this, + # texwrap is on, we turn it off if we detect we're in a table: + # + if (($latex_rendering eq 'texwrap') && &is_inside_of($tagstack, "table")) { + $latex_rendering = 'parpic'; } - &Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src"); + # &Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src"); #if original gif/jpg/png file exist do following: my $origsrc=$src; @@ -3163,6 +3179,7 @@ sub start_pre { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= '\begin{verbatim}'; + &Apache::lonxml::disable_LaTeX_substitutions(); } return $currentstring; } @@ -3174,6 +3191,7 @@ sub end_pre { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= '\end{verbatim}'; + &Apache::lonxml::enable_LaTeX_substitutions(); } return $currentstring; }