File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.76: download - view: text, annotated - select for diffs
Wed Jul 24 19:56:32 2002 UTC (21 years, 10 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Added 1. correction for stupid way of coming to the next line (used by Ray)
<m>\\</m>;
      2. corrected \underline for a few html tags to work in latex2e.

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

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