File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.69: download - view: text, annotated - select for diffs
Thu Jul 11 14:40:14 2002 UTC (21 years, 10 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
1. Does correct scaling of any GIF picture even in the case of absence
of definition of the size (by author). 2) Small change in table environment
(I missed & sign in previous version for tables without boundary).

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

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