File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.193: download - view: text, annotated - select for diffs
Mon Jan 12 15:44:30 2004 UTC (20 years, 5 months ago) by albertel
Branches: MAIN
CVS tags: version_1_1_X, version_1_1_3, version_1_1_2, version_1_1_1, HEAD
- Undoing 1.190, to fix BUG#2562 which reopens BUG#1894
- sigh

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

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