File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.194: download - view: text, annotated - select for diffs
Wed Jan 28 17:16:27 2004 UTC (20 years, 4 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- consolidated tth init sections
- course parameter for tth for setting tth parameters

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

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