File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.168: download - view: text, annotated - select for diffs
Tue Aug 26 21:31:19 2003 UTC (20 years, 8 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- no comment

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

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