File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.171: download - view: text, annotated - select for diffs
Fri Sep 5 19:35:40 2003 UTC (20 years, 8 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Added a line at the very end of xml/html documents (looks better if you print a sequence).

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

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