File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.219: download - view: text, annotated - select for diffs
Thu Jun 3 14:57:05 2004 UTC (20 years ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Bug 3035 (vertical space in TeX) is fixed.

    1: # The LearningOnline Network with CAPA
    2: # Tags Default Definition Module 
    3: #
    4: # $Id: londefdef.pm,v 1.219 2004/06/03 14:57:05 sakharuk Exp $
    5: # 
    6: #
    7: # Copyright Michigan State University Board of Trustees
    8: #
    9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   10: #
   11: # LON-CAPA is free software; you can redistribute it and/or modify
   12: # it under the terms of the GNU General Public License as published by
   13: # the Free Software Foundation; either version 2 of the License, or
   14: # (at your option) any later version.
   15: #
   16: # LON-CAPA is distributed in the hope that it will be useful,
   17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19: # GNU General Public License for more details.
   20: #
   21: # You should have received a copy of the GNU General Public License
   22: # along with LON-CAPA; if not, write to the Free Software
   23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   24: #
   25: # /home/httpd/html/adm/gpl.txt
   26: #
   27: # http://www.lon-capa.org/
   28: ## Copyright for TtHfunc and TtMfunc by Ian Hutchinson. 
   29: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into 
   30: # binary executable programs or libraries distributed by the 
   31: # Michigan State University (the "Licensee"), but any binaries so 
   32: # distributed are hereby licensed only for use in the context
   33: # of a program or computational system for which the Licensee is the 
   34: # primary author or distributor, and which performs substantial 
   35: # additional tasks beyond the translation of (La)TeX into HTML.
   36: # The C source of the Code may not be distributed by the Licensee
   37: # to any other parties under any circumstances.
   38: #
   39: #
   40: # last modified 06/26/00 by Alexander Sakharuk
   41: # 11/6,11/30,02/01/01,5/4 Gerd Kortemeyer
   42: # 01/18 Alex Sakharuk
   43: 
   44: package Apache::londefdef; 
   45: 
   46: use Apache::lonnet();
   47: use strict;
   48: use Apache::lonxml;
   49: use Apache::File();
   50: use Image::Magick;
   51: use Apache::lonmenu();
   52: use Apache::lonmeta();
   53: use Apache::Constants qw(:common);
   54: 
   55: 
   56: BEGIN {
   57: 
   58:     &Apache::lonxml::register('Apache::londefdef',('a','abbr','acronym','accessrule','address','allow','applet','area','b','base','basefont','bgo','bgsound','big','blink','blockquote','blankspace','body','br','button','caption','center','cite','code','col','colgroup','dd','del','dfn','dir','div','dl','dt','em','embed','externallink','fieldset','font','form','frame','frameset','h1','h2','h3','h4','h5','h6','head','hr','html','i','iframe','img','input','ins','insert','isindex','kbd','keygen','label','layer','legend','li','link','m','map','marquee','menu','meta','multicol','nobr','noembed','noframes','nolayer','noscript','object','ol','optgroup','option','output','p','param','pre','q','s','samp','select','server','small','spacer','span','strike','strong','sub','sup','table','tbody','td','textarea','tfoot','th','thead','title','tr','tt','tthoption','u','ul','var','wbr','hideweboutput'));
   59: 
   60: }
   61: 
   62: sub initialize_londefdef {
   63:     $Apache::londefdef::TD_redirection=0;
   64:     @Apache::londefdef::table = ();
   65:     $Apache::londefdef::select=0;
   66:     @Apache::londefdef::description=();
   67:     $Apache::londefdef::DD_redirection=0;
   68:     $Apache::londefdef::DT_redirection=0;
   69: }
   70: 
   71: #======================= TAG SUBROUTINES =====================
   72: #-- <output>
   73: sub start_output {
   74:     my ($target) = @_;
   75:     if ($target eq 'meta') { $Apache::lonxml::metamode--; }
   76:     return '';
   77: }
   78: sub end_output {
   79:     my ($target) = @_;
   80:     if ($target eq 'meta') { $Apache::lonxml::metamode++; }
   81:     return '';
   82: }
   83: #-- <m> tag
   84: sub start_m {
   85:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
   86:     my $currentstring = '';
   87:     my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser);
   88:     if ($target eq 'web' || $target eq 'analyze') {
   89: 	$inside ='\\documentstyle{article}'.$inside;
   90: 	&Apache::lonxml::debug("M is starting with:$inside:");
   91: 	my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
   92: 	if ($eval eq 'on') {
   93: 	    $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
   94: 	    #&Apache::lonxml::debug("M is evaulated to:$inside:");
   95: 	}
   96: 	$currentstring = &Apache::lontexconvert::converted(\$inside);
   97: 	if ($Apache::lontexconvert::errorstring) {
   98: 	    &Apache::lonxml::warning("tth error: ".
   99: 				     $Apache::lontexconvert::errorstring);
  100: 	    $Apache::lontexconvert::errorstring='';
  101: 	}
  102: 	#&Apache::lonxml::debug("M is ends with:$currentstring:");
  103: 	$Apache::lonxml::post_evaluate=0;
  104:     } elsif ($target eq 'tex') {
  105: 	$currentstring = $inside;
  106: 	my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
  107: 	if ($eval eq 'on') {
  108: 	    $currentstring=&Apache::run::evaluate($currentstring,$safeeval,$$parstack[-1]);
  109: 	}
  110: 	if ($currentstring=~/^(\s*\\\\\s*)*$/) {$currentstring = ' \vskip 0 mm ';}
  111: 	$Apache::lonxml::post_evaluate=0;
  112:     }
  113:     return $currentstring;
  114: }
  115: 
  116: sub end_m {
  117:     my ($target,$token) = @_;
  118:     my $currentstring = '';
  119:     if ($target eq 'tex') {
  120: 	$currentstring = "";
  121:     }
  122:     return $currentstring;
  123: }
  124: 
  125: sub start_tthoption {
  126:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  127:     my $result;
  128:     if ($target eq 'web') {
  129: 	my $inside = &Apache::lonxml::get_all_text("/tthoption",$parser);
  130: 	$inside=~s/^\s*//;
  131: 	if ($ENV{'browser.mathml'}) {
  132: 	    &tth::ttmoptions($inside);
  133: 	} else {
  134: 	    &tth::tthoptions($inside);
  135: 	}
  136:     }
  137:     return $result;
  138: }
  139: 
  140: sub end_tthoption {
  141:     my ($target,$token) = @_;
  142:     my $result;
  143:     return $result;
  144: }
  145: 
  146: #-- <html> tag (end tag optional)
  147: sub start_html {
  148:     my ($target,$token) = @_;
  149:     my $currentstring = '';
  150:     my $options=$ENV{'course.'.$ENV{'request.course.id'}.'.tthoptions'};
  151:     &Apache::lontexconvert::init_tth();
  152:     if ($target eq 'web' || $target eq 'edit') {
  153: 	$currentstring = &Apache::lonxml::xmlbegin().
  154: 	    &Apache::lonxml::fontsettings();     
  155:     } elsif ($target eq 'tex') {
  156: 	@Apache::londefdef::table = ();
  157: 	$currentstring .= '\documentclass[letterpaper]{article}';
  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) = @_;
  180:     my $currentstring = '';
  181:     if ($target eq 'web') {
  182: 	$currentstring = &Apache::lonxml::xmlend();
  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];     
  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: 	if ($$tagstack[-1] eq 'p') {
 1137: 	    my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
 1138: 	    if ($align eq 'center') {		
 1139: 		$currentstring .= '\end{center}';
 1140: 	    } elsif ($align eq 'right') {
 1141: 		$currentstring .= '}}';
 1142: 	    } elsif ($align eq 'left') {
 1143: 		$currentstring .= '}\hfill}';
 1144: 	    }
 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: 	if (($$tagstack[-2] eq 'b') || ($$tagstack[-2] eq 'strong')) {
 1158: 	    $currentstring .= ' \vskip 0 mm ';
 1159: 	} elsif ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') {
 1160: 	    $currentstring .= '\strut \\\\ \strut ';
 1161: 	}
 1162:     }
 1163:     return $currentstring;
 1164: }
 1165: 
 1166: sub end_br {
 1167:     my ($target,$token) = @_;
 1168:     my $currentstring = '';
 1169:     if ($target eq 'web') {
 1170: 	$currentstring .= $token->[2];
 1171:     }
 1172:     return $currentstring;
 1173: }
 1174: 
 1175: #-- <big> tag (end tag required)
 1176: sub start_big {
 1177:     my ($target,$token) = @_;
 1178:     my $currentstring = '';
 1179:     if ($target eq 'web') {
 1180: 	$currentstring .= $token->[4];
 1181:     } elsif ($target eq 'tex') {
 1182: 	$currentstring .= '{\large ';
 1183:     } 
 1184:     return $currentstring;
 1185: }
 1186: 
 1187: sub end_big {
 1188:     my ($target,$token) = @_;
 1189:     my $currentstring = '';
 1190:     if ($target eq 'web') {
 1191: 	$currentstring .= $token->[2];
 1192:     } elsif ($target eq 'tex') {
 1193: 	$currentstring .= '}';
 1194:     }
 1195:     return $currentstring;
 1196: }
 1197: 
 1198: #-- <small> tag (end tag required)
 1199: sub start_small {
 1200:     my ($target,$token) = @_;
 1201:     my $currentstring = '';
 1202:     if ($target eq 'web') {
 1203: 	$currentstring .= $token->[4];
 1204:     } elsif ($target eq 'tex') {
 1205: 	$currentstring .= '{\footnotesize ';
 1206:     }
 1207:     return $currentstring;
 1208: }
 1209: 
 1210: sub end_small {
 1211:     my ($target,$token) = @_;
 1212:     my $currentstring = '';
 1213:     if ($target eq 'web') {
 1214: 	$currentstring .= $token->[2];
 1215:     } elsif ($target eq 'tex') {
 1216: 	$currentstring .= '}';
 1217:     }
 1218:     return $currentstring;
 1219: }
 1220: 
 1221: #-- <basefont> tag (end tag forbidden)
 1222: sub start_basefont {
 1223:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1224:     my $currentstring = '';
 1225:     if ($target eq 'web') {
 1226: 	$currentstring = $token->[4];     
 1227:     } elsif ($target eq 'tex') {
 1228: 	my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
 1229: 	if (defined $basesize) {
 1230: 	    $currentstring = '{\\'.$basesize.' ';
 1231: 	}
 1232:     }
 1233:     return $currentstring;
 1234: }
 1235: 
 1236: sub end_basefont {
 1237:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1238:     my $currentstring = '';
 1239:     if ($target eq 'web') {
 1240: 	$currentstring = $token->[4];     
 1241:     } elsif ($target eq 'tex') {
 1242: 	my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
 1243: 	if (defined $basesize) {
 1244: 	    $currentstring = '}';
 1245: 	}
 1246:     }
 1247:     return $currentstring;
 1248: }
 1249: 
 1250: #-- <font> tag (end tag required)
 1251: sub start_font {
 1252:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1253:     my $currentstring = '';
 1254:     if ($target eq 'web') {
 1255: 	my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
 1256: 	if ($face!~/symbol/i) {
 1257: 	    if (($ENV{'browser.fontenhance'} eq 'on') || 
 1258: 		($ENV{'browser.blackwhite'} eq 'on')) { return ''; }
 1259: 	}
 1260: 	$currentstring = $token->[4];     
 1261:     }  elsif ($target eq 'tex') {
 1262: 	my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
 1263: 	if (defined $fontsize) {
 1264: 	    $currentstring = '{\\'.$fontsize.' ';
 1265: 	}
 1266:     }
 1267:     return $currentstring;
 1268: }
 1269: 
 1270: sub end_font {
 1271:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1272:     my $currentstring = '';
 1273:     if ($target eq 'web') {
 1274: 	$currentstring = $token->[2];    
 1275:     }  elsif ($target eq 'tex') {
 1276: 	my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
 1277: 	if (defined $fontsize) {
 1278: 	    $currentstring = '}';
 1279: 	}
 1280:     }
 1281:     return $currentstring;
 1282: }
 1283:  
 1284: #-- <strike> tag (end tag required)
 1285: sub start_strike {
 1286:     my ($target,$token) = @_;
 1287:     my $currentstring = '';
 1288:     if ($target eq 'web') {
 1289: 	$currentstring .= $token->[4];
 1290:     } elsif ($target eq 'tex') {
 1291: 	&Apache::lonxml::startredirection();
 1292:     } 
 1293:     return $currentstring;
 1294: }
 1295: 
 1296: sub end_strike {
 1297:     my ($target,$token) = @_;
 1298:     my $currentstring = '';
 1299:     if ($target eq 'web') {
 1300: 	$currentstring .= $token->[2];
 1301:     } elsif ($target eq 'tex') {
 1302: 	$currentstring=&Apache::lonxml::endredirection();
 1303: 	$currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g; 
 1304: 	$currentstring=~s/^\s*(\S)/\\underline\{$1/; 
 1305: 	$currentstring=~s/(\S)\s*$/$1\}/;
 1306:     }
 1307:     return $currentstring;
 1308: }
 1309: 
 1310: #-- <s> tag (end tag required)
 1311: sub start_s {
 1312:     my ($target,$token) = @_;
 1313:     my $currentstring = '';
 1314:     if ($target eq 'web') {
 1315: 	$currentstring .= $token->[4];
 1316:     } elsif ($target eq 'tex') {
 1317: 	&Apache::lonxml::startredirection();
 1318:     } 
 1319:     return $currentstring;
 1320: }
 1321: 
 1322: sub end_s {
 1323:     my ($target,$token) = @_;
 1324:     my $currentstring = '';
 1325:     if ($target eq 'web') {
 1326: 	$currentstring .= $token->[2];
 1327:     } elsif ($target eq 'tex') {
 1328: 	$currentstring=&Apache::lonxml::endredirection();
 1329: 	$currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
 1330: 	$currentstring=~s/^\s*(\S)/\\underline\{$1/;
 1331: 	$currentstring=~s/(\S)\s*$/$1\}/;	
 1332:     }
 1333:     return $currentstring;
 1334: }
 1335: 
 1336: #-- <sub> tag (end tag required)
 1337: sub start_sub {
 1338:     my ($target,$token) = @_;
 1339:     my $currentstring = '';
 1340:     if ($target eq 'web') {
 1341: 	$currentstring .= $token->[4];
 1342:     } elsif ($target eq 'tex') {
 1343: 	$currentstring .= '\ensuremath{_{';
 1344:     } 
 1345:     return $currentstring;
 1346: }
 1347: 
 1348: sub end_sub {
 1349:     my ($target,$token) = @_;
 1350:     my $currentstring = '';
 1351:     if ($target eq 'web') {
 1352: 	$currentstring .= $token->[2];
 1353:     } elsif ($target eq 'tex') {
 1354: 	$currentstring .= '}}';
 1355:     }
 1356:     return $currentstring;
 1357: }
 1358: 
 1359: #-- <sup> tag (end tag required)
 1360: sub start_sup {
 1361:     my ($target,$token) = @_;
 1362:     my $currentstring = '';
 1363:     if ($target eq 'web') {
 1364: 	$currentstring .= $token->[4];
 1365:     } elsif ($target eq 'tex') {
 1366: 	$currentstring .= '\ensuremath{^{';
 1367:     } 
 1368:     return $currentstring;
 1369: }
 1370: 
 1371: sub end_sup {
 1372:     my ($target,$token) = @_;
 1373:     my $currentstring = '';
 1374:     if ($target eq 'web') {
 1375: 	$currentstring .= $token->[2];
 1376:     } elsif ($target eq 'tex') {
 1377: 	$currentstring .= '}}';
 1378:     }
 1379:     return $currentstring;
 1380: }
 1381: 
 1382: #-- <hr> tag (end tag forbidden)
 1383: sub start_hr {
 1384:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1385:     my $currentstring = '';
 1386:     if ($target eq 'web') {
 1387: 	$currentstring .= $token->[4];
 1388:     } elsif ($target eq 'tex') {
 1389: 	my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
 1390: 	if (defined $LaTeXwidth) {
 1391: 	    if ($LaTeXwidth=~/^%/) {
 1392: 		substr($LaTeXwidth,0,1)='';
 1393: 		$LaTeXwidth=($LaTeXwidth/100).'\textwidth';
 1394: 	    }
 1395: 	} else {
 1396: 	    $LaTeXwidth ='0.9\textwidth';
 1397: 	}
 1398: 	my ($pre,$post);
 1399: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
 1400: 	if (($align eq 'center') || (not defined $align)) {
 1401: 	    $pre=''; $post='';
 1402: 	} elsif ($align eq 'left') {
 1403: 	    $pre='\rlap{'; $post='} \hfill';
 1404: 	} elsif ($align eq 'right') {
 1405: 	    $pre=' \hfill \llap{'; $post='}';
 1406: 	}
 1407: 	$currentstring .= ' \vskip 0 mm \noindent\makebox['.$LaTeXwidth.']{'.$pre.'\makebox['.
 1408:                                     $LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm ';
 1409:     } 
 1410:     return $currentstring;
 1411: }
 1412: 
 1413: sub end_hr {
 1414:     my ($target,$token) = @_;
 1415:     my $currentstring = '';
 1416:     if ($target eq 'web') {
 1417: 	$currentstring .= $token->[2];
 1418:     }
 1419:     return $currentstring;
 1420: }
 1421: 
 1422: #-- <div> tag (end tag required)
 1423: sub start_div {
 1424:     my ($target,$token) = @_;
 1425:     my $currentstring = '';
 1426:     if ($target eq 'web') {
 1427: 	$currentstring .= $token->[4];
 1428:     } 
 1429:     return $currentstring;
 1430: }
 1431: 
 1432: sub end_div {
 1433:     my ($target,$token) = @_;
 1434:     my $currentstring = '';
 1435:     if ($target eq 'web') {
 1436: 	$currentstring .= $token->[2];
 1437:     } 
 1438:     return $currentstring;
 1439: }
 1440: 
 1441: #-- <a> tag (end tag required)
 1442: sub start_a {
 1443:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1444:     my $currentstring = '';
 1445:     if ($target eq 'web') {
 1446: 	$currentstring .= $token->[4];
 1447:     } elsif ($target eq 'tex') {
 1448: 	my $a=&Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1);
 1449: 	my $b=&Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1);
 1450: 	if ($a=~/\S/) {
 1451: 	    $a=~s/([^\\])%/$1\\\%/g;
 1452: 	    $currentstring .= '\ref{URI: '.$a.'}';
 1453: 	} elsif ($b=~/\S/) {
 1454: 	    $currentstring .= '\ref{Anchor: '.$b.'}';
 1455: 	} else {
 1456: 	    $currentstring.='';
 1457: 	}
 1458:     }
 1459:     return $currentstring;
 1460: }
 1461: 
 1462: sub end_a {
 1463:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1464:     my $currentstring = '';
 1465:     if ($target eq 'web') {
 1466: 	$currentstring .= $token->[2];
 1467:     }
 1468:     return $currentstring;
 1469: }
 1470: 
 1471: #-- <li> tag (end tag optional)
 1472: sub start_li {
 1473:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1474:     my $currentstring = '';
 1475:     if ($target eq 'web') {
 1476: 	$currentstring = $token->[4];     
 1477:     } elsif ($target eq 'tex') {
 1478: 	my  $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,1);
 1479: 	if ($type=~/circle/) {
 1480: 	    $currentstring .= ' \item[o] ';
 1481: 	} elsif ($type=~/square/) {
 1482: 	    $currentstring .= ' \item[$\Box$] ';
 1483: 	} elsif ($type ne '') { 
 1484: 	    $currentstring .= ' \item['.$type.'] ';
 1485: 	} else {
 1486: 	    $currentstring .= ' \item ';
 1487: 	}  
 1488:     } 
 1489:     return $currentstring;
 1490: }
 1491: 
 1492: sub end_li {
 1493:     my ($target,$token) = @_;
 1494:     my $currentstring = '';
 1495:     if ($target eq 'web') {
 1496: 	$currentstring = $token->[2];     
 1497:     } 
 1498:     return $currentstring;
 1499: }
 1500: 
 1501: #-- <u> tag (end tag required)
 1502: sub start_u {
 1503:     my ($target,$token) = @_;
 1504:     my $currentstring = '';
 1505:     if ($target eq 'web') {
 1506: 	$currentstring .= $token->[4];
 1507:     } elsif ($target eq 'tex') {
 1508: 	&Apache::lonxml::startredirection();
 1509:     } 
 1510:     return $currentstring;
 1511: }
 1512: 
 1513: sub end_u {
 1514:     my ($target,$token) = @_;
 1515:     my $currentstring = '';
 1516:     if ($target eq 'web') {
 1517: 	$currentstring .= $token->[2];
 1518:     } elsif ($target eq 'tex') {
 1519: 	$currentstring=&Apache::lonxml::endredirection();
 1520: 	$currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
 1521: 	$currentstring=~s/^\s*(\S)/\\underline\{$1/;
 1522: 	$currentstring=~s/(\S)\s*$/$1\}/;		
 1523:     }
 1524:     return $currentstring;
 1525: }
 1526: 
 1527: #-- <ul> tag (end tag required)
 1528: sub start_ul {
 1529:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1530:     my $currentstring = '';
 1531:     if ($target eq 'web') {
 1532: 	$currentstring = $token->[4];     
 1533:     } elsif ($target eq 'tex') {
 1534: 	my $TeXtype=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
 1535: 	if ($TeXtype eq 'disc') {
 1536: 	    $currentstring .= ' \renewcommand{\labelitemi}{$\bullet$}
 1537:                                 \renewcommand{\labelitemii}{$\bullet$} 
 1538:                                 \renewcommand{\labelitemiii}{$\bullet$}
 1539:                                 \renewcommand{\labelitemiv}{$\bullet$}';
 1540: 	} elsif ($TeXtype eq 'circle') {
 1541: 	    $currentstring .= ' \renewcommand{\labelitemi}{$\circ$}
 1542:                                 \renewcommand{\labelitemii}{$\circ$} 
 1543:                                 \renewcommand{\labelitemiii}{$\circ$}
 1544:                                 \renewcommand{\labelitemiv}{$\circ$}';
 1545: 	} elsif ($TeXtype eq 'square') {
 1546: 	    $currentstring .= ' \renewcommand{\labelitemi}{$\diamond$}
 1547:                                 \renewcommand{\labelitemii}{$\diamond$} 
 1548:                                 \renewcommand{\labelitemiii}{$\diamond$}
 1549:                                 \renewcommand{\labelitemiv}{$\diamond$}';
 1550: 	}
 1551: 	$currentstring .= '\begin{itemize}';  
 1552:     } 
 1553:     return $currentstring;
 1554: }
 1555: 
 1556: sub end_ul {
 1557:     my ($target,$token) = @_;
 1558:     my $currentstring = '';
 1559:     if ($target eq 'web') {
 1560: 	$currentstring = $token->[2];     
 1561:     } elsif ($target eq 'tex') {
 1562: 	$currentstring = '\end{itemize} \renewcommand{\labelitemi}{$\bullet$}
 1563:                                 \renewcommand{\labelitemii}{$\bullet$} 
 1564:                                 \renewcommand{\labelitemiii}{$\bullet$}
 1565:                                 \renewcommand{\labelitemiv}{$\bullet$}';  
 1566:     } 
 1567:     return $currentstring;
 1568: }
 1569: 
 1570: #-- <menu> tag (end tag required)
 1571: sub start_menu {
 1572:     my ($target,$token) = @_;
 1573:     my $currentstring = '';
 1574:     if ($target eq 'web') {
 1575: 	$currentstring = $token->[4];     
 1576:     } elsif ($target eq 'tex') {
 1577: 	$currentstring = " \\begin{itemize} ";  
 1578:     } 
 1579:     return $currentstring;
 1580: }
 1581: 
 1582: sub end_menu {
 1583:     my ($target,$token) = @_;
 1584:     my $currentstring = '';
 1585:     if ($target eq 'web') {
 1586: 	$currentstring = $token->[2];     
 1587:     } elsif ($target eq 'tex') {
 1588: 	$currentstring = " \\end{itemize}";  
 1589:     } 
 1590:     return $currentstring;
 1591: }
 1592: 
 1593: #-- <dir> tag (end tag required)
 1594: sub start_dir {
 1595:     my ($target,$token) = @_;
 1596:     my $currentstring = '';
 1597:     if ($target eq 'web') {
 1598: 	$currentstring = $token->[4];     
 1599:     } elsif ($target eq 'tex') {
 1600: 	$currentstring = " \\begin{itemize} ";  
 1601:     } 
 1602:     return $currentstring;
 1603: }
 1604: 
 1605: sub end_dir {
 1606:     my ($target,$token) = @_;
 1607:     my $currentstring = '';
 1608:     if ($target eq 'web') {
 1609: 	$currentstring = $token->[2];     
 1610:     } elsif ($target eq 'tex') {
 1611: 	$currentstring = " \\end{itemize}";  
 1612:     } 
 1613:     return $currentstring;
 1614: }
 1615: 
 1616: #-- <ol> tag (end tag required)
 1617: sub start_ol {
 1618:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1619:     my $currentstring = '';
 1620:     if ($target eq 'web') {
 1621: 	$currentstring = $token->[4];     
 1622:     } elsif ($target eq 'tex') {
 1623: 	my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
 1624: 	if ($type eq '1') {
 1625: 	    $currentstring .= ' \renewcommand{\labelenumi}{\arabic{enumi}.}
 1626:                                 \renewcommand{\labelenumii}{\arabic{enumii}.} 
 1627:                                 \renewcommand{\labelenumiii}{\arabic{enumiii}.}
 1628:                                 \renewcommand{\labelenumiv}{\arabic{enumiv}.}';
 1629: 	} elsif ($type eq 'A') {
 1630: 	    $currentstring .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}
 1631:                                 \renewcommand{\labelenumii}{\Alph{enumii}.} 
 1632:                                 \renewcommand{\labelenumiii}{\Alph{enumiii}.}
 1633:                                 \renewcommand{\labelenumiv}{\Alph{enumiv}.}';
 1634: 	} elsif ($type eq 'a') {
 1635: 	    $currentstring .= ' \renewcommand{\labelenumi}{\alph{enumi}.}
 1636:                                 \renewcommand{\labelenumii}{\alph{enumii}.}
 1637:                                 \renewcommand{\labelenumiii}{\alph{enumiii}.}
 1638:                                 \renewcommand{\labelenumiv}{\alph{enumiv}.} ';
 1639: 	} elsif ($type eq 'i') {
 1640: 	    $currentstring .= ' \renewcommand{\labelenumi}{\roman{enumi}.}
 1641:                                 \renewcommand{\labelenumii}{\roman{enumii}.}
 1642:                                 \renewcommand{\labelenumiii}{\roman{enumiii}.}
 1643:                                 \renewcommand{\labelenumiv}{\roman{enumiv}.} ';
 1644: 	} elsif ($type eq 'I') {
 1645: 	    $currentstring .= ' \renewcommand{\labelenumi}{\Roman{enumi}.}
 1646:                                 \renewcommand{\labelenumii}{\Roman{enumii}.}
 1647:                                 \renewcommand{\labelenumiii}{\Roman{enumiii}.}
 1648:                                 \renewcommand{\labelenumiv}{\Roman{enumiv}.} ';
 1649: 	}
 1650: 	$currentstring .= '\begin{enumerate}';  
 1651:     } 
 1652:     return $currentstring;
 1653: }
 1654: 
 1655: sub end_ol {
 1656:     my ($target,$token) = @_;
 1657:     my $currentstring = '';
 1658:     if ($target eq 'web') {
 1659: 	$currentstring = $token->[2];     
 1660:     } elsif ($target eq 'tex') {
 1661: 	$currentstring = '\end{enumerate} \renewcommand{\labelenumi}{\arabic{enumi}.}
 1662:                                           \renewcommand{\labelenumii}{\arabic{enumii}.}
 1663:                                           \renewcommand{\labelenumiii}{\arabic{enumiii}.}
 1664:                                           \renewcommand{\labelenumiv}{\arabic{enumiv}.}';  
 1665:     } 
 1666:     return $currentstring;
 1667: }
 1668: 
 1669: #-- <dl> tag (end tag required)
 1670: sub start_dl {
 1671:     my ($target,$token) = @_;
 1672:     my $currentstring = '';
 1673:     if ($target eq 'web') {
 1674: 	$currentstring = $token->[4];     
 1675:     } elsif ($target eq 'tex') {
 1676: 	$currentstring = '\begin{description}';
 1677: 	@Apache::londefdef::description=();
 1678: 	$Apache::londefdef::DD_redirection=0;
 1679: 	$Apache::londefdef::DT_redirection=0;
 1680:     } 
 1681:     return $currentstring;
 1682: }
 1683: 
 1684: sub end_dl {
 1685:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1686:     my $currentstring = '';
 1687:     if ($target eq 'web') {
 1688: 	$currentstring = $token->[2];     
 1689:     } elsif ($target eq 'tex') {
 1690: 	if ($Apache::londefdef::DT_redirection) {
 1691: 	    my $data=&item_cleanup;
 1692: 	    push @Apache::londefdef::description,'\item['.$data.']';
 1693: 	    $Apache::londefdef::DT_redirection=0;
 1694: 	} elsif ($Apache::londefdef::DD_redirection) {
 1695: 	    $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection();
 1696: 	}
 1697: 	foreach my $element (@Apache::londefdef::description) {
 1698: 	    $currentstring.=' '.$element.' ';
 1699: 	}
 1700: 	@Apache::londefdef::description=();
 1701: 	$currentstring.='\end{description}';  
 1702:     } 
 1703:     return $currentstring;
 1704: }
 1705: 
 1706: #-- <dt> tag (end tag optional)
 1707: sub start_dt {
 1708:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1709:     my $currentstring='';
 1710:     if ($target eq 'web') {
 1711: 	$currentstring = $token->[4];     
 1712:     } elsif ($target eq 'tex') {
 1713: 	if ($Apache::londefdef::DT_redirection) {
 1714: 	    my $data=&item_cleanup;
 1715: 	    push @Apache::londefdef::description,'\item['.$data.']';
 1716: 	    $Apache::londefdef::DT_redirection=0;
 1717: 	} elsif ($Apache::londefdef::DD_redirection) {
 1718: 	    $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection();
 1719: 	    $Apache::londefdef::DD_redirection=0;
 1720: 	}
 1721: 	&Apache::lonxml::startredirection();
 1722: 	$Apache::londefdef::DT_redirection=1;
 1723:     } 
 1724:     return $currentstring;
 1725: }
 1726: 
 1727: sub end_dt {
 1728:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1729:     my $currentstring = '';
 1730:     if ($target eq 'web') {
 1731: 	$currentstring = $token->[2];    
 1732:     } elsif ($target eq 'tex') {
 1733: 	my $data=&item_cleanup;
 1734: 	push @Apache::londefdef::description,'\item['.$data.']';
 1735: 	$Apache::londefdef::DT_redirection=0;
 1736:     } 
 1737:     return $currentstring;
 1738: }
 1739: 
 1740: sub item_cleanup {
 1741:     my $item=&Apache::lonxml::endredirection();
 1742:     $item=~s/\\begin{center}//g;
 1743:     $item=~s/\\end{center}//g;
 1744:     return $item;
 1745: }
 1746: 
 1747: #-- <dd> tag (end tag optional)
 1748: sub start_dd {
 1749:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1750:     my $currentstring = '';
 1751:     if ($target eq 'web') {
 1752: 	$currentstring = $token->[4];     
 1753:     } elsif ($target eq 'tex') {
 1754: 	if ($Apache::londefdef::DT_redirection) {
 1755: 	    my $data=&item_cleanup;
 1756: 	    push @Apache::londefdef::description,'\item['.$data.']';
 1757: 	    $Apache::londefdef::DT_redirection=0;
 1758: 	}
 1759: 	$Apache::londefdef::DD_redirection=1;
 1760: 	&Apache::lonxml::startredirection();
 1761:     } 
 1762:     return $currentstring;
 1763: }
 1764: 
 1765: sub end_dd {
 1766:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1767:     my $currentstring = '';
 1768:     if ($target eq 'web') {
 1769: 	$currentstring = $token->[2];    
 1770:     }  elsif ($target eq 'tex') {
 1771: 	$Apache::londefdef::description[-1].=&Apache::lonxml::endredirection();
 1772: 	$Apache::londefdef::DD_redirection=0;
 1773:     }
 1774:     return $currentstring;
 1775: }
 1776: 
 1777: #-- <table> tag (end tag required)
 1778: #list of supported attributes: border,width,TeXwidth
 1779: sub start_table {
 1780:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1781:     my ($textwidth,$currentstring)=('','');
 1782:     if ($target eq 'web') {
 1783: 	$currentstring = $token->[4];     
 1784:     } elsif ($target eq 'tex') {
 1785: 	my $aa = {};
 1786: 	push @Apache::londefdef::table, $aa; 
 1787: 	$Apache::londefdef::table[-1]{'row_number'} = -1;
 1788:         #table's width 
 1789:         #default coincides with text line length
 1790: 	if ($#Apache::londefdef::table==0) {
 1791: 	    $textwidth=&recalc($ENV{'form.textwidth'}); #result is always in mm
 1792: 	    $textwidth=~/(\d+\.?\d*)/;
 1793: 	    $textwidth=0.95*$1; #accounts "internal" LaTeX space for table frame
 1794: 	} else {
 1795: 	    if ($Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]=~/\d/) {
 1796: 		#the maximum width of nested table is determined by LATeX width of parent cell
 1797: 		$textwidth=$Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]; 
 1798: 	    } else {
 1799:               #try to use all space not used before (minus 5% for LaTeX table internal) - rather silly
 1800: 		my $textwidth=$Apache::londefdef::table[-2]{'width'};
 1801: 		for (my $i=0;$i<$Apache::londefdef::table[-2]{'counter_columns'};$i++) {
 1802: 		    $textwidth=$textwidth-$Apache::londefdef::table[-2]{'TeXlen'}[0][$i];
 1803: 		}
 1804: 	    }
 1805: 	}
 1806: 	my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
 1807: 	if (not defined $TeXwidth) {
 1808: 	    my $htmlwidth = &Apache::lonxml::get_param('width',$parstack,$safeeval,undef,1);
 1809: 	    if ($htmlwidth=~/%/) {
 1810:                 $Apache::londefdef::table[-1]{'percent'}=1;
 1811: 		$htmlwidth=~/(\d+)/;
 1812: 		$Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;;
 1813: 	    } else {
 1814: 		$Apache::londefdef::table[-1]{'width'}=$textwidth;
 1815: 	    }
 1816: 	} elsif ($TeXwidth=~/%/) {
 1817: 	    $Apache::londefdef::table[-1]{'percent'}=1;
 1818: 	    $TeXwidth=~/(\d+)/;
 1819:             $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;
 1820: 	} else {
 1821: 	    $Apache::londefdef::table[-1]{'width'}=$TeXwidth;
 1822: 	}        
 1823:         #table's border
 1824: 	my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval); 
 1825:         my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
 1826: 	unless (defined $border) { $border = 0; }
 1827: 	if ($border) { 
 1828: 	    $Apache::londefdef::table[-1]{'hinc'} = '\hline '; 
 1829: 	    $Apache::londefdef::table[-1]{'vinc'} = '&'; 
 1830: 	    $Apache::londefdef::table[-1]{'vvinc'} = '|';
 1831: 	} else {
 1832: 	    $Apache::londefdef::table[-1]{'hinc'} = ''; 
 1833: 	    $Apache::londefdef::table[-1]{'vinc'} = '&'; 
 1834: 	    $Apache::londefdef::table[-1]{'vvinc'} = '';
 1835: 	}
 1836: 	if ($#Apache::londefdef::table==0) {
 1837: 	    $Apache::londefdef::table[-1]{'output'}='\strut\newline\strut\setlength{\tabcolsep}{1 mm}';
 1838: 	}
 1839: 	$Apache::londefdef::table[-1]{'output'}.=' \noindent \begin{tabular} ';
 1840:         $Apache::londefdef::table[-1]{'TeXlen'}=[];
 1841:         $Apache::londefdef::table[-1]{'objectlen'}=[];
 1842:         $Apache::londefdef::table[-1]{'maxlen'}=[];
 1843:         $Apache::londefdef::table[-1]{'minlen'}=[];
 1844:         $Apache::londefdef::table[-1]{'content'}=[];
 1845:         $Apache::londefdef::table[-1]{'align'}=[];
 1846:         $currentstring='\keephidden{NEW TABLE ENTRY}';
 1847:    }
 1848:     return $currentstring;
 1849: }
 1850:  
 1851: sub end_table {
 1852:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1853:     my $currentstring = '';
 1854:     if ($target eq 'web') {
 1855: 	$currentstring = $token->[2];     
 1856:     } elsif ($target eq 'tex') {
 1857: 	my $inmemory = '';
 1858: 	my $output = '';
 1859: 	my $WARNING='';
 1860:         #width of columns from TeXwidth attributes
 1861: 	for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
 1862: 	    for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
 1863: 		if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]<$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn]) {
 1864: 		    $Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]=$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn];
 1865: 		}	
 1866: 	    }
 1867: 	}
 1868:         #free space and number of empty columns
 1869: 	my ($available_space,$empty_columns)=($Apache::londefdef::table[-1]{'width'},0);
 1870: ##	&Apache::lonnet::logthis("Available space $Apache::londefdef::table[-1]{'width'}");
 1871: 	for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
 1872: 	    if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]==0) {
 1873: 		$empty_columns++;
 1874: 	    } else {
 1875: 		$available_space=$available_space-$Apache::londefdef::table[-1]{'TeXlen'}[0][$jn];
 1876: 	    }
 1877: 	}
 1878:         #boundaries for contents columns
 1879: 	my @min_len=();#columns can not be narrower 
 1880: 	my @max_len=();#maximum length of column
 1881: 	for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
 1882: 		my ($localmin,$localmax)=(0,0);
 1883: 		for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
 1884: 		    if ($localmin<$Apache::londefdef::table[-1]{'minlen'}[$in][$jn]) {
 1885: 			$localmin=$Apache::londefdef::table[-1]{'minlen'}[$in][$jn];
 1886: 		    }
 1887: 		    if ($localmax<$Apache::londefdef::table[-1]{'maxlen'}[$in][$jn]) {
 1888: 			$localmax=$Apache::londefdef::table[-1]{'maxlen'}[$in][$jn];
 1889: 		    }
 1890: 		}
 1891: 		push @min_len, $localmin;
 1892: 		push @max_len, $localmax;
 1893: 	}
 1894: 	for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
 1895: 	    my $localmin=0,;
 1896: 	    for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
 1897: 		if ($localmin<$Apache::londefdef::table[-1]{'objectlen'}[$in][$jn]) {
 1898: 		    $localmin=$Apache::londefdef::table[-1]{'objectlen'}[$in][$jn];
 1899: 		}
 1900: 	    }
 1901: 	    if ($max_len[$jn]<$localmin) {$max_len[$jn]=$localmin;}#object size is bigger
 1902: 	    if ($min_len[$jn]<$localmin) {$min_len[$jn]=$localmin;}#object size is bigger
 1903: 	    if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]!=0) {
 1904: 		$min_len[$jn]=0;
 1905: 		$max_len[$jn]=0;
 1906: 	    }
 1907: 	}
 1908:        #final adjustment of column width
 1909: 	my @fwidth=@{$Apache::londefdef::table[-1]{'TeXlen'}[0]};#final width array
 1910: 	my @adjust=();
 1911:         #step 1. adjustment by maximum value
 1912: 	my $space_neeeded=0;
 1913: 	for (my $jn=0;$jn<=$#max_len;$jn++) {
 1914: 	    $space_neeeded=$space_neeeded+$max_len[$jn];
 1915: 	}
 1916: 	if ($space_neeeded<=$available_space) {
 1917: 	    for (my $jn=0;$jn<=$#max_len;$jn++) {
 1918: 		if ($fwidth[$jn]==0) {
 1919: 		    $fwidth[$jn]=$max_len[$jn];
 1920: 		}
 1921: 	    }
 1922: 	} else {
 1923:         #step 2. adjustment by minimum value (estimation)
 1924: 	    $space_neeeded=0;
 1925: 	    for (my $jn=0;$jn<=$#min_len;$jn++) {
 1926: 		$space_neeeded+=$min_len[$jn];
 1927: 	    }
 1928: 	    if ($space_neeeded>$available_space) {
 1929: 		$WARNING=' \textbf{NOT ENOUGH SPACE FOR TABLE} ';
 1930: 		for (my $jn=0;$jn<=$#max_len;$jn++) {
 1931: 		    if ($fwidth[$jn]==0) {
 1932: 			$fwidth[$jn]=$min_len[$jn];
 1933: 		    }
 1934: 		}
 1935: 	    } else {
 1936: 	      #step 3. adjustment over minimal + corrections
 1937: 		my $enlarge_coef=$available_space/$space_neeeded;
 1938: 		my $acsessive=0;
 1939: 		for (my $jn=0;$jn<=$#min_len;$jn++) {
 1940: 		    $adjust[$jn]=$min_len[$jn]*$enlarge_coef;
 1941: 		    if ($adjust[$jn]>$max_len[$jn]) {
 1942: 			$fwidth[$jn]=$max_len[$jn];
 1943: 			$acsessive=$acsessive+$adjust[$jn]-$max_len[$jn];
 1944: 			$adjust[$jn]=0;
 1945: 		    }
 1946: 		}
 1947: 		if ($acsessive>0) {
 1948: 		#we have an excess of space and can redistribute it
 1949: 		    my $notempty_columns=0;
 1950: 		    for (my $jn=0;$jn<=$#min_len;$jn++) {
 1951: 			if ($adjust[$jn]!=0) {
 1952: 			    $notempty_columns++;
 1953: 			}
 1954: 		    }
 1955: 		    my $per_column=$acsessive/$notempty_columns;
 1956: 		    for (my $jn=0;$jn<=$#min_len;$jn++) {
 1957: 			if ($adjust[$jn]!=0) {
 1958: 			    $adjust[$jn]+=$per_column;
 1959: 			    $fwidth[$jn]=$adjust[$jn];
 1960: 			}
 1961: 		    }
 1962: 		}
 1963: 	    }
 1964: 	}
 1965:         #recalculation for the use of all available width if width is defined in %
 1966:         if ($Apache::londefdef::table[-1]{'percent'}==1) {
 1967: 	    my $current=0; 
 1968: 	    for (my $i=0;$i<=$#fwidth;$i++) {  
 1969: 		$current+=$fwidth[$i];
 1970: 	    }
 1971: 	    my $coef=$Apache::londefdef::table[-1]{'width'}/$current;
 1972: 	    for (my $i=0;$i<=$#fwidth;$i++) {  
 1973: 		$fwidth[$i]*=$coef;
 1974: 	    }
 1975: 	}
 1976:         #removing of empty columns if allowed
 1977:         my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
 1978: 	if ($permission eq 'yes') {
 1979: 	    my @cleaned_table=();
 1980:             my @cleaned_header=();
 1981: 	    my $colind=0;
 1982: 	    for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
 1983: 		if ($fwidth[$jn]!=0) {
 1984: 		    #we need to copy column
 1985: 		    for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
 1986: 			$cleaned_table[$in][$colind]=$Apache::londefdef::table[-1]{'content'}[$in][$jn];
 1987: 			$cleaned_header[$colind]=$fwidth[$jn];
 1988: 		    }
 1989: 		    $colind++;
 1990: 		}
 1991: 	    }
 1992: 	    $Apache::londefdef::table[-1]{'content'}=\@cleaned_table;
 1993: 	    @fwidth=@cleaned_header;
 1994: 	}
 1995: 	#construct header of the table
 1996: 	my $header_of_table = '{'.$Apache::londefdef::table[-1]{'vvinc'};
 1997: 	for (my $in=0;$in<=$#fwidth;$in++) {
 1998: 	    $header_of_table.='p{'.$fwidth[$in].' mm}'.$Apache::londefdef::table[-1]{'vvinc'};
 1999: 	}
 2000: 	$header_of_table .= '}';
 2001: 	#fill the table
 2002: 	for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
 2003: 	    for (my $jn=0;$jn<=$#fwidth;$jn++) {
 2004: 		if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
 2005: 		    $output.='\begin{center}';
 2006: 		} elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
 2007: 		    $output.=' \hfill \llap{'
 2008: 		}
 2009: 		$output.=$Apache::londefdef::table[-1]{'content'}[$in][$jn];
 2010: 		if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
 2011: 		    $output.='\end{center}';
 2012: 		} elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
 2013: 		    $output.='} ';
 2014: 		}
 2015:                 if ($jn!=$#fwidth) {$output.=' '.$Apache::londefdef::table[-1]{'vinc'};}
 2016: 	    }
 2017: 	    $output.=' \\\\ '.$Apache::londefdef::table[-1]{'hinc'}.' ';
 2018: 	}
 2019: 	$Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut\newline\strut ';
 2020: 	if ($#Apache::londefdef::table > 0) {	    
 2021: 	    my $inmemory = $Apache::londefdef::table[-1]{'output'};
 2022: 	    pop @Apache::londefdef::table;
 2023: 	    push @{$Apache::londefdef::table[-1]{'include'}}, $inmemory;
 2024: 	} else {
 2025: 	    $currentstring .= $Apache::londefdef::table[-1]{'output'};
 2026: 	    pop @Apache::londefdef::table;
 2027: 	    undef @Apache::londefdef::table;
 2028: 	}
 2029:     }
 2030:     return $currentstring;
 2031: }
 2032: 
 2033: #-- <tr> tag (end tag optional)
 2034: sub start_tr {
 2035:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2036:     my $currentstring = '';
 2037:     if ($target eq 'web') {
 2038: 	$currentstring = $token->[4];     
 2039:     } elsif ($target eq 'tex') {
 2040: 	$Apache::londefdef::table[-1]{'row_number'}++;
 2041: 	my $alignchar=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
 2042: 	if ($alignchar ne '') {
 2043: 	    push @ {$Apache::londefdef::table[-1]{'rows'} },substr($alignchar,0,1);
 2044: 	} else {
 2045: 	    push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l';
 2046: 	}
 2047: 	push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'});
 2048: 	$Apache::londefdef::table[-1]{'counter_columns'} = -1;
 2049: 	push @ {$Apache::londefdef::table[-1]{'TeXlen'}}, [];
 2050: 	push @ {$Apache::londefdef::table[-1]{'objectlen'}}, [];
 2051: 	push @ {$Apache::londefdef::table[-1]{'minlen'}}, [];
 2052: 	push @ {$Apache::londefdef::table[-1]{'maxlen'}}, [];
 2053: 	push @ {$Apache::londefdef::table[-1]{'content'}}, [];
 2054:     } 
 2055:     return $currentstring;
 2056: }
 2057:         
 2058: sub end_tr {
 2059:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2060:     my $currentstring = '';
 2061:     if ($target eq 'web') {
 2062: 	$currentstring = $token->[2];     
 2063:     } elsif ($target eq 'tex') {
 2064: 	if ($Apache::londefdef::TD_redirection) {
 2065: 	    &end_td_tex($parstack,$parser,$safeeval);    
 2066: 	}
 2067:     }
 2068:     return $currentstring;
 2069: }
 2070: 
 2071: #-- <td> tag (end tag optional)
 2072: sub start_td {
 2073:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2074:     my $currentstring = '';
 2075:     if ($target eq 'web') {
 2076: 	$currentstring = $token->[4];     
 2077:     } elsif ($target eq 'tex') {
 2078: 	$Apache::londefdef::TD_redirection = 1;
 2079: 	&tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval);
 2080:     } 
 2081:     return $currentstring;
 2082: }   
 2083:     
 2084: sub tag_check {
 2085:     my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
 2086:     my @ar=@$parstack; 
 2087:     for (my $i=$#ar-1;$i>=0;$i--) {
 2088: 	if (lc($$tagstack[$i]) eq $good_tag) {
 2089: 	    &start_td_tex($parstack,$parser,$safeeval);
 2090: 	    last;
 2091: 	} elsif (lc($$tagstack[$i]) eq $bad_tag) {
 2092: 	    splice @ar, $i+1;
 2093: 	    &end_td_tex(\@ar,$parser,$safeeval);
 2094: 	    &start_td_tex($parstack,$parser,$safeeval);
 2095: 	    last;
 2096: 	}
 2097:     }
 2098:     return '';
 2099: }
 2100:  
 2101: sub start_td_tex {
 2102:     my ($parstack,$parser,$safeeval) = @_;
 2103:     my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
 2104:     if ($alignchar eq '') {
 2105: 	$alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
 2106:     }
 2107:     push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
 2108:     $Apache::londefdef::table[-1]{'counter_columns'}++;
 2109:     my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
 2110:     if (defined $TeXwidth) {		
 2111: 	my $current_length=&recalc($TeXwidth);
 2112: 	$current_length=~/(\d+\.?\d*)/;
 2113: 	push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
 2114:     }
 2115:     &Apache::lonxml::startredirection();
 2116:     return '';
 2117: }
 2118: 
 2119: sub end_td_tex {
 2120:     my ($parstack,$parser,$safeeval) = @_;
 2121:     my $current_row = $Apache::londefdef::table[-1]{'row_number'};
 2122:     my $data=&Apache::lonxml::endredirection();
 2123:     my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
 2124:     if (defined $TeXwidth) {		
 2125: 	push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2126: 	push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2127: 	push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2128:     } else {
 2129: 	if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
 2130: 	    my $garbage_data=$data;
 2131: 	    my $fwidth=0;
 2132:             while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
 2133: 		my $current_length=&recalc($1);
 2134: 		$current_length=~/(\d+\.?\d*)/;
 2135: 		if ($fwidth<$1) {$fwidth=$1;}
 2136: 		$garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
 2137: 	    }
 2138:             while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
 2139: 		my $current_length=$1;
 2140: 		if ($fwidth<$current_length) {$fwidth=$current_length;}
 2141: 		$garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
 2142: 	    }
 2143: 	    push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2144: 	    push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
 2145: 	    push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2146: 	    push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2147: 	} else {  
 2148: 	    $data=~s/^\s+(\S.*)/$1/; 
 2149: 	    $data=~s/(.*\S)\s+$/$1/;
 2150: 	    $data=~s/(\s)+/$1/;
 2151: 	    my ($current_length,$min_length)=(0,0);
 2152: 	    if ($data=~/\\vskip/) {
 2153:                 my $newdata=$data;
 2154: 		$newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
 2155: 		my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
 2156: 		foreach my $elementdata (@newdata) {
 2157: 		    my $lengthnewdata=2.5*&LATEX_length($elementdata);
 2158: 		    if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
 2159:                     my @words=split(/ /,$elementdata);
 2160: 		    foreach my $word (@words) {
 2161: 			my $lengthword=2.5*&LATEX_length($word);
 2162: 			if ($min_length<$lengthword) {$min_length=$lengthword;}
 2163: 		    }
 2164: 		}
 2165: 	    } else {
 2166: 		$current_length=2.5*&LATEX_length($data);
 2167:                     my @words=split(/ /,$data);
 2168: 		    foreach my $word (@words) {
 2169: 			my $lengthword=2.5*&LATEX_length($word);
 2170: 			if ($min_length<$lengthword) {$min_length=$lengthword;}
 2171: 		    }
 2172: 	    }
 2173: 	    push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2174: 	    push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2175: 	    push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
 2176: 	    push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
 2177: 	}        
 2178:     }
 2179: 	for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {         
 2180: 	    $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
 2181: 	}
 2182:     push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
 2183:     return'';
 2184: }
 2185: 
 2186: sub end_td {
 2187:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2188:     my $currentstring = '';
 2189:     if ($target eq 'web') {
 2190: 	$currentstring = $token->[2];     
 2191:     } elsif ($target eq 'tex') {
 2192:         $Apache::londefdef::TD_redirection =0;
 2193: 	&end_td_tex($parstack,$parser,$safeeval);
 2194:     }
 2195:     return $currentstring;
 2196: }
 2197: 
 2198: #-- <th> tag (end tag optional)
 2199: sub start_th {
 2200:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2201:     my $currentstring = '';
 2202:     if ($target eq 'web') {
 2203: 	$currentstring = $token->[4];     
 2204:     } elsif ($target eq 'tex') {
 2205: 	my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
 2206: 	if ($what_to_push eq '') {
 2207: 	    $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);;
 2208: 	}
 2209: 	push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push;
 2210: 	$Apache::londefdef::table[-1]{'counter_columns'}++;
 2211: 	&Apache::lonxml::startredirection();
 2212:     } 
 2213:     return $currentstring;
 2214: }   
 2215:      
 2216: sub end_th {
 2217:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2218:     my $currentstring = '';
 2219:     if ($target eq 'web') {
 2220: 	$currentstring = $token->[2];     
 2221:     } elsif ($target eq 'tex') {
 2222: 	my $current_row = $Apache::londefdef::table[-1]{'row_number'};
 2223: 	my $data=&Apache::lonxml::endredirection();
 2224: 	my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
 2225: 	if (defined $TeXwidth) {		
 2226: 	    my $current_length=&recalc($TeXwidth);
 2227: 	    $current_length=~/(\d+)/;
 2228: 	    $Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
 2229: 	    $Apache::londefdef::table[-1]{'length'} .= '0,';
 2230: 	} else {
 2231: 	    if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
 2232: 		my $current_length=&recalc($1);
 2233: 		$current_length=~/(\d+)/;
 2234: 		$Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
 2235: 		$Apache::londefdef::table[-1]{'length'} .= '0,';
 2236: 	    } else {     
 2237: 		$data=~/^\s*(\S.*)/;
 2238: 		$data=$1;
 2239: 		$data=~/(.*\S)\s*$/;
 2240: 		$data=$1;
 2241: 		my $current_length=2*length($data);
 2242: 		$Apache::londefdef::table[-1]{'length'} .= $current_length.',';
 2243: 		$Apache::londefdef::table[-1]{'TeXlength'} .= '0,';
 2244: 	    }        
 2245: 	}
 2246: 	for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {                                
 2247: 	    $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
 2248: 	}
 2249: 	$data='\textbf{'.$data.'}';
 2250: 	@{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'};
 2251:     }
 2252:     return $currentstring;
 2253: }
 2254: #-- <img> tag (end tag forbidden)
 2255: sub start_img {
 2256:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2257:     my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,
 2258: 					 undef,1);
 2259:     if (not $src and ($target eq 'web' or $target eq 'tex')) { 
 2260: 	my $inside = &Apache::lonxml::get_all_text("/img",$parser);
 2261: 	&Apache::lonnet::logthis("inside was $inside");
 2262: 	return '';
 2263:     }
 2264:     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
 2265:     my $currentstring = '';
 2266:     my $scaling = .3;
 2267:     if ($target eq 'web') {
 2268: 	if ($ENV{'browser.imagesuppress'} ne 'on') {
 2269: 	    $currentstring.= $token->[4];
 2270: 	} else {
 2271: 	    my $alttag= &Apache::lonxml::get_param
 2272: 		('alt',$parstack,$safeeval,undef,1);
 2273: 	    unless ($alttag) {
 2274: 		$alttag=&Apache::lonmeta::alttag
 2275: 		    ($Apache::lonxml::pwd[-1],$src);
 2276: 	    }
 2277: 	    $currentstring.='[IMAGE: '.$alttag.']';
 2278: 	}
 2279:     } elsif ($target eq 'tex') {
 2280: 	$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
 2281:         #if uploaded restore the path
 2282: 	if ($src=~/^\/uploaded\/([^\/]+)\/([^\/]+)\/simplepage\/([^\/]+)$/) {
 2283: 	    $src=&Apache::loncommon::propath($1,$2).'/userfiles/simplepage/'.$3;
 2284: 	} elsif ($src=~/^\/uploaded\/([^\/]+)\/([^\/]+)\/aboutme\/([^\/]+)$/) {
 2285: 	    $src=&Apache::loncommon::propath($1,$2).'/userfiles/aboutme/'.$3;
 2286: 	}
 2287: 	#if original gif/jpg/png file exist do following:
 2288: 	if (-e $src) {
 2289: 	    #what is the image size?
 2290: 	    my $width_param=&image_size($src,$scaling,$parstack,$safeeval);
 2291:             my ($file,$path)=&file_path($src); 
 2292: 	    my $newsrc = $src;
 2293: 	    $newsrc =~ s/\.(gif|jpg|png)$/.eps/i;
 2294: 	    $file=~s/\.(gif|jpg|png)$/.eps/i;
 2295: 	    #where can we find the picture?
 2296: 	    if (-e $newsrc) {
 2297: 		#eps counterpart for image exist 
 2298: 		if ($path) {
 2299: 		    $currentstring .= '\vskip 1 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
 2300: 		}
 2301: 	    } else {
 2302: 		#there is no eps counterpart for image - check for ps one
 2303: 		$newsrc =~ s/\.eps$/\.ps/;
 2304: 		if (-e $newsrc) {
 2305: 		    #ps counterpart for image exist 
 2306: 		    $file =~ s/\.eps$/\.ps/;
 2307: 		    if ($path) {
 2308: 			$currentstring .= '\vskip 1 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
 2309: 		    }
 2310: 		} else {
 2311: 		    #care about eps dynamical generation
 2312: 		    $currentstring.='\vskip 1 mm '.&eps_generation($src,$file,$width_param);
 2313: 		}
 2314: 	    }
 2315: 	} else {
 2316: 	    #original image file doesn't exist so check the alt attribute
 2317: 	    my $alt = 
 2318: 		&Apache::lonxml::get_param('alt',$parstack,$safeeval,undef,1);
 2319: 	    unless ($alt) {
 2320: 		$alt=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
 2321: 	    }
 2322: 
 2323: 	    if ($alt) {
 2324: 		$currentstring .= ' '.$alt.' ';
 2325: 	    } else {
 2326: 		#<allow> tag will care about replication 
 2327: 	    }
 2328: 	}
 2329:     } elsif ($target eq 'edit') {
 2330: 	$currentstring .=&Apache::edit::tag_start($target,$token);
 2331: 	$currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70).
 2332: 	    &Apache::edit::browse('src',undef,'alt').' '.
 2333: 	    &Apache::edit::search('src',undef,'alt').'<br />';
 2334: 	$currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'<br />';
 2335: 	$currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5);
 2336: 	$currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'<br />';
 2337: 	$currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5);
 2338: 	$currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5);
 2339: 	$currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
 2340: 	my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval);
 2341: 	my $alt=&Apache::lonxml::get_param('alt',$parstack,$safeeval);
 2342: 	my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval);
 2343: 	my $height=&Apache::lonxml::get_param('height',$parstack,$safeeval);
 2344: 	$currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
 2345: 	if ($width) { $currentstring.=' width="'.$width.'" '; }
 2346: 	if ($height) { $currentstring.=' height="'.$height.'" '; }
 2347: 	$currentstring .= ' />';
 2348:     } elsif ($target eq 'modified') {
 2349: 	my ($osrc,$owidth,$oheight)=
 2350: 	    ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
 2351: 	my $ctag=&Apache::edit::get_new_args($token,$parstack,
 2352: 					     $safeeval,'src','alt',
 2353: 					     'TeXwidth','TeXheight',
 2354: 					     'width','height');
 2355: 	my ($nsrc,$nwidth,$nheight)=
 2356: 	    ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
 2357: 	my $loc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$nsrc);
 2358: 	&image_replication($loc);
 2359: 	my ($iwidth,$iheight);
 2360: 	if (-e $loc) {
 2361: 	    my $image = Image::Magick->new;
 2362: 	    $image->Read($loc);
 2363: 	    ($iwidth, $iheight) = ($image->Get('width'),
 2364: 				   $image->Get('height'));
 2365: 	}
 2366: 	if ($osrc ne $nsrc || (!$nwidth && !$nheight)) {
 2367: 	    # changed image or no size specified,
 2368:             # if they didn't explicitly change the 
 2369:             # width or height use the ones from the image
 2370: 	    if ($iwidth && $iheight) {
 2371: 		if ($owidth == $nwidth || (!$nwidth && !$nheight)) {
 2372: 		    $token->[2]{'width'} = $iwidth;$ctag=1;
 2373: 		}
 2374: 		if ($oheight == $nheight || (!$nwidth && !$nheight)) {
 2375: 		    $token->[2]{'height'}=$iheight;$ctag=1;
 2376: 		}
 2377: 	    }
 2378: 	}
 2379: 	my ($cwidth,$cheight)=($token->[2]{'width'},$token->[2]{'height'});
 2380: 	# if we don't have a width or height
 2381: 	if ($iwidth && $cwidth && !$cheight) {
 2382: 	    $token->[2]{'height'}=int(($cwidth/$iwidth)*$iheight);$ctag=1;
 2383: 	}
 2384: 	if ($iheight && $cheight && !$cwidth) {
 2385: 	    $token->[2]{'width'}=int(($cheight/$iheight)*$iwidth);$ctag=1;
 2386: 	}
 2387: 	if ($ctag) {$currentstring=&Apache::edit::rebuild_tag($token);}
 2388:     }
 2389:     return $currentstring;
 2390: }
 2391: 
 2392: sub end_img {
 2393:     my ($target,$token) = @_;
 2394:     my $currentstring = '';
 2395:     if ($target eq 'web') {
 2396: 	$currentstring = $token->[2];
 2397:     } elsif ($target eq 'tex') {
 2398: 	$currentstring = '';
 2399:     }
 2400:     return $currentstring;
 2401: }
 2402: 
 2403: #-- <applet> tag (end tag required)
 2404: sub start_applet {
 2405:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2406:     
 2407:     my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,undef,1);
 2408:     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$code;
 2409:     
 2410:     my $archive=&Apache::lonxml::get_param('archive',$parstack,$safeeval,
 2411: 					   undef,1);
 2412:     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$archive;
 2413:     
 2414:     my $currentstring = '';
 2415:     if ($target eq 'web') {
 2416: 	if ($ENV{'browser.appletsuppress'} ne 'on') {
 2417: 	    $currentstring = $token->[4];
 2418: 	} else {
 2419: 	    my $alttag= &Apache::lonxml::get_param('alt',$parstack,
 2420: 						   $safeeval,undef,1);
 2421: 	    unless ($alttag) {
 2422: 		$alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
 2423: 						 $code);
 2424: 	    }
 2425: 	    $currentstring='[APPLET: '.$alttag.']';
 2426: 	}
 2427:     } elsif ($target eq 'tex') {
 2428: 	my $alttag= &Apache::lonxml::get_param('alt',$parstack,
 2429: 					       $safeeval,undef,1);
 2430: 	unless ($alttag) {
 2431: 	    my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,
 2432: 						undef,1);
 2433: 	    $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
 2434: 					     $code);
 2435: 	}
 2436: 	$currentstring.='\begin{center} \fbox{Java Applet: '.$alttag.
 2437: 	    '.}\end{center}';
 2438:     } 
 2439:     return $currentstring;
 2440: }
 2441: 
 2442: sub end_applet {
 2443:     my ($target,$token) = @_;
 2444:     my $currentstring = '';
 2445:     if ($target eq 'web') {
 2446: 	$currentstring = $token->[2];
 2447:     } elsif ($target eq 'tex') {
 2448:     } 
 2449:     return $currentstring;
 2450: }
 2451: 
 2452: #-- <embed> tag (end tag optional/required)
 2453: sub start_embed {    
 2454:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2455:     my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
 2456:     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
 2457:     my $currentstring = '';
 2458:     if ($target eq 'web') {
 2459: 	if ($ENV{'browser.embedsuppress'} ne 'on') {
 2460: 	    $currentstring = $token->[4];
 2461: 	} else {
 2462: 	    my $alttag=&Apache::lonxml::get_param
 2463: 		('alt',$parstack,$safeeval,undef,1);
 2464: 	    unless ($alttag) {
 2465: 		$alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
 2466: 	    }
 2467: 	    $currentstring='[EMBED: '.$alttag.']';
 2468: 	}
 2469:     } elsif ($target eq 'tex') {
 2470:     } 
 2471:     return $currentstring;
 2472: }
 2473: 
 2474: sub end_embed {
 2475:     my ($target,$token) = @_;
 2476:     my $currentstring = '';
 2477:     if ($target eq 'web') {
 2478: 	$currentstring = $token->[2];     
 2479:     } elsif ($target eq 'tex') {  
 2480:     } 
 2481:     return $currentstring;
 2482: }
 2483: 
 2484: #-- <param> tag (end tag forbidden)
 2485: sub start_param {
 2486:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2487:     if (&Apache::lonxml::get_param
 2488: 	('name',$parstack,$safeeval,undef,1)=~/^cabbase$/i) {
 2489: 	$Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
 2490: 	    &Apache::lonxml::get_param('value',$parstack,$safeeval,undef,1);
 2491:     }   
 2492:     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=   
 2493: 	&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
 2494:     my $currentstring = '';
 2495:     if ($target eq 'web') {
 2496: 	$currentstring = $token->[4];     
 2497:     } elsif ($target eq 'tex') {
 2498:     } 
 2499:     return $currentstring;
 2500: }
 2501: 
 2502: sub end_param {
 2503:     my ($target,$token) = @_;
 2504:     my $currentstring = '';
 2505:     if ($target eq 'web') {
 2506: 	$currentstring = $token->[2];     
 2507:     } elsif ($target eq 'tex') {
 2508:     } 
 2509:     return $currentstring;
 2510: }
 2511: 
 2512: #-- <allow> tag
 2513: sub start_allow {
 2514:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2515:     my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
 2516:     $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
 2517:     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
 2518: 	&Apache::lonnet::clutter($src);
 2519:     &image_replication($src);
 2520:     my $result;
 2521:     if ($target eq 'edit') {
 2522: 	$result .=&Apache::edit::tag_start($target,$token);
 2523: 	$result .=&Apache::edit::text_arg('File Spec:','src',$token,70);
 2524: 	$result .=&Apache::edit::end_row();#.&Apache::edit::start_spanning_row();
 2525:     } elsif ($target eq 'modified') {
 2526: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
 2527: 						     $safeeval,'src');
 2528: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
 2529:     }
 2530:     return $result;
 2531: }
 2532: 
 2533: sub end_allow {
 2534:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2535:     if ( $target eq 'edit') { return (&Apache::edit::end_table()); }
 2536:     return '';
 2537: }
 2538: 
 2539: #-- Frames (end tag required)
 2540: #-- <frameset>
 2541: sub start_frameset {
 2542:     my ($target,$token) = @_;
 2543:     my $currentstring = '';
 2544:     if ($target eq 'web') { 
 2545: 	if (!$Apache::lonxml::registered &&
 2546: 	    $ENV{'request.state'} eq 'published') {
 2547: 	    $currentstring.='<head>'.
 2548: 		&Apache::lonmenu::registerurl(undef,$target).'</head>';
 2549: 	}
 2550: 	my $onLoad='';
 2551: 	foreach my $key (keys(%{$token->[2]})) {
 2552: 	    if ($key =~ /^onload$/i) {
 2553: 		$onLoad.=$token->[2]->{$key}.';';
 2554: 		delete($token->[2]->{$key});
 2555: 	    }
 2556: 	}
 2557: 	$token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad;
 2558: 	my $onUnload='';
 2559: 	foreach my $key (keys(%{$token->[2]})) {
 2560: 	    if ($key =~ /^onunload$/i) {
 2561: 		$onUnload.=$token->[2]->{$key}.';';
 2562: 		delete($token->[2]->{$key});
 2563: 	    }
 2564: 	}
 2565: 	$token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents().
 2566: 	    ';'.$onUnload;
 2567: 	
 2568: 	$currentstring .= '<'.$token->[1];
 2569: 	foreach (keys %{$token->[2]}) {
 2570: 	    $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
 2571: 	}
 2572: 	$currentstring.='>';
 2573:     }
 2574:     return $currentstring;
 2575: }
 2576: 
 2577: sub end_frameset {
 2578:     my ($target,$token) = @_;
 2579:     my $currentstring = '';
 2580:     if ($target eq 'web') {
 2581: 	$currentstring = $token->[2];
 2582:     }
 2583:     return $currentstring;
 2584: }
 2585: 
 2586: #-- <xmp> (end tag required)
 2587: sub start_xmp {
 2588:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2589:     my $currentstring = '';
 2590:     if ($target eq 'web') {
 2591: 	$currentstring .= $token->[4];
 2592:     } elsif ($target eq 'tex') {
 2593: 	$currentstring .= '\begin{verbatim}';
 2594:     } 
 2595:     return $currentstring;
 2596: }
 2597: 
 2598: sub end_xmp {
 2599:     my ($target,$token) = @_;
 2600:     my $currentstring = '';
 2601:     if ($target eq 'web') {
 2602: 	$currentstring .= $token->[2];
 2603:     } elsif ($target eq 'tex') {
 2604: 	$currentstring .= '\end{verbatim}';
 2605:     }
 2606:     return $currentstring;
 2607: }
 2608: 
 2609: #-- <pre> (end tag required)
 2610: sub start_pre {
 2611:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2612:     my $currentstring = '';
 2613:     if ($target eq 'web') {
 2614: 	$currentstring .= $token->[4];
 2615:     } elsif ($target eq 'tex') {
 2616: 	$currentstring .= '\begin{verbatim}';
 2617:     } 
 2618:     return $currentstring;
 2619: }
 2620: 
 2621: sub end_pre {
 2622:     my ($target,$token) = @_;
 2623:     my $currentstring = '';
 2624:     if ($target eq 'web') {
 2625: 	$currentstring .= $token->[2];
 2626:     } elsif ($target eq 'tex') {
 2627: 	$currentstring .= '\end{verbatim}';
 2628:     }
 2629:     return $currentstring;
 2630: }
 2631: 
 2632: #-- <insert>
 2633: sub start_insert {
 2634:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2635:     my $currentstring = '';
 2636:     if ($target eq 'web') {
 2637: 	my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
 2638: 	$currentstring .= '<b>'.$display.'</b>';;
 2639:     }
 2640:     return $currentstring;
 2641: }
 2642: 
 2643: sub end_insert {
 2644:     my ($target,$token) = @_;
 2645:     my $currentstring = '';
 2646:     if ($target eq 'web') {
 2647: 	$currentstring .= '';
 2648:     }
 2649:     return $currentstring;
 2650: }
 2651: 
 2652: #-- <externallink>
 2653: sub start_externallink {
 2654:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2655:     my $currentstring = '';
 2656:     if ($target eq 'web') {
 2657: 	my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
 2658: 	$currentstring .= '<b>'.$display.'</b>';;
 2659:     }
 2660:     return $currentstring;
 2661: }
 2662: 
 2663: sub end_externallink {
 2664:     my ($target,$token) = @_;
 2665:     my $currentstring = '';
 2666:     if ($target eq 'web') {
 2667: 	$currentstring .= '';
 2668:     }
 2669:     return $currentstring;
 2670: }
 2671: 
 2672: #-- <blankspace heigth="">
 2673: sub start_blankspace {
 2674:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2675:     my $currentstring = '';
 2676:     if ($target eq 'tex') {
 2677: 	my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval,undef,1);
 2678: 	$currentstring .= '\vskip '.$howmuch.' ';
 2679:     }
 2680:     return $currentstring;
 2681: }
 2682: 
 2683: sub end_blankspace {
 2684:     my ($target,$token) = @_;
 2685:     my $currentstring = '';
 2686:     if ($target eq 'tex') {
 2687: 	$currentstring .= '';
 2688:     }
 2689:     return $currentstring;
 2690: }
 2691: 
 2692: #-- <abbr> tag (end tag required)
 2693: sub start_abbr {
 2694:     my ($target,$token) = @_;
 2695:     my $currentstring = '';
 2696:     if ($target eq 'web') {
 2697: 	$currentstring = $token->[4];     
 2698:     } 
 2699:     return $currentstring;
 2700: }
 2701: 
 2702: sub end_abbr {
 2703:     my ($target,$token) = @_;
 2704:     my $currentstring = '';
 2705:     if ($target eq 'web') {
 2706: 	$currentstring = $token->[2];    
 2707:     } 
 2708:     return $currentstring;
 2709: }
 2710: 
 2711: #-- <acronym> tag (end tag required)
 2712: sub start_acronym {
 2713:     my ($target,$token) = @_;
 2714:     my $currentstring = '';
 2715:     if ($target eq 'web') {
 2716: 	$currentstring = $token->[4];     
 2717:     } 
 2718:     return $currentstring;
 2719: }
 2720: 
 2721: sub end_acronym {
 2722:     my ($target,$token) = @_;
 2723:     my $currentstring = '';
 2724:     if ($target eq 'web') {
 2725: 	$currentstring = $token->[2];    
 2726:     } 
 2727:     return $currentstring;
 2728: }
 2729: 
 2730: #-- <area> tag (end tag forbidden)
 2731: sub start_area {
 2732:     my ($target,$token) = @_;
 2733:     my $currentstring = '';
 2734:     if ($target eq 'web') {
 2735: 	$currentstring = $token->[4];     
 2736:     } 
 2737:     return $currentstring;
 2738: }
 2739: 
 2740: sub end_area {
 2741:     my ($target,$token) = @_;
 2742:     my $currentstring = '';
 2743:     if ($target eq 'web') {
 2744: 	$currentstring = $token->[2];    
 2745:     } 
 2746:     return $currentstring;
 2747: }
 2748: 
 2749: #-- <base> tag (end tag forbidden)
 2750: sub start_base {
 2751:     my ($target,$token) = @_;
 2752:     my $currentstring = '';
 2753:     if ($target eq 'web') {
 2754: 	$currentstring = $token->[4];     
 2755:     }
 2756:     return $currentstring;
 2757: }
 2758: 
 2759: sub end_base {
 2760:     my ($target,$token) = @_;
 2761:     my $currentstring = '';
 2762:     if ($target eq 'web') {
 2763: 	$currentstring = $token->[2];    
 2764:     } 
 2765:     return $currentstring;
 2766: }
 2767: 
 2768: #-- <bdo> tag (end tag required)
 2769: sub start_bdo {
 2770:     my ($target,$token) = @_;
 2771:     my $currentstring = '';
 2772:     if ($target eq 'web') {
 2773: 	$currentstring = $token->[4];     
 2774:     } 
 2775:     return $currentstring;
 2776: }
 2777: 
 2778: sub end_bdo {
 2779:     my ($target,$token) = @_;
 2780:     my $currentstring = '';
 2781:     if ($target eq 'web') {
 2782: 	$currentstring = $token->[2];    
 2783:     } 
 2784:     return $currentstring;
 2785: }
 2786: 
 2787: #-- <bgsound> tag (end tag optional)
 2788: sub start_bgsound {
 2789:     my ($target,$token) = @_;
 2790:     my $currentstring = '';
 2791:     if ($target eq 'web') {
 2792: 	$currentstring = $token->[4];     
 2793:     } 
 2794:     return $currentstring;
 2795: }
 2796: 
 2797: sub end_bgsound {
 2798:     my ($target,$token) = @_;
 2799:     my $currentstring = '';
 2800:     if ($target eq 'web') {
 2801: 	$currentstring = $token->[2];    
 2802:     } 
 2803:     return $currentstring;
 2804: }
 2805: 
 2806: #-- <blink> tag (end tag required)
 2807: sub start_blink {
 2808:     my ($target,$token) = @_;
 2809:     my $currentstring = '';
 2810:     if ($target eq 'web') {
 2811: 	$currentstring = $token->[4];     
 2812:     } 
 2813:     return $currentstring;
 2814: }
 2815: 
 2816: sub end_blink {
 2817:     my ($target,$token) = @_;
 2818:     my $currentstring = '';
 2819:     if ($target eq 'web') {
 2820: 	$currentstring = $token->[2];    
 2821:     } 
 2822:     return $currentstring;
 2823: }
 2824: 
 2825: #-- <blockquote> tag (end tag required)
 2826: sub start_blockquote {
 2827:     my ($target,$token) = @_;
 2828:     my $currentstring = '';
 2829:     if ($target eq 'web') {
 2830: 	$currentstring = $token->[4];     
 2831:     } 
 2832:     return $currentstring;
 2833: }
 2834: 
 2835: sub end_blockquote {
 2836:     my ($target,$token) = @_;
 2837:     my $currentstring = '';
 2838:     if ($target eq 'web') {
 2839: 	$currentstring = $token->[2];    
 2840:     } 
 2841:     return $currentstring;
 2842: }
 2843: 
 2844: #-- <button> tag (end tag required)
 2845: sub start_button {
 2846:     my ($target,$token) = @_;
 2847:     my $currentstring = '';
 2848:     if ($target eq 'web') {
 2849: 	$currentstring = $token->[4];     
 2850:     } 
 2851:     return $currentstring;
 2852: }
 2853: 
 2854: sub end_button {
 2855:     my ($target,$token) = @_;
 2856:     my $currentstring = '';
 2857:     if ($target eq 'web') {
 2858: 	$currentstring = $token->[2];    
 2859:     } 
 2860:     return $currentstring;
 2861: }
 2862: 
 2863: #-- <caption> tag (end tag required)
 2864: sub start_caption {
 2865:     my ($target,$token) = @_;
 2866:     my $currentstring = '';
 2867:     if ($target eq 'web') {
 2868: 	$currentstring = $token->[4];     
 2869:     } 
 2870:     return $currentstring;
 2871: }
 2872: 
 2873: sub end_caption {
 2874:     my ($target,$token) = @_;
 2875:     my $currentstring = '';
 2876:     if ($target eq 'web') {
 2877: 	$currentstring = $token->[2];    
 2878:     } 
 2879:     return $currentstring;
 2880: }
 2881: 
 2882: #-- <col> tag (end tag forbdden)
 2883: sub start_col {
 2884:     my ($target,$token) = @_;
 2885:     my $currentstring = '';
 2886:     if ($target eq 'web') {
 2887: 	$currentstring = $token->[4];     
 2888:     } 
 2889:     return $currentstring;
 2890: }
 2891: 
 2892: sub end_col {
 2893:     my ($target,$token) = @_;
 2894:     my $currentstring = '';
 2895:     if ($target eq 'web') {
 2896: 	$currentstring = $token->[2];    
 2897:     } 
 2898:     return $currentstring;
 2899: }
 2900: 
 2901: #-- <colgroup> tag (end tag optional)
 2902: sub start_colgroup {
 2903:     my ($target,$token) = @_;
 2904:     my $currentstring = '';
 2905:     if ($target eq 'web') {
 2906: 	$currentstring = $token->[4];     
 2907:     } 
 2908:     return $currentstring;
 2909: }
 2910: 
 2911: sub end_colgroup {
 2912:     my ($target,$token) = @_;
 2913:     my $currentstring = '';
 2914:     if ($target eq 'web') {
 2915: 	$currentstring = $token->[2];    
 2916:     } 
 2917:     return $currentstring;
 2918: }
 2919: 
 2920: #-- <del> tag (end tag required)
 2921: sub start_del {
 2922:     my ($target,$token) = @_;
 2923:     my $currentstring = '';
 2924:     if ($target eq 'web') {
 2925: 	$currentstring = $token->[4];     
 2926:     } 
 2927:     return $currentstring;
 2928: }
 2929: 
 2930: sub end_del {
 2931:     my ($target,$token) = @_;
 2932:     my $currentstring = '';
 2933:     if ($target eq 'web') {
 2934: 	$currentstring = $token->[2];    
 2935:     } 
 2936:     return $currentstring;
 2937: }
 2938: 
 2939: #-- <fieldset> tag (end tag required)
 2940: sub start_fieldset {
 2941:     my ($target,$token) = @_;
 2942:     my $currentstring = '';
 2943:     if ($target eq 'web') {
 2944: 	$currentstring = $token->[4];     
 2945:     } 
 2946:     return $currentstring;
 2947: }
 2948: 
 2949: sub end_fieldset {
 2950:     my ($target,$token) = @_;
 2951:     my $currentstring = '';
 2952:     if ($target eq 'web') {
 2953: 	$currentstring = $token->[2];    
 2954:     } 
 2955:     return $currentstring;
 2956: }
 2957: 
 2958: #-- <frame> tag (end tag forbidden)
 2959: sub start_frame {
 2960:     my ($target,$token) = @_;
 2961:     my $currentstring = '';
 2962:     if ($target eq 'web') {
 2963: 	$currentstring = $token->[4];     
 2964:     } 
 2965:     return $currentstring;
 2966: }
 2967: 
 2968: sub end_frame {
 2969:     my ($target,$token) = @_;
 2970:     my $currentstring = '';
 2971:     if ($target eq 'web') {
 2972: 	$currentstring = $token->[2];    
 2973:     } 
 2974:     return $currentstring;
 2975: }
 2976: 
 2977: #-- <iframe> tag (end tag required)
 2978: sub start_iframe {
 2979:     my ($target,$token) = @_;
 2980:     my $currentstring = '';
 2981:     if ($target eq 'web') {
 2982: 	$currentstring = $token->[4];     
 2983:     } 
 2984:     return $currentstring;
 2985: }
 2986: 
 2987: sub end_iframe {
 2988:     my ($target,$token) = @_;
 2989:     my $currentstring = '';
 2990:     if ($target eq 'web') {
 2991: 	$currentstring = $token->[2];    
 2992:     } 
 2993:     return $currentstring;
 2994: }
 2995: 
 2996: #-- <ins> tag (end tag required)
 2997: sub start_ins {
 2998:     my ($target,$token) = @_;
 2999:     my $currentstring = '';
 3000:     if ($target eq 'web') {
 3001: 	$currentstring = $token->[4];     
 3002:     } 
 3003:     return $currentstring;
 3004: }
 3005: 
 3006: sub end_ins {
 3007:     my ($target,$token) = @_;
 3008:     my $currentstring = '';
 3009:     if ($target eq 'web') {
 3010: 	$currentstring = $token->[2];    
 3011:     } 
 3012:     return $currentstring;
 3013: }
 3014: 
 3015: #-- <isindex> tag (end tag forbidden)
 3016: sub start_isindex {
 3017:     my ($target,$token) = @_;
 3018:     my $currentstring = '';
 3019:     if ($target eq 'web') {
 3020: 	$currentstring = $token->[4];     
 3021:     } 
 3022:     return $currentstring;
 3023: }
 3024: 
 3025: sub end_isindex {
 3026:     my ($target,$token) = @_;
 3027:     my $currentstring = '';
 3028:     if ($target eq 'web') {
 3029: 	$currentstring = $token->[2];    
 3030:     } 
 3031:     return $currentstring;
 3032: }
 3033: 
 3034: #-- <keygen> tag (end tag forbidden)
 3035: sub start_keygen {
 3036:     my ($target,$token) = @_;
 3037:     my $currentstring = '';
 3038:     if ($target eq 'web') {
 3039: 	$currentstring = $token->[4];     
 3040:     } 
 3041:     return $currentstring;
 3042: }
 3043: 
 3044: sub end_keygen {
 3045:     my ($target,$token) = @_;
 3046:     my $currentstring = '';
 3047:     if ($target eq 'web') {
 3048: 	$currentstring = $token->[2];    
 3049:     } 
 3050:     return $currentstring;
 3051: }
 3052: 
 3053: #-- <label> tag
 3054: sub start_label {
 3055:     my ($target,$token) = @_;
 3056:     my $currentstring = '';
 3057:     if ($target eq 'web') {
 3058: 	$currentstring = $token->[4];     
 3059:     } 
 3060:     return $currentstring;
 3061: }
 3062: 
 3063: sub end_label {
 3064:     my ($target,$token) = @_;
 3065:     my $currentstring = '';
 3066:     if ($target eq 'web') {
 3067: 	$currentstring = $token->[2];    
 3068:     } 
 3069:     return $currentstring;
 3070: }
 3071: 
 3072: #-- <layer> tag (end tag required)
 3073: sub start_layer {
 3074:     my ($target,$token) = @_;
 3075:     my $currentstring = '';
 3076:     if ($target eq 'web') {
 3077: 	$currentstring = $token->[4];     
 3078:     } 
 3079:     return $currentstring;
 3080: }
 3081: 
 3082: sub end_layer {
 3083:     my ($target,$token) = @_;
 3084:     my $currentstring = '';
 3085:     if ($target eq 'web') {
 3086: 	$currentstring = $token->[2];    
 3087:     } 
 3088:     return $currentstring;
 3089: }
 3090: 
 3091: #-- <legend> tag (end tag required)
 3092: sub start_legend {
 3093:     my ($target,$token) = @_;
 3094:     my $currentstring = '';
 3095:     if ($target eq 'web') {
 3096: 	$currentstring = $token->[4];     
 3097:     } 
 3098:     return $currentstring;
 3099: }
 3100: 
 3101: sub end_legend {
 3102:     my ($target,$token) = @_;
 3103:     my $currentstring = '';
 3104:     if ($target eq 'web') {
 3105: 	$currentstring = $token->[2];    
 3106:     } 
 3107:     return $currentstring;
 3108: }
 3109: 
 3110: #-- <link> tag (end tag forbidden)
 3111: sub start_link {
 3112:     my ($target,$token) = @_;
 3113:     my $currentstring = '';
 3114:     if ($target eq 'web') {
 3115: 	$currentstring = $token->[4];     
 3116:     } 
 3117:     return $currentstring;
 3118: }
 3119: 
 3120: sub end_link {
 3121:     my ($target,$token) = @_;
 3122:     my $currentstring = '';
 3123:     if ($target eq 'web') {
 3124: 	$currentstring = $token->[2];    
 3125:     } 
 3126:     return $currentstring;
 3127: }
 3128: 
 3129: #-- <marquee> tag (end tag optional)
 3130: sub start_marquee {
 3131:     my ($target,$token) = @_;
 3132:     my $currentstring = '';
 3133:     if ($target eq 'web') {
 3134: 	$currentstring = $token->[4];     
 3135:     } 
 3136:     return $currentstring;
 3137: }
 3138: 
 3139: sub end_marquee {
 3140:     my ($target,$token) = @_;
 3141:     my $currentstring = '';
 3142:     if ($target eq 'web') {
 3143: 	$currentstring = $token->[2];    
 3144:     } 
 3145:     return $currentstring;
 3146: }
 3147: 
 3148: #-- <multicol> tag (end tag required)
 3149: sub start_multicol {
 3150:     my ($target,$token) = @_;
 3151:     my $currentstring = '';
 3152:     if ($target eq 'web') {
 3153: 	$currentstring = $token->[4];     
 3154:     } 
 3155:     return $currentstring;
 3156: }
 3157: 
 3158: sub end_multicol {
 3159:     my ($target,$token) = @_;
 3160:     my $currentstring = '';
 3161:     if ($target eq 'web') {
 3162: 	$currentstring = $token->[2];    
 3163:     } 
 3164:     return $currentstring;
 3165: }
 3166: 
 3167: #-- <nobr> tag (end tag required)
 3168: sub start_nobr {
 3169:     my ($target,$token) = @_;
 3170:     my $currentstring = '';
 3171:     if ($target eq 'web') {
 3172: 	$currentstring = $token->[4];     
 3173:     }  elsif ($target eq 'tex') {
 3174: 	$currentstring='\mbox{';
 3175:     }
 3176:     return $currentstring;
 3177: }
 3178: 
 3179: sub end_nobr {
 3180:     my ($target,$token) = @_;
 3181:     my $currentstring = '';
 3182:     if ($target eq 'web') {
 3183: 	$currentstring = $token->[2];    
 3184:     }   elsif ($target eq 'tex') {
 3185: 	$currentstring='}';
 3186:     }
 3187:     return $currentstring;
 3188: }
 3189: 
 3190: #-- <noembed> tag (end tag required)
 3191: sub start_noembed {
 3192:     my ($target,$token) = @_;
 3193:     my $currentstring = '';
 3194:     if ($target eq 'web') {
 3195: 	$currentstring = $token->[4];     
 3196:     } 
 3197:     return $currentstring;
 3198: }
 3199: 
 3200: sub end_noembed {
 3201:     my ($target,$token) = @_;
 3202:     my $currentstring = '';
 3203:     if ($target eq 'web') {
 3204: 	$currentstring = $token->[2];    
 3205:     } 
 3206:     return $currentstring;
 3207: }
 3208: 
 3209: #-- <noframes> tag (end tag required)
 3210: sub start_noframes {
 3211:     my ($target,$token) = @_;
 3212:     my $currentstring = '';
 3213:     if ($target eq 'web') {
 3214: 	$currentstring = $token->[4];     
 3215:     } 
 3216:     return $currentstring;
 3217: }
 3218: 
 3219: sub end_noframes {
 3220:     my ($target,$token) = @_;
 3221:     my $currentstring = '';
 3222:     if ($target eq 'web') {
 3223: 	$currentstring = $token->[2];    
 3224:     } 
 3225:     return $currentstring;
 3226: }
 3227: 
 3228: #-- <nolayer> tag (end tag required)
 3229: sub start_nolayer {
 3230:     my ($target,$token) = @_;
 3231:     my $currentstring = '';
 3232:     if ($target eq 'web') {
 3233: 	$currentstring = $token->[4];     
 3234:     } 
 3235:     return $currentstring;
 3236: }
 3237: 
 3238: sub end_nolayer {
 3239:     my ($target,$token) = @_;
 3240:     my $currentstring = '';
 3241:     if ($target eq 'web') {
 3242: 	$currentstring = $token->[2];    
 3243:     } 
 3244:     return $currentstring;
 3245: }
 3246: 
 3247: #-- <noscript> tag (end tag required)
 3248: sub start_noscript {
 3249:     my ($target,$token) = @_;
 3250:     my $currentstring = '';
 3251:     if ($target eq 'web') {
 3252: 	$currentstring = $token->[4];     
 3253:     } 
 3254:     return $currentstring;
 3255: }
 3256: 
 3257: sub end_noscript {
 3258:     my ($target,$token) = @_;
 3259:     my $currentstring = '';
 3260:     if ($target eq 'web') {
 3261: 	$currentstring = $token->[2];    
 3262:     } 
 3263:     return $currentstring;
 3264: }
 3265: 
 3266: #-- <object> tag (end tag required)
 3267: sub start_object {
 3268:     my ($target,$token) = @_;
 3269:     my $currentstring = '';
 3270:     if ($target eq 'web') {
 3271: 	$currentstring = $token->[4];     
 3272:     } 
 3273:     return $currentstring;
 3274: }
 3275: 
 3276: sub end_object {
 3277:     my ($target,$token) = @_;
 3278:     my $currentstring = '';
 3279:     if ($target eq 'web') {
 3280: 	$currentstring = $token->[2];    
 3281:     } 
 3282:     return $currentstring;
 3283: }
 3284: 
 3285: #-- <optgroup> tag (end tag required)
 3286: sub start_optgroup {
 3287:     my ($target,$token) = @_;
 3288:     my $currentstring = '';
 3289:     if ($target eq 'web') {
 3290: 	$currentstring = $token->[4];     
 3291:     } 
 3292:     return $currentstring;
 3293: }
 3294: 
 3295: sub end_optgroup {
 3296:     my ($target,$token) = @_;
 3297:     my $currentstring = '';
 3298:     if ($target eq 'web') {
 3299: 	$currentstring = $token->[2];    
 3300:     } 
 3301:     return $currentstring;
 3302: }
 3303: 
 3304: #-- <samp> tag (end tag required)
 3305: sub start_samp {
 3306:     my ($target,$token) = @_;
 3307:     my $currentstring = '';
 3308:     if ($target eq 'web') {
 3309: 	$currentstring = $token->[4];     
 3310:     } elsif ($target eq 'tex') {
 3311: 	$currentstring='\texttt{';
 3312:     }
 3313:     return $currentstring;
 3314: }
 3315: 
 3316: sub end_samp {
 3317:     my ($target,$token) = @_;
 3318:     my $currentstring = '';
 3319:     if ($target eq 'web') {
 3320: 	$currentstring = $token->[2];    
 3321:     } elsif ($target eq 'tex') {
 3322: 	$currentstring='}';
 3323:     }
 3324:     return $currentstring;
 3325: }
 3326: 
 3327: #-- <server> tag
 3328: sub start_server {
 3329:     my ($target,$token) = @_;
 3330:     my $currentstring = '';
 3331:     if ($target eq 'web') {
 3332: 	$currentstring = $token->[4];     
 3333:     } 
 3334:     return $currentstring;
 3335: }
 3336: 
 3337: sub end_server {
 3338:     my ($target,$token) = @_;
 3339:     my $currentstring = '';
 3340:     if ($target eq 'web') {
 3341: 	$currentstring = $token->[2];    
 3342:     } 
 3343:     return $currentstring;
 3344: }
 3345: 
 3346: #-- <spacer> tag (end tag forbidden)
 3347: sub start_spacer {
 3348:     my ($target,$token) = @_;
 3349:     my $currentstring = '';
 3350:     if ($target eq 'web') {
 3351: 	$currentstring = $token->[4];     
 3352:     } 
 3353:     return $currentstring;
 3354: }
 3355: 
 3356: sub end_spacer {
 3357:     my ($target,$token) = @_;
 3358:     my $currentstring = '';
 3359:     if ($target eq 'web') {
 3360: 	$currentstring = $token->[2];    
 3361:     } 
 3362:     return $currentstring;
 3363: }
 3364: 
 3365: #-- <span> tag (end tag required)
 3366: sub start_span {
 3367:     my ($target,$token) = @_;
 3368:     my $currentstring = '';
 3369:     if ($target eq 'web') {
 3370: 	$currentstring = $token->[4];     
 3371:     } 
 3372:     return $currentstring;
 3373: }
 3374: 
 3375: sub end_span {
 3376:     my ($target,$token) = @_;
 3377:     my $currentstring = '';
 3378:     if ($target eq 'web') {
 3379: 	$currentstring = $token->[2];    
 3380:     } 
 3381:     return $currentstring;
 3382: }
 3383: 
 3384: #-- <tbody> tag (end tag optional)
 3385: sub start_tbody {
 3386:     my ($target,$token) = @_;
 3387:     my $currentstring = '';
 3388:     if ($target eq 'web') {
 3389: 	$currentstring = $token->[4];     
 3390:     } 
 3391:     return $currentstring;
 3392: }
 3393: 
 3394: sub end_tbody {
 3395:     my ($target,$token) = @_;
 3396:     my $currentstring = '';
 3397:     if ($target eq 'web') {
 3398: 	$currentstring = $token->[2];    
 3399:     } 
 3400:     return $currentstring;
 3401: }
 3402: 
 3403: #-- <tfoot> tag (end tag optional)
 3404: sub start_tfoot {
 3405:     my ($target,$token) = @_;
 3406:     my $currentstring = '';
 3407:     if ($target eq 'web') {
 3408: 	$currentstring = $token->[4];     
 3409:     } 
 3410:     return $currentstring;
 3411: }
 3412: 
 3413: sub end_tfoot {
 3414:     my ($target,$token) = @_;
 3415:     my $currentstring = '';
 3416:     if ($target eq 'web') {
 3417: 	$currentstring = $token->[2];    
 3418:     } 
 3419:     return $currentstring;
 3420: }
 3421: 
 3422: #-- <thead> tag (end tag optional)
 3423: sub start_thead {
 3424:     my ($target,$token) = @_;
 3425:     my $currentstring = '';
 3426:     if ($target eq 'web') {
 3427: 	$currentstring = $token->[4];     
 3428:     } 
 3429:     return $currentstring;
 3430: }
 3431: 
 3432: sub end_thead {
 3433:     my ($target,$token) = @_;
 3434:     my $currentstring = '';
 3435:     if ($target eq 'web') {
 3436: 	$currentstring = $token->[2];    
 3437:     } 
 3438:     return $currentstring;
 3439: }
 3440: 
 3441: #-- <var> tag
 3442: sub start_var {
 3443:     my ($target,$token) = @_;
 3444:     my $currentstring = '';
 3445:     if ($target eq 'web') {
 3446: 	$currentstring = $token->[4];     
 3447:     } elsif ($target eq 'tex') {
 3448: 	$currentstring = '\textit{'; 
 3449:     }
 3450:     return $currentstring;
 3451: }
 3452: 
 3453: sub end_var {
 3454:     my ($target,$token) = @_;
 3455:     my $currentstring = '';
 3456:     if ($target eq 'web') {
 3457: 	$currentstring = $token->[2];
 3458:     } elsif ($target eq 'tex') {
 3459: 	$currentstring = '}'; 
 3460:     } 
 3461:     return $currentstring;
 3462: }
 3463: 
 3464: #-- <wbr> tag (end tag forbidden)
 3465: sub start_wbr {
 3466:     my ($target,$token) = @_;
 3467:     my $currentstring = '';
 3468:     if ($target eq 'web') {
 3469: 	$currentstring = $token->[4];     
 3470:     } 
 3471:     return $currentstring;
 3472: }
 3473: 
 3474: sub end_wbr {
 3475:     my ($target,$token) = @_;
 3476:     my $currentstring = '';
 3477:     if ($target eq 'web') {
 3478: 	$currentstring = $token->[2];    
 3479:     } 
 3480:     return $currentstring;
 3481: }
 3482: 
 3483: #-- <hideweboutput> tag
 3484: sub start_hideweboutput {
 3485:     my ($target,$token) = @_;
 3486:     if ($target eq 'web') {
 3487: 	&Apache::lonxml::startredirection();     
 3488:     } 
 3489:     return '';
 3490: }
 3491: 
 3492: sub end_hideweboutput {
 3493:     my ($target,$token) = @_;
 3494:     my $currentstring = '';
 3495:     if ($target eq 'web') {
 3496: 	$currentstring = &Apache::lonxml::endredirection();    
 3497:     } 
 3498:     return '';
 3499: }
 3500: 
 3501: 
 3502: sub image_replication {
 3503:     my $src = shift;
 3504:     if (not -e $src) { &Apache::lonnet::repcopy($src); }
 3505:     #replicates eps or ps 
 3506:     my $epssrc = my $pssrc = $src;
 3507:     $epssrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i;
 3508:     $pssrc  =~ s/\.(gif|jpg|jpeg|png)$/.ps/i;
 3509:     if (not -e $epssrc && not -e $pssrc) {
 3510: 	my $result=&Apache::lonnet::repcopy($epssrc);
 3511: 	if ($result ne OK) { &Apache::lonnet::repcopy($pssrc); }
 3512:     }
 3513:     return '';
 3514: }
 3515: 
 3516: sub image_size {
 3517:     my ($src,$scaling,$parstack,$safeeval)=@_;
 3518:     #size of image from gif/jpg/jpeg/png 
 3519:     my $image = Image::Magick->new;
 3520:     my $current_figure = $image->Read($src);
 3521:     my $width_param = $image->Get('width') * $scaling;;
 3522:     my $height_param = $image->Get('height') * $scaling;;
 3523:     undef $image;
 3524:     #do we have any specified LaTeX size of the picture?
 3525:     my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval);
 3526:     my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval);
 3527:     #do we have any specified web size of the picture?
 3528:     my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval,
 3529: 					   undef,1);
 3530:     if ($TeXwidth ne '') {  
 3531: 	if ($TeXwidth=~/(\d+)\s*\%/) {
 3532: 	    $width_param = $1*$ENV{'form.textwidth'}/100;
 3533: 	} else { 
 3534: 	    $width_param = $TeXwidth;
 3535: 	}
 3536:     } elsif ($TeXheight ne '') {
 3537: 	$width_param = $TeXheight/$height_param*$width_param;
 3538:     } elsif ($width ne '') {
 3539: 	$width_param = $width*$scaling;      
 3540:     }
 3541:     if ($width_param > $ENV{'form.textwidth'}) {$width_param =0.95*$ENV{'form.textwidth'}}
 3542:     return $width_param;
 3543: }
 3544: 
 3545: sub eps_generation {
 3546:     my ($src,$file,$width_param) = @_;	     
 3547:     my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat";
 3548:     my $temp_file = Apache::File->new('>>'.$filename); 
 3549:     print $temp_file "$src\n";
 3550:     my $newsrc = $src;
 3551:     $newsrc =~ s/(\.gif|\.jpg|\.jpeg)$/\.eps/i;
 3552:     $newsrc=~s/\/home\/httpd\/html\/res//;
 3553:     $newsrc=~s/\/home\/([^\/]*)\/public_html\//\/$1\//;
 3554:     $newsrc=~s/\/\.\//\//;
 3555:     $newsrc=~s/\/([^\/]+)\.(ps|eps)/\//;
 3556:     if ($newsrc=~/\/home\/httpd\/lonUsers\//) {
 3557: 	$newsrc=~s/\/home\/httpd\/lonUsers//;
 3558: 	$newsrc=~s/\/([^\/]+)\/(\w)\/(\w)\/(\w)\//\/$1\//;
 3559:     }
 3560:     return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
 3561: }
 3562: 
 3563: sub file_path {     
 3564:     my $src=shift;
 3565:     my ($file,$path); 
 3566:     if ($src =~ m!(.*)/([^/]*)$!) {
 3567: 	$file = $2; 
 3568: 	$path = $1.'/'; 
 3569:     } 
 3570:     return $file,$path;
 3571: }
 3572: 
 3573: sub recalc {
 3574:     my $argument = shift;
 3575:     if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}
 3576:     $argument=~/\s*(\d+\.?\d*)\s*(mm|cm|in|pc|pt)/;
 3577:     my $value=$1;
 3578:     my $units=$2;
 3579:     if ($units eq 'cm') {
 3580: 	$value*=10;
 3581:     } elsif ($units eq 'in') {
 3582: 	$value*=25.4;
 3583:     } elsif ($units eq 'pc') {
 3584: 	$value*=(25.4*12/72.27);
 3585:     } elsif ($units eq 'pt') {
 3586: 	$value*=(25.4/72.27);
 3587:     }
 3588:     return $value.' mm';
 3589: }
 3590: 
 3591: sub LATEX_length {
 3592:     my $garbage=shift;
 3593:     $garbage=~s/^\s+$//;
 3594:     $garbage=~s/^\s+(\S.*)/$1/;#space before 
 3595:     $garbage=~s/(.*\S)\s+$/$1/;#space after 
 3596:     $garbage=~s/(\s)+/$1/;#only one space
 3597:     $garbage=~s/(\\begin{([^\}]+)}|\\end{([^\}]+)})//g;#remove LaTeX \begin{...} and \end{...}
 3598:     $garbage=~s/(\$\_\{|\$\_|\$\^{|\$\^|\}\$)//g;#remove $_{,$_,$^{,$^,}$
 3599:     $garbage=~s/([^\\])\$/$1/g;#$
 3600:     $garbage=~s/(\\ensuremath\{\_\{|\\ensuremath\{\_|\\ensuremath\{\^{|\\ensuremath\{\^|\})//g;#remove \ensuremath{...}
 3601:    $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;
 3602:     $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;
 3603:     $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;
 3604:     $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;
 3605:     $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;
 3606:     $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;
 3607:     $garbage=~s/(\\hat{([^}]+)}|\\check{([^}]+)}|\\dot{([^}]+)}|\\breve{([^}]+)}|\\acute{([^}]+)}|\\ddot{([^}]+)}|\\grave{([^}]+)}|\\tilde{([^}]+)}|\\mathring{([^}]+)}|\\bar{([^}]+)}|\\vec{([^}]+)})/$1/g;
 3608:     #remove some other LaTeX command
 3609:     $garbage=~s|\\(\w+)\\|\\|g;	 
 3610:     $garbage=~s|\\(\w+)(\s*)|$2|g;	 	 
 3611:     $garbage=~s|\+|11|g;
 3612: 
 3613:     &Apache::lonnet::logthis("garbage was just $garbage");
 3614:     my  $value=length($garbage);
 3615:     return $value;
 3616: }
 3617: 
 3618: 
 3619: 
 3620: 
 3621: 1;
 3622: __END__

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