File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.145: download - view: text, annotated - select for diffs
Fri Jun 27 14:01:19 2003 UTC (20 years, 11 months ago) by albertel
Branches: MAIN
CVS tags: version_0_99_3, HEAD
- commenting out batchmode for now (notready for 0.99.3)

    1: # The LearningOnline Network with CAPA
    2: # Tags Default Definition Module 
    3: #
    4: # $Id: londefdef.pm,v 1.145 2003/06/27 14:01:19 albertel 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: use Apache::lonmenu();
   53: use Apache::lonmeta();
   54: 
   55: BEGIN {
   56: 
   57:     &Apache::lonxml::register('Apache::londefdef',('a','abbr','acronym','accessrule','address','allow','applet','area','b','base','basefont','bgo','bgsound','big','blink','blockquote','blankspace','body','br','button','caption','center','cite','code','col','colgroup','dd','del','dfn','dir','div','dl','dt','em','embed','externallink','fieldset','font','form','frame','frameset','h1','h2','h3','h4','h5','h6','head','hr','html','i','iframe','img','input','ins','insert','isindex','kbd','keygen','label','layer','legend','li','link','m','map','marquee','menu','meta','multicol','nobr','noembed','noframes','nolayer','noscript','object','ol','optgroup','option','output','p','param','pre','q','s','samp','select','server','small','spacer','span','strike','strong','sub','sup','table','tbody','td','textarea','tfoot','th','thead','title','tr','tt','tthoption','u','ul','var','wbr','hideweboutput'));
   58: 
   59: }
   60: 
   61: #======================= TAG SUBROUTINES =====================
   62: #-- <output>
   63: sub start_output {
   64:     my ($target) = @_;
   65:     if ($target eq 'meta') { $Apache::lonxml::metamode--; }
   66:     return '';
   67: }
   68: sub end_output {
   69:     my ($target) = @_;
   70:     if ($target eq 'meta') { $Apache::lonxml::metamode++; }
   71:     return '';
   72: }
   73: #-- <m> tag
   74: sub start_m {
   75:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
   76:     my $currentstring = '';
   77:     if ($target eq 'web') {
   78: 	$Apache::lonxml::prevent_entity_encode++;
   79: 	my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser);
   80: 	$inside ='\\documentstyle{article}'.$inside;
   81: 	&Apache::lonxml::debug("M is starting with:$inside:");
   82: 	my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
   83: 	if ($eval eq 'on') {
   84: 	    $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
   85: 	    #&Apache::lonxml::debug("M is evaulated to:$inside:");
   86: 	}
   87: 	$currentstring = &Apache::lontexconvert::converted(\$inside);
   88: 	if ($Apache::lontexconvert::errorstring) {
   89: 	    &Apache::lonxml::warning("tth error: ".
   90: 				     $Apache::lontexconvert::errorstring);
   91: 	    $Apache::lontexconvert::errorstring='';
   92: 	}
   93: 	#&Apache::lonxml::debug("M is ends with:$currentstring:");
   94:     } elsif ($target eq 'tex') {
   95: 	$currentstring = &Apache::lonxml::get_all_text_unbalanced("/m",$parser);
   96: 	if ($currentstring=~/^(\s*\\\\\s*)*$/) {$currentstring = ' \vskip 0 mm ';}
   97:     } else {
   98: 	my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser);
   99:     }
  100:     return $currentstring;
  101: }
  102: 
  103: sub end_m {
  104:     my ($target,$token) = @_;
  105:     my $currentstring = '';
  106:     if ($target eq 'web') {
  107: 	$Apache::lonxml::prevent_entity_encode--;
  108:     } elsif ($target eq 'tex') {
  109: 	$currentstring = "";
  110:     } elsif ($target eq 'meta') {
  111:     }
  112:     return $currentstring;
  113: }
  114: 
  115: sub start_tthoption {
  116:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  117:     my $result;
  118:     if ($target eq 'web') {
  119: 	my $inside = &Apache::lonxml::get_all_text("/tthoption",$parser);
  120: 	$inside=~s/^\s*//;
  121: 	if ($ENV{'browser.mathml'}) {
  122: 	    &tth::ttmoptions($inside);
  123: 	} else {
  124: 	    &tth::tthoptions($inside);
  125: 	}
  126:     }
  127:     return $result;
  128: }
  129: 
  130: sub end_tthoption {
  131:     my ($target,$token) = @_;
  132:     my $result;
  133:     return $result;
  134: }
  135: 
  136: #-- <html> tag    
  137: sub start_html {
  138:     my ($target,$token) = @_;
  139:     my $currentstring = '';
  140:     if ($ENV{'browser.mathml'}) {
  141: 	&tth::ttminit();
  142: 	if ($ENV{'browser.unicode'}) {
  143: 	    &tth::ttmoptions('-L -u1');
  144: 	} else {
  145: 	    &tth::ttmoptions('-L -u0');
  146: 	}
  147:     } else {
  148: 	&tth::tthinit();
  149: 	if ($ENV{'browser.unicode'}) {
  150: 	    &tth::tthoptions('-L -u1');
  151: 	} else {
  152: 	    &tth::tthoptions('-L -u0');
  153: 	}
  154:     }
  155:     if ($target eq 'web') {
  156: 	$currentstring = &Apache::lonxml::xmlbegin().
  157: 	    &Apache::lonxml::fontsettings();     
  158:     } elsif ($target eq 'tex') {
  159: 	@Apache::londefdef::table = ();
  160: 	$currentstring .= '\documentclass[letterpaper]{article}'.
  161:                            #'\batchmode'.
  162:                            '\newcommand{\keephidden}[1]{}
  163:                            \renewcommand{\deg}{$^{\circ}$}
  164:                            \usepackage{textcomp}
  165:                            \usepackage[dvips]{graphicx}
  166:                            \usepackage{epsfig}\usepackage{calc}
  167: \newenvironment{choicelist}{\begin{list}{}{\setlength{\rightmargin}{0in}\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.05in}\setlength{\itemsep}{0.022in}\setlength{\parsep}{0in}\setlength{\belowdisplayskip}{0.04in}\setlength{\abovedisplayskip}{0.05in}\setlength{\abovedisplayshortskip}{-0.04in}\setlength{\belowdisplayshortskip}{0.04in}}}{\end{list}}';
  168:     }
  169:     return $currentstring;
  170: }
  171: 
  172: sub end_html {
  173:     my ($target,$token) = @_;
  174:     my $currentstring = '';
  175:     if ($target eq 'web') {
  176: 	$currentstring = &Apache::lonxml::xmlend();
  177:     }
  178:     return $currentstring;
  179: }
  180: 
  181: #-- <head> tag
  182: sub start_head {
  183:     my ($target,$token) = @_;
  184:     my $currentstring = '';
  185:     if ($target eq 'web') {
  186: 	$currentstring = $token->[4];     
  187:     } 
  188:     return $currentstring;
  189: }
  190: 
  191: sub end_head {
  192:     my ($target,$token) = @_;
  193:     my $currentstring = '';
  194:     if ($target eq 'web') {
  195: 	$currentstring = &Apache::lonmenu::registerurl(undef,$target).
  196: 	    $token->[2];    
  197:     } 
  198:     return $currentstring;
  199: }
  200: 
  201: #-- <map> tag
  202: sub start_map {
  203:     my ($target,$token) = @_;
  204:     my $currentstring = '';
  205:     if ($target eq 'web') {
  206: 	$currentstring = $token->[4];     
  207:     } 
  208:     return $currentstring;
  209: }
  210: 
  211: sub end_map {
  212:     my ($target,$token) = @_;
  213:     my $currentstring = '';
  214:     if ($target eq 'web') {
  215: 	$currentstring = $token->[2];    
  216:     } 
  217:     return $currentstring;
  218: }
  219: 
  220: #-- <select> tag
  221: sub start_select {
  222:     my ($target,$token) = @_;
  223:     my $currentstring = '';
  224:     if ($target eq 'web') {
  225: 	$currentstring = $token->[4];     
  226:     } 
  227:     return $currentstring;
  228: }
  229: 
  230: sub end_select {
  231:     my ($target,$token) = @_;
  232:     my $currentstring = '';
  233:     if ($target eq 'web') {
  234: 	$currentstring = $token->[2];    
  235:     } 
  236:     return $currentstring;
  237: }
  238: 
  239: #-- <option> tag
  240: sub start_option {
  241:     my ($target,$token) = @_;
  242:     my $currentstring = '';
  243:     if ($target eq 'web') {
  244: 	$currentstring = $token->[4];     
  245:     } 
  246:     return $currentstring;
  247: }
  248: 
  249: sub end_option {
  250:     my ($target,$token) = @_;
  251:     my $currentstring = '';
  252:     if ($target eq 'web') {
  253: 	$currentstring = $token->[2];    
  254:     } 
  255:     return $currentstring;
  256: }
  257: 
  258: #-- <input> tag
  259: sub start_input {
  260:     my ($target,$token) = @_;
  261:     my $currentstring = '';
  262:     if ($target eq 'web') {
  263: 	$currentstring = $token->[4];     
  264:     } 
  265:     return $currentstring;
  266: }
  267: 
  268: sub end_input {
  269:     my ($target,$token) = @_;
  270:     my $currentstring = '';
  271:     if ($target eq 'web') {
  272: 	$currentstring = $token->[2];    
  273:     } 
  274:     return $currentstring;
  275: }
  276: 
  277: #-- <textarea> tag
  278: sub start_textarea {
  279:     my ($target,$token) = @_;
  280:     my $currentstring = '';
  281:     if ($target eq 'web') {
  282: 	$currentstring = $token->[4];     
  283:     } 
  284:     return $currentstring;
  285: }
  286: 
  287: sub end_textarea {
  288:     my ($target,$token) = @_;
  289:     my $currentstring = '';
  290:     if ($target eq 'web') {
  291: 	$currentstring = $token->[2];    
  292:     } 
  293:     return $currentstring;
  294: }
  295: 
  296: #-- <form> tag
  297: sub start_form {
  298:     my ($target,$token) = @_;
  299:     my $currentstring = '';
  300:     if ($target eq 'web') {
  301: 	$currentstring = $token->[4];     
  302:     } 
  303:     return $currentstring;
  304: }
  305: 
  306: sub end_form {
  307:     my ($target,$token) = @_;
  308:     my $currentstring = '';
  309:     if ($target eq 'web') {
  310: 	$currentstring = $token->[2];    
  311:     } 
  312:     return $currentstring;
  313: }
  314: 
  315: #-- <title> tag
  316: sub start_title {
  317:     my ($target,$token) = @_;
  318:     my $currentstring = '';
  319:     if ($target eq 'web') {
  320: 	$currentstring = $token->[4];     
  321:     } elsif ($target eq 'tex') {
  322: 	$currentstring .= '\keephidden{' 
  323:     }
  324:     if ($target eq 'meta') {
  325: 	$currentstring='<title>';
  326: 	&start_output();
  327:     }
  328:     return $currentstring;
  329: }
  330: 
  331: sub end_title {
  332:     my ($target,$token) = @_;
  333:     my $currentstring = '';
  334:     if ($target eq 'web') {
  335: 	$currentstring = $token->[2];    
  336:     } elsif ($target eq 'tex') {
  337: 	$currentstring .= '}';
  338:     }  
  339:     if ($target eq 'meta') {
  340: 	&end_output();
  341: 	$currentstring='</title>';
  342:     } 
  343:     return $currentstring;
  344: }
  345: 
  346: #-- <meta> tag
  347: sub start_meta {
  348:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  349:     my $currentstring = '';
  350:     if ($target eq 'web') {
  351: 	my $args='';
  352: 	if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
  353: 	if ($args eq '') {
  354: 	    &Apache::lonxml::get_all_text("/meta",$parser);
  355: 	} else {
  356: 	    $currentstring = $token->[4];
  357: 	}
  358:     } elsif ($target eq 'meta') {
  359: 	unless (&Apache::lonxml::get_param
  360: 		('http-equiv',$parstack,$safeeval,undef,1)) {
  361: 	    my $name=$token->[2]->{'name'};
  362: 	    $name=~tr/A-Z/a-z/;
  363: 	    $name=~s/\s/\_/gs;
  364: 	    $name=~s/\W//gs;
  365: 	    if ($name) {
  366: 		$currentstring='<'.$name.'>'.
  367: 		    &Apache::lonxml::get_param
  368: 			('content',$parstack,$safeeval,undef,1).
  369: 			'</'.$name.'>';
  370: 	    }
  371: 	}
  372:     } elsif ($target eq 'tex') {
  373: 	&Apache::lonxml::startredirection();
  374:     }
  375:     return $currentstring;
  376: }
  377: 
  378: sub end_meta {
  379:     my ($target,$token,$tagstack,$parstack,$parser) = @_;
  380:     my $currentstring = '';
  381:     if ($target eq 'web') {
  382: 	my $args='';
  383: 	if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
  384: 	if ($args ne '') {
  385: 	    $currentstring = $token->[4];
  386: 	}
  387:     } elsif ($target eq 'tex') {
  388: 	$currentstring=&Apache::lonxml::endredirection();
  389: 	$currentstring='';
  390:     }
  391:     return $currentstring;
  392: }
  393: 
  394: # accessrule
  395: sub start_accessrule {
  396:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  397:     my $currentstring = '';
  398:     my $eff=&Apache::lonxml::get_param
  399: 	('effect',$parstack,$safeeval,undef,1);
  400:     my $realm=&Apache::lonxml::get_param
  401: 	('realm',$parstack,$safeeval,undef,1);
  402:     my $role=&Apache::lonxml::get_param
  403: 	('role',$parstack,$safeeval,undef,1);
  404:     $realm=~s/\s+//g;
  405:     $realm=~s/\//\_/g;
  406:     $realm=~s/^\_//;
  407:     $realm=~s/\W/\;/g;
  408:     $role=~s/\s+//g;
  409:     $role=~s/\//\_/g;
  410:     $role=~s/\W/\;/g;
  411:     if ($target eq 'web') {
  412: 	my $args='';
  413: 	if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
  414: 	if ($args eq '') {
  415: 	    &Apache::lonxml::get_all_text("/accessrule",$parser);
  416: 	} else {
  417: 	    $currentstring = $token->[4];
  418: 	}
  419:     }
  420:     if ($target eq 'meta') {
  421: 	$currentstring='<rule>'.$eff.':'.$realm.':'.$role.'</rule>';
  422:     }
  423:     return $currentstring;
  424: }
  425: 
  426: sub end_accessrule {
  427:     my ($target,$token,$tagstack,$parstack,$parser) = @_;
  428:     my $currentstring = '';
  429:     if ($target eq 'web') {
  430: 	my $args='';
  431: 	if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
  432: 	if ($args ne '') {
  433: 	    $currentstring = $token->[4];
  434: 	}
  435:     } 
  436:     return $currentstring;
  437: }
  438: 
  439: #-- <body> tag
  440: sub start_body {
  441:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  442:     my $currentstring = '';
  443:     if ($target eq 'web') {
  444: 	if (!$Apache::lonxml::registered) {
  445: 	    $currentstring.='<head>'.
  446: 		&Apache::lonmenu::registerurl(undef,$target).'</head>';
  447: 	}
  448: 	my $onLoad='';
  449: 	foreach my $key (keys(%{$token->[2]})) {
  450: 	    if ($key =~ /^onload$/i) {
  451: 		$onLoad.=$token->[2]->{$key}.';';
  452: 		delete($token->[2]->{$key});
  453: 	    }
  454: 	}
  455: 	$token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad;
  456: 	my $onUnload='';
  457: 	foreach my $key (keys(%{$token->[2]})) {
  458: 	    if ($key =~ /^onunload$/i) {
  459: 		$onUnload.=$token->[2]->{$key}.';';
  460: 		delete($token->[2]->{$key});
  461: 	    }
  462: 	}
  463: 	$token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents().
  464: 	    ';'.$onUnload;
  465: 	
  466: 	$currentstring .= '<'.$token->[1];
  467: 	foreach (keys %{$token->[2]}) {
  468: 	    $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
  469: 	}
  470: 	$currentstring.='>';
  471: 	if ($ENV{'request.state'} ne 'published') {
  472: 	    $currentstring.=(<<EDITBUTTON);
  473: 		<form method="post">
  474: 		<input type="submit" name="editmode" value="Edit" />
  475: 		</form>
  476: EDITBUTTON
  477: 	} else {
  478: 	    $currentstring.=&Apache::lonmenu::menubuttons(undef,$target,1);
  479: 	}
  480:     } elsif ($target eq 'tex') {
  481: 	$currentstring = '\begin{document}';  
  482:     } 
  483:     return $currentstring;
  484: }
  485: 
  486: sub end_body {
  487:     my ($target,$token) = @_;
  488:     my $currentstring = '';
  489:     if ($target eq 'web') {
  490: 	$currentstring = $token->[2];     
  491:     } elsif ($target eq 'tex') {
  492: 	$currentstring = '\end{document}';  
  493:     } 
  494:     return $currentstring;
  495: }
  496: 
  497: #-- <center> tag
  498: sub start_center {
  499:     my ($target,$token) = @_;
  500:     my $currentstring = '';
  501:     if ($target eq 'web') {
  502: 	$currentstring = $token->[4];     
  503:     } elsif ($target eq 'tex') {
  504: 	$currentstring = '\begin{center}';  
  505:     }
  506:     return $currentstring;
  507: }
  508: 
  509: sub end_center {
  510:     my ($target,$token) = @_;
  511:     my $currentstring = '';
  512:     if ($target eq 'web') {
  513: 	$currentstring = $token->[2];     
  514:     } elsif ($target eq 'tex') {
  515: 	$currentstring = '\end{center}';  
  516:     }
  517:     return $currentstring;
  518: }
  519: 
  520: #-- <b> tag
  521: sub start_b {
  522:     my ($target,$token) = @_;
  523:     my $currentstring = '';
  524:     if ($target eq 'web') {
  525: 	$currentstring = $token->[4];     
  526:     } elsif ($target eq 'tex') {
  527: 	$currentstring = '\textbf{';  
  528:     } 
  529:     return $currentstring;
  530: }
  531: 
  532: sub end_b {
  533:     my ($target,$token) = @_;
  534:     my $currentstring = '';
  535:     if ($target eq 'web') {
  536: 	$currentstring = $token->[2];     
  537:     } elsif ($target eq 'tex') {
  538: 	$currentstring = '}';  
  539:     } 
  540:     return $currentstring;
  541: }
  542: 
  543: #-- <strong> tag
  544: sub start_strong {
  545:     my ($target,$token) = @_;
  546:     my $currentstring = '';
  547:     if ($target eq 'web') {
  548: 	$currentstring = $token->[4];     
  549:     } elsif ($target eq 'tex') {
  550: 	$currentstring = '\textbf{';  
  551:     } 
  552:     return $currentstring;
  553: }
  554: 
  555: sub end_strong {
  556:     my ($target,$token) = @_;
  557:     my $currentstring = '';
  558:     if ($target eq 'web') {
  559: 	
  560: 	$currentstring = $token->[2];     
  561:     } elsif ($target eq 'tex') {
  562: 	$currentstring = '}';  
  563:     }
  564:     return $currentstring;
  565: }
  566: 
  567: #-- <h1> tag
  568: sub start_h1 {
  569:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  570:     my $currentstring = '';
  571:     if ($target eq 'web') {
  572: 	$currentstring .= $token->[4];
  573:     } elsif ($target eq 'tex') {
  574: 	my $pre;
  575: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  576: 	if (($align eq 'center') || (not defined $align)) {
  577: 	    $pre='\begin{center}';
  578: 	} elsif ($align eq 'left') {
  579: 	    $pre='\rlap{';
  580: 	} elsif ($align eq 'right') {
  581: 	    $pre=' \hfill \llap{';
  582: 	}
  583: 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
  584: 	if (not defined $TeXsize) {$TeXsize="large";}
  585: 	$currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 
  586:     } elsif ($target eq 'meta') {
  587: 	$currentstring='<subject>';
  588: 	&start_output();
  589:     }
  590:     return $currentstring;
  591: }
  592: 
  593: sub end_h1 {
  594:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  595:     my $currentstring = '';
  596:     if ($target eq 'web') {
  597: 	$currentstring .= $token->[2];
  598:     } elsif ($target eq 'tex') {
  599: 	my $post;
  600: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  601: 	if (($align eq 'center') || (not defined $align)) {
  602: 	    $post='\end{center}';
  603: 	} elsif ($align eq 'left') {
  604: 	    $post='} \hfill'.'\vskip 0 mm ';
  605: 	} elsif ($align eq 'right') {
  606: 	    $post='}'.'\vskip 0 mm ';
  607: 	}
  608: 	$currentstring .= '}}'.$post;
  609:     } elsif ($target eq 'meta') {
  610: 	&end_output();
  611: 	$currentstring='</subject>';
  612:     } 
  613:     return $currentstring;
  614: }
  615: 
  616: #-- <h2> tag
  617: sub start_h2 {
  618:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  619:     my $currentstring = '';
  620:     if ($target eq 'web') {
  621: 	$currentstring .= $token->[4];
  622:     } elsif ($target eq 'tex') {
  623: 	my $pre;
  624: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  625: 	if (($align eq 'center') || (not defined $align)) {
  626: 	    $pre='\begin{center}';
  627: 	} elsif ($align eq 'left') {
  628: 	    $pre='\rlap{';
  629: 	} elsif ($align eq 'right') {
  630: 	    $pre=' \hfill \llap{';
  631: 	}
  632: 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
  633: 	if (not defined $TeXsize) {$TeXsize="large";}
  634: 	$currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 
  635:     } 
  636:     return $currentstring;
  637: }
  638: 
  639: sub end_h2 {
  640:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  641:     my $currentstring = '';
  642:     if ($target eq 'web') {
  643: 	$currentstring .= $token->[2];
  644:     } elsif ($target eq 'tex') {
  645: 	my $post;
  646: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  647: 	if (($align eq 'center') || (not defined $align)) {
  648: 	    $post='\end{center}';
  649: 	} elsif ($align eq 'left') {
  650: 	    $post='} \hfill'.'\vskip 0 mm ';
  651: 	} elsif ($align eq 'right') {
  652: 	    $post='}'.'\vskip 0 mm ';
  653: 	}
  654: 	$currentstring .= '}}'.$post;
  655:     } 
  656:     return $currentstring;
  657: }
  658: 
  659: #-- <h3> tag
  660: sub start_h3 {
  661:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  662:     my $currentstring = '';
  663:     if ($target eq 'web') {
  664: 	$currentstring .= $token->[4];
  665:     } elsif ($target eq 'tex') {
  666: 	my $pre;
  667: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  668: 	if (($align eq 'center') || (not defined $align)) {
  669: 	    $pre='\begin{center}';
  670: 	} elsif ($align eq 'left') {
  671: 	    $pre='\rlap{';
  672: 	} elsif ($align eq 'right') {
  673: 	    $pre=' \hfill \llap{';
  674: 	}
  675: 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
  676: 	if (not defined $TeXsize) {$TeXsize="large";}
  677: 	$currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 
  678:     } 
  679:     return $currentstring;
  680: }
  681: 
  682: sub end_h3 {
  683:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  684:     my $currentstring = '';
  685:     if ($target eq 'web') {
  686: 	$currentstring .= $token->[2];
  687:     } elsif ($target eq 'tex') {
  688: 	my $post;
  689: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  690: 	if (($align eq 'center') || (not defined $align)) {
  691: 	    $post='\end{center}';
  692: 	} elsif ($align eq 'left') {
  693: 	    $post='} \hfill'.'\vskip 0 mm ';
  694: 	} elsif ($align eq 'right') {
  695: 	    $post='}'.'\vskip 0 mm ';
  696: 	}
  697: 	$currentstring .= '}}'.$post;
  698:     } 
  699:     return $currentstring;
  700: }
  701: 
  702: #-- <h4> tag
  703: sub start_h4 {
  704:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  705:     my $currentstring = '';
  706:     if ($target eq 'web') {
  707: 	$currentstring .= $token->[4];
  708:     } elsif ($target eq 'tex') {
  709: 	my $pre;
  710: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  711: 	if (($align eq 'center') || (not defined $align)) {
  712: 	    $pre='\begin{center}';
  713: 	} elsif ($align eq 'left') {
  714: 	    $pre='\rlap{';
  715: 	} elsif ($align eq 'right') {
  716: 	    $pre=' \hfill \llap{';
  717: 	}
  718: 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
  719: 	if (not defined $TeXsize) {$TeXsize="large";}
  720: 	$currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 
  721:     } 
  722:     return $currentstring;
  723: }
  724: 
  725: sub end_h4 {
  726:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  727:     my $currentstring = '';
  728:     if ($target eq 'web') {
  729: 	$currentstring .= $token->[2];
  730:     } elsif ($target eq 'tex') {
  731: 	my $post;
  732: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  733: 	if (($align eq 'center') || (not defined $align)) {
  734: 	    $post='\end{center}';
  735: 	} elsif ($align eq 'left') {
  736: 	    $post='} \hfill'.'\vskip 0 mm ';
  737: 	} elsif ($align eq 'right') {
  738: 	    $post='}'.'\vskip 0 mm ';
  739: 	}
  740: 	$currentstring .= '}}'.$post;
  741:     } 
  742:     return $currentstring;
  743: }
  744: 
  745: #-- <h5> tag
  746: sub start_h5 {
  747:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  748:     my $currentstring = '';
  749:     if ($target eq 'web') {
  750: 	$currentstring .= $token->[4];
  751:     } elsif ($target eq 'tex') {
  752: 	my $pre;
  753: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  754: 	if (($align eq 'center') || (not defined $align)) {
  755: 	    $pre='\begin{center}';
  756: 	} elsif ($align eq 'left') {
  757: 	    $pre='\rlap{';
  758: 	} elsif ($align eq 'right') {
  759: 	    $pre=' \hfill \llap{';
  760: 	}
  761: 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
  762: 	if (not defined $TeXsize) {$TeXsize="large";}
  763: 	$currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 
  764:     } 
  765:     return $currentstring;
  766: }
  767: 
  768: sub end_h5 {
  769:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  770:     my $currentstring = '';
  771:     if ($target eq 'web') {
  772: 	$currentstring .= $token->[2];
  773:     } elsif ($target eq 'tex') {
  774: 	my $post;
  775: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  776: 	if (($align eq 'center') || (not defined $align)) {
  777: 	    $post='\end{center}';
  778: 	} elsif ($align eq 'left') {
  779: 	    $post='} \hfill'.'\vskip 0 mm ';
  780: 	} elsif ($align eq 'right') {
  781: 	    $post='}'.'\vskip 0 mm ';
  782: 	}
  783: 	$currentstring .= '}}'.$post;
  784:     } 
  785:     return $currentstring;
  786: }
  787: 
  788: #-- <h6> tag
  789: sub start_h6 {
  790:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  791:     my $currentstring = '';
  792:     if ($target eq 'web') {
  793: 	$currentstring .= $token->[4];
  794:     } elsif ($target eq 'tex') {
  795: 	my $pre;
  796: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  797: 	if (($align eq 'center') || (not defined $align)) {
  798: 	    $pre='\begin{center}';
  799: 	} elsif ($align eq 'left') {
  800: 	    $pre='\rlap{';
  801: 	} elsif ($align eq 'right') {
  802: 	    $pre=' \hfill \llap{';
  803: 	}
  804: 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
  805: 	if (not defined $TeXsize) {$TeXsize="large";}
  806: 	$currentstring .= $pre.'{\\'.$TeXsize.' \textbf{'; 
  807:     } 
  808:     return $currentstring;
  809: }
  810: 
  811: sub end_h6 {
  812:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  813:     my $currentstring = '';
  814:     if ($target eq 'web') {
  815: 	$currentstring .= $token->[2];
  816:     } elsif ($target eq 'tex') {
  817: 	my $post;
  818: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  819: 	if (($align eq 'center') || (not defined $align)) {
  820: 	    $post='\end{center}';
  821: 	} elsif ($align eq 'left') {
  822: 	    $post='} \hfill'.'\vskip 0 mm ';
  823: 	} elsif ($align eq 'right') {
  824: 	    $post='}'.'\vskip 0 mm ';
  825: 	}
  826: 	$currentstring .= '}}'.$post;
  827:     } 
  828:     return $currentstring;
  829: }
  830: 
  831: #--- <cite> tag
  832: sub start_cite {
  833:     my ($target,$token) = @_;
  834:     my $currentstring = '';
  835:     if ($target eq 'web') {
  836: 	$currentstring .= $token->[4];
  837:     } elsif ($target eq 'tex') {
  838: 	$currentstring .= "\\textit{";
  839:     }
  840:     return $currentstring;
  841: }
  842: 
  843: sub end_cite {
  844:     my ($target,$token) = @_;
  845:     my $currentstring = '';
  846:     if ($target eq 'web') {
  847: 	$currentstring .= $token->[2];
  848:     } elsif ($target eq 'tex') {
  849: 	$currentstring .= "}";
  850:     }
  851:     return $currentstring;
  852: }
  853: 
  854: #-- <i> tag
  855: sub start_i {
  856:     my ($target,$token) = @_;
  857:     my $currentstring = '';
  858:     if ($target eq 'web') {
  859: 	$currentstring .= $token->[4];
  860:     } elsif ($target eq 'tex') {
  861: 	$currentstring .= '\textit{';
  862:     }
  863:     return $currentstring;
  864: }
  865: 
  866: sub end_i {
  867:     my ($target,$token) = @_;
  868:     my $currentstring = '';
  869:     if ($target eq 'web') {
  870: 	$currentstring .= $token->[2];
  871:     } elsif ($target eq 'tex') {
  872: 	$currentstring .= '}';
  873:     } 
  874:     return $currentstring;
  875: }
  876: 
  877: #-- <address> tag
  878: sub start_address {
  879:     my ($target,$token) = @_;
  880:     my $currentstring = '';
  881:     if ($target eq 'web') {
  882: 	$currentstring .= $token->[4];
  883:     } elsif ($target eq 'tex') {
  884: 	$currentstring .= "\\textit{";
  885:     }
  886:     return $currentstring;
  887: }
  888: 
  889: sub end_address {
  890:     my ($target,$token) = @_;
  891:     my $currentstring = '';
  892:     if ($target eq 'web') {
  893: 	$currentstring .= $token->[2];
  894:     } elsif ($target eq 'tex') {
  895: 	$currentstring .= "}";
  896:     }
  897:     return $currentstring;
  898: }
  899: 
  900: #-- <dfn> tag
  901: sub start_dfn {
  902:     my ($target,$token) = @_;
  903:     my $currentstring = '';
  904:     if ($target eq 'web') {
  905: 	$currentstring .= $token->[4];
  906:     } elsif ($target eq 'tex') {
  907: 	$currentstring .= "\\textit{";
  908:     } 
  909:     return $currentstring;
  910: }
  911: 
  912: sub end_dfn {
  913:     my ($target,$token) = @_;
  914:     my $currentstring = '';
  915:     if ($target eq 'web') {
  916: 	$currentstring .= $token->[2];
  917:     } elsif ($target eq 'tex') {
  918: 	$currentstring .= "}";
  919:     }
  920:     return $currentstring;
  921: }
  922: 
  923: #-- <tt> tag
  924: sub start_tt {
  925:     my ($target,$token) = @_;
  926:     my $currentstring = '';
  927:     if ($target eq 'web') {
  928: 	$currentstring .= $token->[4];
  929:     } elsif ($target eq 'tex') {
  930: 	$currentstring .= '\texttt{';
  931:     }
  932:     return $currentstring;
  933: }
  934: 
  935: sub end_tt {
  936:     my ($target,$token) = @_;
  937:     my $currentstring = '';
  938:     if ($target eq 'web') {
  939: 	$currentstring .= $token->[2];
  940:     } elsif ($target eq 'tex') {
  941: 	$currentstring .= '}';
  942:     }
  943:     return $currentstring;
  944: }
  945: 
  946: #-- <kbd> tag
  947: sub start_kbd {
  948:     my ($target,$token) = @_;
  949:     my $currentstring = '';
  950:     if ($target eq 'web') {
  951: 	$currentstring .= $token->[4];
  952:     } elsif ($target eq 'tex') {
  953: 	$currentstring .= "\\texttt";
  954:     }
  955:     return $currentstring;
  956: }
  957: 
  958: sub end_kbd {
  959:     my ($target,$token) = @_;
  960:     my $currentstring = '';
  961:     if ($target eq 'web') {
  962: 	$currentstring .= $token->[2];
  963:     } elsif ($target eq 'tex') {
  964: 	$currentstring .= "}";
  965:     }
  966:     return $currentstring;
  967: }
  968: 
  969: #-- <code> tag
  970: sub start_code {
  971:     my ($target,$token) = @_;
  972:     my $currentstring = '';
  973:     if ($target eq 'web') {
  974: 	$currentstring .= $token->[4];
  975:     } elsif ($target eq 'tex') {
  976: 	$currentstring .= '\texttt{';
  977:     } 
  978:     return $currentstring;
  979: }
  980: 
  981: sub end_code {
  982:     my ($target,$token) = @_;
  983:     my $currentstring = '';
  984:     if ($target eq 'web') {
  985: 	$currentstring .= $token->[2];
  986:     } elsif ($target eq 'tex') {
  987: 	$currentstring .= '}';
  988:     } 
  989:     return $currentstring;
  990: }
  991: 
  992: #-- <em> tag
  993: sub start_em {
  994:     my ($target,$token) = @_;
  995:     my $currentstring = '';
  996:     if ($target eq 'web') {
  997: 	$currentstring .= $token->[4];
  998:     } elsif ($target eq 'tex') {
  999: 	$currentstring .= '\emph{';
 1000:     }
 1001:     return $currentstring;
 1002: }
 1003: 
 1004: sub end_em {
 1005:     my ($target,$token) = @_;
 1006:     my $currentstring = '';
 1007:     if ($target eq 'web') {
 1008: 	$currentstring .= $token->[2];
 1009:     } elsif ($target eq 'tex') {
 1010: 	$currentstring .= '}';
 1011:     } 
 1012:     return $currentstring;
 1013: }
 1014: 
 1015: #-- <q> tag
 1016: sub start_q {
 1017:     my ($target,$token) = @_;
 1018:     my $currentstring = '';
 1019:     if ($target eq 'web') {
 1020: 	$currentstring .= $token->[4];
 1021:     } elsif ($target eq 'tex') {
 1022: 	$currentstring .= "\\emph{";
 1023:     }
 1024:     return $currentstring;
 1025: }
 1026: 
 1027: sub end_q {
 1028:     my ($target,$token) = @_;
 1029:     my $currentstring = '';
 1030:     if ($target eq 'web') {
 1031: 	$currentstring .= $token->[2];
 1032:     } elsif ($target eq 'tex') {
 1033: 	$currentstring .= "}";
 1034:     } 
 1035:     return $currentstring;
 1036: }
 1037: 
 1038: #-- <p> tag
 1039: sub start_p {
 1040:     my ($target,$token) = @_;
 1041:     my $currentstring = '';
 1042:     if ($target eq 'web') {
 1043: 	$currentstring .= $token->[4];
 1044:     } elsif ($target eq 'tex') {
 1045: 	$currentstring .= '\par ';
 1046:     }
 1047:     return $currentstring;
 1048: }
 1049: 
 1050: sub end_p {
 1051:     my ($target,$token) = @_;
 1052:     my $currentstring = '';
 1053:     if ($target eq 'web') {
 1054: 	$currentstring .= $token->[2];
 1055:     }
 1056:     return $currentstring;
 1057: }
 1058: 
 1059: #-- <br> tag
 1060: sub start_br {
 1061:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1062:     my $currentstring = '';
 1063:     if ($target eq 'web') {
 1064: 	$currentstring .= $token->[4];
 1065:     } elsif ($target eq 'tex') {
 1066: 	if ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') {
 1067: 	    $currentstring .= '\vskip 0.2 mm';
 1068: 	}
 1069:     }
 1070:     return $currentstring;
 1071: }
 1072: 
 1073: sub end_br {
 1074:     my ($target,$token) = @_;
 1075:     my $currentstring = '';
 1076:     if ($target eq 'web') {
 1077: 	$currentstring .= $token->[2];
 1078:     }
 1079:     return $currentstring;
 1080: }
 1081: 
 1082: #-- <big> tag
 1083: sub start_big {
 1084:     my ($target,$token) = @_;
 1085:     my $currentstring = '';
 1086:     if ($target eq 'web') {
 1087: 	$currentstring .= $token->[4];
 1088:     } elsif ($target eq 'tex') {
 1089: 	$currentstring .= '{\large ';
 1090:     } 
 1091:     return $currentstring;
 1092: }
 1093: 
 1094: sub end_big {
 1095:     my ($target,$token) = @_;
 1096:     my $currentstring = '';
 1097:     if ($target eq 'web') {
 1098: 	$currentstring .= $token->[2];
 1099:     } elsif ($target eq 'tex') {
 1100: 	$currentstring .= '}';
 1101:     }
 1102:     return $currentstring;
 1103: }
 1104: 
 1105: #-- <small> tag
 1106: sub start_small {
 1107:     my ($target,$token) = @_;
 1108:     my $currentstring = '';
 1109:     if ($target eq 'web') {
 1110: 	$currentstring .= $token->[4];
 1111:     } elsif ($target eq 'tex') {
 1112: 	$currentstring .= '{\footnotesize ';
 1113:     }
 1114:     return $currentstring;
 1115: }
 1116: 
 1117: sub end_small {
 1118:     my ($target,$token) = @_;
 1119:     my $currentstring = '';
 1120:     if ($target eq 'web') {
 1121: 	$currentstring .= $token->[2];
 1122:     } elsif ($target eq 'tex') {
 1123: 	$currentstring .= '}';
 1124:     }
 1125:     return $currentstring;
 1126: }
 1127: 
 1128: #-- <basefont> tag
 1129: sub start_basefont {
 1130:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1131:     my $currentstring = '';
 1132:     if ($target eq 'web') {
 1133: 	$currentstring = $token->[4];     
 1134:     } elsif ($target eq 'tex') {
 1135: 	my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
 1136: 	if (defined $basesize) {
 1137: 	    $currentstring = '{\\'.$basesize.' ';
 1138: 	}
 1139:     }
 1140:     return $currentstring;
 1141: }
 1142: 
 1143: sub end_basefont {
 1144:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1145:     my $currentstring = '';
 1146:     if ($target eq 'web') {
 1147: 	$currentstring = $token->[4];     
 1148:     } elsif ($target eq 'tex') {
 1149: 	my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
 1150: 	if (defined $basesize) {
 1151: 	    $currentstring = '}';
 1152: 	}
 1153:     }
 1154:     return $currentstring;
 1155: }
 1156: 
 1157: #-- <font> tag
 1158: sub start_font {
 1159:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1160:     my $currentstring = '';
 1161:     if ($target eq 'web') {
 1162: 	my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
 1163: 	if ($face=~/symbol/i) {$Apache::lonxml::prevent_entity_encode++;}
 1164: 	$currentstring = $token->[4];     
 1165:     }  elsif ($target eq 'tex') {
 1166: 	my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
 1167: 	if (defined $fontsize) {
 1168: 	    $currentstring = '{\\'.$fontsize.' ';
 1169: 	}
 1170:     }
 1171:     return $currentstring;
 1172: }
 1173: 
 1174: sub end_font {
 1175:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1176:     my $currentstring = '';
 1177:     if ($target eq 'web') {
 1178: 	my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
 1179: 	if ($face=~/symbol/i) {$Apache::lonxml::prevent_entity_encode--;}
 1180: 	$currentstring = $token->[2];    
 1181:     }  elsif ($target eq 'tex') {
 1182: 	my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
 1183: 	if (defined $fontsize) {
 1184: 	    $currentstring = '}';
 1185: 	}
 1186:     }
 1187:     return $currentstring;
 1188: }
 1189:  
 1190: #-- <strike> tag
 1191: sub start_strike {
 1192:     my ($target,$token) = @_;
 1193:     my $currentstring = '';
 1194:     if ($target eq 'web') {
 1195: 	$currentstring .= $token->[4];
 1196:     } elsif ($target eq 'tex') {
 1197: 	&Apache::lonxml::startredirection();
 1198:     } 
 1199:     return $currentstring;
 1200: }
 1201: 
 1202: sub end_strike {
 1203:     my ($target,$token) = @_;
 1204:     my $currentstring = '';
 1205:     if ($target eq 'web') {
 1206: 	$currentstring .= $token->[2];
 1207:     } elsif ($target eq 'tex') {
 1208: 	$currentstring=&Apache::lonxml::endredirection();
 1209: 	$currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g; 
 1210: 	$currentstring=~s/^\s*(\S)/\\underline\{$1/; 
 1211: 	$currentstring=~s/(\S)\s*$/$1\}/;
 1212:     }
 1213:     return $currentstring;
 1214: }
 1215: 
 1216: #-- <s> tag
 1217: sub start_s {
 1218:     my ($target,$token) = @_;
 1219:     my $currentstring = '';
 1220:     if ($target eq 'web') {
 1221: 	$currentstring .= $token->[4];
 1222:     } elsif ($target eq 'tex') {
 1223: 	&Apache::lonxml::startredirection();
 1224:     } 
 1225:     return $currentstring;
 1226: }
 1227: 
 1228: sub end_s {
 1229:     my ($target,$token) = @_;
 1230:     my $currentstring = '';
 1231:     if ($target eq 'web') {
 1232: 	$currentstring .= $token->[2];
 1233:     } elsif ($target eq 'tex') {
 1234: 	$currentstring=&Apache::lonxml::endredirection();
 1235: 	$currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
 1236: 	$currentstring=~s/^\s*(\S)/\\underline\{$1/;
 1237: 	$currentstring=~s/(\S)\s*$/$1\}/;	
 1238:     }
 1239:     return $currentstring;
 1240: }
 1241: 
 1242: #-- <sub> tag
 1243: sub start_sub {
 1244:     my ($target,$token) = @_;
 1245:     my $currentstring = '';
 1246:     if ($target eq 'web') {
 1247: 	$currentstring .= $token->[4];
 1248:     } elsif ($target eq 'tex') {
 1249: 	$currentstring .= "\$_{ ";
 1250:     } 
 1251:     return $currentstring;
 1252: }
 1253: 
 1254: sub end_sub {
 1255:     my ($target,$token) = @_;
 1256:     my $currentstring = '';
 1257:     if ($target eq 'web') {
 1258: 	$currentstring .= $token->[2];
 1259:     } elsif ($target eq 'tex') {
 1260: 	$currentstring .= " }\$";
 1261:     }
 1262:     return $currentstring;
 1263: }
 1264: 
 1265: #-- <sup> tag
 1266: sub start_sup {
 1267:     my ($target,$token) = @_;
 1268:     my $currentstring = '';
 1269:     if ($target eq 'web') {
 1270: 	$currentstring .= $token->[4];
 1271:     } elsif ($target eq 'tex') {
 1272: 	$currentstring .= "\$^{ ";
 1273:     } 
 1274:     return $currentstring;
 1275: }
 1276: 
 1277: sub end_sup {
 1278:     my ($target,$token) = @_;
 1279:     my $currentstring = '';
 1280:     if ($target eq 'web') {
 1281: 	$currentstring .= $token->[2];
 1282:     } elsif ($target eq 'tex') {
 1283: 	$currentstring .= " }\$";
 1284:     }
 1285:     return $currentstring;
 1286: }
 1287: 
 1288: #-- <hr> tag
 1289: sub start_hr {
 1290:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1291:     my $currentstring = '';
 1292:     if ($target eq 'web') {
 1293: 	$currentstring .= $token->[4];
 1294:     } elsif ($target eq 'tex') {
 1295: 	my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,0);
 1296: 	if (defined $LaTeXwidth) {
 1297: 	    if ($LaTeXwidth=~/^%/) {
 1298: 		substr($LaTeXwidth,0,1)='';
 1299: 		$LaTeXwidth=($LaTeXwidth/100).'\textwidth';
 1300: 	    }
 1301: 	} else {
 1302: 	    $LaTeXwidth ='0.95\textwidth';
 1303: 	}
 1304: 	my ($pre,$post);
 1305: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
 1306: 	if (($align eq 'center') || (not defined $align)) {
 1307: 	    $pre=''; $post='';
 1308: 	} elsif ($align eq 'left') {
 1309: 	    $pre='\rlap{'; $post='} \hfill';
 1310: 	} elsif ($align eq 'right') {
 1311: 	    $pre=' \hfill \llap{'; $post='}';
 1312: 	}
 1313: 	$currentstring .= ' \vskip 0 mm \noindent\makebox[\textwidth]{'.$pre.'\makebox['.
 1314:                                     $LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm ';
 1315:     } 
 1316:     return $currentstring;
 1317: }
 1318: 
 1319: sub end_hr {
 1320:     my ($target,$token) = @_;
 1321:     my $currentstring = '';
 1322:     if ($target eq 'web') {
 1323: 	$currentstring .= $token->[2];
 1324:     } elsif ($target eq 'tex') {
 1325:     } 
 1326:     return $currentstring;
 1327: }
 1328: 
 1329: #-- <div> tag
 1330: sub start_div {
 1331:     my ($target,$token) = @_;
 1332:     my $currentstring = '';
 1333:     if ($target eq 'web') {
 1334: 	$currentstring .= $token->[4];
 1335:     } 
 1336:     return $currentstring;
 1337: }
 1338: 
 1339: sub end_div {
 1340:     my ($target,$token) = @_;
 1341:     my $currentstring = '';
 1342:     if ($target eq 'web') {
 1343: 	$currentstring .= $token->[2];
 1344:     } 
 1345:     return $currentstring;
 1346: }
 1347: 
 1348: #-- <a> tag
 1349: sub start_a {
 1350:     my ($target,$token) = @_;
 1351:     my $currentstring = '';
 1352:     if ($target eq 'web') {
 1353: 	$currentstring .= $token->[4];
 1354:     } elsif ($target eq 'tex') {
 1355:     }
 1356:     return $currentstring;
 1357: }
 1358: 
 1359: sub end_a {
 1360:     my ($target,$token,$tagstack,$stackref) = @_;
 1361:     my $currentstring = '';
 1362:     if ($target eq 'web') {
 1363: 	$currentstring .= $token->[2];
 1364:     } elsif ($target eq 'tex') {
 1365: 	my  $tempor_var = $stackref->[$#$stackref];
 1366: 	if (index($tempor_var,'name') != -1 ) {
 1367: 	    $tempor_var =~ s/name=([^,]*),/$1/g;
 1368: 	} elsif (index($tempor_var,'href') != -1 ) {
 1369: 	    $tempor_var =~ s/href=([^,]*),/$1/g;
 1370: 	    $currentstring .= " \\ref{$tempor_var}";
 1371: 	}
 1372:     }
 1373:     return $currentstring;
 1374: }
 1375: 
 1376: #-- <li> tag
 1377: sub start_li {
 1378:     my ($target,$token,$tagstack,$stackref) = @_;
 1379:     my $currentstring = '';
 1380:     if ($target eq 'web') {
 1381: 	$currentstring = $token->[4];     
 1382:     } elsif ($target eq 'tex') {
 1383: 	my  $tempor_var = $stackref->[$#$stackref];
 1384: 	if (index($tempor_var,'circle') != -1 ) {
 1385: 	    $currentstring .= " \\item[o] ";
 1386: 	} elsif (index($tempor_var,'square') != -1 ) {
 1387: 	    $currentstring .= " \\item[$\Box$] ";
 1388: 	} elsif ($tempor_var ne '') { 
 1389: 	    $_ = $tempor_var;
 1390: 	    m/my\s*([^=]*)=/;
 1391: 	    $currentstring .= " \\item[$1] ";
 1392: 	} else {
 1393: 	    $currentstring .= " \\item ";
 1394: 	}  
 1395:     } 
 1396:     return $currentstring;
 1397: }
 1398: 
 1399: sub end_li {
 1400:     my ($target,$token) = @_;
 1401:     my $currentstring = '';
 1402:     if ($target eq 'web') {
 1403: 	$currentstring = $token->[2];     
 1404:     } 
 1405:     return $currentstring;
 1406: }
 1407: 
 1408: #-- <u> tag
 1409: sub start_u {
 1410:     my ($target,$token) = @_;
 1411:     my $currentstring = '';
 1412:     if ($target eq 'web') {
 1413: 	$currentstring .= $token->[4];
 1414:     } elsif ($target eq 'tex') {
 1415: 	&Apache::lonxml::startredirection();
 1416:     } 
 1417:     return $currentstring;
 1418: }
 1419: 
 1420: sub end_u {
 1421:     my ($target,$token) = @_;
 1422:     my $currentstring = '';
 1423:     if ($target eq 'web') {
 1424: 	$currentstring .= $token->[2];
 1425:     } elsif ($target eq 'tex') {
 1426: 	$currentstring=&Apache::lonxml::endredirection();
 1427: 	$currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
 1428: 	$currentstring=~s/^\s*(\S)/\\underline\{$1/;
 1429: 	$currentstring=~s/(\S)\s*$/$1\}/;		
 1430:     }
 1431:     return $currentstring;
 1432: }
 1433: 
 1434: #-- <ul> tag
 1435: sub start_ul {
 1436:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1437:     my $currentstring = '';
 1438:     if ($target eq 'web') {
 1439: 	$currentstring = $token->[4];     
 1440:     } elsif ($target eq 'tex') {
 1441: 	my $TeXtype=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
 1442: 	if ($TeXtype eq 'disc') {
 1443: 	    $currentstring .= ' \renewcommand{\labelitemi}{$\bullet$}
 1444:                                 \renewcommand{\labelitemii}{$\bullet$} 
 1445:                                 \renewcommand{\labelitemiii}{$\bullet$}
 1446:                                 \renewcommand{\labelitemiv}{$\bullet$}';
 1447: 	} elsif ($TeXtype eq 'circle') {
 1448: 	    $currentstring .= ' \renewcommand{\labelitemi}{$\circ$}
 1449:                                 \renewcommand{\labelitemii}{$\circ$} 
 1450:                                 \renewcommand{\labelitemiii}{$\circ$}
 1451:                                 \renewcommand{\labelitemiv}{$\circ$}';
 1452: 	} elsif ($TeXtype eq 'square') {
 1453: 	    $currentstring .= ' \renewcommand{\labelitemi}{$\diamond$}
 1454:                                 \renewcommand{\labelitemii}{$\diamond$} 
 1455:                                 \renewcommand{\labelitemiii}{$\diamond$}
 1456:                                 \renewcommand{\labelitemiv}{$\diamond$}';
 1457: 	}
 1458: 	$currentstring .= '\begin{itemize}';  
 1459:     } 
 1460:     return $currentstring;
 1461: }
 1462: 
 1463: sub end_ul {
 1464:     my ($target,$token) = @_;
 1465:     my $currentstring = '';
 1466:     if ($target eq 'web') {
 1467: 	$currentstring = $token->[2];     
 1468:     } elsif ($target eq 'tex') {
 1469: 	$currentstring = '\end{itemize} \renewcommand{\labelitemi}{$\bullet$}
 1470:                                 \renewcommand{\labelitemii}{$\bullet$} 
 1471:                                 \renewcommand{\labelitemiii}{$\bullet$}
 1472:                                 \renewcommand{\labelitemiv}{$\bullet$}';  
 1473:     } 
 1474:     return $currentstring;
 1475: }
 1476: 
 1477: #-- <menu> tag
 1478: sub start_menu {
 1479:     my ($target,$token) = @_;
 1480:     my $currentstring = '';
 1481:     if ($target eq 'web') {
 1482: 	$currentstring = $token->[4];     
 1483:     } elsif ($target eq 'tex') {
 1484: 	$currentstring = " \\begin{itemize} ";  
 1485:     } 
 1486:     return $currentstring;
 1487: }
 1488: 
 1489: sub end_menu {
 1490:     my ($target,$token) = @_;
 1491:     my $currentstring = '';
 1492:     if ($target eq 'web') {
 1493: 	$currentstring = $token->[2];     
 1494:     } elsif ($target eq 'tex') {
 1495: 	$currentstring = " \\end{itemize}";  
 1496:     } 
 1497:     return $currentstring;
 1498: }
 1499: 
 1500: #-- <dir> tag
 1501: sub start_dir {
 1502:     my ($target,$token) = @_;
 1503:     my $currentstring = '';
 1504:     if ($target eq 'web') {
 1505: 	$currentstring = $token->[4];     
 1506:     } elsif ($target eq 'tex') {
 1507: 	$currentstring = " \\begin{itemize} ";  
 1508:     } 
 1509:     return $currentstring;
 1510: }
 1511: 
 1512: sub end_dir {
 1513:     my ($target,$token) = @_;
 1514:     my $currentstring = '';
 1515:     if ($target eq 'web') {
 1516: 	$currentstring = $token->[2];     
 1517:     } elsif ($target eq 'tex') {
 1518: 	$currentstring = " \\end{itemize}";  
 1519:     } 
 1520:     return $currentstring;
 1521: }
 1522: 
 1523: #-- <ol> tag
 1524: sub start_ol {
 1525:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1526:     my $currentstring = '';
 1527:     if ($target eq 'web') {
 1528: 	$currentstring = $token->[4];     
 1529:     } elsif ($target eq 'tex') {
 1530: 	my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
 1531: 	if ($type eq '1') {
 1532: 	    $currentstring .= ' \renewcommand{\labelenumi}{\arabic{enumi}.}
 1533:                                 \renewcommand{\labelenumii}{\arabic{enumii}.} 
 1534:                                 \renewcommand{\labelenumiii}{\arabic{enumiii}.}
 1535:                                 \renewcommand{\labelenumiv}{\arabic{enumiv}.}';
 1536: 	} elsif ($type eq 'A') {
 1537: 	    $currentstring .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}
 1538:                                 \renewcommand{\labelenumii}{\Alph{enumii}.} 
 1539:                                 \renewcommand{\labelenumiii}{\Alph{enumiii}.}
 1540:                                 \renewcommand{\labelenumiv}{\Alph{enumiv}.}';
 1541: 	} elsif ($type eq 'a') {
 1542: 	    $currentstring .= ' \renewcommand{\labelenumi}{\alph{enumi}.}
 1543:                                 \renewcommand{\labelenumii}{\alph{enumii}.}
 1544:                                 \renewcommand{\labelenumiii}{\alph{enumiii}.}
 1545:                                 \renewcommand{\labelenumiv}{\alph{enumiv}.} ';
 1546: 	} elsif ($type eq 'i') {
 1547: 	    $currentstring .= ' \renewcommand{\labelenumi}{\roman{enumi}.}
 1548:                                 \renewcommand{\labelenumii}{\roman{enumii}.}
 1549:                                 \renewcommand{\labelenumiii}{\roman{enumiii}.}
 1550:                                 \renewcommand{\labelenumiv}{\roman{enumiv}.} ';
 1551: 	} elsif ($type eq 'I') {
 1552: 	    $currentstring .= ' \renewcommand{\labelenumi}{\Roman{enumi}.}
 1553:                                 \renewcommand{\labelenumii}{\Roman{enumii}.}
 1554:                                 \renewcommand{\labelenumiii}{\Roman{enumiii}.}
 1555:                                 \renewcommand{\labelenumiv}{\Roman{enumiv}.} ';
 1556: 	}
 1557: 	$currentstring .= '\begin{enumerate}';  
 1558:     } 
 1559:     return $currentstring;
 1560: }
 1561: 
 1562: sub end_ol {
 1563:     my ($target,$token) = @_;
 1564:     my $currentstring = '';
 1565:     if ($target eq 'web') {
 1566: 	$currentstring = $token->[2];     
 1567:     } elsif ($target eq 'tex') {
 1568: 	$currentstring = '\end{enumerate} \renewcommand{\labelenumi}{\arabic{enumi}.}
 1569:                                           \renewcommand{\labelenumii}{\arabic{enumii}.}
 1570:                                           \renewcommand{\labelenumiii}{\arabic{enumiii}.}
 1571:                                           \renewcommand{\labelenumiv}{\arabic{enumiv}.}';  
 1572:     } 
 1573:     return $currentstring;
 1574: }
 1575: 
 1576: #-- <dl> tag
 1577: sub start_dl {
 1578:     my ($target,$token) = @_;
 1579:     my $currentstring = '';
 1580:     if ($target eq 'web') {
 1581: 	$currentstring = $token->[4];     
 1582:     } elsif ($target eq 'tex') {
 1583: 	$currentstring = '\begin{description}';  
 1584:     } 
 1585:     return $currentstring;
 1586: }
 1587: 
 1588: sub end_dl {
 1589:     my ($target,$token) = @_;
 1590:     my $currentstring = '';
 1591:     if ($target eq 'web') {
 1592: 	$currentstring = $token->[2];     
 1593:     } elsif ($target eq 'tex') {
 1594: 	$currentstring = '\end{description}';  
 1595:     } 
 1596:     return $currentstring;
 1597: }
 1598: 
 1599: #-- <dt> tag
 1600: sub start_dt {
 1601:     my ($target,$token) = @_;
 1602:     my $currentstring = '';
 1603:     if ($target eq 'web') {
 1604: 	$currentstring = $token->[4];     
 1605:     } elsif ($target eq 'tex') {
 1606: 	$currentstring = '\item[';  
 1607:     } 
 1608:     return $currentstring;
 1609: }
 1610: 
 1611: sub end_dt {
 1612:     my ($target,$token) = @_;
 1613:     my $currentstring = '';
 1614:     if ($target eq 'web') {
 1615: 	$currentstring = $token->[2];    
 1616:     } elsif ($target eq 'tex') {
 1617: 	$currentstring = ']';  
 1618:     } 
 1619:     return $currentstring;
 1620: }
 1621: 
 1622: #-- <dd> tag
 1623: sub start_dd {
 1624:     my ($target,$token) = @_;
 1625:     my $currentstring = '';
 1626:     if ($target eq 'web') {
 1627: 	$currentstring = $token->[4];     
 1628:     } 
 1629:     return $currentstring;
 1630: }
 1631: 
 1632: sub end_dd {
 1633:     my ($target,$token) = @_;
 1634:     my $currentstring = '';
 1635:     if ($target eq 'web') {
 1636: 	$currentstring = $token->[2];    
 1637:     } 
 1638:     return $currentstring;
 1639: }
 1640: 
 1641: #-- <table> tag
 1642: sub start_table {
 1643:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1644:     my $textwidth='';
 1645:     if (not defined @Apache::londefdef::table) {
 1646: 	$textwidth=&recalc($ENV{'form.textwidth'});
 1647: 	$textwidth=~/(\d+\.?\d*)/;
 1648: 	$textwidth=0.95*$1;
 1649:     } else {
 1650: 	$textwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
 1651:     }
 1652:     my $currentstring = '';
 1653:     if ($target eq 'web') {
 1654: 	$currentstring = $token->[4];     
 1655:     } elsif ($target eq 'tex') {
 1656: 	my $aa = {};
 1657: 	push @Apache::londefdef::table, $aa; 
 1658: 	$Apache::londefdef::table[-1]{'row_number'} = -1;
 1659:         #table's width
 1660: 	my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
 1661: 	if (not defined $TeXwidth) {
 1662: 	    my $htmlwidth = &Apache::lonxml::get_param('width',$parstack,$safeeval,undef,1);
 1663: 	    if ($htmlwidth=~/%/) {
 1664: 		$htmlwidth=~/(\d+)/;
 1665: 		my $value=$1*$textwidth/100;
 1666: 		$Apache::londefdef::table[-1]{'width'}=$value;
 1667: 	    } else {
 1668: 		$Apache::londefdef::table[-1]{'width'}=$textwidth;
 1669: 	    }
 1670: 	} elsif ($TeXwidth=~/%/) {
 1671: 	    $TeXwidth=~/(\d+)/;
 1672: 	    my $value=$1*$textwidth/100;
 1673:             $Apache::londefdef::table[-1]{'width'}=$value;
 1674: 	} else {
 1675: 	    $Apache::londefdef::table[-1]{'width'}=$textwidth;
 1676: 	}        
 1677:         #table's border
 1678: 	my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval,undef,1); 
 1679: 	unless (defined $border) { $border = 0; }
 1680: 	if ($border) { 
 1681: 	    $Apache::londefdef::table[-1]{'hinc'} = '\hline '; 
 1682: 	    $Apache::londefdef::table[-1]{'vinc'} = '&'; 
 1683: 	    $Apache::londefdef::table[-1]{'vvinc'} = '|';
 1684: 	} else {
 1685: 	    $Apache::londefdef::table[-1]{'hinc'} = ''; 
 1686: 	    $Apache::londefdef::table[-1]{'vinc'} = '&'; 
 1687: 	    $Apache::londefdef::table[-1]{'vvinc'} = '';
 1688: 	}
 1689: 	$Apache::londefdef::table[-1]{'output'} = ' \noindent \begin{tabular} ';
 1690: 	$currentstring = '\keephidden{NEW TABLE ENTRY}';
 1691:     }
 1692:     return $currentstring;
 1693: }
 1694:  
 1695: sub end_table {
 1696:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1697:     my $currentstring = '';
 1698:     if ($target eq 'web') {
 1699: 	$currentstring = $token->[2];     
 1700:     } elsif ($target eq 'tex') {
 1701: 	my $inmemory = '';
 1702: 	my $output = '';
 1703: 	#construct header of the table
 1704: 	my $header_of_table = '{'.$Apache::londefdef::table[-1]{'vvinc'};
 1705: 	for (my $in=0;$in<=$Apache::londefdef::table[-1]{'counter_columns'};$in++) {
 1706: 	    $header_of_table .= $Apache::londefdef::table[-1]{'columns'}[$in].$Apache::londefdef::table[-1]{'vvinc'};
 1707: 	}
 1708: 	$header_of_table .= '}';
 1709: 	#define the length of the table cells
 1710: 	#always starts with TeXwidth (if defined everything else is ignored)
 1711: 	my @length_row_final = split(/,/,$Apache::londefdef::table[-1]{'TeXlengthrow'}[0]);
 1712: 	for (my $in=1;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
 1713: 	    my @length_row = split(/,/,$Apache::londefdef::table[-1]{'TeXlengthrow'}[$in]);
 1714: 	    for (my $jn=0;$jn<=$#length_row;$jn++) {
 1715: 		if ($length_row_final[$jn]<$length_row[$jn]) {$length_row_final[$jn]=$length_row[$jn];}
 1716: 	    }
 1717: 	}
 1718: 	#continues trying estimate the width of raw data
 1719: 	my @length_raw_row = split(/,/,$Apache::londefdef::table[-1]{'lengthrow'}[0]);
 1720: 	for (my $in=1;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
 1721: 	    my @length_row = split(/,/,$Apache::londefdef::table[-1]{'lengthrow'}[$in]);
 1722: 	    for (my $jn=0;$jn<=$#length_row;$jn++) {
 1723: 		if ($length_raw_row[$jn]<$length_row[$jn]) {$length_raw_row[$jn]=$length_row[$jn];}
 1724: 	    }
 1725: 	}
 1726:         #comparing of TeXwidth and raw data width
 1727: 	my $available_length=$Apache::londefdef::table[-1]{'width'};
 1728: 	my $needed=0;
 1729: 	for (my $jn=0;$jn<=$#length_row_final;$jn++) {
 1730: 	    if ($length_row_final[$jn]!=0) {
 1731: 		$available_length=$available_length-$length_row_final[$jn];
 1732: 		$needed++;
 1733: 	    }
 1734: 	}
 1735: 	$needed=$#length_row_final-$needed+1;
 1736: 	for (my $jn=0;$jn<=$#length_row_final;$jn++) {
 1737: 	    if ($length_row_final[$jn]==0) {
 1738: 		if ($length_raw_row[$jn]<$available_length/3) {
 1739: 		    $length_row_final[$jn]=$length_raw_row[$jn];
 1740: 		    $available_length=$available_length-$length_raw_row[$jn];
 1741: 		    $needed--;
 1742: 		}
 1743: 	    }
 1744: 	}
 1745: 	for (my $jn=0;$jn<=$#length_row_final;$jn++) {
 1746: 	    if ($length_row_final[$jn]==0) {
 1747: 		$length_row_final[$jn]=0.9*$available_length/$needed;
 1748: 	    }
 1749: 	}
 1750: 	#fill the table
 1751: 	for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
 1752: 	    for (my $jn=0;$jn<=$#length_row_final;$jn++) {
 1753: 		my $substituted=$length_row_final[$jn];
 1754: 		$Apache::londefdef::table[-1]{'rowdata'}[$in]=~s/TOBECHANGEDONNUMBER/$substituted mm/;
 1755: 	    }
 1756: 	    $output .=  $Apache::londefdef::table[-1]{'rowdata'}[$in];
 1757: 	    chop $output;
 1758: 	    $output .= ' \\\\ ';
 1759: 	}
 1760: 	$Apache::londefdef::table[-1]{'output'} .= $header_of_table.$output.$Apache::londefdef::table[-1]{'hinc'}.'\end{tabular}\vskip 0 mm ';
 1761: 	if ($#Apache::londefdef::table > 0) {	    
 1762: 	    my $inmemory = $Apache::londefdef::table[-1]{'output'};
 1763: 	    pop @Apache::londefdef::table;
 1764: 	    push @{$Apache::londefdef::table[-1]{'include'}}, $inmemory;
 1765: 	} else {
 1766: 	    $currentstring .= $Apache::londefdef::table[-1]{'output'};
 1767: 	    pop @Apache::londefdef::table;
 1768: 	    undef @Apache::londefdef::table;
 1769: 	}
 1770:     }
 1771:     return $currentstring;
 1772: }
 1773: 
 1774: #-- <tr> tag
 1775: sub start_tr {
 1776:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1777:     my $currentstring = '';
 1778:     if ($target eq 'web') {
 1779: 	$currentstring = $token->[4];     
 1780:     } elsif ($target eq 'tex') {
 1781: 	$Apache::londefdef::table[-1]{'row_number'}++;
 1782: 	my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
 1783: 	if ($alignchar ne '') {
 1784: 	    push @ {$Apache::londefdef::table[-1]{'rows'} }, $alignchar;
 1785: 	} else {
 1786: 	    push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l';
 1787: 	}
 1788: 	push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'});
 1789: 	$Apache::londefdef::table[-1]{'counter_columns'} = -1;
 1790: 	$Apache::londefdef::table[-1]{'TeXlength'} = '';
 1791:  	$Apache::londefdef::table[-1]{'length'} = '';
 1792:     } 
 1793:     return $currentstring;
 1794: }
 1795:         
 1796: sub end_tr {
 1797:     my ($target,$token) = @_;
 1798:     my $currentstring = '';
 1799:     if ($target eq 'web') {
 1800: 	$currentstring = $token->[2];     
 1801:     } elsif ($target eq 'tex') {
 1802: 	push @{ $Apache::londefdef::table[-1]{'TeXlengthrow'} },$Apache::londefdef::table[-1]{'TeXlength'};
 1803: 	push @{ $Apache::londefdef::table[-1]{'lengthrow'} },$Apache::londefdef::table[-1]{'length'};
 1804:     }
 1805:     return $currentstring;
 1806: }
 1807: 
 1808: #-- <td> tag
 1809: sub start_td {
 1810:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1811:     my $currentstring = '';
 1812:     if ($target eq 'web') {
 1813: 	$currentstring = $token->[4];     
 1814:     } elsif ($target eq 'tex') {
 1815: 	my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
 1816: 	if ($what_to_push eq '') {
 1817: 	    $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);;
 1818: 	}
 1819: 	push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push;
 1820: 	$Apache::londefdef::table[-1]{'counter_columns'}++;
 1821: 	&Apache::lonxml::startredirection();
 1822:     } 
 1823:     return $currentstring;
 1824: }   
 1825:      
 1826: sub end_td {
 1827:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1828:     my $currentstring = '';
 1829:     if ($target eq 'web') {
 1830: 	$currentstring = $token->[2];     
 1831:     } elsif ($target eq 'tex') {
 1832: 	my $current_row = $Apache::londefdef::table[-1]{'row_number'};
 1833: 	my $data=&Apache::lonxml::endredirection();
 1834: 	my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
 1835: 	if (defined $TeXwidth) {		
 1836: 	    my $current_length=&recalc($TeXwidth);
 1837: 	    $current_length=~/(\d+)/;
 1838: 	    $Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
 1839: 	    $Apache::londefdef::table[-1]{'length'} .= '0,';
 1840: 	} else {
 1841: 	    if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
 1842: 		my $current_length=&recalc($1);
 1843: 		$current_length=~/(\d+\.?\d*)/;
 1844: 		$Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
 1845: 		$Apache::londefdef::table[-1]{'length'} .= '0,';
 1846: 	    } else {     
 1847: 		$data=~/^\s*(\S.*)/;
 1848: 		$data=$1;
 1849: 		$data=~/(.*\S)\s*$/;
 1850: 		$data=$1;
 1851: 		my $current_length=2*length($data);
 1852: 		$Apache::londefdef::table[-1]{'length'} .= $current_length.',';
 1853: 		$Apache::londefdef::table[-1]{'TeXlength'} .= '0,';
 1854: 	    }        
 1855: 	}
 1856: 	for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {         
 1857: 	    $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
 1858: 	}
 1859: 	@{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'};
 1860:     }
 1861:     return $currentstring;
 1862: }
 1863: 
 1864: #-- <th> tag
 1865: sub start_th {
 1866:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1867:     my $currentstring = '';
 1868:     if ($target eq 'web') {
 1869: 	$currentstring = $token->[4];     
 1870:     } elsif ($target eq 'tex') {
 1871: 	my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
 1872: 	if ($what_to_push eq '') {
 1873: 	    $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);;
 1874: 	}
 1875: 	push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push;
 1876: 	$Apache::londefdef::table[-1]{'counter_columns'}++;
 1877: 	&Apache::lonxml::startredirection();
 1878:     } 
 1879:     return $currentstring;
 1880: }   
 1881:      
 1882: sub end_th {
 1883:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1884:     my $currentstring = '';
 1885:     if ($target eq 'web') {
 1886: 	$currentstring = $token->[2];     
 1887:     } elsif ($target eq 'tex') {
 1888: 	my $current_row = $Apache::londefdef::table[-1]{'row_number'};
 1889: 	my $data=&Apache::lonxml::endredirection();
 1890: 	my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
 1891: 	if (defined $TeXwidth) {		
 1892: 	    my $current_length=&recalc($TeXwidth);
 1893: 	    $current_length=~/(\d+)/;
 1894: 	    $Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
 1895: 	    $Apache::londefdef::table[-1]{'length'} .= '0,';
 1896: 	} else {
 1897: 	    if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
 1898: 		my $current_length=&recalc($1);
 1899: 		$current_length=~/(\d+)/;
 1900: 		$Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
 1901: 		$Apache::londefdef::table[-1]{'length'} .= '0,';
 1902: 	    } else {     
 1903: 		$data=~/^\s*(\S.*)/;
 1904: 		$data=$1;
 1905: 		$data=~/(.*\S)\s*$/;
 1906: 		$data=$1;
 1907: 		my $current_length=2*length($data);
 1908: 		$Apache::londefdef::table[-1]{'length'} .= $current_length.',';
 1909: 		$Apache::londefdef::table[-1]{'TeXlength'} .= '0,';
 1910: 	    }        
 1911: 	}
 1912: 	for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {                                
 1913: 	    $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
 1914: 	}
 1915: 	$data='\textbf{'.$data.'}';
 1916: 	@{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'};
 1917:     }
 1918:     return $currentstring;
 1919: }
 1920: #-- <img> tag
 1921: sub start_img {
 1922:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1923:     my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,
 1924: 					 undef,1);
 1925:     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
 1926:     my $currentstring = '';
 1927:     my $width_param = '';
 1928:     my $height_param = '';
 1929:     my $scaling = .3;
 1930:     
 1931:     if ($target eq 'web') {
 1932: 	if ($ENV{'browser.imagesuppress'} ne 'on') {
 1933: 	    $currentstring = $token->[4];
 1934: 	} else {
 1935: 	    my $alttag= &Apache::lonxml::get_param
 1936: 		('alt',$parstack,$safeeval,undef,1);
 1937: 	    unless ($alttag) {
 1938: 		$alttag=&Apache::lonmeta::alttag
 1939: 		    ($Apache::lonxml::pwd[-1],$src);
 1940: 	    }
 1941: 	    $currentstring='[IMAGE: '.$alttag.']';
 1942: 	}
 1943:     } elsif ($target eq 'tex') {
 1944: 	$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
 1945: 	&image_replication($src);
 1946: 	
 1947: 	#if original gif/jpg/png file exist do following:
 1948: 	if (-e $src) {          
 1949: 	    #defines the default size of image
 1950: 	    my $image = Image::Magick->new;
 1951: 	    my $current_figure = $image->Read($src);
 1952: 	    $width_param = $image->Get('width') * $scaling;;
 1953: 	    $height_param = $image->Get('height') * $scaling;;
 1954: 	    undef $image;
 1955: 	    #do we have any specified size of the picture?
 1956: 	    my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval);
 1957: 	    my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval);
 1958: 	    my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval,
 1959: 						   undef,1);
 1960: 	    if ($TeXwidth ne '') {  
 1961: 		if ($TeXwidth=~/(\d+)\s*\%/) {
 1962: 		    $width_param = $1*$ENV{'form.textwidth'}/100;
 1963: 		} else { 
 1964: 		    $width_param = $TeXwidth;
 1965: 		}
 1966: 	    } elsif ($TeXheight ne '') {
 1967: 		$width_param = $TeXheight/$height_param*$width_param;
 1968: 	    } elsif ($width ne '') {
 1969: 		$width_param = $width*$scaling;      
 1970: 	    }
 1971: 	    my $file;
 1972: 	    my $path;	
 1973: 	    if ($src =~ m!(.*)/([^/]*)$!) {
 1974: 		$file = $2; 
 1975: 		$path = $1.'/'; 
 1976: 	    } 
 1977: 	    my $newsrc = $src;
 1978: 	    $newsrc =~ s/\.(gif|jpg|png)$/.eps/i;
 1979: 	    $file=~s/\.(gif|jpg|png)$/.eps/i;
 1980: 	    #where can we find the picture?
 1981: 	    if (-e $newsrc) {
 1982: 		#eps counterpart for image exist 
 1983: 		if ($path) {
 1984: 		    $currentstring .= '\vskip 1 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
 1985: 		}
 1986: 	    } else {
 1987: 		#there is no eps counterpart for image - check for ps one
 1988: 		$newsrc =~ s/\.eps$/\.ps/;
 1989: 		if (-e $newsrc) {
 1990: 		    #ps counterpart for image exist 
 1991: 		    $file =~ s/\.eps$/\.ps/;
 1992: 		    if ($path) {
 1993: 			$currentstring .= '\vskip 1 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
 1994: 		    }
 1995: 		} else {
 1996: 		    #there aren't eps or ps - so create eps 
 1997: 		    my $temp_file;
 1998: 		    my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat";
 1999: 		    $temp_file = Apache::File->new('>>'.$filename); 
 2000: 		    print $temp_file "$src\n";
 2001: 		    $currentstring .= '\vskip 1 mm \graphicspath{{/home/httpd/prtspool/}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
 2002: 		}
 2003: 	    }
 2004: 	} else {
 2005: 	    #original image file doesn't exist so check the alt attribute
 2006: 	    my $alt = 
 2007: 		&Apache::lonxml::get_param('alt',$parstack,$safeeval,undef,1);
 2008: 	    unless ($alt) {
 2009: 		$alt=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
 2010: 	    }
 2011: 
 2012: 	    if ($alt) {
 2013: 		$currentstring .= ' '.$alt.' ';
 2014: 	    } else {
 2015: 		#<allow> tag will care about replication 
 2016: 	    }
 2017: 	}
 2018:     }
 2019:     return $currentstring;
 2020: }
 2021: 
 2022: sub end_img {
 2023:     my ($target,$token) = @_;
 2024:     my $currentstring = '';
 2025:     if ($target eq 'web') {
 2026: 	$currentstring = $token->[2];
 2027:     } elsif ($target eq 'tex') {
 2028: 	$currentstring = '';
 2029:     }
 2030:     return $currentstring;
 2031: }
 2032: 
 2033: #-- <applet> tag
 2034: sub start_applet {
 2035:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2036:     
 2037:     my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,undef,1);
 2038:     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$code;
 2039:     
 2040:     my $archive=&Apache::lonxml::get_param('archive',$parstack,$safeeval,
 2041: 					   undef,1);
 2042:     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$archive;
 2043:     
 2044:     my $currentstring = '';
 2045:     if ($target eq 'web') {
 2046: 	if ($ENV{'browser.appletsuppress'} ne 'on') {
 2047: 	    $currentstring = $token->[4];
 2048: 	} else {
 2049: 	    my $alttag= &Apache::lonxml::get_param('alt',$parstack,
 2050: 						   $safeeval,undef,1);
 2051: 	    unless ($alttag) {
 2052: 		$alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
 2053: 						 $code);
 2054: 	    }
 2055: 	    $currentstring='[APPLET: '.$alttag.']';
 2056: 	}
 2057:     } elsif ($target eq 'tex') {
 2058: 	$currentstring = " \\begin{figure} ";
 2059:     } 
 2060:     return $currentstring;
 2061: }
 2062: 
 2063: sub end_applet {
 2064:     my ($target,$token) = @_;
 2065:     my $currentstring = '';
 2066:     if ($target eq 'web') {
 2067: 	$currentstring = $token->[2];
 2068:     } elsif ($target eq 'tex') {
 2069: 	$currentstring = " \\end{figure}";
 2070:     } 
 2071:     return $currentstring;
 2072: }
 2073: 
 2074: #-- <embed> tag
 2075: sub start_embed {    
 2076:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2077:     my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
 2078:     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
 2079:     my $currentstring = '';
 2080:     if ($target eq 'web') {
 2081: 	if ($ENV{'browser.embedsuppress'} ne 'on') {
 2082: 	    $currentstring = $token->[4];
 2083: 	} else {
 2084: 	    my $alttag=&Apache::lonxml::get_param
 2085: 		('alt',$parstack,$safeeval,undef,1);
 2086: 	    unless ($alttag) {
 2087: 		$alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
 2088: 	    }
 2089: 	    $currentstring='[EMBED: '.$alttag.']';
 2090: 	}
 2091:     } elsif ($target eq 'tex') {
 2092: 	$currentstring = " \\begin{figure} ";  
 2093:     } 
 2094:     return $currentstring;
 2095: }
 2096: 
 2097: sub end_embed {
 2098:     my ($target,$token) = @_;
 2099:     my $currentstring = '';
 2100:     if ($target eq 'web') {
 2101: 	$currentstring = $token->[2];     
 2102:     } elsif ($target eq 'tex') {
 2103: 	$currentstring = " \\end{figure}";  
 2104:     } 
 2105:     return $currentstring;
 2106: }
 2107: 
 2108: #-- <param> tag
 2109: sub start_param {
 2110:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2111:     if (&Apache::lonxml::get_param
 2112: 	('name',$parstack,$safeeval,undef,1)=~/^cabbase$/i) {
 2113: 	$Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
 2114: 	    &Apache::lonxml::get_param('value',$parstack,$safeeval,undef,1);
 2115:     }   
 2116:     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=   
 2117: 	&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
 2118:     my $currentstring = '';
 2119:     if ($target eq 'web') {
 2120: 	$currentstring = $token->[4];     
 2121:     } elsif ($target eq 'tex') {
 2122: 	$currentstring = " \\begin{figure} ";  
 2123:     } 
 2124:     return $currentstring;
 2125: }
 2126: 
 2127: sub end_param {
 2128:     my ($target,$token) = @_;
 2129:     my $currentstring = '';
 2130:     if ($target eq 'web') {
 2131: 	$currentstring = $token->[2];     
 2132:     } elsif ($target eq 'tex') {
 2133: 	$currentstring = " \\end{figure}";  
 2134:     } 
 2135:     return $currentstring;
 2136: }
 2137: 
 2138: #-- <allow> tag
 2139: sub start_allow {
 2140:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2141:     my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
 2142:     $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
 2143:     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
 2144: 	&Apache::lonnet::clutter($src);
 2145:     &image_replication($src);
 2146:     my $result;
 2147:     if ($target eq 'edit') {
 2148: 	$result .=&Apache::edit::tag_start($target,$token);
 2149: 	$result .=&Apache::edit::text_arg('File Spec:','src',$token,70);
 2150: 	$result .=&Apache::edit::end_row();#.&Apache::edit::start_spanning_row();
 2151:     } elsif ($target eq 'modified') {
 2152: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
 2153: 						     $safeeval,'src');
 2154: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
 2155:     }
 2156:     return $result;
 2157: }
 2158: 
 2159: sub end_allow {
 2160:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2161:     if ( $target eq 'edit') { return (&Apache::edit::end_table()); }
 2162:     return '';
 2163: }
 2164: 
 2165: #-- Frames
 2166: sub start_frameset {
 2167:     my ($target,$token) = @_;
 2168:     my $currentstring = '';
 2169:     if ($target eq 'web') { 
 2170: 	if (!$Apache::lonxml::registered) {
 2171: 	    $currentstring.='<head>'.
 2172: 		&Apache::lonmenu::registerurl(undef,$target).'</head>';
 2173: 	}
 2174: 	my $onLoad='';
 2175: 	foreach my $key (keys(%{$token->[2]})) {
 2176: 	    if ($key =~ /^onload$/i) {
 2177: 		$onLoad.=$token->[2]->{$key}.';';
 2178: 		delete($token->[2]->{$key});
 2179: 	    }
 2180: 	}
 2181: 	$token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad;
 2182: 	my $onUnload='';
 2183: 	foreach my $key (keys(%{$token->[2]})) {
 2184: 	    if ($key =~ /^onunload$/i) {
 2185: 		$onUnload.=$token->[2]->{$key}.';';
 2186: 		delete($token->[2]->{$key});
 2187: 	    }
 2188: 	}
 2189: 	$token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents().
 2190: 	    ';'.$onUnload;
 2191: 	
 2192: 	$currentstring .= '<'.$token->[1];
 2193: 	foreach (keys %{$token->[2]}) {
 2194: 	    $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
 2195: 	}
 2196: 	$currentstring.='>';
 2197:     }
 2198:     return $currentstring;
 2199: }
 2200: 
 2201: sub end_frameset {
 2202:     my ($target,$token) = @_;
 2203:     my $currentstring = '';
 2204:     if ($target eq 'web') {
 2205: 	$currentstring = $token->[2];
 2206:     }
 2207:     return $currentstring;
 2208: }
 2209: 
 2210: #-- <pre>
 2211: sub start_pre {
 2212:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2213:     my $currentstring = '';
 2214:     if ($target eq 'web') {
 2215: 	$currentstring .= $token->[4];
 2216:     } elsif ($target eq 'tex') {
 2217: 	$currentstring .= '\begin{verbatim}';
 2218:     } 
 2219:     return $currentstring;
 2220: }
 2221: 
 2222: sub end_pre {
 2223:     my ($target,$token) = @_;
 2224:     my $currentstring = '';
 2225:     if ($target eq 'web') {
 2226: 	$currentstring .= $token->[2];
 2227:     } elsif ($target eq 'tex') {
 2228: 	$currentstring .= '\end{verbatim}';
 2229:     }
 2230:     return $currentstring;
 2231: }
 2232: 
 2233: #-- <insert>
 2234: sub start_insert {
 2235:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2236:     my $currentstring = '';
 2237:     if ($target eq 'web') {
 2238: 	my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
 2239: 	$currentstring .= '<b>'.$display.'</b>';;
 2240:     }
 2241:     return $currentstring;
 2242: }
 2243: 
 2244: sub end_insert {
 2245:     my ($target,$token) = @_;
 2246:     my $currentstring = '';
 2247:     if ($target eq 'web') {
 2248: 	$currentstring .= '';
 2249:     }
 2250:     return $currentstring;
 2251: }
 2252: 
 2253: #-- <externallink>
 2254: sub start_externallink {
 2255:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2256:     my $currentstring = '';
 2257:     if ($target eq 'web') {
 2258: 	my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
 2259: 	$currentstring .= '<b>'.$display.'</b>';;
 2260:     }
 2261:     return $currentstring;
 2262: }
 2263: 
 2264: sub end_externallink {
 2265:     my ($target,$token) = @_;
 2266:     my $currentstring = '';
 2267:     if ($target eq 'web') {
 2268: 	$currentstring .= '';
 2269:     }
 2270:     return $currentstring;
 2271: }
 2272: 
 2273: #-- <blankspace heigth="">
 2274: sub start_blankspace {
 2275:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2276:     my $currentstring = '';
 2277:     if ($target eq 'tex') {
 2278: 	my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval,undef,1);
 2279: 	$currentstring .= '\vskip '.$howmuch.' ';
 2280:     }
 2281:     return $currentstring;
 2282: }
 2283: 
 2284: sub end_blankspace {
 2285:     my ($target,$token) = @_;
 2286:     my $currentstring = '';
 2287:     if ($target eq 'tex') {
 2288: 	$currentstring .= '';
 2289:     }
 2290:     return $currentstring;
 2291: }
 2292: 
 2293: #-- <abbr> tag
 2294: sub start_abbr {
 2295:     my ($target,$token) = @_;
 2296:     my $currentstring = '';
 2297:     if ($target eq 'web') {
 2298: 	$currentstring = $token->[4];     
 2299:     } 
 2300:     return $currentstring;
 2301: }
 2302: 
 2303: sub end_abbr {
 2304:     my ($target,$token) = @_;
 2305:     my $currentstring = '';
 2306:     if ($target eq 'web') {
 2307: 	$currentstring = $token->[2];    
 2308:     } 
 2309:     return $currentstring;
 2310: }
 2311: 
 2312: #-- <acronym> tag
 2313: sub start_acronym {
 2314:     my ($target,$token) = @_;
 2315:     my $currentstring = '';
 2316:     if ($target eq 'web') {
 2317: 	$currentstring = $token->[4];     
 2318:     } 
 2319:     return $currentstring;
 2320: }
 2321: 
 2322: sub end_acronym {
 2323:     my ($target,$token) = @_;
 2324:     my $currentstring = '';
 2325:     if ($target eq 'web') {
 2326: 	$currentstring = $token->[2];    
 2327:     } 
 2328:     return $currentstring;
 2329: }
 2330: 
 2331: #-- <area> tag
 2332: sub start_area {
 2333:     my ($target,$token) = @_;
 2334:     my $currentstring = '';
 2335:     if ($target eq 'web') {
 2336: 	$currentstring = $token->[4];     
 2337:     } 
 2338:     return $currentstring;
 2339: }
 2340: 
 2341: sub end_area {
 2342:     my ($target,$token) = @_;
 2343:     my $currentstring = '';
 2344:     if ($target eq 'web') {
 2345: 	$currentstring = $token->[2];    
 2346:     } 
 2347:     return $currentstring;
 2348: }
 2349: 
 2350: #-- <base> tag
 2351: sub start_base {
 2352:     my ($target,$token) = @_;
 2353:     my $currentstring = '';
 2354:     if ($target eq 'web') {
 2355: 	$currentstring = $token->[4];     
 2356:     } 
 2357:     return $currentstring;
 2358: }
 2359: 
 2360: sub end_base {
 2361:     my ($target,$token) = @_;
 2362:     my $currentstring = '';
 2363:     if ($target eq 'web') {
 2364: 	$currentstring = $token->[2];    
 2365:     } 
 2366:     return $currentstring;
 2367: }
 2368: 
 2369: #-- <bdo> tag
 2370: sub start_bdo {
 2371:     my ($target,$token) = @_;
 2372:     my $currentstring = '';
 2373:     if ($target eq 'web') {
 2374: 	$currentstring = $token->[4];     
 2375:     } 
 2376:     return $currentstring;
 2377: }
 2378: 
 2379: sub end_bdo {
 2380:     my ($target,$token) = @_;
 2381:     my $currentstring = '';
 2382:     if ($target eq 'web') {
 2383: 	$currentstring = $token->[2];    
 2384:     } 
 2385:     return $currentstring;
 2386: }
 2387: 
 2388: #-- <bgsound> tag
 2389: sub start_bgsound {
 2390:     my ($target,$token) = @_;
 2391:     my $currentstring = '';
 2392:     if ($target eq 'web') {
 2393: 	$currentstring = $token->[4];     
 2394:     } 
 2395:     return $currentstring;
 2396: }
 2397: 
 2398: sub end_bgsound {
 2399:     my ($target,$token) = @_;
 2400:     my $currentstring = '';
 2401:     if ($target eq 'web') {
 2402: 	$currentstring = $token->[2];    
 2403:     } 
 2404:     return $currentstring;
 2405: }
 2406: 
 2407: #-- <blink> tag
 2408: sub start_blink {
 2409:     my ($target,$token) = @_;
 2410:     my $currentstring = '';
 2411:     if ($target eq 'web') {
 2412: 	$currentstring = $token->[4];     
 2413:     } 
 2414:     return $currentstring;
 2415: }
 2416: 
 2417: sub end_blink {
 2418:     my ($target,$token) = @_;
 2419:     my $currentstring = '';
 2420:     if ($target eq 'web') {
 2421: 	$currentstring = $token->[2];    
 2422:     } 
 2423:     return $currentstring;
 2424: }
 2425: 
 2426: #-- <blockquote> tag
 2427: sub start_blockquote {
 2428:     my ($target,$token) = @_;
 2429:     my $currentstring = '';
 2430:     if ($target eq 'web') {
 2431: 	$currentstring = $token->[4];     
 2432:     } 
 2433:     return $currentstring;
 2434: }
 2435: 
 2436: sub end_blockquote {
 2437:     my ($target,$token) = @_;
 2438:     my $currentstring = '';
 2439:     if ($target eq 'web') {
 2440: 	$currentstring = $token->[2];    
 2441:     } 
 2442:     return $currentstring;
 2443: }
 2444: 
 2445: #-- <button> tag
 2446: sub start_button {
 2447:     my ($target,$token) = @_;
 2448:     my $currentstring = '';
 2449:     if ($target eq 'web') {
 2450: 	$currentstring = $token->[4];     
 2451:     } 
 2452:     return $currentstring;
 2453: }
 2454: 
 2455: sub end_button {
 2456:     my ($target,$token) = @_;
 2457:     my $currentstring = '';
 2458:     if ($target eq 'web') {
 2459: 	$currentstring = $token->[2];    
 2460:     } 
 2461:     return $currentstring;
 2462: }
 2463: 
 2464: #-- <caption> tag
 2465: sub start_caption {
 2466:     my ($target,$token) = @_;
 2467:     my $currentstring = '';
 2468:     if ($target eq 'web') {
 2469: 	$currentstring = $token->[4];     
 2470:     } 
 2471:     return $currentstring;
 2472: }
 2473: 
 2474: sub end_caption {
 2475:     my ($target,$token) = @_;
 2476:     my $currentstring = '';
 2477:     if ($target eq 'web') {
 2478: 	$currentstring = $token->[2];    
 2479:     } 
 2480:     return $currentstring;
 2481: }
 2482: 
 2483: #-- <col> tag
 2484: sub start_col {
 2485:     my ($target,$token) = @_;
 2486:     my $currentstring = '';
 2487:     if ($target eq 'web') {
 2488: 	$currentstring = $token->[4];     
 2489:     } 
 2490:     return $currentstring;
 2491: }
 2492: 
 2493: sub end_col {
 2494:     my ($target,$token) = @_;
 2495:     my $currentstring = '';
 2496:     if ($target eq 'web') {
 2497: 	$currentstring = $token->[2];    
 2498:     } 
 2499:     return $currentstring;
 2500: }
 2501: 
 2502: #-- <colgroup> tag
 2503: sub start_colgroup {
 2504:     my ($target,$token) = @_;
 2505:     my $currentstring = '';
 2506:     if ($target eq 'web') {
 2507: 	$currentstring = $token->[4];     
 2508:     } 
 2509:     return $currentstring;
 2510: }
 2511: 
 2512: sub end_colgroup {
 2513:     my ($target,$token) = @_;
 2514:     my $currentstring = '';
 2515:     if ($target eq 'web') {
 2516: 	$currentstring = $token->[2];    
 2517:     } 
 2518:     return $currentstring;
 2519: }
 2520: 
 2521: #-- <del> tag
 2522: sub start_del {
 2523:     my ($target,$token) = @_;
 2524:     my $currentstring = '';
 2525:     if ($target eq 'web') {
 2526: 	$currentstring = $token->[4];     
 2527:     } 
 2528:     return $currentstring;
 2529: }
 2530: 
 2531: sub end_del {
 2532:     my ($target,$token) = @_;
 2533:     my $currentstring = '';
 2534:     if ($target eq 'web') {
 2535: 	$currentstring = $token->[2];    
 2536:     } 
 2537:     return $currentstring;
 2538: }
 2539: 
 2540: #-- <fieldset> tag
 2541: sub start_fieldset {
 2542:     my ($target,$token) = @_;
 2543:     my $currentstring = '';
 2544:     if ($target eq 'web') {
 2545: 	$currentstring = $token->[4];     
 2546:     } 
 2547:     return $currentstring;
 2548: }
 2549: 
 2550: sub end_fieldset {
 2551:     my ($target,$token) = @_;
 2552:     my $currentstring = '';
 2553:     if ($target eq 'web') {
 2554: 	$currentstring = $token->[2];    
 2555:     } 
 2556:     return $currentstring;
 2557: }
 2558: 
 2559: #-- <frame> tag
 2560: sub start_frame {
 2561:     my ($target,$token) = @_;
 2562:     my $currentstring = '';
 2563:     if ($target eq 'web') {
 2564: 	$currentstring = $token->[4];     
 2565:     } 
 2566:     return $currentstring;
 2567: }
 2568: 
 2569: sub end_frame {
 2570:     my ($target,$token) = @_;
 2571:     my $currentstring = '';
 2572:     if ($target eq 'web') {
 2573: 	$currentstring = $token->[2];    
 2574:     } 
 2575:     return $currentstring;
 2576: }
 2577: 
 2578: #-- <iframe> tag
 2579: sub start_iframe {
 2580:     my ($target,$token) = @_;
 2581:     my $currentstring = '';
 2582:     if ($target eq 'web') {
 2583: 	$currentstring = $token->[4];     
 2584:     } 
 2585:     return $currentstring;
 2586: }
 2587: 
 2588: sub end_iframe {
 2589:     my ($target,$token) = @_;
 2590:     my $currentstring = '';
 2591:     if ($target eq 'web') {
 2592: 	$currentstring = $token->[2];    
 2593:     } 
 2594:     return $currentstring;
 2595: }
 2596: 
 2597: #-- <ins> tag
 2598: sub start_ins {
 2599:     my ($target,$token) = @_;
 2600:     my $currentstring = '';
 2601:     if ($target eq 'web') {
 2602: 	$currentstring = $token->[4];     
 2603:     } 
 2604:     return $currentstring;
 2605: }
 2606: 
 2607: sub end_ins {
 2608:     my ($target,$token) = @_;
 2609:     my $currentstring = '';
 2610:     if ($target eq 'web') {
 2611: 	$currentstring = $token->[2];    
 2612:     } 
 2613:     return $currentstring;
 2614: }
 2615: 
 2616: #-- <isindex> tag
 2617: sub start_isindex {
 2618:     my ($target,$token) = @_;
 2619:     my $currentstring = '';
 2620:     if ($target eq 'web') {
 2621: 	$currentstring = $token->[4];     
 2622:     } 
 2623:     return $currentstring;
 2624: }
 2625: 
 2626: sub end_isindex {
 2627:     my ($target,$token) = @_;
 2628:     my $currentstring = '';
 2629:     if ($target eq 'web') {
 2630: 	$currentstring = $token->[2];    
 2631:     } 
 2632:     return $currentstring;
 2633: }
 2634: 
 2635: #-- <keygen> tag
 2636: sub start_keygen {
 2637:     my ($target,$token) = @_;
 2638:     my $currentstring = '';
 2639:     if ($target eq 'web') {
 2640: 	$currentstring = $token->[4];     
 2641:     } 
 2642:     return $currentstring;
 2643: }
 2644: 
 2645: sub end_keygen {
 2646:     my ($target,$token) = @_;
 2647:     my $currentstring = '';
 2648:     if ($target eq 'web') {
 2649: 	$currentstring = $token->[2];    
 2650:     } 
 2651:     return $currentstring;
 2652: }
 2653: 
 2654: #-- <label> tag
 2655: sub start_label {
 2656:     my ($target,$token) = @_;
 2657:     my $currentstring = '';
 2658:     if ($target eq 'web') {
 2659: 	$currentstring = $token->[4];     
 2660:     } 
 2661:     return $currentstring;
 2662: }
 2663: 
 2664: sub end_label {
 2665:     my ($target,$token) = @_;
 2666:     my $currentstring = '';
 2667:     if ($target eq 'web') {
 2668: 	$currentstring = $token->[2];    
 2669:     } 
 2670:     return $currentstring;
 2671: }
 2672: 
 2673: #-- <layer> tag
 2674: sub start_layer {
 2675:     my ($target,$token) = @_;
 2676:     my $currentstring = '';
 2677:     if ($target eq 'web') {
 2678: 	$currentstring = $token->[4];     
 2679:     } 
 2680:     return $currentstring;
 2681: }
 2682: 
 2683: sub end_layer {
 2684:     my ($target,$token) = @_;
 2685:     my $currentstring = '';
 2686:     if ($target eq 'web') {
 2687: 	$currentstring = $token->[2];    
 2688:     } 
 2689:     return $currentstring;
 2690: }
 2691: 
 2692: #-- <legend> tag
 2693: sub start_legend {
 2694:     my ($target,$token) = @_;
 2695:     my $currentstring = '';
 2696:     if ($target eq 'web') {
 2697: 	$currentstring = $token->[4];     
 2698:     } 
 2699:     return $currentstring;
 2700: }
 2701: 
 2702: sub end_legend {
 2703:     my ($target,$token) = @_;
 2704:     my $currentstring = '';
 2705:     if ($target eq 'web') {
 2706: 	$currentstring = $token->[2];    
 2707:     } 
 2708:     return $currentstring;
 2709: }
 2710: 
 2711: #-- <link> tag
 2712: sub start_link {
 2713:     my ($target,$token) = @_;
 2714:     my $currentstring = '';
 2715:     if ($target eq 'web') {
 2716: 	$currentstring = $token->[4];     
 2717:     } 
 2718:     return $currentstring;
 2719: }
 2720: 
 2721: sub end_link {
 2722:     my ($target,$token) = @_;
 2723:     my $currentstring = '';
 2724:     if ($target eq 'web') {
 2725: 	$currentstring = $token->[2];    
 2726:     } 
 2727:     return $currentstring;
 2728: }
 2729: 
 2730: #-- <marquee> tag
 2731: sub start_marquee {
 2732:     my ($target,$token) = @_;
 2733:     my $currentstring = '';
 2734:     if ($target eq 'web') {
 2735: 	$currentstring = $token->[4];     
 2736:     } 
 2737:     return $currentstring;
 2738: }
 2739: 
 2740: sub end_marquee {
 2741:     my ($target,$token) = @_;
 2742:     my $currentstring = '';
 2743:     if ($target eq 'web') {
 2744: 	$currentstring = $token->[2];    
 2745:     } 
 2746:     return $currentstring;
 2747: }
 2748: 
 2749: #-- <malticol> tag
 2750: sub start_malticol {
 2751:     my ($target,$token) = @_;
 2752:     my $currentstring = '';
 2753:     if ($target eq 'web') {
 2754: 	$currentstring = $token->[4];     
 2755:     } 
 2756:     return $currentstring;
 2757: }
 2758: 
 2759: sub end_malticol {
 2760:     my ($target,$token) = @_;
 2761:     my $currentstring = '';
 2762:     if ($target eq 'web') {
 2763: 	$currentstring = $token->[2];    
 2764:     } 
 2765:     return $currentstring;
 2766: }
 2767: 
 2768: #-- <nobr> tag
 2769: sub start_nobr {
 2770:     my ($target,$token) = @_;
 2771:     my $currentstring = '';
 2772:     if ($target eq 'web') {
 2773: 	$currentstring = $token->[4];     
 2774:     } 
 2775:     return $currentstring;
 2776: }
 2777: 
 2778: sub end_nobr {
 2779:     my ($target,$token) = @_;
 2780:     my $currentstring = '';
 2781:     if ($target eq 'web') {
 2782: 	$currentstring = $token->[2];    
 2783:     } 
 2784:     return $currentstring;
 2785: }
 2786: 
 2787: #-- <noembed> tag
 2788: sub start_noembed {
 2789:     my ($target,$token) = @_;
 2790:     my $currentstring = '';
 2791:     if ($target eq 'web') {
 2792: 	$currentstring = $token->[4];     
 2793:     } 
 2794:     return $currentstring;
 2795: }
 2796: 
 2797: sub end_noembed {
 2798:     my ($target,$token) = @_;
 2799:     my $currentstring = '';
 2800:     if ($target eq 'web') {
 2801: 	$currentstring = $token->[2];    
 2802:     } 
 2803:     return $currentstring;
 2804: }
 2805: 
 2806: #-- <noframes> tag
 2807: sub start_noframes {
 2808:     my ($target,$token) = @_;
 2809:     my $currentstring = '';
 2810:     if ($target eq 'web') {
 2811: 	$currentstring = $token->[4];     
 2812:     } 
 2813:     return $currentstring;
 2814: }
 2815: 
 2816: sub end_noframes {
 2817:     my ($target,$token) = @_;
 2818:     my $currentstring = '';
 2819:     if ($target eq 'web') {
 2820: 	$currentstring = $token->[2];    
 2821:     } 
 2822:     return $currentstring;
 2823: }
 2824: 
 2825: #-- <nolayer> tag
 2826: sub start_nolayer {
 2827:     my ($target,$token) = @_;
 2828:     my $currentstring = '';
 2829:     if ($target eq 'web') {
 2830: 	$currentstring = $token->[4];     
 2831:     } 
 2832:     return $currentstring;
 2833: }
 2834: 
 2835: sub end_nolayer {
 2836:     my ($target,$token) = @_;
 2837:     my $currentstring = '';
 2838:     if ($target eq 'web') {
 2839: 	$currentstring = $token->[2];    
 2840:     } 
 2841:     return $currentstring;
 2842: }
 2843: 
 2844: #-- <noscript> tag
 2845: sub start_noscript {
 2846:     my ($target,$token) = @_;
 2847:     my $currentstring = '';
 2848:     if ($target eq 'web') {
 2849: 	$currentstring = $token->[4];     
 2850:     } 
 2851:     return $currentstring;
 2852: }
 2853: 
 2854: sub end_noscript {
 2855:     my ($target,$token) = @_;
 2856:     my $currentstring = '';
 2857:     if ($target eq 'web') {
 2858: 	$currentstring = $token->[2];    
 2859:     } 
 2860:     return $currentstring;
 2861: }
 2862: 
 2863: #-- <object> tag
 2864: sub start_object {
 2865:     my ($target,$token) = @_;
 2866:     my $currentstring = '';
 2867:     if ($target eq 'web') {
 2868: 	$currentstring = $token->[4];     
 2869:     } 
 2870:     return $currentstring;
 2871: }
 2872: 
 2873: sub end_object {
 2874:     my ($target,$token) = @_;
 2875:     my $currentstring = '';
 2876:     if ($target eq 'web') {
 2877: 	$currentstring = $token->[2];    
 2878:     } 
 2879:     return $currentstring;
 2880: }
 2881: 
 2882: #-- <optgroup> tag
 2883: sub start_optgroup {
 2884:     my ($target,$token) = @_;
 2885:     my $currentstring = '';
 2886:     if ($target eq 'web') {
 2887: 	$currentstring = $token->[4];     
 2888:     } 
 2889:     return $currentstring;
 2890: }
 2891: 
 2892: sub end_optgroup {
 2893:     my ($target,$token) = @_;
 2894:     my $currentstring = '';
 2895:     if ($target eq 'web') {
 2896: 	$currentstring = $token->[2];    
 2897:     } 
 2898:     return $currentstring;
 2899: }
 2900: 
 2901: #-- <samp> tag
 2902: sub start_samp {
 2903:     my ($target,$token) = @_;
 2904:     my $currentstring = '';
 2905:     if ($target eq 'web') {
 2906: 	$currentstring = $token->[4];     
 2907:     } 
 2908:     return $currentstring;
 2909: }
 2910: 
 2911: sub end_samp {
 2912:     my ($target,$token) = @_;
 2913:     my $currentstring = '';
 2914:     if ($target eq 'web') {
 2915: 	$currentstring = $token->[2];    
 2916:     } 
 2917:     return $currentstring;
 2918: }
 2919: 
 2920: #-- <server> tag
 2921: sub start_server {
 2922:     my ($target,$token) = @_;
 2923:     my $currentstring = '';
 2924:     if ($target eq 'web') {
 2925: 	$currentstring = $token->[4];     
 2926:     } 
 2927:     return $currentstring;
 2928: }
 2929: 
 2930: sub end_server {
 2931:     my ($target,$token) = @_;
 2932:     my $currentstring = '';
 2933:     if ($target eq 'web') {
 2934: 	$currentstring = $token->[2];    
 2935:     } 
 2936:     return $currentstring;
 2937: }
 2938: 
 2939: #-- <spacer> tag
 2940: sub start_spacer {
 2941:     my ($target,$token) = @_;
 2942:     my $currentstring = '';
 2943:     if ($target eq 'web') {
 2944: 	$currentstring = $token->[4];     
 2945:     } 
 2946:     return $currentstring;
 2947: }
 2948: 
 2949: sub end_spacer {
 2950:     my ($target,$token) = @_;
 2951:     my $currentstring = '';
 2952:     if ($target eq 'web') {
 2953: 	$currentstring = $token->[2];    
 2954:     } 
 2955:     return $currentstring;
 2956: }
 2957: 
 2958: #-- <span> tag
 2959: sub start_span {
 2960:     my ($target,$token) = @_;
 2961:     my $currentstring = '';
 2962:     if ($target eq 'web') {
 2963: 	$currentstring = $token->[4];     
 2964:     } 
 2965:     return $currentstring;
 2966: }
 2967: 
 2968: sub end_span {
 2969:     my ($target,$token) = @_;
 2970:     my $currentstring = '';
 2971:     if ($target eq 'web') {
 2972: 	$currentstring = $token->[2];    
 2973:     } 
 2974:     return $currentstring;
 2975: }
 2976: 
 2977: #-- <tbody> tag
 2978: sub start_tbody {
 2979:     my ($target,$token) = @_;
 2980:     my $currentstring = '';
 2981:     if ($target eq 'web') {
 2982: 	$currentstring = $token->[4];     
 2983:     } 
 2984:     return $currentstring;
 2985: }
 2986: 
 2987: sub end_tbody {
 2988:     my ($target,$token) = @_;
 2989:     my $currentstring = '';
 2990:     if ($target eq 'web') {
 2991: 	$currentstring = $token->[2];    
 2992:     } 
 2993:     return $currentstring;
 2994: }
 2995: 
 2996: #-- <tfoot> tag
 2997: sub start_tfoot {
 2998:     my ($target,$token) = @_;
 2999:     my $currentstring = '';
 3000:     if ($target eq 'web') {
 3001: 	$currentstring = $token->[4];     
 3002:     } 
 3003:     return $currentstring;
 3004: }
 3005: 
 3006: sub end_tfoot {
 3007:     my ($target,$token) = @_;
 3008:     my $currentstring = '';
 3009:     if ($target eq 'web') {
 3010: 	$currentstring = $token->[2];    
 3011:     } 
 3012:     return $currentstring;
 3013: }
 3014: 
 3015: #-- <thead> tag
 3016: sub start_thead {
 3017:     my ($target,$token) = @_;
 3018:     my $currentstring = '';
 3019:     if ($target eq 'web') {
 3020: 	$currentstring = $token->[4];     
 3021:     } 
 3022:     return $currentstring;
 3023: }
 3024: 
 3025: sub end_thead {
 3026:     my ($target,$token) = @_;
 3027:     my $currentstring = '';
 3028:     if ($target eq 'web') {
 3029: 	$currentstring = $token->[2];    
 3030:     } 
 3031:     return $currentstring;
 3032: }
 3033: 
 3034: #-- <var> tag
 3035: sub start_var {
 3036:     my ($target,$token) = @_;
 3037:     my $currentstring = '';
 3038:     if ($target eq 'web') {
 3039: 	$currentstring = $token->[4];     
 3040:     } 
 3041:     return $currentstring;
 3042: }
 3043: 
 3044: sub end_var {
 3045:     my ($target,$token) = @_;
 3046:     my $currentstring = '';
 3047:     if ($target eq 'web') {
 3048: 	$currentstring = $token->[2];    
 3049:     } 
 3050:     return $currentstring;
 3051: }
 3052: 
 3053: #-- <wbr> tag
 3054: sub start_wbr {
 3055:     my ($target,$token) = @_;
 3056:     my $currentstring = '';
 3057:     if ($target eq 'web') {
 3058: 	$currentstring = $token->[4];     
 3059:     } 
 3060:     return $currentstring;
 3061: }
 3062: 
 3063: sub end_wbr {
 3064:     my ($target,$token) = @_;
 3065:     my $currentstring = '';
 3066:     if ($target eq 'web') {
 3067: 	$currentstring = $token->[2];    
 3068:     } 
 3069:     return $currentstring;
 3070: }
 3071: 
 3072: 
 3073: #-- <hideweboutput> tag
 3074: sub start_hideweboutput {
 3075:     my ($target,$token) = @_;
 3076:     if ($target eq 'web') {
 3077: 	&Apache::lonxml::startredirection();     
 3078:     } 
 3079:     return '';
 3080: }
 3081: 
 3082: sub end_hideweboutput {
 3083:     my ($target,$token) = @_;
 3084:     my $currentstring = '';
 3085:     if ($target eq 'web') {
 3086: 	$currentstring = &Apache::lonxml::endredirection();    
 3087:     } 
 3088:     return '';
 3089: }
 3090: 
 3091: 
 3092: sub image_replication {
 3093:     my $src = shift;
 3094:     if (not -e $src) {
 3095: 	#replicates image itself
 3096: 	&Apache::lonnet::repcopy($src);
 3097: 	#replicates eps or ps 
 3098: 	my $newsrc = $src;
 3099: 	$newsrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i;
 3100: 	if (not -e $newsrc) {
 3101: 	    if (&Apache::lonnet::repcopy($newsrc) ne 'OK') {
 3102: 		$newsrc =~ s/\.eps$/\.ps/;
 3103: 		&Apache::lonnet::repcopy($newsrc);
 3104: 	    }
 3105: 	}
 3106:     }
 3107:     return '';
 3108: }
 3109: 
 3110: sub recalc {
 3111:     my $argument = shift;
 3112:     if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}
 3113:     $argument=~/\s*(\d+\.?\d*)\s*(mm|cm|in|pc|pt)/;
 3114:     my $value=$1;
 3115:     my $units=$2;
 3116:     if ($units eq 'cm') {
 3117: 	$value*=10;
 3118:     } elsif ($units eq 'in') {
 3119: 	$value*=25.4;
 3120:     } elsif ($units eq 'pc') {
 3121: 	$value*=(25.4*12/72.27);
 3122:     } elsif ($units eq 'pt') {
 3123: 	$value*=(25.4/72.27);
 3124:     }
 3125:     return $value.' mm';
 3126: }
 3127: 
 3128: 1;
 3129: __END__

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