File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.237: download - view: text, annotated - select for diffs
Wed Aug 25 19:08:32 2004 UTC (19 years, 9 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Bug 3388 (Mix and Match printing wrong) is fixed. The source of bug is presence of type="A" attribute directly in <li> tags not in <ol> tag. This is why I was forced to define a new globals: array @Apache:londefdef::alphabit and scalar $Apache::londefdef::alphabit_infdex to trace the current value of index.

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

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