File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.229: download - view: text, annotated - select for diffs
Thu Jul 15 15:13:52 2004 UTC (19 years, 10 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Bug 3103 (things that print on s10 don't print on data)  is fixed. I changed algorithm (table) to rescale the size of images in the case of unsufficient space. It works for static images only (at this stage). I mean that it could not work for randomlabel problems. But I did not see any example with the whole random label problem in one table cell. Nevertheless I will continue to work with table algorithm to take into account all possible cases.

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

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