--- loncom/xml/londefdef.pm	2011/09/15 19:10:45	1.415.4.4
+++ loncom/xml/londefdef.pm	2010/08/04 14:20:26	1.419
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.415.4.4 2011/09/15 19:10:45 raeburn Exp $
+# $Id: londefdef.pm,v 1.419 2010/08/04 14:20:26 raeburn Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -48,7 +48,6 @@ use Image::Magick;
 use Apache::lonmenu();
 use Apache::lonmeta();
 use Apache::lonlocal;
-use Apache::loncommon();
 use Apache::Constants qw(:common);
 use File::Basename;
 use LONCAPA();
@@ -590,7 +589,7 @@ sub start_body {
 sub edit_controls {
     my ($nochgview) = @_;
     my $result .= '
-<form method="post" action="">
+<form method="post">
 <div class="LC_edit_problem_header">';
     unless ($nochgview) {
         $result .= '
@@ -602,12 +601,7 @@ sub edit_controls {
     $result .= '
 <div><input type="submit" name="editmode" accesskey="e" value="'.&mt('Edit').'" />';
     if (($env{'request.course.id'}) && ($env{'form.forceedit'})) {
-        my $viewtext = &mt('Course View');
-        if (&Apache::loncommon::course_type() eq 'Community') {
-            $viewtext = &mt('Community View');
-        }
-        $result .= ('&nbsp;' x 3).'<input type="button" value="'.
-                   $viewtext.'" onclick="javascript:location.href=currentURL" />';
+        $result .= ('&nbsp;' x 3).'<input type="button" value="'.&mt('Course View').'" onclick="javascript:location.href=currentURL" />';
     }
     $result .= '</div>
 </div>
@@ -2045,50 +2039,35 @@ sub start_table {
     } elsif ($target eq 'tex') {
 	&disable_para();	# Can't have paras in a table.
 
+
+	#  New table code:
+
 	#  Get the parameters that we can do something about:
 
 	my $border = &Apache::lonxml::get_param('border', $parstack, $safeeval, undef, 0);
 	my $width  = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval, undef, 0);
 	my $theme  = &Apache::lonxml::get_param('TeXtheme', $parstack, $safeeval, undef, 0);
 	my $align  = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 0);
-        my $cell_border = &Apache::lonxml::get_param('rules', $parstack, $safeeval, undef, 0);
 
 	# The only thing that needs any figuring out is the width.. and then only if it is
 	# a percent. If not it's assumed to be some valid TeX measurement unit e.g. 3.0cm
 	#
 
 	my $table = new Apache::lontable();
-        if ((defined $border) && ($border > 0)) {
-        #    &Apache::lonnet::logthis("Turning on table borders: $border");
-            $table->table_border(1);
-            if (!defined $cell_border) {
-                $table->cell_border(1); # Default for rules is all if rules not defined.
-            }
-        }
-
-        if ((defined $cell_border)) {
-            if ($cell_border eq 'all') {
-                $table->cell_border(1);
-            } elsif ($cell_border eq 'rows') {
-                $table->cell_border(2);
-            } elsif ($cell_border eq 'cols') {
-                $table->cell_border(3);
-            } elsif($cell_border eq 'groups') {
-                $table->cell_border(4);
-            } else {
-                $table->cell_border(0);
-            }
-        }
-        if (defined $theme) {
+	if ($border ne '' && $border != 0) {
+	    $table->table_border(1);
+	    $table->cell_border(1);
+	}
+	if ($theme ne '') {
 	    $table->theme($theme);
 	}
-	if (defined $align) {
+	if ($align ne '') {
 	    $table->alignment($align);
 	}
 
 	# Missing width is most of page width
 
-	if (!(defined $width)) {
+	if ($width eq "") {
 	    $width = '70%';
 	}
 	
@@ -2106,6 +2085,88 @@ sub start_table {
 	push(@Apache::londefdef::table, $table);
         $currentstring.=' \keephidden{NEW TABLE ENTRY}';
 
+	#--------------------------------------------------------
+	#  Old table code here.
+	#--------------------------------------------------------
+
+
+	if (0) {
+	push(@Apache::londefdef::table, {}); 
+	$Apache::londefdef::table[-1]{'row_number'} = -1;
+        #maximum table's width (default coincides with text line length)
+	if ($#Apache::londefdef::table==0) {
+	    $textwidth=&recalc($env{'form.textwidth'}); #result is always in mm
+	    $textwidth=~/(\d+\.?\d*)/;
+	    $textwidth=0.85*$1; #accounts "internal" LaTeX space for table frame
+	} else {
+	    if ($Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]=~/\d/) {
+		#the maximum width of nested table is determined by LATeX width of parent cell
+		$textwidth=$Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]; 
+	    } else {
+              #try to use all space not used before (minus 5% for LaTeX table internal) - rather silly
+		$textwidth=$Apache::londefdef::table[-2]{'width'};
+		for (my $i=0;$i<$Apache::londefdef::table[-2]{'counter_columns'};$i++) {
+		    $textwidth=$textwidth-$Apache::londefdef::table[-2]{'TeXlen'}[0][$i];
+		}
+	    }
+	}
+
+	# width either comes forced from the TeXwidth or the width parameters.
+	# in either case it can be a percentage or absolute width.
+	# in the width case we ignore absolute width 
+	my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
+	if (!defined($TeXwidth)) {
+	    my $htmlwidth = &Apache::lonxml::get_param('width',$parstack,
+						       $safeeval,undef,1);
+	    if ($htmlwidth =~ /%/) {
+		$TeXwidth = $htmlwidth;
+	    } else { 
+		$TeXwidth = $textwidth;
+	    }
+	}
+	# if the width is specified as a % it is converted to an absolute width.
+	# otherwise.. just plugged right in the hash
+
+	if ($TeXwidth=~/%/) {
+	    $TeXwidth=~/(\d+)/;
+            $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); 
+        my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
+	unless (defined $border) { $border = 0; }
+	if ($border) { 
+	    $Apache::londefdef::table[-1]{'hinc'} = '\hline '; 
+	    $Apache::londefdef::table[-1]{'vinc'} = '&'; 
+	    $Apache::londefdef::table[-1]{'vvinc'} = '|';
+	} else {
+	    $Apache::londefdef::table[-1]{'hinc'} = ''; 
+	    $Apache::londefdef::table[-1]{'vinc'} = '&'; 
+	    $Apache::londefdef::table[-1]{'vvinc'} = '';
+	}
+	if ($#Apache::londefdef::table==0) {
+	    #    Note that \newline seems to destroy the alignment envs.
+	    # $Apache::londefdef::table[-1]{'output'}='\strut\newline\strut\setlength{\tabcolsep}{1 mm}';
+	    $Apache::londefdef::table[-1]{'output'}='\strut'.'\\\\'."\n".'\strut\setlength{\tabcolsep}{1 mm}';
+	}
+	$Apache::londefdef::table[-1]{'output'}.=' \noindent \begin{tabular} ';
+        $Apache::londefdef::table[-1]{'TeXlen'}=[];
+        $Apache::londefdef::table[-1]{'objectlen'}=[];
+        $Apache::londefdef::table[-1]{'objectsignal'}=[];
+        $Apache::londefdef::table[-1]{'maxlen'}=[];
+        $Apache::londefdef::table[-1]{'minlen'}=[];
+        $Apache::londefdef::table[-1]{'content'}=[];
+        $Apache::londefdef::table[-1]{'align'}=[];
+        $currentstring.=' \keephidden{NEW TABLE ENTRY}';
+    }
+
     }
     return $currentstring;
 }
@@ -2118,6 +2179,8 @@ sub end_table {
     } elsif ($target eq 'tex') {
 
 
+	#  New table code:
+
 	my $table = pop(@Apache::londefdef::table);
 	my $t     = $table->generate();
 	$currentstring = $t->generate_string();
@@ -2659,26 +2722,17 @@ sub tag_check {
 #
 
 sub cell_config_hash {
-    my ($align, $rowspan, $colspan, $width) = @_;
-    if ($rowspan ne '') {
-        $rowspan =~ s/^\s+|\s+$//g;
-    }
-    if ($colspan ne '') {
-        $colspan =~ s/^\s+|\s+$//g;
-    }
+    my ($align, $rowspan, $colspan) = @_;
     my %config;
     if ($align ne '') {
 	$config{'halign'} = $align;
     }
-    if (($colspan =~ /^\d+$/) && ($colspan > 0)) {
+    if ($colspan ne "") {
 	$config{'colspan'} = $colspan;
     }
-    if (($rowspan =~ /^\d+$/) && ($rowspan > 0)) {
+    if ($rowspan ne '') {
 	$config{'rowspan'} = $rowspan;
     }
-    if ($width ne '') {
-        $config{'width'} = $width;
-    }
     return \%config;
 }
  
@@ -2690,11 +2744,11 @@ sub start_td_tex {
     # attributes, but empty of text.  end_td_tex will
     # fetch the contents from the recursive parse and
     # fill the cell with them:
-    my $align   = &Apache::lonxml::get_param('align', $parstack, $safeeval);
-    my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval);
-    my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval);
-    my $width   = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval);
-    my $config = &cell_config_hash($align, $rowspan, $colspan, $width);
+    my $align   = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 1);
+    my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval, undef, 1);
+    my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval, undef, 1);
+
+    my $config = &cell_config_hash($align, $rowspan, $colspan);
 
     my $table = $Apache::londefdef::table[-1];
     $table->add_cell('', $config);
@@ -3105,24 +3159,13 @@ sub start_img {
    # Render unto browsers that which are the browser's...
 
     if ($target eq 'web' || $target eq 'webgrade') {
-	if ($env{'browser.imagesuppress'} ne 'on') {
-	    my $enc = ('yes' eq 
-		       lc(&Apache::lonxml::get_param('encrypturl',$parstack,
-						     $safeeval)));
-	    $currentstring.=&Apache::lonenc::encrypt_ref($token,{'src'=>$src},
-							 $enc);
-	} else {
-	    my $alttag = &Apache::lonxml::get_param('alt',$parstack,$safeeval,
-						    undef,1);
-	    if (!$alttag) {
-		$alttag = &Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
-						   $src);
-	    }
-	    $currentstring.='[IMAGE: '.$alttag.']';
-	}
-
-	# and render unto TeX that which is LaTeX
+        my $enc = ('yes' eq 
+                   lc(&Apache::lonxml::get_param('encrypturl',$parstack,
+                      $safeeval)));
+        $currentstring.=&Apache::lonenc::encrypt_ref($token,{'src'=>$src},
+                         $enc);
 
+    # and render unto TeX that which is LaTeX
     } elsif ($target eq 'tex') {
 	#
 	#  The alignment will require some superstructure to be put around
@@ -3223,7 +3266,7 @@ sub start_img {
 						   ['', 'none','parbox', 'parpic', 'wrapfigure'], $token, 2);
         my $alt=    &Apache::lonxml::get_param('alt',$parstack,$safeeval);
         my $enc=    &Apache::lonxml::get_param('encrypturl',$parstack,$safeeval);
-
+ 
 	$currentstring .=&Apache::edit::select_arg('Encrypt URL:','encrypturl',
 						   ['no','yes'], $token, 2);
         if (($alt=~/\S/) && (lc($enc) eq 'yes')) {
@@ -3237,10 +3280,10 @@ sub start_img {
         if ($token->[2]{'src'}=~/\$/) {
            $currentstring.=&mt('Variable image source');
         } elsif ($token->[2]{'src'}=~/\S/) {
-           $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
-           if ($width) { $currentstring.=' width="'.$width.'" '; }
-           if ($height) { $currentstring.=' height="'.$height.'" '; }
-           $currentstring .= ' />';
+	   $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
+	   if ($width) { $currentstring.=' width="'.$width.'" '; }
+	   if ($height) { $currentstring.=' height="'.$height.'" '; }
+	   $currentstring .= ' />';
         } else {
            $currentstring.=&mt("No image source specified");
         }
@@ -3311,23 +3354,12 @@ sub start_applet {
     &Apache::lonxml::extlink($archive);
     my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {
-	if ($env{'browser.appletsuppress'} ne 'on') {
-	    $currentstring = &Apache::lonenc::encrypt_ref($token,
-							  {'code'=>$code,
-							   'archive'=>$archive}
-							  );
-	} else {
-	    my $alttag= &Apache::lonxml::get_param('alt',$parstack,
-						   $safeeval,undef,1);
-	    unless ($alttag) {
-		$alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
-						 $code);
-	    }
-	    $currentstring='[APPLET: '.$alttag.']';
-	}
+        $currentstring = &Apache::lonenc::encrypt_ref($token,
+                                                      {'code'=>$code,
+                                                       'archive'=>$archive}
+                                                     );
     } elsif ($target eq 'tex') {
-	# Turn off some stuff we can't be inside thank you LaTeX
-	
+        # Turn off some stuff we can't be inside thank you LaTeX
 
 	my $restart_sub = 0;
 	my $restart_sup = 0;
@@ -3391,16 +3423,7 @@ sub start_embed {
     &Apache::lonxml::extlink($src);
     my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {
-	if ($env{'browser.embedsuppress'} ne 'on') {
-	    $currentstring=&Apache::lonenc::encrypt_ref($token,{'src'=>$src});
-	} else {
-	    my $alttag=&Apache::lonxml::get_param
-		('alt',$parstack,$safeeval,undef,1);
-	    unless ($alttag) {
-		$alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
-	    }
-	    $currentstring='[EMBED: '.$alttag.']';
-	}
+    $currentstring=&Apache::lonenc::encrypt_ref($token,{'src'=>$src}); 
     } elsif ($target eq 'tex') {
     } 
     return $currentstring;
@@ -3410,9 +3433,10 @@ sub end_embed {
     my ($target,$token) = @_;
     my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {
-	$currentstring = $token->[2];     
-    } elsif ($target eq 'tex') {  
-    } 
+        $currentstring = $token->[2];
+    } elsif ($target eq 'tex') {
+        # ./.
+    }
     return $currentstring;
 }
 
@@ -3850,12 +3874,16 @@ sub end_colgroup {
     return $currentstring;
 }
 
+
 #-- <del> tag (end tag required)
 sub start_del {
     my ($target,$token) = @_;
     my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {
 	$currentstring = $token->[4];     
+    } elsif ($target eq 'tex') {
+	&disable_para();
+	$currentstring .= '\st{';  
     } 
     return $currentstring;
 }
@@ -3864,7 +3892,10 @@ sub end_del {
     my ($target,$token) = @_;
     my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {
-	$currentstring = $token->[2];    
+	$currentstring = $token->[2];     
+    } elsif ($target eq 'tex') {
+	&enable_para();
+	$currentstring = '}';
     } 
     return $currentstring;
 }
@@ -4800,6 +4831,7 @@ sub latex_header {
 	"\\usepackage{xcolor}\n".
 	'\usepackage{calc}'.
 	'\usepackage{amsmath}'.
+    '\usepackage{soul}',
 	'\usepackage{amssymb}'.
 	'\usepackage{amsfonts}'.
 	'\usepackage{amsthm}'.