Diff for /loncom/xml/londefdef.pm between versions 1.131 and 1.198

version 1.131, 2003/05/07 16:59:01 version 1.198, 2004/02/19 19:34:09
Line 25 Line 25
 # /home/httpd/html/adm/gpl.txt  # /home/httpd/html/adm/gpl.txt
 #  #
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  ## Copyright for TtHfunc and TtMfunc by Ian Hutchinson. 
 # Copyright for TtHfunc and TtMfunc by Ian Hutchinson.   
 # TtHfunc and TtMfunc (the "Code") may be compiled and linked into   # TtHfunc and TtMfunc (the "Code") may be compiled and linked into 
 # binary executable programs or libraries distributed by the   # binary executable programs or libraries distributed by the 
 # Michigan State University (the "Licensee"), but any binaries so   # Michigan State University (the "Licensee"), but any binaries so 
Line 51  use Apache::File(); Line 50  use Apache::File();
 use Image::Magick;  use Image::Magick;
 use Apache::lonmenu();  use Apache::lonmenu();
 use Apache::lonmeta();  use Apache::lonmeta();
   use Apache::Constants qw(:common);
   
   
 BEGIN {  BEGIN {
   
     &Apache::lonxml::register('Apache::londefdef',('a','abbr','acronym','accessrule','address','allow','applet','area','b','base','basefont','bgo','bgsound','big','blink','blockquote','blankspace','body','br','button','caption','center','cite','code','col','colgroup','dd','del','dfn','dir','div','dl','dt','em','embed','externallink','fieldset','font','form','frame','frameset','h1','h2','h3','h4','h5','h6','head','hr','html','i','iframe','img','input','ins','insert','isindex','kbd','keygen','label','layer','legend','li','link','m','map','marquee','menu','meta','multicol','nobr','noembed','noframes','nolayer','noscript','object','ol','optgroup','option','output','p','param','pre','q','s','samp','select','server','small','spacer','span','strike','strong','sub','sup','table','tbody','td','textarea','tfoot','th','thead','title','tr','tt','tthoption','u','ul','var','wbr'));      &Apache::lonxml::register('Apache::londefdef',('a','abbr','acronym','accessrule','address','allow','applet','area','b','base','basefont','bgo','bgsound','big','blink','blockquote','blankspace','body','br','button','caption','center','cite','code','col','colgroup','dd','del','dfn','dir','div','dl','dt','em','embed','externallink','fieldset','font','form','frame','frameset','h1','h2','h3','h4','h5','h6','head','hr','html','i','iframe','img','input','ins','insert','isindex','kbd','keygen','label','layer','legend','li','link','m','map','marquee','menu','meta','multicol','nobr','noembed','noframes','nolayer','noscript','object','ol','optgroup','option','output','p','param','pre','q','s','samp','select','server','small','spacer','span','strike','strong','sub','sup','table','tbody','td','textarea','tfoot','th','thead','title','tr','tt','tthoption','u','ul','var','wbr','hideweboutput'));
   
 }  }
   
   sub initialize_londefdef {
       $Apache::londefdef::TD_redirection=0;
       @Apache::londefdef::table = ();
       $Apache::londefdef::select=0;
       @Apache::londefdef::description=();
       $Apache::londefdef::DD_redirection=0;
       $Apache::londefdef::DT_redirection=0;
   }
   
 #======================= TAG SUBROUTINES =====================  #======================= TAG SUBROUTINES =====================
 #-- <output>  #-- <output>
 sub start_output {  sub start_output {
Line 72  sub end_output { Line 82  sub end_output {
 }  }
 #-- <m> tag  #-- <m> tag
 sub start_m {  sub start_m {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser);
       if ($target eq 'web' || $target eq 'analyze') {
  $Apache::lonxml::prevent_entity_encode++;   $Apache::lonxml::prevent_entity_encode++;
  my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser);  
  $inside ='\\documentstyle{article}'.$inside;   $inside ='\\documentstyle{article}'.$inside;
  &Apache::lonxml::debug("M is starting with:$inside:");   &Apache::lonxml::debug("M is starting with:$inside:");
  my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);   my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
Line 91  sub start_m { Line 101  sub start_m {
     $Apache::lontexconvert::errorstring='';      $Apache::lontexconvert::errorstring='';
  }   }
  #&Apache::lonxml::debug("M is ends with:$currentstring:");   #&Apache::lonxml::debug("M is ends with:$currentstring:");
    $Apache::lonxml::post_evaluate=0;
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = &Apache::lonxml::get_all_text_unbalanced("/m",$parser);   $currentstring = $inside;
    my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
    if ($eval eq 'on') {
       $currentstring=&Apache::run::evaluate($currentstring,$safeeval,$$parstack[-1]);
    }
  if ($currentstring=~/^(\s*\\\\\s*)*$/) {$currentstring = ' \vskip 0 mm ';}   if ($currentstring=~/^(\s*\\\\\s*)*$/) {$currentstring = ' \vskip 0 mm ';}
     } else {   $Apache::lonxml::post_evaluate=0;
  my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser);  
     }      }
     return $currentstring;      return $currentstring;
 }  }
Line 133  sub end_tthoption { Line 147  sub end_tthoption {
     return $result;      return $result;
 }  }
   
 #-- <html> tag      #-- <html> tag (end tag optional)
 sub start_html {  sub start_html {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($ENV{'browser.mathml'}) {      my $options=$ENV{'course.'.$ENV{'request.course.id'}.'.tthoptions'};
  &tth::ttminit();      &Apache::lontexconvert::init_tth();
  if ($ENV{'browser.unicode'}) {      if ($target eq 'web' || $target eq 'edit') {
     &tth::ttmoptions('-L -u1');  
  } else {  
     &tth::ttmoptions('-L -u0');  
  }  
     } else {  
  &tth::tthinit();  
  if ($ENV{'browser.unicode'}) {  
     &tth::tthoptions('-L -u1');  
  } else {  
     &tth::tthoptions('-L -u0');  
  }  
     }  
     if ($target eq 'web') {  
  $currentstring = &Apache::lonxml::xmlbegin().   $currentstring = &Apache::lonxml::xmlbegin().
     &Apache::lonxml::fontsettings();           &Apache::lonxml::fontsettings();     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  @Apache::londefdef::table = ();   @Apache::londefdef::table = ();
  $currentstring .= '\documentclass[letterpaper]{article}   $currentstring .= '\documentclass[letterpaper]{article}';
                            \newcommand{\keephidden}[1]{}   if ($ENV{'form.latex_type'}=~'batchmode') {$currentstring .='\batchmode';} 
    $currentstring .= '\newcommand{\keephidden}[1]{}
                            \renewcommand{\deg}{$^{\circ}$}                             \renewcommand{\deg}{$^{\circ}$}
                              \usepackage{longtable}
                            \usepackage{textcomp}                             \usepackage{textcomp}
                              \usepackage{makeidx}
                            \usepackage[dvips]{graphicx}                             \usepackage[dvips]{graphicx}
                            \usepackage{epsfig}\usepackage{calc}                             \usepackage{epsfig}\usepackage{calc}
 \newenvironment{choicelist}{\begin{list}{}{\setlength{\rightmargin}{0in}\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.05in}\setlength{\itemsep}{0.022in}\setlength{\parsep}{0in}\setlength{\belowdisplayskip}{0.04in}\setlength{\abovedisplayskip}{0.05in}\setlength{\abovedisplayshortskip}{-0.04in}\setlength{\belowdisplayshortskip}{0.04in}}}{\end{list}}';  \newenvironment{choicelist}{\begin{list}{}{\setlength{\rightmargin}{0in}\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.05in}\setlength{\itemsep}{0.022in}\setlength{\parsep}{0in}\setlength{\belowdisplayskip}{0.04in}\setlength{\abovedisplayskip}{0.05in}\setlength{\abovedisplayshortskip}{-0.04in}\setlength{\belowdisplayshortskip}{0.04in}}}{\end{list}}
   \renewenvironment{theindex}{\begin{list}{}{{\vskip 1mm \noindent \large\textbf{Index}} \newline \setlength{\rightmargin}{0in}\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.01in}\setlength{\itemsep}{0.1in}\setlength{\parsep}{-0.02in}\setlength{\belowdisplayskip}{0.01in}\setlength{\abovedisplayskip}{0.01in}\setlength{\abovedisplayshortskip}{-0.04in}\setlength{\belowdisplayshortskip}{0.01in}}}{\end{list}}';
     }      }
     return $currentstring;      return $currentstring;
 }  }
Line 177  sub end_html { Line 182  sub end_html {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <head> tag  #-- <head> tag (end tag optional)
 sub start_head {  sub start_head {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 190  sub start_head { Line 195  sub start_head {
 sub end_head {  sub end_head {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web' && $ENV{'request.state'} eq 'published') {
  $currentstring = &Apache::lonmenu::registerurl(undef,$target).   $currentstring = &Apache::lonmenu::registerurl(undef,$target).
     $token->[2];          $token->[2];    
     }       } 
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <map> tag  #-- <map> tag (end tag required)
 sub start_map {  sub start_map {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 216  sub end_map { Line 221  sub end_map {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <select> tag  #-- <select> tag (end tag required)
 sub start_select {  sub start_select {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     }       }  elsif ($target eq 'tex') {
    $Apache::londefdef::select=0;
       }
     return $currentstring;      return $currentstring;
 }  }
   
Line 235  sub end_select { Line 242  sub end_select {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <option> tag  #-- <option> tag (end tag optional)
 sub start_option {  sub start_option {
     my ($target,$token) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     }       } elsif ($target eq 'tex') {
    $Apache::londefdef::select++;
    if ($Apache::londefdef::select == 1) {
       $currentstring='\noindent\fbox{'.&Apache::lonxml::get_param('value',$parstack,$safeeval).'}\keephidden{';
    } else {
       $currentstring='\keephidden{';
    }
       }
     return $currentstring;      return $currentstring;
 }  }
   
Line 250  sub end_option { Line 264  sub end_option {
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[2];       $currentstring = $token->[2];    
     }       }  elsif ($target eq 'tex') {
    $currentstring='}';
       }
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <input> tag  #-- <input> tag (end tag forbidden)
 sub start_input {  sub start_input {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 273  sub end_input { Line 289  sub end_input {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <textarea> tag  #-- <textarea> tag (end tag required)
 sub start_textarea {  sub start_textarea {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 292  sub end_textarea { Line 308  sub end_textarea {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <form> tag  #-- <form> tag (end tag required)
 sub start_form {  sub start_form {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 311  sub end_form { Line 327  sub end_form {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <title> tag  #-- <title> tag (end tag required)
 sub start_title {  sub start_title {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= '\keephidden{'    $currentstring .= '\keephidden{Title of the document:  ' 
     }      }
     if ($target eq 'meta') {      if ($target eq 'meta') {
  $currentstring='<title>';   $currentstring='<title>';
  &start_output();   &start_output($target);
     }      }
     return $currentstring;      return $currentstring;
 }  }
Line 336  sub end_title { Line 352  sub end_title {
  $currentstring .= '}';   $currentstring .= '}';
     }        }  
     if ($target eq 'meta') {      if ($target eq 'meta') {
  &end_output();   &end_output($target);
  $currentstring='</title>';   $currentstring='</title>';
     }       } 
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <meta> tag  #-- <meta> tag (end tag forbidden)
 sub start_meta {  sub start_meta {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 354  sub start_meta { Line 370  sub start_meta {
  } else {   } else {
     $currentstring = $token->[4];      $currentstring = $token->[4];
  }   }
     }      } elsif ($target eq 'meta') {
     if ($target eq 'meta') {  
  unless (&Apache::lonxml::get_param   unless (&Apache::lonxml::get_param
  ('http-equiv',$parstack,$safeeval,undef,1)) {   ('http-equiv',$parstack,$safeeval,undef,1)) {
     my $name=$token->[2]->{'name'};      my $name=$token->[2]->{'name'};
Line 363  sub start_meta { Line 378  sub start_meta {
     $name=~s/\s/\_/gs;      $name=~s/\s/\_/gs;
     $name=~s/\W//gs;      $name=~s/\W//gs;
     if ($name) {      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      &Apache::lonxml::get_param
  ('content',$parstack,$safeeval,undef,1).   ('content',$parstack,$safeeval,undef,1).
     '</'.$name.'>';   '</'.$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') {
    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;      return $currentstring;
 }  }
   
 sub end_meta {  sub end_meta {
     my ($target,$token,$tagstack,$parstack,$parser) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  my $args='';   my $args='';
Line 382  sub end_meta { Line 417  sub end_meta {
  if ($args ne '') {   if ($args ne '') {
     $currentstring = $token->[4];      $currentstring = $token->[4];
  }   }
     }       } elsif ($target eq 'tex') {
    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::endredirection();
    }
       }
     return $currentstring;      return $currentstring;
 }  }
   
Line 431  sub end_accessrule { Line 472  sub end_accessrule {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <body> tag  #-- <body> tag (end tag required)
 sub start_body {  sub start_body {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  if (!$Apache::lonxml::registered) {   if ($Apache::lonhomework::parsing_a_problem) {
       &Apache::lonxml::warning("<body> tag found inside of <problem> tag this can cause problems.");
       return '';
    }
    if (!$Apache::lonxml::registered && 
       $ENV{'request.state'} eq 'published') {
     $currentstring.='<head>'.      $currentstring.='<head>'.
  &Apache::lonmenu::registerurl(undef,$target).'</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='';   my $onLoad='';
  foreach my $key (keys(%{$token->[2]})) {   foreach my $key (keys(%{$token->[2]})) {
     if ($key =~ /^onload$/i) {      if ($key =~ /^onload$/i) {
Line 484  sub end_body { Line 553  sub end_body {
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[2];        $currentstring = $token->[2];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = '\end{document}';     $currentstring = '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}';  
     }       } 
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <center> tag  #-- <center> tag (end tag required)
 sub start_center {  sub start_center {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 497  sub start_center { Line 566  sub start_center {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = '\begin{center}';     $currentstring = '\begin{center}';  
     }  elsif ($target eq 'latexsource') {      }
  $currentstring = '\begin{center}';    
     }   
     return $currentstring;      return $currentstring;
 }  }
   
Line 510  sub end_center { Line 577  sub end_center {
  $currentstring = $token->[2];        $currentstring = $token->[2];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = '\end{center}';     $currentstring = '\end{center}';  
     }  elsif ($target eq 'latexsource') {      }
  $currentstring = '\end{center}';    
     }   
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <b> tag  #-- <b> tag (end tag required)
 sub start_b {  sub start_b {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 524  sub start_b { Line 589  sub start_b {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = '\textbf{';     $currentstring = '\textbf{';  
     }  elsif ($target eq 'latexsource') {  
  $currentstring = '\textbf{';    
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 537  sub end_b { Line 600  sub end_b {
  $currentstring = $token->[2];        $currentstring = $token->[2];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = '}';     $currentstring = '}';  
     } elsif ($target eq 'latexsource') {  
  $currentstring = '}';    
     }       } 
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <strong> tag  #-- <strong> tag (end tag required)
 sub start_strong {  sub start_strong {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 551  sub start_strong { Line 612  sub start_strong {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = '\textbf{';     $currentstring = '\textbf{';  
     } elsif ($target eq 'latexsource') {  
  $currentstring = '\textbf{';    
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 560  sub start_strong { Line 619  sub start_strong {
 sub end_strong {  sub end_strong {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
   
  $currentstring = $token->[2];        $currentstring = $token->[2];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = '}';     $currentstring = '}';  
     }  elsif ($target eq 'latexsource') {      }
  $currentstring = '}';    
     }   
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <h1> tag  #-- <h1> tag (end tag required)
 sub start_h1 {  sub start_h1 {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 592  sub start_h1 { Line 648  sub start_h1 {
  $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';    $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 
     } elsif ($target eq 'meta') {      } elsif ($target eq 'meta') {
  $currentstring='<subject>';   $currentstring='<subject>';
  &start_output();   &start_output($target);
     }      }
     return $currentstring;      return $currentstring;
 }  }
Line 614  sub end_h1 { Line 670  sub end_h1 {
  }   }
  $currentstring .= '}}'.$post;   $currentstring .= '}}'.$post;
     } elsif ($target eq 'meta') {      } elsif ($target eq 'meta') {
  &end_output();   &end_output($target);
  $currentstring='</subject>';   $currentstring='</subject>';
     }       } 
     return $currentstring;      return $currentstring;
Line 835  sub end_h6 { Line 891  sub end_h6 {
     return $currentstring;      return $currentstring;
 }  }
   
 #--- <cite> tag  #--- <cite> tag (end tag required)
 sub start_cite {  sub start_cite {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= "\\textit{";   $currentstring .= '\textit{';
     }  elsif ($target eq 'latexsource') {      }
  $currentstring .= "\\textit{";  
     }   
     return $currentstring;      return $currentstring;
 }  }
   
Line 855  sub end_cite { Line 909  sub end_cite {
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[2];   $currentstring .= $token->[2];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= "}";   $currentstring .= '}';
     }  elsif ($target eq 'latexsource') {      }
  $currentstring .= "}";  
     }   
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <i> tag  #-- <i> tag (end tag required)
 sub start_i {  sub start_i {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 870  sub start_i { Line 922  sub start_i {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= '\textit{';   $currentstring .= '\textit{';
     }  elsif ($target eq 'latexsource') {      }
  $currentstring .= '\textit{';  
     }   
     return $currentstring;      return $currentstring;
 }  }
   
Line 883  sub end_i { Line 933  sub end_i {
  $currentstring .= $token->[2];   $currentstring .= $token->[2];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= '}';   $currentstring .= '}';
     } elsif ($target eq 'latexsource') {  
  $currentstring .= '}';  
     }       } 
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <address> tag  #-- <address> tag (end tag required)
 sub start_address {  sub start_address {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= "\\textit{";   $currentstring .= '\textit{';
     } elsif ($target eq 'latexsource') {      }
  $currentstring .= "\\textit{";  
     }   
     return $currentstring;      return $currentstring;
 }  }
   
Line 909  sub end_address { Line 955  sub end_address {
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[2];   $currentstring .= $token->[2];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= "}";   $currentstring .= '}';
     } elsif ($target eq 'latexsource') {  
  $currentstring .= "}";  
     }      }
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <dfn> tag  #-- <dfn> tag (end tag required)
 sub start_dfn {  sub start_dfn {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= "\\textit{";   $currentstring .= '\textit{';
     } elsif ($target eq 'latexsource') {  
  $currentstring .= "\\textit{";  
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 936  sub end_dfn { Line 978  sub end_dfn {
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[2];   $currentstring .= $token->[2];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= "}";   $currentstring .= '}';
     } elsif ($target eq 'latexsource') {      }
  $currentstring .= "}";  
     }   
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <tt> tag  #-- <tt> tag (end tag required)
 sub start_tt {  sub start_tt {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 951  sub start_tt { Line 991  sub start_tt {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= '\texttt{';   $currentstring .= '\texttt{';
     } elsif ($target eq 'latexsource') {      }
  $currentstring .= '\texttt{';  
     }   
     return $currentstring;      return $currentstring;
 }  }
   
Line 964  sub end_tt { Line 1002  sub end_tt {
  $currentstring .= $token->[2];   $currentstring .= $token->[2];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= '}';   $currentstring .= '}';
     } elsif ($target eq 'latexsource') {  
  $currentstring .= '}';  
     }      }
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <kbd> tag  #-- <kbd> tag (end tag required)
 sub start_kbd {  sub start_kbd {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= "\\texttt";   $currentstring .= '\texttt{';
     } elsif ($target eq 'latexsource') {      }
  $currentstring .= "\\texttt{";  
     }   
     return $currentstring;      return $currentstring;
 }  }
   
Line 990  sub end_kbd { Line 1024  sub end_kbd {
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[2];   $currentstring .= $token->[2];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= "}";   $currentstring .= '}';
     } elsif ($target eq 'latexsource') {      }
  $currentstring .= "}";  
     }   
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <code> tag  #-- <code> tag (end tag required)
 sub start_code {  sub start_code {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 1020  sub end_code { Line 1052  sub end_code {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <em> tag  #-- <em> tag (end tag required)
 sub start_em {  sub start_em {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 1028  sub start_em { Line 1060  sub start_em {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= '\emph{';   $currentstring .= '\emph{';
     } elsif ($target eq 'latexsource') {      }
  $currentstring .= '\emph{';  
     }   
     return $currentstring;      return $currentstring;
 }  }
   
Line 1041  sub end_em { Line 1071  sub end_em {
  $currentstring .= $token->[2];   $currentstring .= $token->[2];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= '}';   $currentstring .= '}';
     } elsif ($target eq 'latexsource') {      } 
  $currentstring .= '}';  
     }    
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <q> tag  #-- <q> tag (end tag required)
 sub start_q {  sub start_q {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= "\\emph{";   $currentstring .= '\emph{';
     }  elsif ($target eq 'latexsource') {  
  $currentstring .= "\\emph{";  
     }      }
     return $currentstring;      return $currentstring;
 }  }
Line 1067  sub end_q { Line 1093  sub end_q {
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[2];   $currentstring .= $token->[2];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= "}";   $currentstring .= '}';
     } elsif ($target eq 'latexsource') {      } 
  $currentstring .= "}";  
     }    
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <p> tag  #-- <p> tag (end tag optional)
   #optional attribute - align="center|left|right"
 sub start_p {  sub start_p {
     my ($target,$token) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= '{\par ';   my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
     } elsif ($target eq 'latexsource') {   if ($align eq 'center') {
  $currentstring .= '{\par ';      $currentstring='\begin{center}\par';
     }    } elsif ($align eq 'right') {
       $currentstring='\makebox['.$ENV{'form.textwidth'}.']{\hfill\llap{';
    } elsif ($align eq 'left') {
       $currentstring='\noindent\makebox['.$ENV{'form.textwidth'}.']{\rlap{';
    }
    my $signal=1;#<p> does not work inside <b>...</b> 
    foreach my $tag (@$tagstack) {if (lc($tag) eq 'b') {$signal=0;}
    if (!$signal) {$currentstring = '';}
    }
       }
     return $currentstring;      return $currentstring;
 }  }
   
 sub end_p {  sub end_p {
     my ($target,$token) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[2];   $currentstring .= $token->[2];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= '}';   if ($$tagstack[-1] eq 'p') {
     } elsif ($target eq 'latexsource') {      my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  $currentstring .= '}';      if ($align eq 'center') {
    $currentstring .= '\end{center}';
       } elsif ($align eq 'right') {
    $currentstring .= '}}';
       } elsif ($align eq 'left') {
    $currentstring .= '}\hfill}';
       }
    }
     }      }
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <br> tag  #-- <br> tag (end tag forbidden)
 sub start_br {  sub start_br {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my $currentstring = '';      my $currentstring = '';
Line 1109  sub start_br { Line 1150  sub start_br {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  if ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') {   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;      return $currentstring;
 }  }
   
Line 1126  sub end_br { Line 1165  sub end_br {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <big> tag  #-- <big> tag (end tag required)
 sub start_big {  sub start_big {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= '\large{';   $currentstring .= '{\large ';
     } elsif ($target eq 'latexsource') {      } 
  $currentstring .= '{\Large ';  
     }    
     return $currentstring;      return $currentstring;
 }  }
   
Line 1147  sub end_big { Line 1184  sub end_big {
  $currentstring .= $token->[2];   $currentstring .= $token->[2];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= '}';   $currentstring .= '}';
     } elsif ($target eq 'latexsource') {  
  $currentstring .= '}';  
     }      }
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <small> tag  #-- <small> tag (end tag required)
 sub start_small {  sub start_small {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 1161  sub start_small { Line 1196  sub start_small {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= '{\footnotesize ';   $currentstring .= '{\footnotesize ';
     } elsif ($target eq 'latexsource') {      }
  $currentstring .= '{\footnotesize ';  
     }   
     return $currentstring;      return $currentstring;
 }  }
   
Line 1174  sub end_small { Line 1207  sub end_small {
  $currentstring .= $token->[2];   $currentstring .= $token->[2];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= '}';   $currentstring .= '}';
     } elsif ($target eq 'latexsource') {  
  $currentstring .= '}';  
     }      }
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <basefont> tag  #-- <basefont> tag (end tag forbidden)
 sub start_basefont {  sub start_basefont {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my $currentstring = '';      my $currentstring = '';
Line 1209  sub end_basefont { Line 1240  sub end_basefont {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <font> tag  #-- <font> tag (end tag required)
 sub start_font {  sub start_font {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);   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];        $currentstring = $token->[4];     
     }  elsif ($target eq 'tex') {      }  elsif ($target eq 'tex') {
  my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);   my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
Line 1242  sub end_font { Line 1278  sub end_font {
     return $currentstring;      return $currentstring;
 }  }
     
 #-- <strike> tag  #-- <strike> tag (end tag required)
 sub start_strike {  sub start_strike {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 1268  sub end_strike { Line 1304  sub end_strike {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <s> tag  #-- <s> tag (end tag required)
 sub start_s {  sub start_s {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 1294  sub end_s { Line 1330  sub end_s {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <sub> tag  #-- <sub> tag (end tag required)
 sub start_sub {  sub start_sub {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= "\$_{ ";   $currentstring .= "\$_{";
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 1312  sub end_sub { Line 1348  sub end_sub {
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[2];   $currentstring .= $token->[2];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= " }\$";   $currentstring .= "}\$";
     }      }
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <sup> tag  #-- <sup> tag (end tag required)
 sub start_sup {  sub start_sup {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= "\$^{ ";   $currentstring .= "\$^{";
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 1335  sub end_sup { Line 1371  sub end_sup {
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[2];   $currentstring .= $token->[2];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= " }\$";   $currentstring .= "}\$";
     }      }
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <hr> tag  #-- <hr> tag (end tag forbidden)
 sub start_hr {  sub start_hr {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } 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 (defined $LaTeXwidth) {
     if ($LaTeXwidth=~/^%/) {      if ($LaTeXwidth=~/^%/) {
  substr($LaTeXwidth,0,1)='';   substr($LaTeXwidth,0,1)='';
  $LaTeXwidth=($LaTeXwidth/100).'\textwidth';   $LaTeXwidth=($LaTeXwidth/100).'\textwidth';
     }      }
  } else {   } else {
     $LaTeXwidth ='0.95\textwidth';      $LaTeXwidth ='0.9\textwidth';
  }   }
  my ($pre,$post);   my ($pre,$post);
  my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);   my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
Line 1365  sub start_hr { Line 1401  sub start_hr {
  } elsif ($align eq 'right') {   } elsif ($align eq 'right') {
     $pre=' \hfill \llap{'; $post='}';      $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 ';                                      $LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm ';
     }       } 
     return $currentstring;      return $currentstring;
Line 1376  sub end_hr { Line 1412  sub end_hr {
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[2];   $currentstring .= $token->[2];
     } elsif ($target eq 'tex') {      }
     }   
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <div> tag  #-- <div> tag (end tag required)
 sub start_div {  sub start_div {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 1400  sub end_div { Line 1435  sub end_div {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <a> tag  #-- <a> tag (end tag required)
 sub start_a {  sub start_a {
     my ($target,$token) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
    my $a=&Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1);
    my $b=&Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1);
    if ($a=~/\S/) {
       $a=~s/([^\\])%/$1\\\%/g;
       $currentstring .= '\ref{URI: '.$a.'}';
    } elsif ($b=~/\S/) {
       $currentstring .= '\ref{Anchor: '.$b.'}';
    } else {
       $currentstring.='';
    }
     }      }
     return $currentstring;      return $currentstring;
 }  }
   
 sub end_a {  sub end_a {
     my ($target,$token,$tagstack,$stackref) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[2];   $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;      return $currentstring;
 }  }
   
 #-- <li> tag  #-- <li> tag (end tag optional)
 sub start_li {  sub start_li {
     my ($target,$token,$tagstack,$stackref) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  my  $tempor_var = $stackref->[$#$stackref];   my  $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,1);
  if (index($tempor_var,'circle') != -1 ) {   if ($type=~/circle/) {
     $currentstring .= " \\item[o] ";      $currentstring .= ' \item[o] ';
  } elsif (index($tempor_var,'square') != -1 ) {   } elsif ($type=~/square/) {
     $currentstring .= " \\item[$\Box$] ";      $currentstring .= ' \item[$\Box$] ';
  } elsif ($tempor_var ne '') {    } elsif ($type ne '') { 
     $_ = $tempor_var;      $currentstring .= ' \item['.$type.'] ';
     m/my\s*([^=]*)=/;  
     $currentstring .= " \\item[$1] ";  
  } else {   } else {
     $currentstring .= " \\item ";      $currentstring .= ' \item ';
  }     }  
     }       } 
     return $currentstring;      return $currentstring;
Line 1460  sub end_li { Line 1495  sub end_li {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <u> tag  #-- <u> tag (end tag required)
 sub start_u {  sub start_u {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 1486  sub end_u { Line 1521  sub end_u {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <ul> tag  #-- <ul> tag (end tag required)
 sub start_ul {  sub start_ul {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 1529  sub end_ul { Line 1564  sub end_ul {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <menu> tag  #-- <menu> tag (end tag required)
 sub start_menu {  sub start_menu {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 1552  sub end_menu { Line 1587  sub end_menu {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <dir> tag  #-- <dir> tag (end tag required)
 sub start_dir {  sub start_dir {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 1575  sub end_dir { Line 1610  sub end_dir {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <ol> tag  #-- <ol> tag (end tag required)
 sub start_ol {  sub start_ol {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 1628  sub end_ol { Line 1663  sub end_ol {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <dl> tag  #-- <dl> tag (end tag required)
 sub start_dl {  sub start_dl {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = '\begin{description}';     $currentstring = '\begin{description}';
    @Apache::londefdef::description=();
    $Apache::londefdef::DD_redirection=0;
    $Apache::londefdef::DT_redirection=0;
     }       } 
     return $currentstring;      return $currentstring;
 }  }
   
 sub end_dl {  sub end_dl {
     my ($target,$token) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[2];        $currentstring = $token->[2];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = '\end{description}';     if ($Apache::londefdef::DT_redirection) {
       my $data=&item_cleanup;
       push @Apache::londefdef::description,'\item['.$data.']';
       $Apache::londefdef::DT_redirection=0;
    } elsif ($Apache::londefdef::DD_redirection) {
       $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection();
    }
    foreach my $element (@Apache::londefdef::description) {
       $currentstring.=' '.$element.' ';
    }
    @Apache::londefdef::description=();
    $currentstring.='\end{description}';  
     }       } 
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <dt> tag  #-- <dt> tag (end tag optional)
 sub start_dt {  sub start_dt {
     my ($target,$token) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring='';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = '\item[';     if ($Apache::londefdef::DT_redirection) {
       my $data=&item_cleanup;
       push @Apache::londefdef::description,'\item['.$data.']';
       $Apache::londefdef::DT_redirection=0;
    } elsif ($Apache::londefdef::DD_redirection) {
       $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection();
       $Apache::londefdef::DD_redirection=0;
    }
    &Apache::lonxml::startredirection();
    $Apache::londefdef::DT_redirection=1;
     }       } 
     return $currentstring;      return $currentstring;
 }  }
   
 sub end_dt {  sub end_dt {
     my ($target,$token) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[2];       $currentstring = $token->[2];    
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = ']';     my $data=&item_cleanup;
    push @Apache::londefdef::description,'\item['.$data.']';
    $Apache::londefdef::DT_redirection=0;
     }       } 
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <dd> tag  sub item_cleanup {
       my $item=&Apache::lonxml::endredirection();
       $item=~s/\\begin{center}//g;
       $item=~s/\\end{center}//g;
       return $item;
   }
   
   #-- <dd> tag (end tag optional)
 sub start_dd {  sub start_dd {
     my ($target,$token) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
       } elsif ($target eq 'tex') {
    if ($Apache::londefdef::DT_redirection) {
       my $data=&item_cleanup;
       push @Apache::londefdef::description,'\item['.$data.']';
       $Apache::londefdef::DT_redirection=0;
    }
    $Apache::londefdef::DD_redirection=1;
    &Apache::lonxml::startredirection();
     }       } 
     return $currentstring;      return $currentstring;
 }  }
   
 sub end_dd {  sub end_dd {
     my ($target,$token) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[2];       $currentstring = $token->[2];    
     }       }  elsif ($target eq 'tex') {
    $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection();
    $Apache::londefdef::DD_redirection=0;
       }
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <table> tag  #-- <table> tag (end tag required)
 sub start_table {  sub start_table {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $textwidth;      my $textwidth='';
     if (not defined @Apache::londefdef::table) {      if (not defined @Apache::londefdef::table) {
  $textwidth=&recalc($ENV{'form.textwidth'});   $textwidth=&recalc($ENV{'form.textwidth'});
  $textwidth=~/(\d+)/;   $textwidth=~/(\d+\.?\d*)/;
  $textwidth=$1;   $textwidth=0.95*$1;
     } else {      } else {
  $textwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);   $textwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
     }      }
Line 1742  sub start_table { Line 1820  sub start_table {
     $Apache::londefdef::table[-1]{'vvinc'} = '';      $Apache::londefdef::table[-1]{'vvinc'} = '';
  }   }
  $Apache::londefdef::table[-1]{'output'} = ' \noindent \begin{tabular} ';   $Apache::londefdef::table[-1]{'output'} = ' \noindent \begin{tabular} ';
  $currentstring = '\keephidden{NEW TABLE ENTRY '.$textwidth.'}';   $currentstring = '\keephidden{NEW TABLE ENTRY}';
     }      }
     return $currentstring;      return $currentstring;
 }  }
Line 1790  sub end_table { Line 1868  sub end_table {
  $needed=$#length_row_final-$needed+1;   $needed=$#length_row_final-$needed+1;
  for (my $jn=0;$jn<=$#length_row_final;$jn++) {   for (my $jn=0;$jn<=$#length_row_final;$jn++) {
     if ($length_row_final[$jn]==0) {      if ($length_row_final[$jn]==0) {
  if ($length_raw_row[$jn]<$available_length/3) {   if ($length_raw_row[$jn]<$available_length) {
     $length_row_final[$jn]=$length_raw_row[$jn];      $length_row_final[$jn]=$length_raw_row[$jn];
     $available_length=$available_length-$length_raw_row[$jn];      $available_length=$available_length-$length_raw_row[$jn];
     $needed--;      $needed--;
Line 1820  sub end_table { Line 1898  sub end_table {
  } else {   } else {
     $currentstring .= $Apache::londefdef::table[-1]{'output'};      $currentstring .= $Apache::londefdef::table[-1]{'output'};
     pop @Apache::londefdef::table;      pop @Apache::londefdef::table;
       undef @Apache::londefdef::table;
  }   }
     }      }
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <tr> tag  #-- <tr> tag (end tag optional)
 sub start_tr {  sub start_tr {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 1848  sub start_tr { Line 1927  sub start_tr {
 }  }
                   
 sub end_tr {  sub end_tr {
     my ($target,$token) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[2];        $currentstring = $token->[2];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
    if ($Apache::londefdef::TD_redirection) {
       &end_td_tex($parstack,$parser,$safeeval);    
    }
  push @{ $Apache::londefdef::table[-1]{'TeXlengthrow'} },$Apache::londefdef::table[-1]{'TeXlength'};   push @{ $Apache::londefdef::table[-1]{'TeXlengthrow'} },$Apache::londefdef::table[-1]{'TeXlength'};
  push @{ $Apache::londefdef::table[-1]{'lengthrow'} },$Apache::londefdef::table[-1]{'length'};   push @{ $Apache::londefdef::table[-1]{'lengthrow'} },$Apache::londefdef::table[-1]{'length'};
     }      }
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <td> tag  #-- <td> tag (end tag optional)
 sub start_td {  sub start_td {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);   $Apache::londefdef::TD_redirection = 1;
  if ($what_to_push eq '') {   &tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval);
     $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);;  
  }  
  push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push;  
  $Apache::londefdef::table[-1]{'counter_columns'}++;  
  &Apache::lonxml::startredirection();  
     }       } 
     return $currentstring;      return $currentstring;
 }     }   
            
   sub tag_check {
       my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
       my @ar=@$parstack; 
       for (my $i=$#ar-1;$i>=0;$i--) {
    if (lc($$tagstack[$i]) eq $good_tag) {
       &start_td_tex($parstack,$parser,$safeeval);
       last;
    } elsif (lc($$tagstack[$i]) eq $bad_tag) {
       splice @ar, $i+1;
       &end_td_tex(\@ar,$parser,$safeeval);
       &start_td_tex($parstack,$parser,$safeeval);
       last;
    }
       }
       return '';
   }
    
   sub start_td_tex {
       my ($parstack,$parser,$safeeval) = @_;
       my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
       if ($what_to_push eq '') {
    $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);;
       }
       push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push;
       $Apache::londefdef::table[-1]{'counter_columns'}++;
       &Apache::lonxml::startredirection();
       return '';
   }
   
   sub end_td_tex {
       my ($parstack,$parser,$safeeval) = @_;
       my $current_row = $Apache::londefdef::table[-1]{'row_number'};
       my $data=&Apache::lonxml::endredirection();
       my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
       if (defined $TeXwidth) {
    my $current_length=&recalc($TeXwidth);
    $current_length=~/(\d+)/;
    $Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
    $Apache::londefdef::table[-1]{'length'} .= '0,';
       } else {
    if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
       my $current_length=&recalc($1);
       $current_length=~/(\d+\.?\d*)/;
       $Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
       $Apache::londefdef::table[-1]{'length'} .= '0,';
    } else {  
       $data=~s/^\s+(\S.*)/$1/; 
       $data=~s/(.*\S)\s+$/$1/;
       $data=~s/(\s)+/$1/;
       my $current_length=0;
       if ($data=~/\\vskip/) {
                   my $newdata=$data;
    $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
    my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
    foreach my $elementdata (@newdata) {
       my $lengthnewdata=1.8*LATEX_length($elementdata);
       if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
    }
       } else {
    $current_length=1.8*LATEX_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++) {         
       $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'};
       return'';
   }
   
 sub end_td {  sub end_td {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[2];        $currentstring = $token->[2];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  my $current_row = $Apache::londefdef::table[-1]{'row_number'};          $Apache::londefdef::TD_redirection =0;
  my $data=&Apache::lonxml::endredirection();   &end_td_tex($parstack,$parser,$safeeval);
  my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);  
  if (defined $TeXwidth) {  
     my $current_length=&recalc($TeXwidth);  
     $current_length=~/(\d+)/;  
     $Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';  
     $Apache::londefdef::table[-1]{'length'} .= '0,';  
  } else {  
     if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {  
  my $current_length=&recalc($1);  
  $current_length=~/(\d+)/;  
  $Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';  
  $Apache::londefdef::table[-1]{'length'} .= '0,';  
     } else {       
  $data=~/^\s*(\S.*)/;  
  $data=$1;  
  $data=~/(.*\S)\s*$/;  
  $data=$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++) {                                  
     $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'};  
     }      }
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <th> tag  #-- <th> tag (end tag optional)
 sub start_th {  sub start_th {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 1971  sub end_th { Line 2094  sub end_th {
     }      }
     return $currentstring;      return $currentstring;
 }  }
 #-- <img> tag  #-- <img> tag (end tag forbidden)
 sub start_img {  sub start_img {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,      my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,
  undef,1);   undef,1);
       if (not $src and ($target eq 'web' or $target eq 'tex')) { 
    my $inside = &Apache::lonxml::get_all_text("/img",$parser);
    &Apache::lonnet::logthis("inside was $inside");
    return '';
       }
     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;      $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
     my $currentstring = '';      my $currentstring = '';
     my $width_param = '';  
     my $height_param = '';  
     my $scaling = .3;      my $scaling = .3;
       
     if ($target eq 'web') {      if ($target eq 'web') {
  if ($ENV{'browser.imagesuppress'} ne 'on') {   if ($ENV{'browser.imagesuppress'} ne 'on') {
     $currentstring = $token->[4];      $currentstring.= $token->[4];
  } else {   } else {
     my $alttag= &Apache::lonxml::get_param      my $alttag= &Apache::lonxml::get_param
  ('alt',$parstack,$safeeval,undef,1);   ('alt',$parstack,$safeeval,undef,1);
Line 1992  sub start_img { Line 2117  sub start_img {
  $alttag=&Apache::lonmeta::alttag   $alttag=&Apache::lonmeta::alttag
     ($Apache::lonxml::pwd[-1],$src);      ($Apache::lonxml::pwd[-1],$src);
     }      }
     $currentstring='[IMAGE: '.$alttag.']';      $currentstring.='[IMAGE: '.$alttag.']';
  }   }
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);   $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
  &image_replication($src);  
   
  #if original gif/jpg/png file exist do following:   #if original gif/jpg/png file exist do following:
  if (-e $src) {             if (-e $src) {
     #defines the default size of image      #what is the image size?
     my $image = Image::Magick->new;      my $width_param=&image_size($src,$scaling,$parstack,$safeeval);
     my $current_figure = $image->Read($src);              my ($file,$path)=&file_path($src); 
     $width_param = $image->Get('width') * $scaling;;  
     $height_param = $image->Get('height') * $scaling;;  
     undef $image;  
     #do we have any specified size of the picture?  
     my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval);  
     my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval);  
     my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval,  
    undef,1);  
     if ($TeXwidth ne '') {    
  if ($TeXwidth=~/(\d+)\s*\%/) {  
     $width_param = $1*$ENV{'form.textwidth'}/100;  
  } else {   
     $width_param = $TeXwidth;  
  }  
     } elsif ($TeXheight ne '') {  
  $width_param = $TeXheight/$height_param*$width_param;  
     } elsif ($width ne '') {  
  $width_param = $width*$scaling;        
     }  
     my $file;  
     my $path;  
     if ($src =~ m!(.*)/([^/]*)$!) {  
  $file = $2;   
  $path = $1.'/';   
     }   
     my $newsrc = $src;      my $newsrc = $src;
     $newsrc =~ s/\.(gif|jpg|png)$/.eps/i;      $newsrc =~ s/\.(gif|jpg|png)$/.eps/i;
     $file=~s/\.(gif|jpg|png)$/.eps/i;      $file=~s/\.(gif|jpg|png)$/.eps/i;
Line 2047  sub start_img { Line 2145  sub start_img {
  $currentstring .= '\vskip 1 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';   $currentstring .= '\vskip 1 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
     }      }
  } else {   } else {
     #there aren't eps or ps - so create eps       #care about eps dynamical generation
     my $temp_file;      $currentstring.='\vskip 1 mm '.&eps_generation($src,$file,$width_param);
     my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat";  
     $temp_file = Apache::File->new('>>'.$filename);   
     print $temp_file "$src\n";  
     $currentstring .= '\vskip 1 mm \graphicspath{{/home/httpd/prtspool/}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';  
  }   }
     }      }
  } else {   } else {
Line 2069  sub start_img { Line 2163  sub start_img {
  #<allow> tag will care about replication    #<allow> tag will care about replication 
     }      }
  }   }
       } elsif ($target eq 'edit') {
    $currentstring .=&Apache::edit::tag_start($target,$token);
    $currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70).
       &Apache::edit::browse('src',undef,'alt').' '.
       &Apache::edit::search('src',undef,'alt').'<br />';
    $currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'<br />';
    $currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5);
    $currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'<br />';
    $currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5);
    $currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5);
    $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
    my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval);
    my $alt=&Apache::lonxml::get_param('alt',$parstack,$safeeval);
    my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval);
    my $height=&Apache::lonxml::get_param('height',$parstack,$safeeval);
    $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
    if ($width) { $currentstring.=' width="'.$width.'" '; }
    if ($height) { $currentstring.=' height="'.$height.'" '; }
    $currentstring .= ' />';
       } elsif ($target eq 'modified') {
    my $constructtag=&Apache::edit::get_new_args($token,$parstack,
        $safeeval,'src','alt',
        'TeXwidth','TeXheight',
        'width','height');
    $src=$token->[2]{'src'};
    if (!$token->[2]{'width'} && !$token->[2]{'height'}) {
       $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
       &image_replication($src);
       if (-e $src) {
    my $image = Image::Magick->new;
    my ($width, $height, $size, $format) = $image->Ping($src);
    if ($width && $height) {
       $token->[2]{'width'} =$width;
       $token->[2]{'height'}=$height;
       $constructtag=1;
    }
       }
    }
    if ($constructtag) {$currentstring=&Apache::edit::rebuild_tag($token);}
     }      }
     return $currentstring;      return $currentstring;
 }  }
Line 2084  sub end_img { Line 2217  sub end_img {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <applet> tag  #-- <applet> tag (end tag required)
 sub start_applet {  sub start_applet {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
           
Line 2109  sub start_applet { Line 2242  sub start_applet {
     $currentstring='[APPLET: '.$alttag.']';      $currentstring='[APPLET: '.$alttag.']';
  }   }
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = " \\begin{figure} ";   my $alttag= &Apache::lonxml::get_param('alt',$parstack,
          $safeeval,undef,1);
    unless ($alttag) {
       my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,
    undef,1);
       $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
        $code);
    }
    $currentstring.='\begin{center} \fbox{Java Applet: '.$alttag.
       '.}\end{center}';
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 2120  sub end_applet { Line 2262  sub end_applet {
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[2];   $currentstring = $token->[2];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = " \\end{figure}";  
     }       } 
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <embed> tag  #-- <embed> tag (end tag optional/required)
 sub start_embed {      sub start_embed {    
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);      my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
Line 2143  sub start_embed { Line 2284  sub start_embed {
     $currentstring='[EMBED: '.$alttag.']';      $currentstring='[EMBED: '.$alttag.']';
  }   }
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = " \\begin{figure} ";    
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 2153  sub end_embed { Line 2293  sub end_embed {
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[2];        $currentstring = $token->[2];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {  
  $currentstring = " \\end{figure}";    
     }       } 
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <param> tag  #-- <param> tag (end tag forbidden)
 sub start_param {  sub start_param {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     if (&Apache::lonxml::get_param      if (&Apache::lonxml::get_param
Line 2173  sub start_param { Line 2312  sub start_param {
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = " \\begin{figure} ";    
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 2184  sub end_param { Line 2322  sub end_param {
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[2];        $currentstring = $token->[2];     
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring = " \\end{figure}";    
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 2194  sub start_allow { Line 2331  sub start_allow {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);      my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
     $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);      $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;      $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
    &Apache::lonnet::clutter($src);
     &image_replication($src);      &image_replication($src);
     my $result;      my $result;
     if ($target eq 'edit') {      if ($target eq 'edit') {
Line 2215  sub end_allow { Line 2353  sub end_allow {
     return '';      return '';
 }  }
   
 #-- Frames  #-- Frames (end tag required)
   #-- <frameset>
 sub start_frameset {  sub start_frameset {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {       if ($target eq 'web') { 
  if (!$Apache::lonxml::registered) {   if (!$Apache::lonxml::registered &&
       $ENV{'request.state'} eq 'published') {
     $currentstring.='<head>'.      $currentstring.='<head>'.
  &Apache::lonmenu::registerurl(undef,$target).'</head>';   &Apache::lonmenu::registerurl(undef,$target).'</head>';
  }   }
  $currentstring .= $token->[4];   my $onLoad='';
    foreach my $key (keys(%{$token->[2]})) {
       if ($key =~ /^onload$/i) {
    $onLoad.=$token->[2]->{$key}.';';
    delete($token->[2]->{$key});
       }
    }
    $token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad;
    my $onUnload='';
    foreach my $key (keys(%{$token->[2]})) {
       if ($key =~ /^onunload$/i) {
    $onUnload.=$token->[2]->{$key}.';';
    delete($token->[2]->{$key});
       }
    }
    $token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents().
       ';'.$onUnload;
   
    $currentstring .= '<'.$token->[1];
    foreach (keys %{$token->[2]}) {
       $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
    }
    $currentstring.='>';
     }      }
     return $currentstring;      return $currentstring;
 }  }
Line 2238  sub end_frameset { Line 2400  sub end_frameset {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <pre>  #-- <xmp> (end tag required)
   sub start_xmp {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
       my $currentstring = '';
       if ($target eq 'web') {
    $currentstring .= $token->[4];
       } elsif ($target eq 'tex') {
    $currentstring .= '\begin{verbatim}';
       } 
       return $currentstring;
   }
   
   sub end_xmp {
       my ($target,$token) = @_;
       my $currentstring = '';
       if ($target eq 'web') {
    $currentstring .= $token->[2];
       } elsif ($target eq 'tex') {
    $currentstring .= '\end{verbatim}';
       }
       return $currentstring;
   }
   
   #-- <pre> (end tag required)
 sub start_pre {  sub start_pre {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[4];   $currentstring .= $token->[4];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  my $width = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);   $currentstring .= '\begin{verbatim}';
  if (not defined $width) {$width ='\textwidth';}  
  $currentstring .= '\parbox['.$width.']{\begin{verbatim}';  
     }       } 
     return $currentstring;      return $currentstring;
 }  }
Line 2258  sub end_pre { Line 2441  sub end_pre {
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring .= $token->[2];   $currentstring .= $token->[2];
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $currentstring .= '\end{verbatim}}';   $currentstring .= '\end{verbatim}';
     }      }
     return $currentstring;      return $currentstring;
 }  }
Line 2323  sub end_blankspace { Line 2506  sub end_blankspace {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <abbr> tag  #-- <abbr> tag (end tag required)
 sub start_abbr {  sub start_abbr {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2342  sub end_abbr { Line 2525  sub end_abbr {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <acronym> tag  #-- <acronym> tag (end tag required)
 sub start_acronym {  sub start_acronym {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2361  sub end_acronym { Line 2544  sub end_acronym {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <area> tag  #-- <area> tag (end tag forbidden)
 sub start_area {  sub start_area {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2380  sub end_area { Line 2563  sub end_area {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <base> tag  #-- <base> tag (end tag forbidden)
 sub start_base {  sub start_base {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     }       }
     return $currentstring;      return $currentstring;
 }  }
   
Line 2399  sub end_base { Line 2582  sub end_base {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <bdo> tag  #-- <bdo> tag (end tag required)
 sub start_bdo {  sub start_bdo {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2418  sub end_bdo { Line 2601  sub end_bdo {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <bgsound> tag  #-- <bgsound> tag (end tag optional)
 sub start_bgsound {  sub start_bgsound {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2437  sub end_bgsound { Line 2620  sub end_bgsound {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <blink> tag  #-- <blink> tag (end tag required)
 sub start_blink {  sub start_blink {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2456  sub end_blink { Line 2639  sub end_blink {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <blockquote> tag  #-- <blockquote> tag (end tag required)
 sub start_blockquote {  sub start_blockquote {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2475  sub end_blockquote { Line 2658  sub end_blockquote {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <button> tag  #-- <button> tag (end tag required)
 sub start_button {  sub start_button {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2494  sub end_button { Line 2677  sub end_button {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <caption> tag  #-- <caption> tag (end tag required)
 sub start_caption {  sub start_caption {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2513  sub end_caption { Line 2696  sub end_caption {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <col> tag  #-- <col> tag (end tag forbdden)
 sub start_col {  sub start_col {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2532  sub end_col { Line 2715  sub end_col {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <colgroup> tag  #-- <colgroup> tag (end tag optional)
 sub start_colgroup {  sub start_colgroup {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2551  sub end_colgroup { Line 2734  sub end_colgroup {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <del> tag  #-- <del> tag (end tag required)
 sub start_del {  sub start_del {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2570  sub end_del { Line 2753  sub end_del {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <fieldset> tag  #-- <fieldset> tag (end tag required)
 sub start_fieldset {  sub start_fieldset {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2589  sub end_fieldset { Line 2772  sub end_fieldset {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <frame> tag  #-- <frame> tag (end tag forbidden)
 sub start_frame {  sub start_frame {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2608  sub end_frame { Line 2791  sub end_frame {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <iframe> tag  #-- <iframe> tag (end tag required)
 sub start_iframe {  sub start_iframe {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2627  sub end_iframe { Line 2810  sub end_iframe {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <ins> tag  #-- <ins> tag (end tag required)
 sub start_ins {  sub start_ins {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2646  sub end_ins { Line 2829  sub end_ins {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <isindex> tag  #-- <isindex> tag (end tag forbidden)
 sub start_isindex {  sub start_isindex {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2665  sub end_isindex { Line 2848  sub end_isindex {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <keygen> tag  #-- <keygen> tag (end tag forbidden)
 sub start_keygen {  sub start_keygen {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2703  sub end_label { Line 2886  sub end_label {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <layer> tag  #-- <layer> tag (end tag required)
 sub start_layer {  sub start_layer {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2722  sub end_layer { Line 2905  sub end_layer {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <legend> tag  #-- <legend> tag (end tag required)
 sub start_legend {  sub start_legend {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2741  sub end_legend { Line 2924  sub end_legend {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <link> tag  #-- <link> tag (end tag forbidden)
 sub start_link {  sub start_link {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2760  sub end_link { Line 2943  sub end_link {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <marquee> tag  #-- <marquee> tag (end tag optional)
 sub start_marquee {  sub start_marquee {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2779  sub end_marquee { Line 2962  sub end_marquee {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <malticol> tag  #-- <multicol> tag (end tag required)
 sub start_malticol {  sub start_multicol {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
Line 2789  sub start_malticol { Line 2972  sub start_malticol {
     return $currentstring;      return $currentstring;
 }  }
   
 sub end_malticol {  sub end_multicol {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
Line 2798  sub end_malticol { Line 2981  sub end_malticol {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <nobr> tag  #-- <nobr> tag (end tag required)
 sub start_nobr {  sub start_nobr {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     }       }  elsif ($target eq 'tex') {
    $currentstring='\mbox{';
       }
     return $currentstring;      return $currentstring;
 }  }
   
Line 2813  sub end_nobr { Line 2998  sub end_nobr {
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[2];       $currentstring = $token->[2];    
     }       }   elsif ($target eq 'tex') {
    $currentstring='}';
       }
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <noembed> tag  #-- <noembed> tag (end tag required)
 sub start_noembed {  sub start_noembed {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2836  sub end_noembed { Line 3023  sub end_noembed {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <noframes> tag  #-- <noframes> tag (end tag required)
 sub start_noframes {  sub start_noframes {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2855  sub end_noframes { Line 3042  sub end_noframes {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <nolayer> tag  #-- <nolayer> tag (end tag required)
 sub start_nolayer {  sub start_nolayer {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2874  sub end_nolayer { Line 3061  sub end_nolayer {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <noscript> tag  #-- <noscript> tag (end tag required)
 sub start_noscript {  sub start_noscript {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2893  sub end_noscript { Line 3080  sub end_noscript {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <object> tag  #-- <object> tag (end tag required)
 sub start_object {  sub start_object {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2912  sub end_object { Line 3099  sub end_object {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <optgroup> tag  #-- <optgroup> tag (end tag required)
 sub start_optgroup {  sub start_optgroup {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2931  sub end_optgroup { Line 3118  sub end_optgroup {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <samp> tag  #-- <samp> tag (end tag required)
 sub start_samp {  sub start_samp {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     }       } elsif ($target eq 'tex') {
    $currentstring='\texttt{';
       }
     return $currentstring;      return $currentstring;
 }  }
   
Line 2946  sub end_samp { Line 3135  sub end_samp {
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[2];       $currentstring = $token->[2];    
     }       } elsif ($target eq 'tex') {
    $currentstring='}';
       }
     return $currentstring;      return $currentstring;
 }  }
   
Line 2969  sub end_server { Line 3160  sub end_server {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <spacer> tag  #-- <spacer> tag (end tag forbidden)
 sub start_spacer {  sub start_spacer {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 2988  sub end_spacer { Line 3179  sub end_spacer {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <span> tag  #-- <span> tag (end tag required)
 sub start_span {  sub start_span {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 3007  sub end_span { Line 3198  sub end_span {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <tbody> tag  #-- <tbody> tag (end tag optional)
 sub start_tbody {  sub start_tbody {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 3026  sub end_tbody { Line 3217  sub end_tbody {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <tfoot> tag  #-- <tfoot> tag (end tag optional)
 sub start_tfoot {  sub start_tfoot {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 3045  sub end_tfoot { Line 3236  sub end_tfoot {
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <thead> tag  #-- <thead> tag (end tag optional)
 sub start_thead {  sub start_thead {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 3070  sub start_var { Line 3261  sub start_var {
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[4];        $currentstring = $token->[4];     
     }       } elsif ($target eq 'tex') {
    $currentstring = '\textit{'; 
       }
     return $currentstring;      return $currentstring;
 }  }
   
Line 3078  sub end_var { Line 3271  sub end_var {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
     if ($target eq 'web') {      if ($target eq 'web') {
  $currentstring = $token->[2];       $currentstring = $token->[2];
       } elsif ($target eq 'tex') {
    $currentstring = '}'; 
     }       } 
     return $currentstring;      return $currentstring;
 }  }
   
 #-- <wbr> tag  #-- <wbr> tag (end tag forbidden)
 sub start_wbr {  sub start_wbr {
     my ($target,$token) = @_;      my ($target,$token) = @_;
     my $currentstring = '';      my $currentstring = '';
Line 3102  sub end_wbr { Line 3297  sub end_wbr {
     return $currentstring;      return $currentstring;
 }  }
   
   #-- <hideweboutput> tag
   sub start_hideweboutput {
       my ($target,$token) = @_;
       if ($target eq 'web') {
    &Apache::lonxml::startredirection();     
       } 
       return '';
   }
   
   sub end_hideweboutput {
       my ($target,$token) = @_;
       my $currentstring = '';
       if ($target eq 'web') {
    $currentstring = &Apache::lonxml::endredirection();    
       } 
       return '';
   }
   
   
 sub image_replication {  sub image_replication {
     my $src = shift;      my $src = shift;
     if (not -e $src) {      if (not -e $src) { &Apache::lonnet::repcopy($src); }
  #replicates image itself      #replicates eps or ps 
  &Apache::lonnet::repcopy($src);      my $epssrc = my $pssrc = $src;
  #replicates eps or ps       $epssrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i;
  my $newsrc = $src;      $pssrc  =~ s/\.(gif|jpg|jpeg|png)$/.ps/i;
  $newsrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i;      if (not -e $epssrc && not -e $pssrc) {
  if (not -e $newsrc) {   my $result=&Apache::lonnet::repcopy($epssrc);
     if (&Apache::lonnet::repcopy($newsrc) ne 'OK') {   if ($result ne OK) { &Apache::lonnet::repcopy($pssrc); }
  $newsrc =~ s/\.eps$/\.ps/;  
  &Apache::lonnet::repcopy($newsrc);  
     }  
  }  
     }      }
     return '';      return '';
 }  }
   
   sub image_size {
       my ($src,$scaling,$parstack,$safeeval)=@_;
       #size of image from gif/jpg/jpeg/png 
       my $image = Image::Magick->new;
       my $current_figure = $image->Read($src);
       my $width_param = $image->Get('width') * $scaling;;
       my $height_param = $image->Get('height') * $scaling;;
       undef $image;
       #do we have any specified LaTeX size of the picture?
       my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval);
       my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval);
       #do we have any specified web size of the picture?
       my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval,
      undef,1);
       if ($TeXwidth ne '') {  
    if ($TeXwidth=~/(\d+)\s*\%/) {
       $width_param = $1*$ENV{'form.textwidth'}/100;
    } else { 
       $width_param = $TeXwidth;
    }
       } elsif ($TeXheight ne '') {
    $width_param = $TeXheight/$height_param*$width_param;
       } elsif ($width ne '') {
    $width_param = $width*$scaling;      
       }
       if ($width_param > $ENV{'form.textwidth'}) {$width_param =0.95*$ENV{'form.textwidth'}}
       return $width_param;
   }
   
   sub eps_generation {
       my ($src,$file,$width_param) = @_;     
       my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat";
       my $temp_file = Apache::File->new('>>'.$filename); 
       print $temp_file "$src\n";
       my $newsrc = $src;
       $newsrc =~ s/(\.gif|\.jpg|\.jpeg)$/\.eps/i;
       $newsrc=~s/\/home\/httpd\/html\/res//;
       $newsrc=~s/\/home\/([^\/]*)\/public_html\//\/$1\//;
       $newsrc=~s/\/\.\//\//;
       $newsrc=~s/\/([^\/]+)\.(ps|eps)/\//;
       return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
   }
   
   sub file_path {     
       my $src=shift;
       my ($file,$path); 
       if ($src =~ m!(.*)/([^/]*)$!) {
    $file = $2; 
    $path = $1.'/'; 
       } 
       return $file,$path;
   }
   
 sub recalc {  sub recalc {
     my $argument = shift;      my $argument = shift;
     if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}      if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}
     $argument=~/\s*(\d+)\s*(mm|cm|in|pc|pt)/;      $argument=~/\s*(\d+\.?\d*)\s*(mm|cm|in|pc|pt)/;
     my $value=$1;      my $value=$1;
     my $units=$2;      my $units=$2;
     if ($units eq 'cm') {      if ($units eq 'cm') {
Line 3138  sub recalc { Line 3401  sub recalc {
     return $value.' mm';      return $value.' mm';
 }  }
   
   sub LATEX_length {
       my $garbage=shift;
       $garbage=~s/^\s+(\S.*)/$1/; 
       $garbage=~s/(.*\S)\s+$/$1/;
       $garbage=~s/(\s)+/$1/;
       $garbage=~s/(\\begin{([^\}]+)}|\\end{([^\}]+)})//g;
       $garbage=~s/(\$\_\{|\$\_|\$\^{|\$\^|\}\$|\$)//g;
       $garbage=~s/(\\alpha|\\beta|\\gamma|\\delta|\\epsilon|\\verepsilon|\\zeta|\\eta|\\theta|\\vartheta|\\iota|\\kappa|\\lambda|\\mu|\\nu|\\xi|\\pi|\\varpi|\\rho|\\varrho|\\sigma|\\varsigma|\\tau|\\upsilon|\\phi|\\varphi|\\chi|\\psi|\\omega|\\Gamma|\\Delta|\\Theta|\\Lambda|\\Xi|\\Pi|\\Sigma|\\Upsilon|\\Phi|\\Psi|\\Omega)/1/g;
       $garbage=~s/(\\pm|\\mp|\\times|\\div|\\cdot|\\ast|\\star|\\dagger|\\ddagger|\\amalg|\\cap|\\cup|\\uplus|\\sqcap|\\sqcup|\\vee|\\wedge|\\oplus|\\ominus|\\otimes|\\circ|\\bullet|\\diamond|\\lhd|\\rhd|\\unlhd|\\unrhd|\\oslash|\\odot|\\bigcirc|\\Box|\\Diamond|\\bigtriangleup|\\bigtriangledown|\\triangleleft|\\triangleright|\\setminus|\\wr)/1/g;
       $garbage=~s/(\\le|\\ll|\\leq|\\ge|\\geq|\\gg|\\neq|\\doreq|\\sim|\\simeq|\\subset|\\subseteq|\\sqsubset|\\sqsubseteq|\\in|\\vdash|\\models|\\supset|\\supseteq|\\sqsupset|\\sqsupseteq|\\ni|\\dash|\\perp|\\approx|\\cong|\\equiv|\\propto|\\prec|\\preceq|\\parallel|\\asymp|\\smile|\\frown|\\bowtie|\\succ|\\succeq|\\mid)/1/g;
       $garbage=~s/(\\not<|\\\\not\\le|\\not\\prec|\\not\\preceq|\\not\\subset|\\not\\subseteq|\\not\\sqsubseteq|\\not\\in|\\not>|\\not\\ge|\\not\\succ|\\notsucceq|\\not\\supset|\\notsupseteq|\\not\\sqsupseteq|\\notin|\\not=|\\not\\equiv|\\not\\sim|\\not\\simeq|\\not\\approx|\\not\\cong|\\not\\asymp)/1/g;
       $garbage=~s/(\\leftarrow|\\gets|\\Leftarrow|\\rightarrow|\\to|\\Rightarrow|\\leftrightarrow|\\Leftrightarrow|\\mapsto|\\hookleftarrow|\\leftharpoonup|\\leftkarpoondown|\\rightleftharpoons|\\longleftarrow|\\Longleftarrow|\\longrightarrow|\\Longrightarrow|\\longleftrightarrow|\\Longleftrightarrow|\\longmapsto|\\hookrightarrow|\\rightharpoonup|\\rightharpoondown|\\uparrow|\\Uparrow|\\downarrow|\\Downarrow|\\updownarrow|\\Updownarrow|\\nearrow|\\searrow|\\swarrow|\\nwarrow)/1/g;
       $garbage=~s/(\\aleph|\\hbar|\\imath|\\jmath|\\ell|\\wp|\\Re|\\Im|\\mho|\\prime|\\emptyset|\\nabla|\\surd|\\partial|\\top|\\bot|\\vdash|\\dashv|\\forall|\\exists|\\neg|\\flat|\\natural|\\sharp|\\\||\\angle|\\backslash|\\Box|\\Diamond|\\triangle|\\clubsuit|\\diamondsuit|\\heartsuit|\\spadesuit|\\Join|\\infty)/ /g;
       $garbage=~s/(\\hat{([^}]+)}|\\check{([^}]+)}|\\dot{([^}]+)}|\\breve{([^}]+)}|\\acute{([^}]+)}|\\ddot{([^}]+)}|\\grave{([^}]+)}|\\tilde{([^}]+)}|\\mathring{([^}]+)}|\\bar{([^}]+)}|\\vec{([^}]+)})/$1/g; 
       my  $value=length($garbage);
       return $value;
   }
   
   
   
   
 1;  1;
 __END__  __END__

Removed from v.1.131  
changed lines
  Added in v.1.198


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>