File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.181: download - view: text, annotated - select for diffs
Tue Oct 14 14:40:33 2003 UTC (20 years, 7 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Implemented <secect> and <option> tags.

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

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