File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.249: download - view: text, annotated - select for diffs
Wed Dec 29 11:39:25 2004 UTC (19 years, 4 months ago) by foxr
Branches: MAIN
CVS tags: HEAD
Add support for TexWrap to edit target.

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

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