File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.201: download - view: text, annotated - select for diffs
Tue Mar 9 20:37:58 2004 UTC (20 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- Added &Apache::lonxml::info, for display informational message (saved changes etc.), messages are suppressed when not in CSTR
- Tryin to address BUG#2305, we were emitting text before the <html> tag (error messages etc.)
   - now exists &Apache::lonxml::message_location() which is used o mark where messages should go
   - &Apache::lonxml::add_messages() which puts the info/warning/error message into the page (And should be called right before display the results of the parse)

- Homework Edit,EditXML, and display modes converted to use this mechanism
- HTML display and Edit converted to use this

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

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