--- loncom/xml/lonxml.pm	2004/07/13 19:12:46	1.330
+++ loncom/xml/lonxml.pm	2004/08/10 18:03:30	1.334
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.330 2004/07/13 19:12:46 albertel Exp $
+# $Id: lonxml.pm,v 1.334 2004/08/10 18:03:30 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -165,13 +165,20 @@ sub xmlbegin {
 }
 
 sub xmlend {
+    my ($target,$tagstack,$parstack,$parser,$safeeval)=@_;
     my $mode='xml';
     my $status='OPEN';
     if ($Apache::lonhomework::parsing_a_problem) {
 	$mode='problem';
 	$status=$Apache::inputtags::status[-1]; 
     }
-    return &Apache::lonfeedback::list_discussion($mode,$status).'</html>';
+    my $discussion=&Apache::lonfeedback::list_discussion($mode,$status,'',$target,$tagstack,$parstack,$parser,$safeeval);
+    if ($target eq 'tex') {
+	&Apache::lonxml::newparser($parser,\$discussion,'');
+	return '';
+    } else {
+	return $discussion.'</html>';
+    }
 }
 
 sub tokeninputfield {
@@ -400,6 +407,7 @@ sub latex_special_symbols {
 	# any & or # leftover should be safe to just escape
         $string=~s/([^\\]|^)\&/$1\\\&/g;
         $string=~s/([^\\]|^)\#/$1\\\#/g;
+        $string=~s/\|/\$\\mid\$/g;
 #single { or } How to escape?
     }
     return $string;
@@ -746,6 +754,7 @@ sub init_safespace {
 
 #need to inspect this class of ops
 # $safeeval->deny(":base_orig");
+  $safeeval->permit("require");
   $safeinit .= ';$external::target="'.$target.'";';
   my $rndseed;
   my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
@@ -1125,7 +1134,8 @@ sub inserteditinfo {
       my $initialize='';
       if ($filetype eq 'html') {
 	  my $addbuttons=&Apache::lonhtmlcommon::htmlareaaddbuttons();
-	  $initialize=&Apache::lonhtmlcommon::htmlareaheaders().(<<FULLPAGE);
+	  $initialize=&Apache::lonhtmlcommon::htmlareaheaders().
+	      &Apache::lonhtmlcommon::spellheader().(<<FULLPAGE);
 <script type="text/javascript">
 $addbuttons
 
@@ -1155,11 +1165,12 @@ $cleanbut
 <input type="submit" name="savethisfile" accesskey="s"  value="$lt{'st'}" />
 <input type="submit" name="viewmode" accesskey="v" value="$lt{'vi'}" />
 BUTTONS
+      $buttons.=&Apache::lonhtmlcommon::spelllink('xmledit','filecont');
       my $editfooter=(<<ENDFOOTER);
 $initialize
 <hr />
 <a name="editsection" />
-<form method="post">
+<form method="post" name="xmledit">
 $xml_help
 <input type="hidden" name="editmode" value="$lt{'ed'}" />
 $buttons<br />