File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.243: download - view: text, annotated - select for diffs
Mon Oct 18 22:02:02 2004 UTC (19 years, 6 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- <dl> <dt> <dd> didn't
     - print the HTML 4.01 examples
     - allows nesting
     - BUG#3549

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

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