File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.238: download - view: text, annotated - select for diffs
Wed Aug 25 19:57:27 2004 UTC (19 years, 8 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- alphabet was misspelled
- count is now always right, added support for more types to <li>

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

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