--- loncom/xml/londefdef.pm 2007/03/13 13:35:39 1.358
+++ loncom/xml/londefdef.pm 2007/04/06 10:23:46 1.362
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Tags Default Definition Module
#
-# $Id: londefdef.pm,v 1.358 2007/03/13 13:35:39 foxr Exp $
+# $Id: londefdef.pm,v 1.362 2007/04/06 10:23:46 foxr Exp $
#
#
# Copyright Michigan State University Board of Trustees
@@ -128,6 +128,7 @@ sub start_m {
#&Apache::lonxml::debug("M is ends with:$currentstring:");
$Apache::lonxml::post_evaluate=0;
} elsif ($target eq 'tex') {
+
$currentstring = $inside;
my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
if ($eval eq 'on') {
@@ -135,11 +136,13 @@ sub start_m {
}
if ($currentstring=~/^(\s*\\\\\s*)*$/) {$currentstring = ' \vskip 0 mm ';}
# detect simple math mode entry exits, and convert them
- # to use \ensuremath
- if ($currentstring=~/^\s*\$[^\$].*[^\$]\$\s*$/) {
- $currentstring=~s/^(\s*)\$/$1/;
- $currentstring=~s/\$(\s*)$/$1/;
- $currentstring='\ensuremath{'.$currentstring.'}';
+ # to use \ensuremath ... unless there's a \verb inside.
+ if (! ($currentstring=~/\\verb/)) {
+ if ($currentstring=~/^\s*\$[^\$].*[^\$]\$\s*$/) {
+ $currentstring=~s/^(\s*)\$/$1/;
+ $currentstring=~s/\$(\s*)$/$1/;
+ $currentstring='\ensuremath{'.$currentstring.'}';
+ }
}
$Apache::lonxml::post_evaluate=0;
}
@@ -1458,6 +1461,27 @@ sub start_hr {
if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
+
+ #
can't be inside of thank you LaTeX.
+ #
+ my $restart_sub = 0;
+ my $restart_sup = 0;
+
+ # Since and are simple tags it's ok to turn off/on
+ # using the start_ stop_ functions.. those tags only care about
+ # $target.
+
+ if (&is_inside_of($tagstack, "sub")) {
+ $restart_sub = 1;
+ $currentstring .= &end_sub($target, $token, $tagstack,
+ $parstack, $parser, $safeeval);
+ }
+ if (&is_inside_of($tagstack, "sup")) {
+ $restart_sup = 1;
+ $currentstring .= &end_sup($target, $token, $tagstack,
+ $parstack, $parser, $safeeval);
+ }
+
my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
if (defined $LaTeXwidth) {
if ($LaTeXwidth=~/^%/) {
@@ -1478,6 +1502,16 @@ sub start_hr {
}
$currentstring .= ' \vskip 0 mm \noindent\makebox['.$LaTeXwidth.']{'.$pre.'\makebox['.
$LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm ';
+ # Turn stuff back on that we can't be inside of.
+
+ if ($restart_sub) {
+ $currentstring .= &start_sub($target, $token, $tagstack,
+ $parstack, $parser, $safeeval);
+ }
+ if ($restart_sup) {
+ $currentstring .= &start_sup($target, $token, $tagstack,
+ $parstack, $parser, $safeeval);
+ }
}
return $currentstring;
}
@@ -1953,12 +1987,19 @@ sub start_table {
}
} else {
$Apache::londefdef::table[-1]{'forcedtablewidth'} = 1;
- }
+ }
+ # This stuff looks a bit hokey..
+ # Percentage width is actually given as an absolute width..
+ # but it appears that unless the 'percent' flag is set,
+ # The table is just allowed to go to its natural width
+ # for now let's always claim 'percent' is set..
+ #
if ($TeXwidth=~/%/) {
$Apache::londefdef::table[-1]{'percent'}=1;
$TeXwidth=~/(\d+)/;
$Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;
} else {
+ $Apache::londefdef::table[-1]{'percent'} = 1; # kludge until we get the intent.
$Apache::londefdef::table[-1]{'width'}=$TeXwidth;
}
# In the end, however the table width cannot be wider than $textwidth...
@@ -1966,7 +2007,6 @@ sub start_table {
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);
my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
@@ -2107,6 +2147,7 @@ sub end_table {
$space_neeeded=$space_neeeded+$max_len[$jn];
}
if ($space_neeeded<=$available_space) {
+
for (my $jn=0;$jn<=$#max_len;$jn++) {
if ($fwidth[$jn]==0) {
$fwidth[$jn]=$max_len[$jn];
@@ -2220,15 +2261,7 @@ sub end_table {
$Apache::londefdef::table[-1]{'content'}=\@cleaned_table;
@fwidth=@cleaned_header;
}
- # At this time we must be sure the table does not overhang the total width
- # this can happen due to our 'average width' adjustment.
- # Total the column widths and see if they are larger than the avail width;
- # If so scale them down in proportion to their percentage of total width.
-
- my $current_total_width = 0;
- for (my $col = 0; $col < $#fwidth; $col++) {
- $current_total_width = $current_total_width + $fwidth[$col];
- }
+
#construct header of the table
my $header_of_table = '{'.$Apache::londefdef::table[-1]{'vvinc'};
@@ -3064,6 +3097,29 @@ sub start_applet {
$currentstring='[APPLET: '.$alttag.']';
}
} elsif ($target eq 'tex') {
+ # Turn off some stuff we can't be inside thank you LaTeX
+
+
+ my $restart_sub = 0;
+ my $restart_sup = 0;
+
+ # Since and are simple tags it's ok to turn off/on
+ # using the start_ stop_ functions.. those tags only care about
+ # $target.
+
+ if (&is_inside_of($tagstack, "sub")) {
+ $restart_sub = 1;
+ $currentstring .= &end_sub($target, $token, $tagstack,
+ $parstack, $parser, $safeeval);
+ }
+ if (&is_inside_of($tagstack, "sup")) {
+ $restart_sup = 1;
+ $currentstring .= &end_sup($target, $token, $tagstack,
+ $parstack, $parser, $safeeval);
+ }
+
+ # Now process the applet; just replace it with its alt attribute.
+
my $alttag= &Apache::lonxml::get_param('alt',$parstack,
$safeeval,undef,1);
unless ($alttag) {
@@ -3074,6 +3130,17 @@ sub start_applet {
}
$currentstring.='\begin{center} \fbox{Java Applet: '.$alttag.
'.}\end{center}';
+
+ # Turn stuff back on that we can't be inside of.
+
+ if ($restart_sub) {
+ $currentstring .= &start_sub($target, $token, $tagstack,
+ $parstack, $parser, $safeeval);
+ }
+ if ($restart_sup) {
+ $currentstring .= &start_sup($target, $token, $tagstack,
+ $parstack, $parser, $safeeval);
+ }
}
return $currentstring;
}