--- loncom/xml/londefdef.pm 2005/07/10 21:43:35 1.278 +++ loncom/xml/londefdef.pm 2005/11/29 00:08:10 1.298 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.278 2005/07/10 21:43:35 www Exp $ +# $Id: londefdef.pm,v 1.298 2005/11/29 00:08:10 foxr Exp $ # # # Copyright Michigan State University Board of Trustees @@ -47,7 +47,8 @@ use Image::Magick; use Apache::lonmenu(); use Apache::lonmeta(); use Apache::Constants qw(:common); - +use File::Basename; +#use Data::Dumper; BEGIN { @@ -55,6 +56,22 @@ BEGIN { } +# +# Dumps all elements of the table structure. +# 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 initialize_londefdef { $Apache::londefdef::TD_redirection=0; @Apache::londefdef::table = (); @@ -109,8 +126,8 @@ sub start_m { # detect simple math mode entry exits, and convert them # to use \ensuremath if ($currentstring=~/^\s*\$[^\$].*[^\$]\$\s*$/) { - $currentstring=~s/^\$//; - $currentstring=~s/\$$//; + $currentstring=~s/^(\s*)\$/$1/; + $currentstring=~s/\$(\s*)$/$1/; $currentstring='\ensuremath{'.$currentstring.'}'; } $Apache::lonxml::post_evaluate=0; @@ -166,6 +183,7 @@ sub start_html { '\usepackage{textcomp}'. '\usepackage{makeidx}'. '\usepackage[dvips]{graphicx}'. + '\usepackage{wrapfig}'. '\usepackage{picins}'. '\usepackage{epsfig}'. '\usepackage{calc}'. @@ -540,6 +558,10 @@ sub start_body { $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"'; } $currentstring.='>'; + &Apache::lontexconvert::jsMath_reset(); + if ($env{'environment.texengine'} eq 'jsMath') { + $currentstring.=&Apache::lontexconvert::jsMath_header(); + } if ($env{'request.state'} ne 'published') { if ($env{'environment.remote'} eq 'off') { $currentstring.= @@ -563,7 +585,7 @@ EDITBUTTON sub end_body { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = &end_p; # Close off unclosed
+ my $currentstring = &end_p(); # Close off unclosed
if ($target eq 'web') { $currentstring .= &Apache::lonxml::xmlend($target,$parser); } elsif ($target eq 'tex') { @@ -575,7 +597,7 @@ sub end_body { #--
sub start_b {
my ($target,$token) = @_;
my $currentstring = '';
if ($target eq 'web') {
$currentstring = $token->[4];
} elsif ($target eq 'tex') {
- $currentstring = '\textbf{';
+ &disable_para();
+ $currentstring .= '\textbf{';
}
return $currentstring;
}
@@ -613,18 +637,21 @@ sub end_b {
if ($target eq 'web') {
$currentstring = $token->[2];
} elsif ($target eq 'tex') {
- $currentstring = '}';
+ &enable_para();
+ $currentstring = '}';
}
return $currentstring;
}
#-- tag (end tag required)
+# NOTE: in TeX mode disables internal
sub start_strong {
my ($target,$token) = @_;
my $currentstring = '';
if ($target eq 'web') {
$currentstring = $token->[4];
} elsif ($target eq 'tex') {
+ &disable_para();
$currentstring = '\textbf{';
}
return $currentstring;
@@ -636,6 +663,7 @@ sub end_strong {
if ($target eq 'web') {
$currentstring = $token->[2];
} elsif ($target eq 'tex') {
+ &enable_para();
$currentstring = '}';
}
return $currentstring;
@@ -644,7 +672,7 @@ sub end_strong {
#--
+# Some tags are fragile meaning that inside of them
+# does not work within TeX mode. This is managed via the
+# counter below:
+#
+
+ my $para_disabled = 0;
+
+sub disable_para {
+ $para_disabled++;
+}
+sub enable_para {
+ $para_disabled--;
+}
+
+
#-- tag (end tag optional)
#optional attribute - align="center|left|right"
sub start_p {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = &end_p; # close off prior para if in progress.
+ my $currentstring = '';
if ($target eq 'web') {
+ $currentstring .= &end_p(); # close off prior para if in progress.
$currentstring .= $token->[4];
- $closing_string = ' tag (end tag required)
sub start_h1 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = &end_p; # Close off any prior para.
+ my $currentstring = &end_p(); # Close off any prior para.
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
@@ -693,7 +721,7 @@ sub end_h1 {
#--
tag
sub start_h2 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = &end_p; # Close off any prior para.
+ my $currentstring = &end_p(); # Close off any prior para.
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
@@ -736,7 +764,7 @@ sub end_h2 {
#--
tag
sub start_h3 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = &end_p; # Close off any prior para.
+ my $currentstring = &end_p(); # Close off any prior para.
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
@@ -779,7 +807,7 @@ sub end_h3 {
#--
tag
sub start_h4 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = &end_p; # Close off any prior para.
+ my $currentstring = &end_p(); # Close off any prior para.
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
@@ -822,7 +850,7 @@ sub end_h4 {
#--
tag
sub start_h5 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = &end_p; # Close off any prior paras.
+ my $currentstring = &end_p(); # Close off any prior paras.
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
@@ -865,7 +893,7 @@ sub end_h5 {
#--
tag
sub start_h6 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = &end_p; # Close off any prior paras.
+ my $currentstring = &end_p(); # Close off any prior paras.
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
@@ -1123,15 +1151,34 @@ sub end_q {
my $closing_string = ''; # String required to close
does not work inside ... - foreach my $tag (@$tagstack) { - if (lc($tag) eq 'b') { - $signal=0; - } - } - if (!$signal) { - $currentstring = &end_p; # Just close the prior? Not sure this is correct - $closing_string = ''; # Probably correct? - } } return $currentstring; @@ -1164,9 +1201,16 @@ sub start_p { # End paragraph processing just requires that we output the # closing string that was saved and blank it. sub end_p { - my $current_string = $closing_string; - $closing_string = ''; # Not in a para anymore. - return $current_string; + # Note only 'tex' mode uses disable_para and enable_para + # so we don't need to know the target in the check below: + + if (!$para_disabled) { + my $current_string = $closing_string; + $closing_string = ''; # Not in a para anymore. + return $current_string; + } else { + return ''; + } } } @@ -1179,6 +1223,9 @@ sub start_br { } elsif ($target eq 'tex') { my @tempo=@$tagstack; my $signal=0; + # Not going to factor this to is_inside_of since that would require + # multiple stack traversals. + # for (my $i=$#tempo;$i>=0;$i--) { if (($tempo[$i] eq 'b') || ($tempo[$i] eq 'strong') || ($tempo[$i] eq 'ol') || ($tempo[$i] eq 'ul') || @@ -1415,7 +1462,7 @@ sub end_sup { #--