--- loncom/xml/londefdef.pm	2003/06/19 18:45:57	1.141
+++ loncom/xml/londefdef.pm	2003/07/25 10:44:36	1.155
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.141 2003/06/19 18:45:57 sakharuk Exp $
+# $Id: londefdef.pm,v 1.155 2003/07/25 10:44:36 www Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -157,10 +157,11 @@ sub start_html {
 	    &Apache::lonxml::fontsettings();     
     } elsif ($target eq 'tex') {
 	@Apache::londefdef::table = ();
-	$currentstring .= '\documentclass[letterpaper]{article}
-                           \batchmode
-                           \newcommand{\keephidden}[1]{}
+	$currentstring .= '\documentclass[letterpaper]{article}';
+	if ($ENV{'form.latex_type'}=~'batchmode') {$currentstring .='\batchmode';} 
+	$currentstring .= '\newcommand{\keephidden}[1]{}
                            \renewcommand{\deg}{$^{\circ}$}
+                           \usepackage{longtable}
                            \usepackage{textcomp}
                            \usepackage[dvips]{graphicx}
                            \usepackage{epsfig}\usepackage{calc}
@@ -363,14 +364,32 @@ sub start_meta {
 	    $name=~s/\s/\_/gs;
 	    $name=~s/\W//gs;
 	    if ($name) {
-		$currentstring='<'.$name.'>'.
+		$currentstring='<'.$name;
+                 my $display=&Apache::lonxml::get_param
+		('display',$parstack,$safeeval,undef,1);
+                if ($display) {
+                    $display=~s/\"/\'/g;
+		    $currentstring.=' display="'.$display.'"';
+                }
+		$currentstring.='>'.
 		    &Apache::lonxml::get_param
 			('content',$parstack,$safeeval,undef,1).
 			'</'.$name.'>';
 	    }
+            my $display=&Apache::lonxml::get_param
+		('display',$parstack,$safeeval,undef,1);
+            if ($display) {
+		$display=&HTML::Entities::encode($display);
+		$currentstring.='<'.$name.'.display>'.$display.
+                               '</'.$name.'.display>';
+            }
 	}
     } elsif ($target eq 'tex') {
-	&Apache::lonxml::startredirection();
+	my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval);
+	my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval);
+	if ((not defined $content) && (not defined $name)) {
+	    &Apache::lonxml::startredirection();
+	}
     }
     return $currentstring;
 }
@@ -445,6 +464,29 @@ sub start_body {
 	    $currentstring.='<head>'.
 		&Apache::lonmenu::registerurl(undef,$target).'</head>';
 	}
+# Accessibility
+	if ($ENV{'browser.imagesuppress'} eq 'on') {
+	    delete($token->[2]->{'background'});
+	}
+	if ($ENV{'browser.fontenhance'} eq 'on') {
+	    my $style='';
+	    foreach my $key (keys(%{$token->[2]})) {
+		if ($key =~ /^style$/i) {
+		    $style.=$token->[2]->{$key}.';';
+		    delete($token->[2]->{$key});
+		}
+	    }
+	    $token->[2]->{'style'}=$style.'; font-size: x-large;';
+	}
+	if ($ENV{'browser.blackwhite'} eq 'on') {
+	    delete($token->[2]->{'font'});
+	    delete($token->[2]->{'link'});
+	    delete($token->[2]->{'alink'});
+	    delete($token->[2]->{'vlink'});
+	    delete($token->[2]->{'bgcolor'});
+	    delete($token->[2]->{'background'});
+	}
+# Overload loads
 	my $onLoad='';
 	foreach my $key (keys(%{$token->[2]})) {
 	    if ($key =~ /^onload$/i) {
@@ -502,9 +544,7 @@ sub start_center {
 	$currentstring = $token->[4];     
     } elsif ($target eq 'tex') {
 	$currentstring = '\begin{center}';  
-    }  elsif ($target eq 'latexsource') {
-	$currentstring = '\begin{center}';  
-    } 
+    }
     return $currentstring;
 }
 
@@ -515,9 +555,7 @@ sub end_center {
 	$currentstring = $token->[2];     
     } elsif ($target eq 'tex') {
 	$currentstring = '\end{center}';  
-    }  elsif ($target eq 'latexsource') {
-	$currentstring = '\end{center}';  
-    } 
+    }
     return $currentstring;
 }
 
@@ -529,8 +567,6 @@ sub start_b {
 	$currentstring = $token->[4];     
     } elsif ($target eq 'tex') {
 	$currentstring = '\textbf{';  
-    }  elsif ($target eq 'latexsource') {
-	$currentstring = '\textbf{';  
     } 
     return $currentstring;
 }
@@ -542,8 +578,6 @@ sub end_b {
 	$currentstring = $token->[2];     
     } elsif ($target eq 'tex') {
 	$currentstring = '}';  
-    } elsif ($target eq 'latexsource') {
-	$currentstring = '}';  
     } 
     return $currentstring;
 }
@@ -556,8 +590,6 @@ sub start_strong {
 	$currentstring = $token->[4];     
     } elsif ($target eq 'tex') {
 	$currentstring = '\textbf{';  
-    } elsif ($target eq 'latexsource') {
-	$currentstring = '\textbf{';  
     } 
     return $currentstring;
 }
@@ -570,9 +602,7 @@ sub end_strong {
 	$currentstring = $token->[2];     
     } elsif ($target eq 'tex') {
 	$currentstring = '}';  
-    }  elsif ($target eq 'latexsource') {
-	$currentstring = '}';  
-    } 
+    }
     return $currentstring;
 }
 
@@ -848,9 +878,7 @@ sub start_cite {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
 	$currentstring .= "\\textit{";
-    }  elsif ($target eq 'latexsource') {
-	$currentstring .= "\\textit{";
-    } 
+    }
     return $currentstring;
 }
 
@@ -861,9 +889,7 @@ sub end_cite {
 	$currentstring .= $token->[2];
     } elsif ($target eq 'tex') {
 	$currentstring .= "}";
-    }  elsif ($target eq 'latexsource') {
-	$currentstring .= "}";
-    } 
+    }
     return $currentstring;
 }
 
@@ -875,9 +901,7 @@ sub start_i {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
 	$currentstring .= '\textit{';
-    }  elsif ($target eq 'latexsource') {
-	$currentstring .= '\textit{';
-    } 
+    }
     return $currentstring;
 }
 
@@ -888,8 +912,6 @@ sub end_i {
 	$currentstring .= $token->[2];
     } elsif ($target eq 'tex') {
 	$currentstring .= '}';
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= '}';
     } 
     return $currentstring;
 }
@@ -902,9 +924,7 @@ sub start_address {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
 	$currentstring .= "\\textit{";
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= "\\textit{";
-    } 
+    }
     return $currentstring;
 }
 
@@ -915,8 +935,6 @@ sub end_address {
 	$currentstring .= $token->[2];
     } elsif ($target eq 'tex') {
 	$currentstring .= "}";
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= "}";
     }
     return $currentstring;
 }
@@ -929,8 +947,6 @@ sub start_dfn {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
 	$currentstring .= "\\textit{";
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= "\\textit{";
     } 
     return $currentstring;
 }
@@ -942,9 +958,7 @@ sub end_dfn {
 	$currentstring .= $token->[2];
     } elsif ($target eq 'tex') {
 	$currentstring .= "}";
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= "}";
-    } 
+    }
     return $currentstring;
 }
 
@@ -956,9 +970,7 @@ sub start_tt {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
 	$currentstring .= '\texttt{';
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= '\texttt{';
-    } 
+    }
     return $currentstring;
 }
 
@@ -969,8 +981,6 @@ sub end_tt {
 	$currentstring .= $token->[2];
     } elsif ($target eq 'tex') {
 	$currentstring .= '}';
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= '}';
     }
     return $currentstring;
 }
@@ -983,9 +993,7 @@ sub start_kbd {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
 	$currentstring .= "\\texttt";
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= "\\texttt{";
-    } 
+    }
     return $currentstring;
 }
 
@@ -996,9 +1004,7 @@ sub end_kbd {
 	$currentstring .= $token->[2];
     } elsif ($target eq 'tex') {
 	$currentstring .= "}";
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= "}";
-    } 
+    }
     return $currentstring;
 }
 
@@ -1033,9 +1039,7 @@ sub start_em {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
 	$currentstring .= '\emph{';
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= '\emph{';
-    } 
+    }
     return $currentstring;
 }
 
@@ -1046,9 +1050,7 @@ sub end_em {
 	$currentstring .= $token->[2];
     } elsif ($target eq 'tex') {
 	$currentstring .= '}';
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= '}';
-    }  
+    } 
     return $currentstring;
 }
 
@@ -1060,8 +1062,6 @@ sub start_q {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
 	$currentstring .= "\\emph{";
-    }  elsif ($target eq 'latexsource') {
-	$currentstring .= "\\emph{";
     }
     return $currentstring;
 }
@@ -1073,9 +1073,7 @@ sub end_q {
 	$currentstring .= $token->[2];
     } elsif ($target eq 'tex') {
 	$currentstring .= "}";
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= "}";
-    }  
+    } 
     return $currentstring;
 }
 
@@ -1086,10 +1084,8 @@ sub start_p {
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
-	$currentstring .= '{\par ';
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= '{\par ';
-    } 
+	$currentstring .= '\par ';
+    }
     return $currentstring;
 }
 
@@ -1098,10 +1094,6 @@ sub end_p {
     my $currentstring = '';
     if ($target eq 'web') {
 	$currentstring .= $token->[2];
-    } elsif ($target eq 'tex') {
-	$currentstring .= '}';
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= '}';
     }
     return $currentstring;
 }
@@ -1114,11 +1106,9 @@ sub start_br {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
 	if ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') {
-	    $currentstring .= '\vskip 0.2 mm';
+	    $currentstring .= '\vskip 0.2 mm ';
 	}
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= '\\';
-    } 
+    }
     return $currentstring;
 }
 
@@ -1139,9 +1129,7 @@ sub start_big {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
 	$currentstring .= '{\large ';
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= '{\Large ';
-    }  
+    } 
     return $currentstring;
 }
 
@@ -1152,8 +1140,6 @@ sub end_big {
 	$currentstring .= $token->[2];
     } elsif ($target eq 'tex') {
 	$currentstring .= '}';
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= '}';
     }
     return $currentstring;
 }
@@ -1166,9 +1152,7 @@ sub start_small {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
 	$currentstring .= '{\footnotesize ';
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= '{\footnotesize ';
-    } 
+    }
     return $currentstring;
 }
 
@@ -1179,8 +1163,6 @@ sub end_small {
 	$currentstring .= $token->[2];
     } elsif ($target eq 'tex') {
 	$currentstring .= '}';
-    } elsif ($target eq 'latexsource') {
-	$currentstring .= '}';
     }
     return $currentstring;
 }
@@ -1220,7 +1202,12 @@ sub start_font {
     my $currentstring = '';
     if ($target eq 'web') {
 	my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
-	if ($face=~/symbol/i) {$Apache::lonxml::prevent_entity_encode++;}
+	if ($face=~/symbol/i) {
+	    $Apache::lonxml::prevent_entity_encode++;
+	} else {
+	    if (($ENV{'browser.fontenhance'} eq 'on') || 
+		($ENV{'browser.blackwhite'} eq 'on')) { return ''; }
+	}
 	$currentstring = $token->[4];     
     }  elsif ($target eq 'tex') {
 	my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
@@ -1352,14 +1339,14 @@ sub start_hr {
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
-	my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,0);
+	my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
 	if (defined $LaTeXwidth) {
 	    if ($LaTeXwidth=~/^%/) {
 		substr($LaTeXwidth,0,1)='';
 		$LaTeXwidth=($LaTeXwidth/100).'\textwidth';
 	    }
 	} else {
-	    $LaTeXwidth ='0.95\textwidth';
+	    $LaTeXwidth ='0.9\textwidth';
 	}
 	my ($pre,$post);
 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
@@ -1370,7 +1357,7 @@ sub start_hr {
 	} elsif ($align eq 'right') {
 	    $pre=' \hfill \llap{'; $post='}';
 	}
-	$currentstring .= ' \vskip 0 mm \noindent\makebox[\textwidth]{'.$pre.'\makebox['.
+	$currentstring .= ' \vskip 0 mm \noindent\makebox['.$LaTeXwidth.']{'.$pre.'\makebox['.
                                     $LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm ';
     } 
     return $currentstring;
@@ -1381,8 +1368,7 @@ sub end_hr {
     my $currentstring = '';
     if ($target eq 'web') {
 	$currentstring .= $token->[2];
-    } elsif ($target eq 'tex') {
-    } 
+    }
     return $currentstring;
 }
 
@@ -1407,50 +1393,43 @@ sub end_div {
 
 #-- <a> tag
 sub start_a {
-    my ($target,$token) = @_;
+    my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';
     if ($target eq 'web') {
 	$currentstring .= $token->[4];
     } elsif ($target eq 'tex') {
+	my $a=&Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1);
+	$a=~s/([^\\])%/$1\\\%/g;
+	$currentstring .= '\ref{'.$a.'}';
     }
     return $currentstring;
 }
 
 sub end_a {
-    my ($target,$token,$tagstack,$stackref) = @_;
+    my ($target,$token,$tagstack,$parstack,$safeeval) = @_;
     my $currentstring = '';
     if ($target eq 'web') {
 	$currentstring .= $token->[2];
-    } elsif ($target eq 'tex') {
-	my  $tempor_var = $stackref->[$#$stackref];
-	if (index($tempor_var,'name') != -1 ) {
-	    $tempor_var =~ s/name=([^,]*),/$1/g;
-	} elsif (index($tempor_var,'href') != -1 ) {
-	    $tempor_var =~ s/href=([^,]*),/$1/g;
-	    $currentstring .= " \\ref{$tempor_var}";
-	}
     }
     return $currentstring;
 }
 
 #-- <li> tag
 sub start_li {
-    my ($target,$token,$tagstack,$stackref) = @_;
+    my ($target,$token,$tagstack,$parstack,$safeeval) = @_;
     my $currentstring = '';
     if ($target eq 'web') {
 	$currentstring = $token->[4];     
     } elsif ($target eq 'tex') {
-	my  $tempor_var = $stackref->[$#$stackref];
-	if (index($tempor_var,'circle') != -1 ) {
-	    $currentstring .= " \\item[o] ";
-	} elsif (index($tempor_var,'square') != -1 ) {
-	    $currentstring .= " \\item[$\Box$] ";
-	} elsif ($tempor_var ne '') { 
-	    $_ = $tempor_var;
-	    m/my\s*([^=]*)=/;
-	    $currentstring .= " \\item[$1] ";
+	my  $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,1);
+	if ($type=~/circle/) {
+	    $currentstring .= ' \item[o] ';
+	} elsif ($type=~/square/) {
+	    $currentstring .= ' \item[$\Box$] ';
+	} elsif ($type ne '') { 
+	    $currentstring .= ' \item['.$type.'] ';
 	} else {
-	    $currentstring .= " \\item ";
+	    $currentstring .= ' \item ';
 	}  
     } 
     return $currentstring;
@@ -1681,10 +1660,16 @@ sub end_dt {
 
 #-- <dd> tag
 sub start_dd {
-    my ($target,$token) = @_;
+    my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';
     if ($target eq 'web') {
 	$currentstring = $token->[4];     
+    } elsif ($target eq 'tex') {
+	if ($$tagstack[-2] eq 'dl') {
+	    $currentstring = ' \item [] ';  
+	} elsif ($$tagstack[-2] eq 'dt') {
+	    $currentstring = ']'; 
+	}
     } 
     return $currentstring;
 }
@@ -1747,7 +1732,7 @@ sub start_table {
 	    $Apache::londefdef::table[-1]{'vvinc'} = '';
 	}
 	$Apache::londefdef::table[-1]{'output'} = ' \noindent \begin{tabular} ';
-	$currentstring = '\keephidden{NEW TABLE ENTRY '.$textwidth.' }';
+	$currentstring = '\keephidden{NEW TABLE ENTRY}';
     }
     return $currentstring;
 }
@@ -1825,7 +1810,7 @@ sub end_table {
 	} else {
 	    $currentstring .= $Apache::londefdef::table[-1]{'output'};
 	    pop @Apache::londefdef::table;
-            undef @Apache::londefdef::table;
+	    undef @Apache::londefdef::table;
 	}
     }
     return $currentstring;
@@ -1903,17 +1888,15 @@ sub end_td {
 		$current_length=~/(\d+\.?\d*)/;
 		$Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
 		$Apache::londefdef::table[-1]{'length'} .= '0,';
-	    } else {     
-		$data=~/^\s*(\S.*)/;
-		$data=$1;
-		$data=~/(.*\S)\s*$/;
-		$data=$1;
+	    } else {  
+		$data=~s/^\s+(\S.*)/$1/;
+		$data=~s/(.*\S)\s+$/$1/;
 		my $current_length=2*length($data);
 		$Apache::londefdef::table[-1]{'length'} .= $current_length.',';
 		$Apache::londefdef::table[-1]{'TeXlength'} .= '0,';
 	    }        
 	}
-	for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {                                
+	for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {         
 	    $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
 	}
 	@{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'};