File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.70: download - view: text, annotated - select for diffs
Thu Jul 11 18:20:00 2002 UTC (21 years, 10 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Corrected with Image::Magick.

    1: # The LearningOnline Network with CAPA
    2: # Tags Default Definition Module 
    3: #
    4: # $Id: londefdef.pm,v 1.70 2002/07/11 18:20:00 sakharuk Exp $
    5: # 
    6: #
    7: # Copyright Michigan State University Board of Trustees
    8: #
    9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   10: #
   11: # LON-CAPA is free software; you can redistribute it and/or modify
   12: # it under the terms of the GNU General Public License as published by
   13: # the Free Software Foundation; either version 2 of the License, or
   14: # (at your option) any later version.
   15: #
   16: # LON-CAPA is distributed in the hope that it will be useful,
   17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19: # GNU General Public License for more details.
   20: #
   21: # You should have received a copy of the GNU General Public License
   22: # along with LON-CAPA; if not, write to the Free Software
   23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   24: #
   25: # /home/httpd/html/adm/gpl.txt
   26: #
   27: # http://www.lon-capa.org/
   28: #
   29: # Copyright for TtHfunc and TtMfunc by Ian Hutchinson. 
   30: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into 
   31: # binary executable programs or libraries distributed by the 
   32: # Michigan State University (the "Licensee"), but any binaries so 
   33: # distributed are hereby licensed only for use in the context
   34: # of a program or computational system for which the Licensee is the 
   35: # primary author or distributor, and which performs substantial 
   36: # additional tasks beyond the translation of (La)TeX into HTML.
   37: # The C source of the Code may not be distributed by the Licensee
   38: # to any other parties under any circumstances.
   39: #
   40: #
   41: # last modified 06/26/00 by Alexander Sakharuk
   42: # 11/6,11/30,02/01/01,5/4 Gerd Kortemeyer
   43: # 01/18 Alex Sakharuk
   44: 
   45: package Apache::londefdef; 
   46: 
   47: use Apache::lonnet;
   48: use strict;
   49: use Apache::lonxml;
   50: use Apache::File();
   51: use Image::Magick;
   52: 
   53: BEGIN {
   54: 
   55:     &Apache::lonxml::register('Apache::londefdef',('m','html','head','map','select','option','input','textarea','form','meta','title','body','center','b','strong','dt','h1','h2','h3','h4','h5','h6','cite','i','address','dd','dl','dir','ol','ul','menu','dfn','kbd','tt','code','em','q','p','br','big','small','basefont','font','s','sub','strike','sup','hr','a','li','u','output','param','applet','img','embed','allow','frameset','pre','insert','externallink','table','tr','th','td','blankspace','bubble','bubbles','bubbleline'));
   56: 
   57: }
   58: 
   59: #======================= TAG SUBROUTINES =====================
   60: #-- <output>
   61: sub start_output {
   62:   my ($target) = @_;
   63:   if ($target eq 'meta') { $Apache::lonxml::metamode--; }
   64:   return '';
   65: }
   66: sub end_output {
   67:   my ($target) = @_;
   68:   if ($target eq 'meta') { $Apache::lonxml::metamode++; }
   69:   return '';
   70: }
   71: #-- <m> tag
   72: sub start_m {
   73:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
   74:   my $currentstring = '';
   75:   if ($target eq 'web') {
   76:     $Apache::lonxml::prevent_entity_encode++;
   77:     my $inside = &Apache::lonxml::get_all_text("/m",$$parser[-1]);
   78:     $inside ='\\documentstyle{article}'.$inside;
   79:     &Apache::lonxml::debug("M is starting with:$inside:");
   80:     my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
   81:     if ($eval eq 'on') {
   82:       $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
   83:       #&Apache::lonxml::debug("M is evaulated to:$inside:");
   84:     }
   85:     $currentstring = &Apache::lontexconvert::converted(\$inside);
   86:     if ($Apache::lontexconvert::errorstring) {
   87:       &Apache::lonxml::warning("tth error: ".
   88: 			       $Apache::lontexconvert::errorstring);
   89:       $Apache::lontexconvert::errorstring='';
   90:     }
   91:     #&Apache::lonxml::debug("M is ends with:$currentstring:");
   92:   } elsif ($target eq 'tex') {
   93:     $currentstring = "";
   94:   }
   95:   return $currentstring;
   96: }
   97: sub end_m {
   98:   my ($target,$token) = @_;
   99:   my $currentstring = '';
  100:   if ($target eq 'web') {
  101:     $Apache::lonxml::prevent_entity_encode--;
  102:   } elsif ($target eq 'tex') {
  103:     $currentstring = "";
  104:   } elsif ($target eq 'meta') {
  105:   }
  106:   return $currentstring;
  107: }
  108: #-- <html> tag    
  109:       sub start_html {
  110: 	    my ($target,$token) = @_;
  111:             my $currentstring = '';
  112: 	    if ($ENV{'browser.mathml'}) {
  113: 	      &tth::ttminit();
  114: 	    } else {
  115: 	      &tth::tthinit();
  116: 	    }
  117:             if ($target eq 'web') {
  118:               $currentstring = &Apache::lonxml::xmlbegin().
  119:                                &Apache::lonxml::fontsettings();     
  120: 	    } elsif ($target eq 'tex') {
  121: 	      @Apache::londefdef::table = ();
  122: 	      $currentstring .= '\documentclass[letterpaper]{article}
  123:                                  \newcommand{\keephidden}[1]{}           
  124:                                  \usepackage[dvips]{graphicx}
  125:                                  \usepackage{epsfig}\usepackage{calc}';
  126: 	    }
  127: 	   return $currentstring;
  128: 	}
  129:         sub end_html {
  130: 	    my ($target,$token) = @_;
  131:             my $currentstring = '';
  132:             if ($target eq 'web') {
  133: 		$currentstring = &Apache::lonxml::xmlend();
  134: 	    }
  135: 	   return $currentstring;
  136: 	}
  137: #-- <head> tag
  138:       sub start_head {
  139: 	    my ($target,$token) = @_;
  140:             my $currentstring = '';
  141:             if ($target eq 'web') {
  142:               $currentstring = $token->[4];     
  143: 	    } 
  144: 	   return $currentstring;
  145: 	}
  146:         sub end_head {
  147: 	    my ($target,$token) = @_;
  148:             my $currentstring = '';
  149:             if ($target eq 'web') {
  150:               $currentstring = &Apache::lonxml::registerurl(undef,$target).
  151:                                $token->[2];    
  152:             } 
  153: 	   return $currentstring;
  154: 	}
  155: #-- <map> tag
  156:       sub start_map {
  157: 	    my ($target,$token) = @_;
  158:             my $currentstring = '';
  159:             if ($target eq 'web') {
  160:               $currentstring = $token->[4];     
  161: 	    } 
  162: 	   return $currentstring;
  163: 	}
  164:         sub end_map {
  165: 	    my ($target,$token) = @_;
  166:             my $currentstring = '';
  167:             if ($target eq 'web') {
  168:               $currentstring = $token->[2];    
  169:             } 
  170: 	   return $currentstring;
  171: 	}
  172: #-- <select> tag
  173:       sub start_select {
  174: 	    my ($target,$token) = @_;
  175:             my $currentstring = '';
  176:             if ($target eq 'web') {
  177:               $currentstring = $token->[4];     
  178: 	    } 
  179: 	   return $currentstring;
  180: 	}
  181:         sub end_select {
  182: 	    my ($target,$token) = @_;
  183:             my $currentstring = '';
  184:             if ($target eq 'web') {
  185:               $currentstring = $token->[2];    
  186:             } 
  187: 	   return $currentstring;
  188: 	}
  189: #-- <option> tag
  190:       sub start_option {
  191: 	    my ($target,$token) = @_;
  192:             my $currentstring = '';
  193:             if ($target eq 'web') {
  194:               $currentstring = $token->[4];     
  195: 	    } 
  196: 	   return $currentstring;
  197: 	}
  198:         sub end_option {
  199: 	    my ($target,$token) = @_;
  200:             my $currentstring = '';
  201:             if ($target eq 'web') {
  202:               $currentstring = $token->[2];    
  203:             } 
  204: 	   return $currentstring;
  205: 	}
  206: #-- <input> tag
  207:       sub start_input {
  208: 	    my ($target,$token) = @_;
  209:             my $currentstring = '';
  210:             if ($target eq 'web') {
  211:               $currentstring = $token->[4];     
  212: 	    } 
  213: 	   return $currentstring;
  214: 	}
  215:         sub end_input {
  216: 	    my ($target,$token) = @_;
  217:             my $currentstring = '';
  218:             if ($target eq 'web') {
  219:               $currentstring = $token->[2];    
  220:             } 
  221: 	   return $currentstring;
  222: 	}
  223: #-- <textarea> tag
  224:       sub start_textarea {
  225: 	    my ($target,$token) = @_;
  226:             my $currentstring = '';
  227:             if ($target eq 'web') {
  228:               $currentstring = $token->[4];     
  229: 	    } 
  230: 	   return $currentstring;
  231: 	}
  232:         sub end_textarea {
  233: 	    my ($target,$token) = @_;
  234:             my $currentstring = '';
  235:             if ($target eq 'web') {
  236:               $currentstring = $token->[2];    
  237:             } 
  238: 	   return $currentstring;
  239: 	}
  240: #-- <form> tag
  241:       sub start_form {
  242: 	    my ($target,$token) = @_;
  243:             my $currentstring = '';
  244:             if ($target eq 'web') {
  245:               $currentstring = $token->[4];     
  246: 	    } 
  247: 	   return $currentstring;
  248: 	}
  249:         sub end_form {
  250: 	    my ($target,$token) = @_;
  251:             my $currentstring = '';
  252:             if ($target eq 'web') {
  253:               $currentstring = $token->[2];    
  254:             } 
  255: 	   return $currentstring;
  256: 	}
  257: #-- <title> tag
  258:       sub start_title {
  259: 	    my ($target,$token) = @_;
  260:             my $currentstring = '';
  261:             if ($target eq 'web') {
  262:               $currentstring = $token->[4];     
  263: 	    } elsif ($target eq 'tex') {
  264:               $currentstring .= '\keephidden{' 
  265: 	    }
  266:             if ($target eq 'meta') {
  267: 		$currentstring='<title>';
  268:                 &start_output();
  269:             }
  270: 	   return $currentstring;
  271: 	}
  272:         sub end_title {
  273: 	    my ($target,$token) = @_;
  274:             my $currentstring = '';
  275:             if ($target eq 'web') {
  276:               $currentstring = $token->[2];    
  277:             } elsif ($target eq 'tex') {
  278:               $currentstring .= '}';
  279: 	    }  
  280:             if ($target eq 'meta') {
  281:                &end_output();
  282:                $currentstring='</title>';
  283:             } 
  284: 	   return $currentstring;
  285: 	}
  286: #-- <meta> tag
  287:       sub start_meta {
  288: 	    my ($target,$token,$tagstack,$parstack,$parser) = @_;
  289:             my $currentstring = '';
  290:             if ($target eq 'web') {
  291: 	      my $args='';
  292: 	      if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
  293: 	      if ($args eq '') {
  294: 		&Apache::lonxml::get_all_text("/meta",$$parser[$#$parser]);
  295: 	      } else {
  296: 		$currentstring = $token->[4];
  297: 	      }
  298: 	    }
  299:             if ($target eq 'meta') {
  300: 		unless ($token->[2]->{'http-equiv'}) {
  301: 		    my $name=$token->[2]->{'name'};
  302:                     $name=~tr/A-Z/a-z/;
  303:                     $name=~s/\s/\_/g;
  304:                     if ($name) {
  305:                        $currentstring='<'.$name.'>'.
  306:                                          $token->[2]->{'content'}.
  307: 			              '</'.$name.'>';
  308: 		    }
  309:                 }
  310: 	    }
  311: 	   return $currentstring;
  312: 	}
  313:       sub end_meta {
  314: 	my ($target,$token,$tagstack,$parstack,$parser) = @_;
  315: 	my $currentstring = '';
  316: 	if ($target eq 'web') {
  317: 	  my $args='';
  318: 	  if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
  319: 	  if ($args ne '') {
  320: 	    $currentstring = $token->[4];
  321: 	  }
  322: 	} 
  323: 	return $currentstring;
  324:       }
  325: #-- <body> tag
  326:         sub start_body {
  327:             my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  328: #	    my ($target,$token) = @_;
  329:             my $currentstring = '';
  330:             if ($target eq 'web') {
  331: 	      if (!$Apache::lonxml::registered) {
  332: 		$currentstring.='<head>'.
  333: 		    &Apache::lonxml::registerurl(undef,$target).'</head>';
  334: 	      }
  335: 	      my $onLoad='';
  336: 	      foreach my $key (keys(%{$token->[2]})) {
  337: 		if ($key =~ /^onload$/i) {
  338: 		  $onLoad.=$token->[2]->{$key}.';';
  339: 		  delete($token->[2]->{$key});
  340: 		}
  341: 	      }
  342: 	      $token->[2]->{'onLoad'}=&Apache::lonxml::loadevents().
  343: 		                       ';'.$onLoad;
  344: 	      my $onUnload='';
  345: 	      foreach my $key (keys(%{$token->[2]})) {
  346: 		if ($key =~ /^onunload$/i) {
  347: 		  $onUnload.=$token->[2]->{$key}.';';
  348: 		  delete($token->[2]->{$key});
  349: 		}
  350: 	      }
  351: 	      $token->[2]->{'onUnload'}=&Apache::lonxml::unloadevents().
  352: 		                         ';'.$onUnload;
  353: 
  354: 	      $currentstring .= '<'.$token->[1];
  355: 	      foreach (keys %{$token->[2]}) {
  356: 	      	$currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
  357: 	      }
  358: 	      $currentstring.='>';
  359: 	      if ($ENV{'request.state'} ne 'published') {
  360: 		$currentstring.=(<<EDITBUTTON);
  361: 		<form method="post">
  362: 		<input type="submit" name="editmode" value="Edit" />
  363: 		</form>
  364: EDITBUTTON
  365: 	      }
  366:        	    } elsif ($target eq 'tex') {
  367:               $currentstring = '\begin{document}';  
  368: 	    } 
  369: 	   return $currentstring;
  370: 	}
  371:         sub end_body {
  372: 	    my ($target,$token) = @_;
  373:             my $currentstring = '';
  374:             if ($target eq 'web') {
  375:               $currentstring = $token->[2];     
  376: 	    } elsif ($target eq 'tex') {
  377:               $currentstring = '\end{document}';  
  378: 	    } 
  379: 	   return $currentstring;
  380: 	}
  381: #-- <center> tag
  382:         sub start_center {
  383: 	    my ($target,$token) = @_;
  384:             my $currentstring = '';
  385:             if ($target eq 'web') {
  386:               $currentstring = $token->[4];     
  387: 	    } elsif ($target eq 'tex') {
  388:               $currentstring = '\begin{center}';  
  389: 	    }  elsif ($target eq 'latexsource') {
  390:               $currentstring = '\begin{center}';  
  391: 	    } 
  392: 	   return $currentstring;
  393: 	}
  394:         sub end_center {
  395: 	    my ($target,$token) = @_;
  396:             my $currentstring = '';
  397:             if ($target eq 'web') {
  398:               $currentstring = $token->[2];     
  399: 	    } elsif ($target eq 'tex') {
  400:               $currentstring = '\end{center}';  
  401: 	    }  elsif ($target eq 'latexsource') {
  402:               $currentstring = '\end{center}';  
  403: 	    } 
  404: 	   return $currentstring;
  405: 	}
  406: #-- <b> tag
  407:         sub start_b {
  408: 	    my ($target,$token) = @_;
  409:             my $currentstring = '';
  410:             if ($target eq 'web') {
  411:               $currentstring = $token->[4];     
  412: 	    } elsif ($target eq 'tex') {
  413:               $currentstring = '\textbf{';  
  414: 	    }  elsif ($target eq 'latexsource') {
  415:               $currentstring = '\textbf{';  
  416: 	    } 
  417: 	   return $currentstring;
  418: 	}
  419:         sub end_b {
  420: 	    my ($target,$token) = @_;
  421:             my $currentstring = '';
  422:             if ($target eq 'web') {
  423:               $currentstring = $token->[2];     
  424: 	    } elsif ($target eq 'tex') {
  425:               $currentstring = '}';  
  426: 
  427: 	    } elsif ($target eq 'latexsource') {
  428:               $currentstring = '}';  
  429: 	    } 
  430: 	   return $currentstring;
  431: 	}
  432: #-- <strong> tag
  433:         sub start_strong {
  434: 	    my ($target,$token) = @_;
  435:             my $currentstring = '';
  436:             if ($target eq 'web') {
  437:               $currentstring = $token->[4];     
  438: 	    } elsif ($target eq 'tex') {
  439:               $currentstring = '\textbf{';  
  440: 	    } elsif ($target eq 'latexsource') {
  441:               $currentstring = '\textbf{';  
  442: 	    } 
  443: 	   return $currentstring;
  444: 	}
  445:         sub end_strong {
  446: 	    my ($target,$token) = @_;
  447:             my $currentstring = '';
  448:             if ($target eq 'web') {
  449: 
  450:               $currentstring = $token->[2];     
  451: 	    } elsif ($target eq 'tex') {
  452:               $currentstring = '}';  
  453: 	    }  elsif ($target eq 'latexsource') {
  454:               $currentstring = '}';  
  455: 	    } 
  456: 	   return $currentstring;
  457: 	}
  458: #-- <h1> tag
  459:         sub start_h1 {
  460: 	    my ($target,$token) = @_;
  461:             my $currentstring = '';
  462:             if ($target eq 'web') {
  463: 	       $currentstring .= $token->[4];
  464: 	    } elsif ($target eq 'tex') {
  465: 		$currentstring .= '\large{\textbf{';
  466: 	    } elsif ($target eq 'meta') {
  467: 		$currentstring='<subject>';
  468:                 &start_output();
  469:             }
  470:            return $currentstring;
  471: 	}
  472:         sub end_h1 {
  473: 	    my ($target,$token) = @_;
  474:             my $currentstring = '';
  475:             if ($target eq 'web') {
  476: 	       $currentstring .= $token->[2];
  477: 	    } elsif ($target eq 'tex') {
  478: 		$currentstring .= '}}';
  479: 	    } elsif ($target eq 'meta') {
  480:                 &end_output();
  481: 		$currentstring='</subject>';
  482:             } 
  483:            return $currentstring;
  484: 	}
  485: #-- <h2> tag
  486:         sub start_h2 {
  487: 	    my ($target,$token) = @_;
  488:             my $currentstring = '';
  489:             if ($target eq 'web') {
  490: 	       $currentstring .= $token->[4];
  491: 	    } elsif ($target eq 'tex') {
  492: 		$currentstring .= '\large{\textbf{';
  493: 	    } 
  494:            return $currentstring;
  495: 	}
  496:         sub end_h2 {
  497: 	    my ($target,$token) = @_;
  498:             my $currentstring = '';
  499:             if ($target eq 'web') {
  500: 	       $currentstring .= $token->[2];
  501: 	    } elsif ($target eq 'tex') {
  502: 		$currentstring .= '}}';
  503: 	    } 
  504:            return $currentstring;
  505: 	}
  506: #-- <h3> tag
  507:         sub start_h3 {
  508: 	    my ($target,$token) = @_;
  509:             my $currentstring = '';
  510:             if ($target eq 'web') {
  511: 	       $currentstring .= $token->[4];
  512: 	    } elsif ($target eq 'tex') {
  513: 		$currentstring .= '\large{\textbf{';
  514: 	    } 
  515:            return $currentstring;
  516: 	}
  517:         sub end_h3 {
  518: 	    my ($target,$token) = @_;
  519:             my $currentstring = '';
  520:             if ($target eq 'web') {
  521: 	       $currentstring .= $token->[2];
  522: 	    } elsif ($target eq 'tex') {
  523: 		$currentstring .= '}}';
  524: 	    } 
  525:            return $currentstring;
  526: 	}
  527: #-- <h4> tag
  528:         sub start_h4 {
  529: 	    my ($target,$token) = @_;
  530:             my $currentstring = '';
  531:             if ($target eq 'web') {
  532: 	       $currentstring .= $token->[4];
  533: 	    } elsif ($target eq 'tex') {
  534: 		$currentstring .= '\large{\textbf{';
  535: 	    } 
  536:            return $currentstring;
  537: 	}
  538:         sub end_h4 {
  539: 	    my ($target,$token) = @_;
  540:             my $currentstring = '';
  541:             if ($target eq 'web') {
  542: 	       $currentstring .= $token->[2];
  543: 	    } elsif ($target eq 'tex') {
  544: 		$currentstring .= '}}';
  545: 	    } 
  546:            return $currentstring;
  547: 	}
  548: #-- <h5> tag
  549:         sub start_h5 {
  550: 	    my ($target,$token) = @_;
  551:             my $currentstring = '';
  552:             if ($target eq 'web') {
  553: 	       $currentstring .= $token->[4];
  554: 	    } elsif ($target eq 'tex') {
  555: 		$currentstring .= '\large{\textbf{';
  556: 	    } 
  557:            return $currentstring;
  558: 	}
  559:         sub end_h5 {
  560: 	    my ($target,$token) = @_;
  561:             my $currentstring = '';
  562:             if ($target eq 'web') {
  563: 	       $currentstring .= $token->[2];
  564: 	    } elsif ($target eq 'tex') {
  565: 		$currentstring .= '}}';
  566: 	    } 
  567:            return $currentstring;
  568: 	}
  569: #-- <h6> tag
  570:         sub start_h6 {
  571: 	    my ($target,$token) = @_;
  572:             my $currentstring = '';
  573:             if ($target eq 'web') {
  574: 	       $currentstring .= $token->[4];
  575: 	    } elsif ($target eq 'tex') {
  576: 		$currentstring .= '\large{\textbf{';
  577: 	    } 
  578:            return $currentstring;
  579: 	}
  580:         sub end_h6 {
  581: 	    my ($target,$token) = @_;
  582:             my $currentstring = '';
  583:             if ($target eq 'web') {
  584: 	       $currentstring .= $token->[2];
  585: 	    } elsif ($target eq 'tex') {
  586: 		$currentstring .= '}}';
  587: 	    } 
  588:            return $currentstring;
  589: 	}
  590: #--- <cite> tag
  591:         sub start_cite {
  592: 	    my ($target,$token) = @_;
  593:             my $currentstring = '';
  594:             if ($target eq 'web') {
  595: 	       $currentstring .= $token->[4];
  596: 	    } elsif ($target eq 'tex') {
  597: 		$currentstring .= "\\textit{";
  598: 	    }  elsif ($target eq 'latexsource') {
  599: 		$currentstring .= "\\textit{";
  600: 	    } 
  601:            return $currentstring;
  602: 	}
  603:         sub end_cite {
  604: 	    my ($target,$token) = @_;
  605:             my $currentstring = '';
  606:             if ($target eq 'web') {
  607: 	       $currentstring .= $token->[2];
  608: 	    } elsif ($target eq 'tex') {
  609: 		$currentstring .= "}";
  610: 	    }  elsif ($target eq 'latexsource') {
  611: 		$currentstring .= "}";
  612: 	    } 
  613:            return $currentstring;
  614: 	}
  615: #-- <i> tag
  616:         sub start_i {
  617: 	    my ($target,$token) = @_;
  618:             my $currentstring = '';
  619:             if ($target eq 'web') {
  620: 	       $currentstring .= $token->[4];
  621: 	    } elsif ($target eq 'tex') {
  622: 		$currentstring .= '\textit{';
  623: 	    }  elsif ($target eq 'latexsource') {
  624: 		$currentstring .= '\textit{';
  625: 	    } 
  626:            return $currentstring;
  627: 	}
  628:         sub end_i {
  629: 	    my ($target,$token) = @_;
  630:             my $currentstring = '';
  631:             if ($target eq 'web') {
  632: 	       $currentstring .= $token->[2];
  633: 	    } elsif ($target eq 'tex') {
  634: 		$currentstring .= '}';
  635: 	    } elsif ($target eq 'latexsource') {
  636: 		$currentstring .= '}';
  637: 	    } 
  638:            return $currentstring;
  639: 	}
  640: #-- <address> tag
  641:         sub start_address {
  642: 	    my ($target,$token) = @_;
  643:             my $currentstring = '';
  644:             if ($target eq 'web') {
  645: 	       $currentstring .= $token->[4];
  646: 	    } elsif ($target eq 'tex') {
  647: 		$currentstring .= "\\textit{";
  648: 	    } elsif ($target eq 'latexsource') {
  649: 		$currentstring .= "\\textit{";
  650: 	    } 
  651:            return $currentstring;
  652: 	}
  653:         sub end_address {
  654: 	    my ($target,$token) = @_;
  655:             my $currentstring = '';
  656:             if ($target eq 'web') {
  657: 	       $currentstring .= $token->[2];
  658: 	    } elsif ($target eq 'tex') {
  659: 		$currentstring .= "}";
  660: 	    } elsif ($target eq 'latexsource') {
  661: 		$currentstring .= "}";
  662: 	    }
  663:            return $currentstring;
  664: 	}
  665: #-- <dfn> tag
  666:         sub start_dfn {
  667: 	    my ($target,$token) = @_;
  668:             my $currentstring = '';
  669:             if ($target eq 'web') {
  670: 	       $currentstring .= $token->[4];
  671: 	    } elsif ($target eq 'tex') {
  672: 		$currentstring .= "\\textit{";
  673: 	    } elsif ($target eq 'latexsource') {
  674: 		$currentstring .= "\\textit{";
  675: 	    } 
  676:            return $currentstring;
  677: 	}
  678:         sub end_dfn {
  679: 	    my ($target,$token) = @_;
  680:             my $currentstring = '';
  681:             if ($target eq 'web') {
  682: 	       $currentstring .= $token->[2];
  683: 	    } elsif ($target eq 'tex') {
  684: 		$currentstring .= "}";
  685: 	    } elsif ($target eq 'latexsource') {
  686: 		$currentstring .= "}";
  687: 	    } 
  688:            return $currentstring;
  689: 	}
  690: #-- <tt> tag
  691:         sub start_tt {
  692: 	    my ($target,$token) = @_;
  693:             my $currentstring = '';
  694:             if ($target eq 'web') {
  695: 	       $currentstring .= $token->[4];
  696: 	    } elsif ($target eq 'tex') {
  697: 		$currentstring .= '\texttt{';
  698: 	    } elsif ($target eq 'latexsource') {
  699: 		$currentstring .= '\texttt{';
  700: 	    } 
  701:            return $currentstring;
  702: 	}
  703:         sub end_tt {
  704: 	    my ($target,$token) = @_;
  705:             my $currentstring = '';
  706:             if ($target eq 'web') {
  707: 	       $currentstring .= $token->[2];
  708: 	    } elsif ($target eq 'tex') {
  709: 		$currentstring .= '}';
  710: 	    } elsif ($target eq 'latexsource') {
  711: 		$currentstring .= '}';
  712: 	    }
  713:            return $currentstring;
  714: 	}
  715: #-- <kbd> tag
  716:         sub start_kbd {
  717: 	    my ($target,$token) = @_;
  718:             my $currentstring = '';
  719:             if ($target eq 'web') {
  720: 	       $currentstring .= $token->[4];
  721: 	    } elsif ($target eq 'tex') {
  722: 		$currentstring .= "\\texttt";
  723: 	    } elsif ($target eq 'latexsource') {
  724: 		$currentstring .= "\\texttt{";
  725: 	    } 
  726:            return $currentstring;
  727: 	}
  728:         sub end_kbd {
  729: 	    my ($target,$token) = @_;
  730:             my $currentstring = '';
  731:             if ($target eq 'web') {
  732: 	       $currentstring .= $token->[2];
  733: 	    } elsif ($target eq 'tex') {
  734: 		$currentstring .= "}";
  735: 	    } elsif ($target eq 'latexsource') {
  736: 		$currentstring .= "}";
  737: 	    } 
  738:            return $currentstring;
  739: 	}
  740: #-- <code> tag
  741:         sub start_code {
  742: 	    my ($target,$token) = @_;
  743:             my $currentstring = '';
  744:             if ($target eq 'web') {
  745: 	       $currentstring .= $token->[4];
  746: 	    } elsif ($target eq 'tex') {
  747: 		$currentstring .= '\texttt{';
  748: 	    } 
  749:            return $currentstring;
  750: 	}
  751:         sub end_code {
  752: 	    my ($target,$token) = @_;
  753:             my $currentstring = '';
  754:             if ($target eq 'web') {
  755: 	       $currentstring .= $token->[2];
  756: 	    } elsif ($target eq 'tex') {
  757: 		$currentstring .= '}';
  758: 	    } 
  759:            return $currentstring;
  760: 	}
  761: #-- <em> tag
  762:         sub start_em {
  763: 	    my ($target,$token) = @_;
  764:             my $currentstring = '';
  765:             if ($target eq 'web') {
  766: 	       $currentstring .= $token->[4];
  767: 	    } elsif ($target eq 'tex') {
  768: 		$currentstring .= '\emph{';
  769: 	    } elsif ($target eq 'latexsource') {
  770: 		$currentstring .= '\emph{';
  771: 	    } 
  772:            return $currentstring;
  773: 	}
  774:         sub end_em {
  775: 	    my ($target,$token) = @_;
  776:             my $currentstring = '';
  777:             if ($target eq 'web') {
  778: 	       $currentstring .= $token->[2];
  779: 	    } elsif ($target eq 'tex') {
  780: 		$currentstring .= '}';
  781: 	    } elsif ($target eq 'latexsource') {
  782: 		$currentstring .= '}';
  783: 	    }  
  784:            return $currentstring;
  785: 	}
  786: #-- <q> tag
  787:         sub start_q {
  788: 	    my ($target,$token) = @_;
  789:             my $currentstring = '';
  790:             if ($target eq 'web') {
  791: 	       $currentstring .= $token->[4];
  792: 	    } elsif ($target eq 'tex') {
  793: 		$currentstring .= "\\emph{";
  794: 	    }  elsif ($target eq 'latexsource') {
  795: 		$currentstring .= "\\emph{";
  796: 	    }
  797:            return $currentstring;
  798: 	}
  799:         sub end_q {
  800: 	    my ($target,$token) = @_;
  801:             my $currentstring = '';
  802:             if ($target eq 'web') {
  803: 	       $currentstring .= $token->[2];
  804: 	    } elsif ($target eq 'tex') {
  805: 		$currentstring .= "}";
  806: 	    } elsif ($target eq 'latexsource') {
  807: 		$currentstring .= "}";
  808: 	    }  
  809:            return $currentstring;
  810: 	}
  811: #-- <p> tag
  812:         sub start_p {
  813: 	    my ($target,$token) = @_;
  814:             my $currentstring = '';
  815:             if ($target eq 'web') {
  816: 	       $currentstring .= $token->[4];
  817: 	    } elsif ($target eq 'tex') {
  818: 		$currentstring .= '{\par ';
  819: 	    } elsif ($target eq 'latexsource') {
  820: 		$currentstring .= '{\par ';
  821: 	    } 
  822:            return $currentstring;
  823: 	}
  824:         sub end_p {
  825: 	    my ($target,$token) = @_;
  826:             my $currentstring = '';
  827:             if ($target eq 'web') {
  828: 	       $currentstring .= $token->[2];
  829: 	    } elsif ($target eq 'tex') {
  830: 	        $currentstring .= '}';
  831:             } elsif ($target eq 'latexsource') {
  832: 	        $currentstring .= '}';
  833:             }
  834:            return $currentstring;
  835: 	}
  836: #-- <br> tag
  837:         sub start_br {
  838: 	    my ($target,$token) = @_;
  839:             my $currentstring = '';
  840:             if ($target eq 'web') {
  841: 	       $currentstring .= $token->[4];
  842: 	    } elsif ($target eq 'tex') {
  843: 		$currentstring .= '\vskip 0 mm';
  844: 	    } elsif ($target eq 'latexsource') {
  845: 		$currentstring .= '\\';
  846: 	    } 
  847:            return $currentstring;
  848: 	}
  849:         sub end_br {
  850: 	    my ($target,$token) = @_;
  851:             my $currentstring = '';
  852:             if ($target eq 'web') {
  853: 	       $currentstring .= $token->[2];
  854: 	    }
  855:            return $currentstring;
  856: 	}
  857: #-- <big> tag
  858:         sub start_big {
  859: 	    my ($target,$token) = @_;
  860:             my $currentstring = '';
  861:             if ($target eq 'web') {
  862: 	       $currentstring .= $token->[4];
  863: 	    } elsif ($target eq 'tex') {
  864: 		$currentstring .= '\large{';
  865: 	    } elsif ($target eq 'latexsource') {
  866: 		$currentstring .= '{\Large ';
  867: 	    }  
  868:            return $currentstring;
  869: 	}
  870:         sub end_big {
  871: 	    my ($target,$token) = @_;
  872:             my $currentstring = '';
  873:             if ($target eq 'web') {
  874: 	       $currentstring .= $token->[2];
  875: 	    } elsif ($target eq 'tex') {
  876: 	        $currentstring .= '}';
  877:             } elsif ($target eq 'latexsource') {
  878: 	        $currentstring .= '}';
  879:             }
  880:            return $currentstring;
  881: 	}
  882: #-- <small> tag
  883:         sub start_small {
  884: 	    my ($target,$token) = @_;
  885:             my $currentstring = '';
  886:             if ($target eq 'web') {
  887: 	       $currentstring .= $token->[4];
  888: 	    } elsif ($target eq 'tex') {
  889: 		$currentstring .= '{\footnotesize ';
  890: 	    } elsif ($target eq 'latexsource') {
  891: 		$currentstring .= '{\footnotesize ';
  892: 	    } 
  893:            return $currentstring;
  894: 	}
  895:         sub end_small {
  896: 	    my ($target,$token) = @_;
  897:             my $currentstring = '';
  898:             if ($target eq 'web') {
  899: 	       $currentstring .= $token->[2];
  900: 	    } elsif ($target eq 'tex') {
  901: 	        $currentstring .= '}';
  902:             } elsif ($target eq 'latexsource') {
  903: 	        $currentstring .= '}';
  904:             }
  905:            return $currentstring;
  906: 	}
  907: #-- <basefont> tag
  908:       sub start_basefont {
  909: 	my ($target,$token) = @_;
  910: 	my $currentstring = '';
  911: 	if ($target eq 'web') {
  912: 	  $currentstring = $token->[4];     
  913: 	} 
  914: 	return $currentstring;
  915:       }
  916:       sub end_basefont {
  917: 	my ($target,$token) = @_;
  918: 	my $currentstring = '';
  919: 	if ($target eq 'web') {
  920: 	  $currentstring = $token->[4];     
  921: 	} 
  922: 	return $currentstring;
  923:       }
  924: #-- <font> tag
  925:          sub start_font {
  926: 	    my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  927:             my $currentstring = '';
  928:             if ($target eq 'web') {
  929: 	      my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
  930: 	      if ($face=~/symbol/i) {$Apache::lonxml::prevent_entity_encode++;}
  931:               $currentstring = $token->[4];     
  932: 	    } 
  933: 	   return $currentstring;
  934: 	}
  935:         sub end_font {
  936: 	    my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  937:             my $currentstring = '';
  938:             if ($target eq 'web') {
  939: 	      my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
  940: 	      if ($face=~/symbol/i) {$Apache::lonxml::prevent_entity_encode--;}
  941:               $currentstring = $token->[2];    
  942:             } 
  943: 	   return $currentstring;
  944: 	} 
  945: #-- <strike> tag
  946:         sub start_strike {
  947: 	    my ($target,$token) = @_;
  948:             my $currentstring = '';
  949:             if ($target eq 'web') {
  950: 	       $currentstring .= $token->[4];
  951: 	    } elsif ($target eq 'tex') {
  952: 		$currentstring .= "{\\underline ";
  953: 	    } 
  954:            return $currentstring;
  955: 	}
  956:         sub end_strike {
  957: 	    my ($target,$token) = @_;
  958:             my $currentstring = '';
  959:             if ($target eq 'web') {
  960: 	       $currentstring .= $token->[2];
  961: 	    } elsif ($target eq 'tex') {
  962: 	        $currentstring .= " }";
  963:             }
  964:            return $currentstring;
  965: 	}
  966: #-- <s> tag
  967:         sub start_s {
  968: 	    my ($target,$token) = @_;
  969:             my $currentstring = '';
  970:             if ($target eq 'web') {
  971: 	       $currentstring .= $token->[4];
  972: 	    } elsif ($target eq 'tex') {
  973: 		$currentstring .= "{\\underline ";
  974: 	    } 
  975:            return $currentstring;
  976: 	}
  977:         sub end_s {
  978: 	    my ($target,$token) = @_;
  979:             my $currentstring = '';
  980:             if ($target eq 'web') {
  981: 	       $currentstring .= $token->[2];
  982: 	    } elsif ($target eq 'tex') {
  983: 	        $currentstring .= " }";
  984:             }
  985:            return $currentstring;
  986: 	}
  987: #-- <sub> tag
  988:         sub start_sub {
  989: 	    my ($target,$token) = @_;
  990:             my $currentstring = '';
  991:             if ($target eq 'web') {
  992: 	       $currentstring .= $token->[4];
  993: 	    } elsif ($target eq 'tex') {
  994: 		$currentstring .= "\$_{ ";
  995: 	    } 
  996:            return $currentstring;
  997: 	}
  998:         sub end_sub {
  999: 	    my ($target,$token) = @_;
 1000:             my $currentstring = '';
 1001:             if ($target eq 'web') {
 1002: 	       $currentstring .= $token->[2];
 1003: 	    } elsif ($target eq 'tex') {
 1004: 	        $currentstring .= " }\$";
 1005:             }
 1006:            return $currentstring;
 1007: 	}
 1008: #-- <sup> tag
 1009:         sub start_sup {
 1010: 	    my ($target,$token) = @_;
 1011:             my $currentstring = '';
 1012:             if ($target eq 'web') {
 1013: 	       $currentstring .= $token->[4];
 1014: 	    } elsif ($target eq 'tex') {
 1015: 		$currentstring .= "\$^{ ";
 1016: 	    } 
 1017:            return $currentstring;
 1018: 	}
 1019:         sub end_sup {
 1020: 	    my ($target,$token) = @_;
 1021:             my $currentstring = '';
 1022:             if ($target eq 'web') {
 1023: 	       $currentstring .= $token->[2];
 1024: 	    } elsif ($target eq 'tex') {
 1025: 	        $currentstring .= " }\$";
 1026:             }
 1027:            return $currentstring;
 1028: 	}
 1029: #-- <hr> tag
 1030:         sub start_hr {
 1031: 	    my ($target,$token) = @_;
 1032:             my $currentstring = '';
 1033:             if ($target eq 'web') {
 1034: 	       $currentstring .= $token->[4];
 1035: 	    } elsif ($target eq 'tex') {
 1036: 		$currentstring .= "\\hline ";
 1037: 	    } 
 1038:            return $currentstring;
 1039: 	}
 1040:         sub end_hr {
 1041: 	    my ($target,$token) = @_;
 1042:             my $currentstring = '';
 1043:             if ($target eq 'web') {
 1044: 	       $currentstring .= $token->[2];
 1045: 	    } elsif ($target eq 'tex') {
 1046: 	    } 
 1047:            return $currentstring;
 1048: 	}
 1049: #-- <a> tag
 1050:         sub start_a {
 1051: 	    my ($target,$token) = @_;
 1052:             my $currentstring = '';
 1053:             if ($target eq 'web') {
 1054: 	       $currentstring .= $token->[4];
 1055: 	    } elsif ($target eq 'tex') {
 1056: 	    }
 1057:            return $currentstring;
 1058: 	}
 1059:         sub end_a {
 1060: 	    my ($target,$token,$tagstack,$stackref) = @_;
 1061:             my $currentstring = '';
 1062:             if ($target eq 'web') {
 1063: 	       $currentstring .= $token->[2];
 1064: 	    } elsif ($target eq 'tex') {
 1065:                 my  $tempor_var = $stackref->[$#$stackref];
 1066: 		if (index($tempor_var,'name') != -1 ) {
 1067: 		    $tempor_var =~ s/name=([^,]*),/$1/g;
 1068: #	        $currentstring .= " \\label{$tempor_var}";
 1069: 	        } elsif (index($tempor_var,'href') != -1 ) {
 1070: 		    $tempor_var =~ s/href=([^,]*),/$1/g;
 1071: 	        $currentstring .= " \\ref{$tempor_var}";
 1072: 	        }
 1073:             }
 1074:            return $currentstring;
 1075: 	}
 1076: #-- <li> tag
 1077:         sub start_li {
 1078: 	    my ($target,$token,$tagstack,$stackref) = @_;
 1079:             my $currentstring = '';
 1080:             if ($target eq 'web') {
 1081:               $currentstring = $token->[4];     
 1082: 	    } elsif ($target eq 'tex') {
 1083:                 my  $tempor_var = $stackref->[$#$stackref];
 1084:                 if (index($tempor_var,'circle') != -1 ) {
 1085: 	          $currentstring .= " \\item[o] ";
 1086: 	        } elsif (index($tempor_var,'square') != -1 ) {
 1087: 	               $currentstring .= " \\item[$\Box$] ";
 1088: 	        } elsif ($tempor_var ne '') { 
 1089: 		       $_ = $tempor_var;
 1090:                        m/my\s*([^=]*)=/;
 1091: 		       $currentstring .= " \\item[$1] ";
 1092: 		} else {
 1093: 		    $currentstring .= " \\item ";
 1094: 	        }  
 1095: 	    } 
 1096: 	   return $currentstring;
 1097: 	}
 1098:         sub end_li {
 1099: 	    my ($target,$token) = @_;
 1100:             my $currentstring = '';
 1101:             if ($target eq 'web') {
 1102:               $currentstring = $token->[2];     
 1103: 	    } 
 1104: 	   return $currentstring;
 1105: 	}
 1106: #-- <u> tag
 1107:         sub start_u {
 1108: 	    my ($target,$token) = @_;
 1109:             my $currentstring = '';
 1110:             if ($target eq 'web') {
 1111: 	       $currentstring .= $token->[4];
 1112: 	    } elsif ($target eq 'tex') {
 1113: 		$currentstring .= "{\\underline ";
 1114: 	    } 
 1115:            return $currentstring;
 1116: 	}
 1117:         sub end_u {
 1118: 	    my ($target,$token) = @_;
 1119:             my $currentstring = '';
 1120:             if ($target eq 'web') {
 1121: 	       $currentstring .= $token->[2];
 1122: 	    } elsif ($target eq 'tex') {
 1123: 	        $currentstring .= " }";
 1124:             }
 1125:            return $currentstring;
 1126: 	}
 1127: #-- <ul> tag
 1128:         sub start_ul {
 1129: 	    my ($target,$token) = @_;
 1130:             my $currentstring = '';
 1131:             if ($target eq 'web') {
 1132:               $currentstring = $token->[4];     
 1133: 	    } elsif ($target eq 'tex') {
 1134:               $currentstring = '\begin{itemize}';  
 1135: 	    } 
 1136: 	   return $currentstring;
 1137: 	}
 1138:         sub end_ul {
 1139: 	    my ($target,$token) = @_;
 1140:             my $currentstring = '';
 1141:             if ($target eq 'web') {
 1142:               $currentstring = $token->[2];     
 1143: 	    } elsif ($target eq 'tex') {
 1144:               $currentstring = '\end{itemize}';  
 1145: 	    } 
 1146: 	   return $currentstring;
 1147: 	}
 1148: #-- <menu> tag
 1149:         sub start_menu {
 1150: 	    my ($target,$token) = @_;
 1151:             my $currentstring = '';
 1152:             if ($target eq 'web') {
 1153:               $currentstring = $token->[4];     
 1154: 	    } elsif ($target eq 'tex') {
 1155:               $currentstring = " \\begin{itemize} ";  
 1156: 	    } 
 1157: 	   return $currentstring;
 1158: 	}
 1159:         sub end_menu {
 1160: 	    my ($target,$token) = @_;
 1161:             my $currentstring = '';
 1162:             if ($target eq 'web') {
 1163:               $currentstring = $token->[2];     
 1164: 	    } elsif ($target eq 'tex') {
 1165:               $currentstring = " \\end{itemize}";  
 1166: 	    } 
 1167: 	   return $currentstring;
 1168: 	}
 1169: #-- <dir> tag
 1170:         sub start_dir {
 1171: 	    my ($target,$token) = @_;
 1172:             my $currentstring = '';
 1173:             if ($target eq 'web') {
 1174:               $currentstring = $token->[4];     
 1175: 	    } elsif ($target eq 'tex') {
 1176:               $currentstring = " \\begin{itemize} ";  
 1177: 	    } 
 1178: 	   return $currentstring;
 1179: 	}
 1180:         sub end_dir {
 1181: 	    my ($target,$token) = @_;
 1182:             my $currentstring = '';
 1183:             if ($target eq 'web') {
 1184:               $currentstring = $token->[2];     
 1185: 	    } elsif ($target eq 'tex') {
 1186:               $currentstring = " \\end{itemize}";  
 1187: 	    } 
 1188: 	   return $currentstring;
 1189: 	}
 1190: #-- <ol> tag
 1191:         sub start_ol {
 1192: 	    my ($target,$token) = @_;
 1193:             my $currentstring = '';
 1194:             if ($target eq 'web') {
 1195:               $currentstring = $token->[4];     
 1196: 	    } elsif ($target eq 'tex') {
 1197:               $currentstring = '\begin{enumerate}';  
 1198: 	    } 
 1199: 	   return $currentstring;
 1200: 	}
 1201:         sub end_ol {
 1202: 	    my ($target,$token) = @_;
 1203:             my $currentstring = '';
 1204:             if ($target eq 'web') {
 1205:               $currentstring = $token->[2];     
 1206: 	    } elsif ($target eq 'tex') {
 1207:               $currentstring = '\end{enumerate}';  
 1208: 	    } 
 1209: 	   return $currentstring;
 1210: 	}
 1211: #-- <dl> tag
 1212:         sub start_dl {
 1213: 	    my ($target,$token) = @_;
 1214:             my $currentstring = '';
 1215:             if ($target eq 'web') {
 1216:               $currentstring = $token->[4];     
 1217: 	    } elsif ($target eq 'tex') {
 1218:               $currentstring = '\begin{description}';  
 1219: 	    } 
 1220: 	   return $currentstring;
 1221: 	}
 1222:         sub end_dl {
 1223: 	    my ($target,$token) = @_;
 1224:             my $currentstring = '';
 1225:             if ($target eq 'web') {
 1226:               $currentstring = $token->[2];     
 1227: 	    } elsif ($target eq 'tex') {
 1228:               $currentstring = '\end{description}';  
 1229: 	    } 
 1230: 	   return $currentstring;
 1231: 	}
 1232: #-- <dt> tag
 1233:         sub start_dt {
 1234: 	    my ($target,$token) = @_;
 1235:             my $currentstring = '';
 1236:             if ($target eq 'web') {
 1237:               $currentstring = $token->[4];     
 1238: 	    } elsif ($target eq 'tex') {
 1239:               $currentstring = '\item[';  
 1240: 	    } 
 1241: 	   return $currentstring;
 1242: 	}
 1243:         sub end_dt {
 1244: 	    my ($target,$token) = @_;
 1245:             my $currentstring = '';
 1246:             if ($target eq 'web') {
 1247:               $currentstring = $token->[2];    
 1248:             } elsif ($target eq 'tex') {
 1249:               $currentstring = ']';  
 1250: 	    } 
 1251: 	   return $currentstring;
 1252: 	}
 1253: #-- <dd> tag
 1254:         sub start_dd {
 1255: 	    my ($target,$token) = @_;
 1256:             my $currentstring = '';
 1257:             if ($target eq 'web') {
 1258:               $currentstring = $token->[4];     
 1259: 	    } 
 1260: 	   return $currentstring;
 1261: 	}
 1262:         sub end_dd {
 1263: 	    my ($target,$token) = @_;
 1264:             my $currentstring = '';
 1265:             if ($target eq 'web') {
 1266:               $currentstring = $token->[2];    
 1267:             } 
 1268: 	   return $currentstring;
 1269: 	}
 1270: #-- <table> tag
 1271:         sub start_table {
 1272: 	    my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1273:             my $currentstring = '';
 1274:             if ($target eq 'web') {
 1275:               $currentstring = $token->[4];     
 1276: 	    } elsif ($target eq 'tex') {
 1277: 		my $aa = {};
 1278: 		push @Apache::londefdef::table, $aa; 
 1279: 		$Apache::londefdef::table[-1]{'row_number'} = -1;
 1280: 		$Apache::londefdef::table[-1]{'output'} = '\begin{tabular} ';
 1281: 		my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval);
 1282: 		unless (defined $border) { $border = 0; }
 1283: 		if ($border) { 
 1284: 		    $Apache::londefdef::table[-1]{'hinc'} = '\hline '; 
 1285: 		    $Apache::londefdef::table[-1]{'vinc'} = '&'; 
 1286: 		    $Apache::londefdef::table[-1]{'vvinc'} = '|';
 1287: 		} else {
 1288: 		    $Apache::londefdef::table[-1]{'hinc'} = ''; 
 1289: 		    $Apache::londefdef::table[-1]{'vinc'} = '&'; 
 1290: 		    $Apache::londefdef::table[-1]{'vvinc'} = '';
 1291: 		}
 1292: 	    } 
 1293: 	   return $currentstring;
 1294: 	}
 1295:         sub end_table {
 1296: 	    my ($target,$token) = @_;
 1297:             my $currentstring = '';
 1298:             if ($target eq 'web') {
 1299:               $currentstring = $token->[2];     
 1300: 	    } elsif ($target eq 'tex') {
 1301: 		my $inmemory = '';
 1302: 		my $output = '';
 1303: 		my $header_of_table = '{'.$Apache::londefdef::table[-1]{'vvinc'};
 1304: 		my $in;
 1305: 		for ($in=0;$in<=$Apache::londefdef::table[-1]{'counter_columns'};$in++) {
 1306: 		    $header_of_table .= $Apache::londefdef::table[-1]{'columns'}[$in].$Apache::londefdef::table[-1]{'vvinc'};
 1307: 		}
 1308: 		$header_of_table .= '}';
 1309: 		for ($in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
 1310: 		    $output .=  $Apache::londefdef::table[-1]{'rowdata'}[$in];
 1311: 		    chop $output;
 1312: 		    $output .= ' \\\\ ';
 1313: 		}
 1314: 		$Apache::londefdef::table[-1]{'output'} .= $header_of_table.$output.$Apache::londefdef::table[-1]{'hinc'}.'\end{tabular}\vskip 0 mm ';
 1315: 		if ($#Apache::londefdef::table > 0) {
 1316: 		    $inmemory = $Apache::londefdef::table[-1]{'output'};
 1317: 		    pop @Apache::londefdef::table;
 1318: 		    $Apache::londefdef::table[-1]{'rowdata'}[$Apache::londefdef::table[-1]{'row_number'}] .= $inmemory;
 1319: 		} else {
 1320: 		    $currentstring = $Apache::londefdef::table[-1]{'output'};
 1321: 		    $currentstring =~ s/\\\\\s+\\\\/\\\\/g; 
 1322: 		    pop @Apache::londefdef::table;
 1323: 		}
 1324: 	    }
 1325: 	   return $currentstring;
 1326: 	}
 1327: #-- <tr> tag
 1328:         sub start_tr {
 1329: 	    my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1330:             my $currentstring = '';
 1331:             if ($target eq 'web') {
 1332:               $currentstring = $token->[4];     
 1333: 	    } elsif ($target eq 'tex') {
 1334: 		$Apache::londefdef::table[-1]{'row_number'}++;
 1335: 		my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval),0,1);
 1336: 		if ($alignchar ne '') {
 1337: 		    push @ {$Apache::londefdef::table[-1]{'rows'} }, $alignchar;
 1338: 		} else {
 1339: 		    push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l';
 1340: 		}
 1341: 		push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'});
 1342: 		$Apache::londefdef::table[-1]{'counter_columns'} = -1;
 1343: 
 1344: 	    } 
 1345: 	   return $currentstring;
 1346: 	}        
 1347:         sub end_tr {
 1348: 	    my ($target,$token) = @_;
 1349:             my $currentstring = '';
 1350:             if ($target eq 'web') {
 1351: 		$currentstring = $token->[2];     
 1352: 	    } elsif ($target eq 'tex') {
 1353: #		$currentstring .= ' START ROW '. $Apache::londefdef::table[-1]{'rowdata'}[$Apache::londefdef::table[-1]{'row_number'}].' END ROW ';
 1354: 	    }
 1355: 	   return $currentstring;
 1356: 	}
 1357: #-- <td> tag
 1358:         sub start_td {
 1359: 	    my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1360:             my $currentstring = '';
 1361:             if ($target eq 'web') {
 1362:               $currentstring = $token->[4];     
 1363: 	    } elsif ($target eq 'tex') {
 1364: 		my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval),0,1);
 1365: 		if ($what_to_push eq '') {
 1366: 		    $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);;
 1367: 		}
 1368: 		    push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push;
 1369: 		$Apache::londefdef::table[-1]{'counter_columns'}++;
 1370: 		&Apache::lonxml::startredirection();
 1371: ;
 1372: 	    } 
 1373: 	   return $currentstring;
 1374: 	}        
 1375:         sub end_td {
 1376: 	    my ($target,$token) = @_;
 1377:             my $currentstring = '';
 1378:             if ($target eq 'web') {
 1379: 		$currentstring = $token->[2];     
 1380: 	    } elsif ($target eq 'tex') {
 1381: 		my $current_row = $Apache::londefdef::table[-1]{'row_number'};
 1382: 		my $data=&Apache::lonxml::endredirection();
 1383: 		@{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= $data.' '.$Apache::londefdef::table[-1]{'vinc'};
 1384: 	    }
 1385: 	   return $currentstring;
 1386: 	}
 1387: #-- <th> tag
 1388:         sub start_th {
 1389: 	    my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1390:             my $currentstring = '';
 1391:             if ($target eq 'web') {
 1392:               $currentstring = $token->[4];     
 1393: 	    } elsif ($target eq 'tex') {
 1394: 		my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval),0,1);
 1395: 		if ($what_to_push eq '') {
 1396: 		    $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);;
 1397: 		}
 1398: 		    push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push;
 1399: 		$Apache::londefdef::table[-1]{'counter_columns'}++;
 1400: 		&Apache::lonxml::startredirection();
 1401: ;
 1402: 	    } 
 1403: 	   return $currentstring;
 1404: 	}        
 1405:         sub end_th {
 1406: 	    my ($target,$token) = @_;
 1407:             my $currentstring = '';
 1408:             if ($target eq 'web') {
 1409: 		$currentstring = $token->[2];     
 1410: 	    } elsif ($target eq 'tex') {
 1411: 		my $current_row = $Apache::londefdef::table[-1]{'row_number'};
 1412: 		my $data=&Apache::lonxml::endredirection();
 1413: 		@{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\bf{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'};
 1414: 	    }
 1415: 	   return $currentstring;
 1416: 	}
 1417: #-- <img> tag
 1418:         sub start_img {
 1419: 	    my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1420:             $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
 1421:                                         $token->[2]->{'src'};
 1422:             my $currentstring = '';
 1423: 	    my $width_param = '';
 1424: 	    my $height_param = '';
 1425: 	    my $scaling = .3;
 1426: 
 1427: 	    if ($target eq 'web') {
 1428:               $currentstring = $token->[4];     
 1429: 	    } elsif ($target eq 'tex') {
 1430: 	      my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval);
 1431: 	      $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
 1432:               my $image = Image::Magick->new;
 1433:               my $current_figure = $image->Read($src);
 1434:               $width_param = $image->Get('width') * $scaling;;
 1435: 	      $height_param = $image->Get('height') * $scaling;;
 1436: 	      undef $image;
 1437: 	      my $epssrc = $src;
 1438: 	      $epssrc =~ s/(\.gif|\.jpg)$/\.eps/i;
 1439: 	      if (not -e $epssrc) {
 1440: 		  my $localfile = $epssrc;
 1441: 		  $localfile =~ s/.*(\/res)/$1/;	
 1442: 		  my $file;
 1443: 		  my $path;	
 1444: 		  if ($localfile =~ m!(.*)/([^/]*)$!) {
 1445: 		      $file = $2;
 1446: 		      $path = $1.'/'; 
 1447: 		  }	
 1448: 		  my $signal_eps = 0;
 1449: 		  my @content_directory = &Apache::lonnet::dirlist($path);
 1450: 		  for (my $iy=0;$iy<=$#content_directory;$iy++) {
 1451: 		      my @tempo_array = split(/&/,$content_directory[$iy]);
 1452: 		      $content_directory[$iy] = $tempo_array[0];
 1453: 		      if ($file eq $tempo_array[0]) {
 1454: 			  $signal_eps = 1;
 1455: 			  last;
 1456: 		      }
 1457: 		  }
 1458: 		  if ($signal_eps) {
 1459: 		      my $eps_file = &Apache::lonnet::getfile($localfile);
 1460: 		  } else {
 1461: 		      $localfile = $src;
 1462: 		      $localfile =~ s/.*(\/res)/$1/;	
 1463: 		      my $as = &Apache::lonnet::getfile($src);		      
 1464: 		  }
 1465: 	      }
 1466: 	      my $file;
 1467: 	      my $path;	
 1468:               if ($src =~ m!(.*)/([^/]*)$!) {
 1469: 		  $file = $2;
 1470: 		  $path = $1.'/'; 
 1471: 	      }
 1472: 	      my $newsrc = $src;
 1473: 	      $newsrc =~ s/(\.gif|\.jpg)$/\.eps/i;
 1474: 	      $file=~s/(\.gif|\.jpg)$/\.eps/i;
 1475:               #do we have any specified size of the picture?
 1476: 	      my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval); 
 1477:               my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval); 
 1478: 	      my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval);
 1479: 	      if ($TeXwidth ne '') { 
 1480: 		  $width_param = $TeXwidth; 
 1481: 	      } elsif ($TeXheight ne '') { 
 1482: 		  $width_param = $TeXheight/$height_param*$width_param;
 1483: 	      } elsif ($width ne '') {
 1484: 		  $width_param = $width*$scaling;      
 1485: 	      }
 1486:               #where can we find the picture?
 1487: 	      if (-e $newsrc) {
 1488: 		  if ($path) {
 1489: 		      $currentstring .= '\noindent\graphicspath{{'.$path.'}}\fbox{\includegraphics[width='.$width_param.' mm]{'.$file.'}} ';
 1490: 		  }
 1491: 	      } else {
 1492: 		  my $temp_file;
 1493: 		  my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat";
 1494: 		  $temp_file = Apache::File->new('>>'.$filename); 
 1495: 		  print $temp_file "$src\n";
 1496: 		  $currentstring .= '\graphicspath{{/home/httpd/prtspool/}}\fbox{\includegraphics[width='.$width_param.' mm]{'.$file.'}} ';
 1497: 	      }
 1498: 	    }
 1499: 	    return $currentstring;
 1500: 	}
 1501:         sub end_img {
 1502: 	    my ($target,$token) = @_;
 1503:             my $currentstring = '';
 1504:             if ($target eq 'web') {
 1505:               $currentstring = $token->[2];
 1506: 	    } elsif ($target eq 'tex') {
 1507:               $currentstring = '';
 1508: 	    }
 1509: 	   return $currentstring;
 1510: 	}
 1511: #-- <applet> tag
 1512: 
 1513:         sub start_applet {
 1514: 	    my ($target,$token) = @_;
 1515:               $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=   
 1516:                                         $token->[2]->{'code'};
 1517:               $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
 1518:                                         $token->[2]->{'archive'};
 1519:             my $currentstring = '';
 1520:             if ($target eq 'web') {
 1521:               $currentstring = $token->[4];
 1522: 	    } elsif ($target eq 'tex') {
 1523:               $currentstring = " \\begin{figure} ";
 1524: 	    } 
 1525: 	   return $currentstring;
 1526: 	}
 1527: sub end_applet {
 1528:     my ($target,$token) = @_;
 1529:     my $currentstring = '';
 1530:     if ($target eq 'web') {
 1531: 	$currentstring = $token->[2];
 1532:     } elsif ($target eq 'tex') {
 1533: 	$currentstring = " \\end{figure}";
 1534:     } 
 1535:     return $currentstring;
 1536: }
 1537: 
 1538: #-- <embed> tag
 1539: 
 1540: sub start_embed {    
 1541:     my ($target,$token) = @_;
 1542:     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
 1543: 	$token->[2]->{'src'};
 1544:     my $currentstring = '';
 1545:     if ($target eq 'web') {
 1546: 	$currentstring = $token->[4];
 1547:     } elsif ($target eq 'tex') {
 1548: 	$currentstring = " \\begin{figure} ";  
 1549:     } 
 1550:     return $currentstring;
 1551: }
 1552:         sub end_embed {
 1553: 	    my ($target,$token) = @_;
 1554:             my $currentstring = '';
 1555:             if ($target eq 'web') {
 1556:               $currentstring = $token->[2];     
 1557: 	    } elsif ($target eq 'tex') {
 1558:               $currentstring = " \\end{figure}";  
 1559: 	    } 
 1560: 	   return $currentstring;
 1561: 	}
 1562: 
 1563: #-- <param> tag
 1564: 
 1565:         sub start_param {
 1566: 	    my ($target,$token) = @_;
 1567: 	    if ($token->[2]->{'name'} eq 'cabbase') {
 1568:                       $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
 1569: 					     $token->[2]->{'value'};
 1570:             }   
 1571:             $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=   
 1572:                                         $token->[2]->{'src'};
 1573:             my $currentstring = '';
 1574:             if ($target eq 'web') {
 1575:               $currentstring = $token->[4];     
 1576: 	    } elsif ($target eq 'tex') {
 1577:               $currentstring = " \\begin{figure} ";  
 1578: 	    } 
 1579: 	   return $currentstring;
 1580: 	}
 1581:         sub end_param {
 1582: 	    my ($target,$token) = @_;
 1583:             my $currentstring = '';
 1584:             if ($target eq 'web') {
 1585:               $currentstring = $token->[2];     
 1586: 	    } elsif ($target eq 'tex') {
 1587:               $currentstring = " \\end{figure}";  
 1588: 	    } 
 1589: 	   return $currentstring;
 1590: 	}
 1591: 
 1592: #-- <allow> tag
 1593: 
 1594:         sub start_allow {
 1595: 	    my ($target,$token) = @_;
 1596: 
 1597:             $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=   
 1598:                                         $token->[2]->{'src'};
 1599: 
 1600: 	   return '';
 1601: 	}
 1602:         sub end_allow {
 1603: 	   return '';
 1604: 	}
 1605: #-- Frames
 1606: 	sub start_frameset {
 1607: 	  my ($target,$token) = @_;
 1608: 	  my $currentstring = '';
 1609: 	  if ($target eq 'web') { 
 1610: 	    if (!$Apache::lonxml::registered) {
 1611: 	      $currentstring.='<head>'.
 1612: 		  &Apache::lonxml::registerurl(undef,$target).'</head>';
 1613: 	    }
 1614: 	    $currentstring .= $token->[4];
 1615: 	  }
 1616: 	  return $currentstring;
 1617: 	}
 1618:         sub end_frameset {
 1619: 	  my ($target,$token) = @_;
 1620: 	  my $currentstring = '';
 1621: 	  if ($target eq 'web') {
 1622: 	    $currentstring = $token->[2];
 1623: 	  }
 1624: 	  return $currentstring;
 1625: 	}
 1626: #-- <pre>
 1627: 	sub start_pre {
 1628: 	    my ($target,$token) = @_;
 1629:             my $currentstring = '';
 1630:             if ($target eq 'web') {
 1631: 	       $currentstring .= $token->[4];
 1632: 	    } elsif ($target eq 'tex') {
 1633: 		$currentstring .= '\begin{verbatim}';
 1634: 	    } 
 1635:            return $currentstring;
 1636: 	}
 1637:         sub end_pre {
 1638: 	    my ($target,$token) = @_;
 1639:             my $currentstring = '';
 1640:             if ($target eq 'web') {
 1641: 	       $currentstring .= $token->[2];
 1642: 	    } elsif ($target eq 'tex') {
 1643: 		$currentstring .= '\end{verbatim}';
 1644: 	    }
 1645:            return $currentstring;
 1646: 	}
 1647: #-- <insert>
 1648: 	sub start_insert {
 1649: 	    my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1650:             my $currentstring = '';
 1651:             if ($target eq 'web') {
 1652: 		my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval);
 1653: 	       $currentstring .= '<b>'.$display.'</b>';;
 1654: 	    }
 1655:            return $currentstring;
 1656: 	}
 1657:         sub end_insert {
 1658: 	    my ($target,$token) = @_;
 1659:             my $currentstring = '';
 1660:             if ($target eq 'web') {
 1661: 	       $currentstring .= '';
 1662: 	    }
 1663:            return $currentstring;
 1664: 	}
 1665: #-- <externallink>
 1666: 	sub start_externallink {
 1667: 	    my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1668:             my $currentstring = '';
 1669:             if ($target eq 'web') {
 1670: 		my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval);
 1671: 	       $currentstring .= '<b>'.$display.'</b>';;
 1672: 	    }
 1673:            return $currentstring;
 1674: 	}
 1675:         sub end_externallink {
 1676: 	    my ($target,$token) = @_;
 1677:             my $currentstring = '';
 1678:             if ($target eq 'web') {
 1679: 	       $currentstring .= '';
 1680: 	    }
 1681:            return $currentstring;
 1682: 	}
 1683: #-- <blankspace heigth="">
 1684:         sub start_blankspace {
 1685: 	    my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1686:             my $currentstring = '';
 1687:             if ($target eq 'tex') {
 1688: 		my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval);
 1689: 		$currentstring .= '\vskip '.$howmuch.' ';
 1690: 	    }
 1691:            return $currentstring;
 1692: 	}
 1693:         sub end_blankspace {
 1694: 	    my ($target,$token) = @_;
 1695:             my $currentstring = '';
 1696:             if ($target eq 'tex') {
 1697: 	       $currentstring .= '';
 1698: 	    }
 1699:            return $currentstring;
 1700: 	}
 1701: 
 1702: 1;
 1703: __END__

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