File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.182: download - view: text, annotated - select for diffs
Thu Oct 16 15:29:45 2003 UTC (20 years, 7 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Bug 2287 (automatic eps generation needs to preserves paths) is partly corrected - it's done for static images. Further neccessary steps are 1) implement the same for randomlabel. problems; 2) implement additional parameter to do previous item for a few students at the same time; 3) make a test for a few more situations.

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

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