File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.197: download - view: text, annotated - select for diffs
Fri Jan 30 17:31:06 2004 UTC (20 years, 3 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Another step in cleanup of <img>.

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

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