--- loncom/xml/lonxml.pm 2005/12/08 19:37:05 1.393 +++ loncom/xml/lonxml.pm 2006/03/08 21:49:26 1.398 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.393 2005/12/08 19:37:05 albertel Exp $ +# $Id: lonxml.pm,v 1.398 2006/03/08 21:49:26 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -149,6 +149,19 @@ $Apache::lonxml::post_evaluate=1; #a header message to emit in the case of any generated warning or errors $Apache::lonxml::warnings_error_header=''; +# Control whether or not LaTeX symbols should be substituted for their +# \ style equivalents...this may be turned off e.g. in an verbatim +# environment. + +$Apache::lonxml::substitute_LaTeX_symbols = 1; # Starts out on. + +sub enable_LaTeX_substitutions { + $Apache::lonxml::substitute_LaTeX_symbols = 1; +} +sub disable_LaTeX_substitutions { + $Apache::lonxml::substitute_LaTeX_symbols = 0; +} + sub xmlbegin { my ($style)=@_; my $output=''; @@ -364,7 +377,7 @@ sub xmlparse { &initdepth(); &init_alarm(); my $finaloutput = &inner_xmlparse($target,\@stack,\@parstack,\@pars, - $safeeval,\%style_for_target); + $safeeval,\%style_for_target,1); if ($env{'request.uri'}) { &writeallows($env{'request.uri'}); @@ -382,6 +395,13 @@ sub xmlparse { sub latex_special_symbols { my ($string,$where)=@_; + # + # If e.g. in verbatim mode, then don't substitute. + # but return original string. + # + if (!($Apache::lonxml::substitute_LaTeX_symbols)) { + return $string; + } if ($where eq 'header') { $string =~ s/(\\|_|\^)/ /g; $string =~ s/(\$|%|\{|\})/\\$1/g; @@ -411,7 +431,7 @@ sub latex_special_symbols { } sub inner_xmlparse { - my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_; + my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target,$start)=@_; my $finaloutput = ''; my $result; my $token; @@ -526,7 +546,7 @@ sub inner_xmlparse { # $finaloutput.=&endredirection; # } - if ($target eq 'grade') { &endredirection(); } + if ( $start && $target eq 'grade') { &endredirection(); } if ( $Apache::lonxml::redirection > $startredirection) { while ($Apache::lonxml::redirection > $startredirection) { $finaloutput .= &endredirection(); @@ -629,6 +649,7 @@ sub setup_globals { @Apache::lonxml::ssi_info=(); $Apache::lonxml::post_evaluate=1; $Apache::lonxml::warnings_error_header=''; + $Apache::lonxml::substitute_LaTeX_symbols = 1; if ($target eq 'meta') { $Apache::lonxml::redirection = 0; $Apache::lonxml::metamode = 1; @@ -1010,6 +1031,28 @@ sub store_counter { return ''; } +{ + my $state; + sub clear_problem_counter { + &Apache::lonnet::logthis(" cpc called from ".(join(':',caller(0)))); + undef($state); + &Apache::lonnet::delenv('form.counter'); + &Apache::lonxml::init_counter(); + &Apache::lonxml::store_counter(); + } + + sub remember_problem_counter { + &Apache::lonnet::transfer_profile_to_env(); + $state = $env{'form.counter'}; + } + + sub restore_problem_counter { + if (defined($state)) { + &Apache::lonnet::appenv(('form.counter' => $state)); + } + } +} + sub get_all_text { my($tag,$pars,$style)= @_; my $gotfullstack=1; @@ -1437,7 +1480,7 @@ ENDNOTFOUND undef($Apache::lonhomework::parsing_a_task); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['rawmode']); - if ($env{'rawmode'}) { $result = $filecontents; } + if ($env{'form.rawmode'}) { $result = $filecontents; } } }