File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.452: download - view: text, annotated - select for diffs
Tue Jun 17 23:22:17 2014 UTC (9 years, 10 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_11_0, HEAD
- On Apache/SSL servers syllabus should always be served by http:// to avoid
  "mixed content" issue when syllabus is an external resource on http:// server).
  - Set $env{'request.use_absolute'} and pass in args to start page so postdata
    is preserved. (bug 6662).
  - Code used for same purpose in rat/lonwrapper.pm rev. 1.44 for external
    resources moved to lonacc.pm to facilitate re-use.
- Detect if syllabus template replaced with uploaded PDF or link to external
  PDF file, and send as arg in call to lonwrapper.pm, to circumvent lack of
  scrolling for multi-page PDFs in iframes on iOS.

    1: # The LearningOnline Network with CAPA
    2: # Tags Default Definition Module 
    3: #
    4: # $Id: londefdef.pm,v 1.452 2014/06/17 23:22:17 raeburn 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: package Apache::londefdef; 
   41: 
   42: use Apache::lonnet;
   43: use strict;
   44: use Apache::lonxml;
   45: use Apache::lontable;
   46: use Image::Magick;
   47: use Apache::lonmenu();
   48: use Apache::lonmeta();
   49: use Apache::lonlocal;
   50: use Apache::loncommon();
   51: use Apache::Constants qw(:common);
   52: use File::Basename;
   53: use LONCAPA();
   54: # use Data::Dumper;
   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','style','sub','sup','table','tbody','td','textarea','tfoot','th','thead','title','tr','tt','tthoption','u','ul','var','wbr','hideweboutput'));
   59: 
   60: }
   61: 
   62: 
   63: sub initialize_londefdef {
   64:     $Apache::londefdef::TD_redirection=0;
   65:     @Apache::londefdef::table = ();
   66:     $Apache::londefdef::select=0;
   67:     undef(@Apache::londefdef::description);
   68:     @Apache::londefdef::DD=(0);
   69:     @Apache::londefdef::DT=(0);
   70:     @Apache::londefdef::seenDT=(0);
   71:     $Apache::londefdef::list_index=0;
   72:     undef($Apache::londefdef::head);
   73:     undef($Apache::londefdef::title);
   74: }
   75: 
   76: #======================= TAG SUBROUTINES =====================
   77: #-- <output>
   78: sub start_output {
   79:     my ($target) = @_;
   80:     if ($target eq 'meta') { $Apache::lonxml::metamode--; }
   81:     return '';
   82: }
   83: sub end_output {
   84:     my ($target) = @_;
   85:     if ($target eq 'meta') { $Apache::lonxml::metamode++; }
   86:     return '';
   87: }
   88: #-- <m> tag
   89: sub start_m {
   90:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
   91:     my $currentstring = '';
   92:     my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser);
   93:     if ($target eq 'web' || $target eq 'analyze') {
   94: 	&Apache::lonxml::debug("M is starting with:$inside:");
   95: 	my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
   96: 	if ($eval eq 'on') {
   97: 	    $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
   98: 	    #&Apache::lonxml::debug("M is evaluated to:$inside:");
   99: 	}
  100: 	my $tex = $inside;
  101: 	my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval);
  102: 	$currentstring = &Apache::lontexconvert::converted(\$inside,$display);
  103: 	if ($Apache::lontexconvert::errorstring) {
  104: 	    my $errormsg='<pre>'.&HTML::Entities::encode($Apache::lontexconvert::errorstring,'<>&"').'</pre> occurred while attempting to convert this TeX: <pre>';
  105: 	    $tex = &HTML::Entities::encode($tex,'<>&"');
  106: 	    my ($linenumber) =
  107: 		($Apache::lontexconvert::errorstring =~ /Line (\d+)/);
  108: 	    if (defined($linenumber)) {
  109: 		my @tex=split("\n",$tex);
  110: 		$tex[$linenumber]='<b><font color="red">'.
  111: 		    $tex[$linenumber].'</font></b>';
  112: 		$tex=join("\n",@tex);
  113: 	    }
  114: 	    &Apache::lonxml::warning($errormsg.$tex.'</pre>');
  115: 	    $Apache::lontexconvert::errorstring='';
  116: 	}
  117: 	#&Apache::lonxml::debug("M is ends with:$currentstring:");
  118: 	$Apache::lonxml::post_evaluate=0;
  119:     } elsif ($target eq 'tex') {
  120: 
  121: 	$currentstring = $inside;
  122: 	my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
  123: 	if ($eval eq 'on') {
  124: 	    $currentstring=&Apache::run::evaluate($currentstring,$safeeval,$$parstack[-1]);
  125: 	}
  126: 	if ($currentstring=~/^(\s*\\\\\s*)*$/) {$currentstring = ' \vskip 0 mm ';}
  127: 	# detect simple math mode entry exits, and convert them
  128:         # to use \ensuremath ... unless there's a \verb inside.
  129: 	if (! ($currentstring=~/\\verb/)) {
  130: 	    if ($currentstring=~/^\s*\$[^\$].*\$\s*$/) {
  131: 		$currentstring=~s/^(\s*)\$/$1/;
  132: 		$currentstring=~s/\$(\s*)$/$1/;
  133: 		$currentstring='\ensuremath{'.$currentstring.'}';
  134: 	    }
  135: 	}
  136: 	$Apache::lonxml::post_evaluate=0;
  137:     }
  138:     return $currentstring;
  139: }
  140: 
  141: sub end_m {
  142:     my ($target,$token) = @_;
  143:     my $currentstring = '';
  144:     if ($target eq 'tex') {
  145: 	$currentstring = "";
  146:     }
  147:     return $currentstring;
  148: }
  149: 
  150: sub start_tthoption {
  151:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
  152:     my $result;
  153:     if ($target eq 'web' || $target eq 'webgrade') {
  154: 	my $inside = &Apache::lonxml::get_all_text("/tthoption",$parser,
  155: 						   $style);
  156: 	$inside=~s/^\s*//;
  157: 	if ($env{'browser.mathml'}) {
  158: 	    &tth::ttmoptions($inside);
  159: 	} else {
  160: 	    &tth::tthoptions($inside);
  161: 	}
  162:     }
  163:     return $result;
  164: }
  165: 
  166: sub end_tthoption {
  167:     my ($target,$token) = @_;
  168:     my $result;
  169:     return $result;
  170: }
  171: 
  172: #-- <html> tag (end tag optional)
  173: sub start_html {
  174:     my ($target,$token) = @_;
  175:     my $currentstring = '';
  176:     if ($target eq 'web' || $target eq 'edit' || $target eq 'webgrade' ) {
  177: 	# start_body() takes care of emitting the <html> 
  178:     } elsif ($target eq 'tex') {
  179: 
  180: 	$currentstring .= &latex_header();
  181:     }
  182:     return $currentstring;
  183: }
  184: 
  185: sub end_html {
  186:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  187:     my $currentstring = '';
  188:     if ($target eq 'web' || $target eq 'webgrade') {
  189: 	# end_body takes care of the </html>
  190:     }
  191:     return $currentstring;
  192: }
  193: 
  194: #-- <head> tag (end tag optional)
  195: sub start_head {
  196:     my ($target,$token) = @_;
  197:     my $currentstring = '';
  198:     if ($target eq 'web' || $target eq 'webgrade') {
  199: 	&Apache::lonxml::startredirection();
  200:     } 
  201:     return $currentstring;
  202: }
  203: 
  204: sub end_head {
  205:     my ($target,$token) = @_;
  206:     my $currentstring = '';
  207:     if (($target eq 'web'      && $env{'request.state'} eq 'published') ||
  208: 	($target eq 'webgrade' && $env{'request.state'} eq 'published')) {
  209: 	# in case there is a </head> but no <head>
  210: 	if ($Apache::lonxml::redirection) {
  211: 	    $Apache::londefdef::head = &Apache::lonxml::endredirection();
  212: 	}
  213:     } 
  214:     return $currentstring;
  215: }
  216: 
  217: #-- <map> tag (end tag required)
  218: sub start_map {
  219:     my ($target,$token) = @_;
  220:     my $currentstring = '';
  221:     if ($target eq 'web' || $target eq 'webgrade') {
  222: 	$currentstring = $token->[4];     
  223:     } 
  224:     return $currentstring;
  225: }
  226: 
  227: sub end_map {
  228:     my ($target,$token) = @_;
  229:     my $currentstring = '';
  230:     if ($target eq 'web' || $target eq 'webgrade') {
  231: 	$currentstring = $token->[2];    
  232:     } 
  233:     return $currentstring;
  234: }
  235: 
  236: #-- <select> tag (end tag required)
  237: sub start_select {
  238:     my ($target,$token) = @_;
  239:     my $currentstring = '';
  240:     if ($target eq 'web' || $target eq 'webgrade') {
  241: 	$currentstring = $token->[4];     
  242:     }  elsif ($target eq 'tex') {
  243: 	$Apache::londefdef::select=0;
  244:     }
  245:     return $currentstring;
  246: }
  247: 
  248: sub end_select {
  249:     my ($target,$token) = @_;
  250:     my $currentstring = '';
  251:     if ($target eq 'web' || $target eq 'webgrade') {
  252: 	$currentstring = $token->[2];    
  253:     } 
  254:     return $currentstring;
  255: }
  256: 
  257: #-- <option> tag (end tag optional)
  258: sub start_option {
  259:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  260:     my $currentstring = '';
  261:     if ($target eq 'web' || $target eq 'webgrade') {
  262: 	$currentstring = $token->[4];     
  263:     } elsif ($target eq 'tex') {
  264: 	$Apache::londefdef::select++;
  265: 	if ($Apache::londefdef::select == 1) {
  266: 	    $currentstring='\noindent\fbox{'.&Apache::lonxml::get_param('value',$parstack,$safeeval).'}\keephidden{';
  267: 	} else {
  268: 	    $currentstring='\keephidden{';
  269: 	}
  270:     }
  271:     return $currentstring;
  272: }
  273: 
  274: sub end_option {
  275:     my ($target,$token) = @_;
  276:     my $currentstring = '';
  277:     if ($target eq 'web' || $target eq 'webgrade') {
  278: 	$currentstring = $token->[2];    
  279:     }  elsif ($target eq 'tex') {
  280: 	$currentstring='}';
  281:     }
  282:     return $currentstring;
  283: }
  284: 
  285: #-- <input> tag (end tag forbidden)
  286: sub start_input {
  287:     my ($target,$token) = @_;
  288:     my $currentstring = '';
  289:     if ($target eq 'web' || $target eq 'webgrade') {
  290: 	$currentstring = $token->[4];     
  291:     } 
  292:     return $currentstring;
  293: }
  294: 
  295: sub end_input {
  296:     my ($target,$token) = @_;
  297:     my $currentstring = '';
  298:     if ($target eq 'web' || $target eq 'webgrade') {
  299: 	$currentstring = $token->[2];    
  300:     } 
  301:     return $currentstring;
  302: }
  303: 
  304: #-- <textarea> tag (end tag required)
  305: sub start_textarea {
  306:     my ($target,$token) = @_;
  307:     my $currentstring = '';
  308:     if ($target eq 'web' || $target eq 'webgrade') {
  309: 	$currentstring = $token->[4];     
  310:     } 
  311:     return $currentstring;
  312: }
  313: 
  314: sub end_textarea {
  315:     my ($target,$token) = @_;
  316:     my $currentstring = '';
  317:     if ($target eq 'web' || $target eq 'webgrade') {
  318: 	$currentstring = $token->[2];    
  319:     } 
  320:     return $currentstring;
  321: }
  322: 
  323: #-- <form> tag (end tag required)
  324: sub start_form {
  325:     my ($target,$token) = @_;
  326:     my $currentstring = '';
  327:     if ($target eq 'web' || $target eq 'webgrade') {
  328: 	$currentstring = $token->[4];     
  329:     } 
  330:     return $currentstring;
  331: }
  332: 
  333: sub end_form {
  334:     my ($target,$token) = @_;
  335:     my $currentstring = '';
  336:     if ($target eq 'web' || $target eq 'webgrade') {
  337: 	$currentstring = $token->[2];    
  338:     } 
  339:     return $currentstring;
  340: }
  341: 
  342: #-- <title> tag (end tag required)
  343: sub start_title {
  344:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
  345:     my $currentstring = '';
  346:     if ($target eq 'web' || $target eq 'webgrade') {
  347: 	$Apache::londefdef::title = 
  348: 	    &Apache::lonxml::get_all_text('/title',$parser,$style);
  349:     } elsif ($target eq 'tex') {
  350: 	$currentstring .= '\keephidden{Title of the document:  ' 
  351:     }
  352:     if ($target eq 'meta') {
  353: 	$currentstring='<title>';
  354: 	&start_output($target);
  355:     }
  356:     return $currentstring;
  357: }
  358: 
  359: sub end_title {
  360:     my ($target,$token) = @_;
  361:     my $currentstring = '';
  362:     if ($target eq 'web' || $target eq 'webgrade') {
  363: 	# start_title takes care of swallowing the title
  364:     } elsif ($target eq 'tex') {
  365: 	$currentstring .= '}';
  366:     }  
  367:     if ($target eq 'meta') {
  368: 	&end_output($target);
  369: 	$currentstring='</title>';
  370:     } 
  371:     return $currentstring;
  372: }
  373: 
  374: #-- <meta> tag (end tag forbidden)
  375: sub start_meta {
  376:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
  377:     my $currentstring = '';
  378:     if ($target eq 'web' || $target eq 'webgrade') {
  379: 	my $args='';
  380: 	if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
  381: 	if ($args eq '') {
  382: 	    &Apache::lonxml::get_all_text("/meta",$parser,$style);
  383: 	} else {
  384: 	    $currentstring = $token->[4];
  385: 	}
  386:         if ($env{'form.grade_imsexport'}) {
  387:             $currentstring = '';
  388:         }
  389:     } elsif ($target eq 'meta') {
  390: 	unless (&Apache::lonxml::get_param
  391: 		('http-equiv',$parstack,$safeeval,undef,1)) {
  392: 	    my $name=$token->[2]->{'name'};
  393: 	    $name=~tr/A-Z/a-z/;
  394: 	    $name=~s/\s/\_/gs;
  395: 	    $name=~s/\W//gs;
  396: 	    if ($name) {
  397: 		$currentstring='<'.$name;
  398:                  my $display=&Apache::lonxml::get_param
  399: 		('display',$parstack,$safeeval,undef,1);
  400:                 if ($display) {
  401:                     $display=~s/\"/\'/g;
  402: 		    $currentstring.=' display="'.$display.'"';
  403:                 }
  404: 		$currentstring.='>'.
  405: 		    &Apache::lonxml::get_param
  406: 			('content',$parstack,$safeeval,undef,1).
  407: 			'</'.$name.'>';
  408: 	    }
  409:             my $display=&Apache::lonxml::get_param
  410: 		('display',$parstack,$safeeval,undef,1);
  411:             if ($display) {
  412: 		$display=&HTML::Entities::encode($display,'<>&"');
  413: 		$currentstring.='<'.$name.'.display>'.$display.
  414:                                '</'.$name.'.display>';
  415:             }
  416: 	}
  417:     } elsif ($target eq 'tex') {
  418: 	my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval);
  419: 	my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval);
  420: 	if ((not defined $content) && (not defined $name)) {
  421: 	    &Apache::lonxml::startredirection();
  422: 	}
  423:     } elsif ($target eq 'edit') {
  424: 	$currentstring .= &Apache::edit::tag_start($target,$token);
  425: 	$currentstring .= &Apache::edit::text_arg('Name:','name',$token,30);
  426: 	$currentstring .= &Apache::edit::text_arg('Content:','content',$token,70);
  427: 	$currentstring .= &Apache::edit::end_row();
  428:     } elsif ($target eq 'modified') {
  429: 	my $constructtag =
  430: 	    &Apache::edit::get_new_args($token,$parstack,$safeeval,
  431: 					'name','content');
  432: 	if ($constructtag) { $currentstring = &Apache::edit::rebuild_tag($token); }
  433:     }
  434:     return $currentstring;
  435: }
  436: 
  437: sub end_meta {
  438:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  439:     my $currentstring = '';
  440:     if ($target eq 'web' || $target eq 'webgrade') {
  441: 	my $args='';
  442: 	if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
  443: 	if ($args ne '') {
  444: 	    $currentstring = $token->[4];
  445: 	}
  446:     } elsif ($target eq 'tex') {
  447: 	my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval);
  448: 	my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval);
  449: 	if ((not defined $content) && (not defined $name)) {
  450: 	    &Apache::lonxml::endredirection();
  451: 	}
  452:     }
  453:     return $currentstring;
  454: }
  455: 
  456: sub insert_meta {
  457:     return '
  458:     <meta />';
  459: }
  460: 
  461: #-- <start> tag
  462: sub start_style {
  463: 	my ($target, $token, $tagstack, $parstack, $parser, $safeeval, $style) = @_;
  464: 	my $currentstring = '';
  465: 
  466: 	if ($target eq 'tex') {
  467: 		Apache::lonxml::startredirection();
  468: 	} else {
  469: 		$currentstring = $token->[4];
  470: 	}
  471: 	
  472: 	return $currentstring;
  473: }
  474: 
  475: sub end_style {
  476: 	my ($target, $token, $tagstack, $parstack, $parser, $safeeval) = @_;
  477: 	my $currentstring = '';
  478: 
  479: 	if ($target eq 'tex') {
  480: 		Apache::lonxml::endredirection();
  481: 	} else {
  482: 		$currentstring = $token->[2];
  483: 	}
  484: 	return $currentstring;
  485: }
  486: 
  487: # accessrule
  488: sub start_accessrule {
  489:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
  490:     my $currentstring = '';
  491:     my $eff  =&Apache::lonxml::get_param('effect',$parstack,$safeeval,undef,1);
  492:     my $realm=&Apache::lonxml::get_param('realm', $parstack,$safeeval,undef,1);
  493:     my $role =&Apache::lonxml::get_param('role',  $parstack,$safeeval,undef,1);
  494:     my $type =&Apache::lonxml::get_param('type',  $parstack,$safeeval,undef,1);
  495: 
  496:     my ($dom,$crs,$sec,$separator);
  497:     if ($type eq 'user') {
  498: 	($dom,$crs,$sec)=split(m{/},$realm);
  499: 	$crs = &LONCAPA::clean_username($crs);
  500: 	$separator = '/';
  501:     } else {
  502: 	($dom,$crs,$sec)=split(/\_/,$realm);
  503: 	$crs = &LONCAPA::clean_courseid($crs);
  504: 	$separator = '_';
  505:     }
  506:     $dom = &LONCAPA::clean_domain($dom);
  507: 
  508:     $sec =~s/\W//;
  509:     $realm = $dom;
  510:     if ($crs =~ /\S/) { $realm .= $separator.$crs; }
  511:     if ($sec =~ /\S/) { $realm .= $separator.$sec; }
  512:     $role=~s/\W//g;
  513: 
  514:     if ($target eq 'web') {
  515: 	my $args='';
  516: 	if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
  517: 	if ($args eq '') {
  518: 	    &Apache::lonxml::get_all_text("/accessrule",$parser,$style);
  519: 	} else {
  520: 	    $currentstring = $token->[4];
  521: 	}
  522:     }
  523:     if ($target eq 'meta') {
  524: 	$currentstring='<rule>'.$eff.':'.$realm.':'.$role.':'.$type.'</rule>';
  525:     }
  526:     return $currentstring;
  527: }
  528: 
  529: sub end_accessrule {
  530:     my ($target,$token,$tagstack,$parstack,$parser) = @_;
  531:     my $currentstring = '';
  532:     if ($target eq 'web') {
  533: 	my $args='';
  534: 	if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
  535: 	if ($args ne '') {
  536: 	    $currentstring = $token->[4];
  537: 	}
  538:     } 
  539:     return $currentstring;
  540: }
  541: 
  542: sub generate_css_links {
  543:     my $links;
  544:     my $css_href = &Apache::lonnet::EXT('resource.0.cssfile');
  545:     if ($css_href =~ /\S/) {
  546: 	&Apache::lonxml::extlink($css_href);
  547: 	$links .= 
  548: 	    '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />';
  549:     }
  550:     return $links;
  551: }
  552: 
  553: #-- <body> tag (end tag required)
  554: sub start_body {
  555:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  556:     my $currentstring = '';
  557: 
  558:     if ($target eq 'web' || $target eq 'webgrade') {
  559: 	if ($Apache::lonhomework::parsing_a_problem) {
  560: 	    &Apache::lonxml::warning("<body> tag found inside of <problem> tag this can cause problems.");
  561: 	    return '';
  562: 	}
  563: 	
  564: 	if (&is_inside_of($tagstack, "head")) {
  565: 	    &end_head(@_);
  566: 	}
  567: 	
  568: 	my $extra_head = &generate_css_links();
  569: 
  570:     # Breadcrumbs
  571:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  572:     if ($env{'request.state'} eq 'construct') {
  573:         my $url=&Apache::lonnet::hreflocation('',$env{'request.filename'});
  574:         &Apache::lonhtmlcommon::add_breadcrumb({
  575:             'text'  => 'Authoring Space',
  576:             'href'  => &Apache::loncommon::authorspace($url),
  577:         });
  578:         &Apache::lonhtmlcommon::add_breadcrumb({
  579:             'text'  => 'HTML Editor',
  580:             'href'  => '',
  581:         });
  582:         # breadcrumbs (and tools) will be created 
  583:         # in start_page->bodytag->innerregister
  584:     } else {
  585:         # FIXME Where are we?
  586:     }
  587: 
  588:         my $args = {'add_entries'    => $token->[2],
  589:                     'force_register' => 1,};
  590:         if ($target eq 'web') {
  591:             $args->{'print_suppress'} = 1;
  592:             if ($env{'request.use_absolute'}) {
  593:                 $args->{'use_absolute'} = $env{'request.use_absolute'};
  594:             }
  595:         }
  596: 	$currentstring = 
  597: 	    &Apache::loncommon::start_page($Apache::londefdef::title,
  598: 					   $Apache::londefdef::head
  599: 					      .$extra_head,$args);
  600:         my $header = '';
  601:         if ($env{'request.state'} ne 'published' &&
  602:             $env{'request.state'} ne 'construct') {
  603:             $header=&Apache::lonmenu::constspaceform();
  604:         }
  605:         if ($env{'request.state'} ne 'published') {
  606:             unless ($env{'form.inhibitmenu'} eq 'yes') {
  607:                 $header.=&edit_controls();
  608:             }
  609:         }
  610:         if ($env{'request.state'} eq 'construct') {
  611:             unless ($env{'form.inhibitmenu'} eq 'yes') {
  612:                 $currentstring.=&Apache::loncommon::head_subbox(
  613:                                     &Apache::loncommon::CSTR_pageheader()
  614:                                    .$header);
  615:             }
  616:         } elsif ($env{'request.state'} eq 'edit') {
  617:             $currentstring.=&Apache::loncommon::head_subbox($header);
  618:         }
  619:         $currentstring.=&Apache::lonxml::message_location();
  620:     } elsif ($target eq 'tex') {
  621:         $currentstring = '';   #  '\begin{document}' is in header.
  622:     }
  623: 
  624:     return $currentstring;
  625: }
  626: 
  627: sub edit_controls {
  628:     my ($nochgview) = @_;
  629:     my $result .= '
  630: <form method="post" action="">
  631: <div class="LC_edit_problem_header">';
  632:     unless ($nochgview) {
  633:         $result .= '
  634: <div class="LC_edit_problem_header_row1">'.
  635: &Apache::lonxml::renderingoptions().'
  636: <input type="submit" name="changeproblemmode" value="'.&mt('Change View').'" />
  637: </div>';
  638:     }
  639:     $result .= '
  640: <div><input type="submit" name="editmode" accesskey="e" value="'.&mt('Edit').'" />';
  641:     if (($env{'request.course.id'}) && ($env{'form.forceedit'})) {
  642:         my $url=&Apache::lonnet::hreflocation('',$env{'request.filename'});
  643:         if ($url =~ /\.html?$/i) {
  644:             my ($cdom,$cnum);
  645:             if ($env{'request.course.id'}) {
  646:                 $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  647:                 $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  648:                 if ($env{'request.filename'} =~ m{/userfiles/supplemental/default|\d+/}) {
  649:                     if (&Apache::lonnet::is_course_upload($env{'request.filename'},
  650:                                                           $cnum,$cdom)) {
  651:                         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  652:                                                                 ['folderpath','title']);
  653:                     }
  654:                 }
  655:             }
  656:             my ($symb,$itemtitle,$displayfile,$caller);
  657:             if ($url =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/}) {
  658:                 $itemtitle = &mt('Syllabus');
  659:                 $caller = "/public/$cdom/$cnum/syllabus";
  660:             } else {
  661:                 $caller = $url;
  662:                 ($symb,$itemtitle,$displayfile) =
  663:                     &Apache::lonxml::get_courseupload_hierarchy($url,
  664:                                                                 $env{'form.folderpath'},
  665:                                                                 $env{'form.title'});
  666:             }
  667:             if (($symb ne '') || ($env{'httpref.'.$url} ne '') ||
  668:                 ($url =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/})) {
  669:                   $result .= ('&nbsp;' x 3).
  670:                              &Apache::lonhtmlcommon::dependencies_button()."\n".
  671:                              &Apache::lonhtmlcommon::dependencycheck_js($symb,
  672:                                  $itemtitle,$url,$env{'form.folderpath'},$caller)."\n";
  673:             }
  674:         }
  675:     }
  676:     $result .= '</div>
  677: </div>
  678: </form>
  679: ';
  680:     return $result;
  681: }
  682: 
  683: sub end_body {
  684:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  685:     my $currentstring = &end_p();	# Close off unclosed <p>
  686:     if ($target eq 'web' || $target eq 'webgrade') {
  687: 	$currentstring .= &Apache::loncommon::end_page({'discussion' => 1});
  688:     } elsif ($target eq 'tex') {
  689: 	$currentstring .= '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}';  
  690:     } 
  691:     return $currentstring;
  692: }
  693: 
  694: # \begin{center} causes a new paragprah spacing that looks odd inside 
  695: # of a table cell.  Same at the end of a \center but with a slightly
  696: # larger space .. hence center_correction and center_end_correction.
  697: #
  698: sub center_correction { return '\vspace*{-6 mm}'; } 
  699: sub center_end_correction { return '\vspace*{-7 mm}'; }
  700: 
  701: #-- <center> tag (end tag required)
  702: sub start_center {
  703:     my ($target,$token,$tagstack) = @_;
  704:     my $currentstring = &end_p();	# Close off any prior para.
  705:     if ($target eq 'web' || $target eq 'webgrade') {
  706: 	$currentstring .= $token->[4];     
  707:     } elsif ($target eq 'tex') {
  708: 	if (&is_inside_of($tagstack, "table")) {
  709: 	    $currentstring .= &center_correction();
  710: 	}
  711: 	$currentstring .= '\begin{center}';  
  712:     }
  713:     return $currentstring;
  714: }
  715: 
  716: sub end_center {
  717:     my ($target,$token,$tagstack) = @_;
  718:     my $currentstring = '';
  719:     if ($target eq 'web' || $target eq 'webgrade') {
  720: 	$currentstring = $token->[2];     
  721:     } elsif ($target eq 'tex') {
  722: 	$currentstring = '\end{center}';  
  723: 	if (&is_inside_of($tagstack, "table")) {
  724: 	    $currentstring .= &center_end_correction();
  725: 	}
  726:     }
  727:     return $currentstring;
  728: }
  729: 
  730: #-- <b> tag (end tag required)
  731: #      NOTE: In TeX mode disables internal <p>
  732: sub start_b {
  733:     my ($target,$token) = @_;
  734:     my $currentstring = '';
  735:     if ($target eq 'web' || $target eq 'webgrade') {
  736: 	$currentstring = $token->[4];     
  737:     } elsif ($target eq 'tex') {
  738: 	&disable_para();
  739: 	$currentstring .= '\textbf{';  
  740:     } 
  741:     return $currentstring;
  742: }
  743: 
  744: sub end_b {
  745:     my ($target,$token) = @_;
  746:     my $currentstring = '';
  747:     if ($target eq 'web' || $target eq 'webgrade') {
  748: 	$currentstring = $token->[2];     
  749:     } elsif ($target eq 'tex') {
  750: 	&enable_para();
  751: 	$currentstring = '}';
  752:     } 
  753:     return $currentstring;
  754: }
  755: 
  756: #-- <strong> tag (end tag required)
  757: #    NOTE: in TeX mode disables internal <p>
  758: sub start_strong {
  759:     my ($target,$token) = @_;
  760:     my $currentstring = '';
  761:     if ($target eq 'web' || $target eq 'webgrade') {
  762: 	$currentstring = $token->[4];     
  763:     } elsif ($target eq 'tex') {
  764: 	&disable_para();
  765: 	$currentstring = '\textbf{';  
  766:     } 
  767:     return $currentstring;
  768: }
  769: 
  770: sub end_strong {
  771:     my ($target,$token) = @_;
  772:     my $currentstring = '';
  773:     if ($target eq 'web' || $target eq 'webgrade') {	
  774: 	$currentstring = $token->[2];     
  775:     } elsif ($target eq 'tex') {
  776: 	&enable_para();
  777: 	$currentstring = '}';  
  778:     }
  779:     return $currentstring;
  780: }
  781: 
  782: #-- <h1> tag (end tag required)
  783: sub start_h1 {
  784:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  785:     my $currentstring = &end_p();	# Close off any prior para.
  786:     if ($target eq 'web' || $target eq 'webgrade') {
  787: 	$currentstring .= $token->[4];
  788:     } elsif ($target eq 'tex') {
  789: 	my $pre;
  790: 	my $align=lc(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1));
  791: 	if ($align eq 'center') {
  792: 	    $pre='\begin{center}';
  793: 	} elsif ($align eq 'left') {
  794: 	    $pre='\rlap{';
  795: 	} elsif ($align eq 'right') {
  796: 	    $pre=' \hfill \llap{';
  797: 	}
  798: 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
  799: 	if (not defined $TeXsize) {$TeXsize="large";}
  800: 	$currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{'; 
  801:     } elsif ($target eq 'meta') {
  802: 	$currentstring.='<subject>';
  803: 	&start_output($target);
  804:     }
  805:     return $currentstring;
  806: }
  807: 
  808: sub end_h1 {
  809:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  810:     my $currentstring = '';
  811:     if ($target eq 'web' || $target eq 'webgrade') {
  812: 	$currentstring .= $token->[2];
  813:     } elsif ($target eq 'tex') {
  814: 	my $post='\vskip 0 mm ';
  815: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  816: 	if ($align eq 'center') {
  817: 	    $post='\end{center}';
  818: 	} elsif ($align eq 'left') {
  819: 	    $post='} \hfill'.'\vskip 0 mm ';
  820: 	} elsif ($align eq 'right') {
  821: 	    $post='}'.'\vskip 0 mm ';
  822: 	}
  823: 	$currentstring .= '}}'.$post;
  824:     } elsif ($target eq 'meta') {
  825: 	&end_output($target);
  826: 	$currentstring='</subject>';
  827:     } 
  828:     return $currentstring;
  829: }
  830: 
  831: #-- <h2> tag
  832: sub start_h2 {
  833:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  834:     my $currentstring = &end_p();	# Close off any prior para.
  835:     if ($target eq 'web' || $target eq 'webgrade') {
  836: 	$currentstring .= $token->[4];
  837:     } elsif ($target eq 'tex') {
  838: 	my $pre;
  839: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  840: 	if ($align eq 'center') {
  841: 	    $pre='\begin{center}';
  842: 	} elsif ($align eq 'left') {
  843: 	    $pre='\rlap{';
  844: 	} elsif ($align eq 'right') {
  845: 	    $pre=' \hfill \llap{';
  846: 	}
  847: 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
  848: 	if (not defined $TeXsize) {$TeXsize="large";}
  849: 	$currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{'; 
  850:     } 
  851:     return $currentstring;
  852: }
  853: 
  854: sub end_h2 {
  855:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  856:     my $currentstring = '';
  857:     if ($target eq 'web' || $target eq 'webgrade') {
  858: 	$currentstring .= $token->[2];
  859:     } elsif ($target eq 'tex') {
  860: 	my $post='\vskip 0 mm ';
  861: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  862: 	if ($align eq 'center') {
  863: 	    $post='\end{center}';
  864: 	} elsif ($align eq 'left') {
  865: 	    $post='} \hfill'.'\vskip 0 mm ';
  866: 	} elsif ($align eq 'right') {
  867: 	    $post='}'.'\vskip 0 mm ';
  868: 	}
  869: 	$currentstring .= '}}'.$post;
  870:     } 
  871:     return $currentstring;
  872: }
  873: 
  874: #-- <h3> tag
  875: sub start_h3 {
  876:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  877:     my $currentstring = &end_p();	# Close off any prior para.
  878:     if ($target eq 'web' || $target eq 'webgrade') {
  879: 	$currentstring .= $token->[4];
  880:     } elsif ($target eq 'tex') {
  881: 	my $pre;
  882: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  883: 	if ($align eq 'center') {
  884: 	    $pre='\begin{center}';
  885: 	} elsif ($align eq 'left') {
  886: 	    $pre='\rlap{';
  887: 	} elsif ($align eq 'right') {
  888: 	    $pre=' \hfill \llap{';
  889: 	}
  890: 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
  891: 	if (not defined $TeXsize) {$TeXsize="large";}
  892: 	$currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{'; 
  893:     } 
  894:     return $currentstring;
  895: }
  896: 
  897: sub end_h3 {
  898:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  899:     my $currentstring = '';
  900:     if ($target eq 'web' || $target eq 'webgrade') {
  901: 	$currentstring .= $token->[2];
  902:     } elsif ($target eq 'tex') {
  903: 	my $post='\vskip 0 mm ';
  904: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  905: 	if ($align eq 'center') {
  906: 	    $post='\end{center}';
  907: 	} elsif ($align eq 'left') {
  908: 	    $post='} \hfill'.'\vskip 0 mm ';
  909: 	} elsif ($align eq 'right') {
  910: 	    $post='}'.'\vskip 0 mm ';
  911: 	}
  912: 	$currentstring .= '}}'.$post;
  913:     } 
  914:     return $currentstring;
  915: }
  916: 
  917: #-- <h4> tag
  918: sub start_h4 {
  919:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  920:     my $currentstring = &end_p();	# Close off any prior para.
  921:     if ($target eq 'web' || $target eq 'webgrade') {
  922: 	$currentstring .= $token->[4];
  923:     } elsif ($target eq 'tex') {
  924: 	my $pre;
  925: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  926: 	if ($align eq 'center') {
  927: 	    $pre='\begin{center}';
  928: 	} elsif ($align eq 'left') {
  929: 	    $pre='\rlap{';
  930: 	} elsif ($align eq 'right') {
  931: 	    $pre=' \hfill \llap{';
  932: 	}
  933: 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
  934: 	if (not defined $TeXsize) {$TeXsize="large";}
  935: 	$currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{'; 
  936:     } 
  937:     return $currentstring;
  938: }
  939: 
  940: sub end_h4 {
  941:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  942:     my $currentstring = '';
  943:     if ($target eq 'web' || $target eq 'webgrade') {
  944: 	$currentstring .= $token->[2];
  945:     } elsif ($target eq 'tex') {
  946: 	my $post='\vskip 0 mm ';
  947: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  948: 	if ($align eq 'center') {
  949: 	    $post='\end{center}';
  950: 	} elsif ($align eq 'left') {
  951: 	    $post='} \hfill'.'\vskip 0 mm ';
  952: 	} elsif ($align eq 'right') {
  953: 	    $post='}'.'\vskip 0 mm ';
  954: 	}
  955: 	$currentstring .= '}}'.$post;
  956:     } 
  957:     return $currentstring;
  958: }
  959: 
  960: #-- <h5> tag
  961: sub start_h5 {
  962:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  963:     my $currentstring = &end_p();	# Close off any prior paras.
  964:     if ($target eq 'web' || $target eq 'webgrade') {
  965: 	$currentstring .= $token->[4];
  966:     } elsif ($target eq 'tex') {
  967: 	my $pre;
  968: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  969: 	if ($align eq 'center') {
  970: 	    $pre='\begin{center}';
  971: 	} elsif ($align eq 'left') {
  972: 	    $pre='\rlap{';
  973: 	} elsif ($align eq 'right') {
  974: 	    $pre=' \hfill \llap{';
  975: 	}
  976: 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
  977: 	if (not defined $TeXsize) {$TeXsize="large";}
  978: 	$currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{'; 
  979:     } 
  980:     return $currentstring;
  981: }
  982: 
  983: sub end_h5 {
  984:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  985:     my $currentstring = '';
  986:     if ($target eq 'web' || $target eq 'webgrade') {
  987: 	$currentstring .= $token->[2];
  988:     } elsif ($target eq 'tex') {
  989: 	my $post='\vskip 0 mm ';
  990: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
  991: 	if ($align eq 'center') {
  992: 	    $post='\end{center}';
  993: 	} elsif ($align eq 'left') {
  994: 	    $post='} \hfill'.'\vskip 0 mm ';
  995: 	} elsif ($align eq 'right') {
  996: 	    $post='}'.'\vskip 0 mm ';
  997: 	}
  998: 	$currentstring .= '}}'.$post;
  999:     } 
 1000:     return $currentstring;
 1001: }
 1002: 
 1003: #-- <h6> tag
 1004: sub start_h6 {
 1005:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1006:     my $currentstring = &end_p();	# Close off any prior paras.
 1007:     if ($target eq 'web' || $target eq 'webgrade') {
 1008: 	$currentstring .= $token->[4];
 1009:     } elsif ($target eq 'tex') {
 1010: 	my $pre;
 1011: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
 1012: 	if ($align eq 'center') {
 1013: 	    $pre='\begin{center}';
 1014: 	} elsif ($align eq 'left') {
 1015: 	    $pre='\rlap{';
 1016: 	} elsif ($align eq 'right') {
 1017: 	    $pre=' \hfill \llap{';
 1018: 	}
 1019: 	my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
 1020: 	if (not defined $TeXsize) {$TeXsize="large";}
 1021: 	$currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{'; 
 1022:     } 
 1023:     return $currentstring;
 1024: }
 1025: 
 1026: sub end_h6 {
 1027:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1028:     my $currentstring = '';
 1029:     if ($target eq 'web' || $target eq 'webgrade') {
 1030: 	$currentstring .= $token->[2];
 1031:     } elsif ($target eq 'tex') {
 1032: 	my $post='\vskip 0 mm ';
 1033: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
 1034: 	if ($align eq 'center') {
 1035: 	    $post='\end{center}';
 1036: 	} elsif ($align eq 'left') {
 1037: 	    $post='} \hfill'.'\vskip 0 mm ';
 1038: 	} elsif ($align eq 'right') {
 1039: 	    $post='}'.'\vskip 0 mm ';
 1040: 	}
 1041: 	$currentstring .= '}}'.$post;
 1042:     } 
 1043:     return $currentstring;
 1044: }
 1045: 
 1046: #--- <cite> tag (end tag required)
 1047: sub start_cite {
 1048:     my ($target,$token) = @_;
 1049:     my $currentstring = '';
 1050:     if ($target eq 'web' || $target eq 'webgrade') {
 1051: 	$currentstring .= $token->[4];
 1052:     } elsif ($target eq 'tex') {
 1053: 	$currentstring .= '\textit{';
 1054:     }
 1055:     return $currentstring;
 1056: }
 1057: 
 1058: sub end_cite {
 1059:     my ($target,$token) = @_;
 1060:     my $currentstring = '';
 1061:     if ($target eq 'web' || $target eq 'webgrade') {
 1062: 	$currentstring .= $token->[2];
 1063:     } elsif ($target eq 'tex') {
 1064: 	$currentstring .= '}';
 1065:     }
 1066:     return $currentstring;
 1067: }
 1068: 
 1069: #-- <i> tag (end tag required)
 1070: sub start_i {
 1071:     my ($target,$token) = @_;
 1072:     my $currentstring = '';
 1073:     if ($target eq 'web' || $target eq 'webgrade') {
 1074: 	$currentstring .= $token->[4];
 1075:     } elsif ($target eq 'tex') {
 1076: 	$currentstring .= '\textit{';
 1077:     }
 1078:     return $currentstring;
 1079: }
 1080: 
 1081: sub end_i {
 1082:     my ($target,$token) = @_;
 1083:     my $currentstring = '';
 1084:     if ($target eq 'web' || $target eq 'webgrade') {
 1085: 	$currentstring .= $token->[2];
 1086:     } elsif ($target eq 'tex') {
 1087: 	$currentstring .= '}';
 1088:     } 
 1089:     return $currentstring;
 1090: }
 1091: 
 1092: #-- <address> tag (end tag required)
 1093: sub start_address {
 1094:     my ($target,$token) = @_;
 1095:     my $currentstring = '';
 1096:     if ($target eq 'web' || $target eq 'webgrade') {
 1097: 	$currentstring .= $token->[4];
 1098:     } elsif ($target eq 'tex') {
 1099: 	$currentstring .= '\textit{';
 1100:     }
 1101:     return $currentstring;
 1102: }
 1103: 
 1104: sub end_address {
 1105:     my ($target,$token) = @_;
 1106:     my $currentstring = '';
 1107:     if ($target eq 'web' || $target eq 'webgrade') {
 1108: 	$currentstring .= $token->[2];
 1109:     } elsif ($target eq 'tex') {
 1110: 	$currentstring .= '}';
 1111:     }
 1112:     return $currentstring;
 1113: }
 1114: 
 1115: #-- <dfn> tag (end tag required)
 1116: sub start_dfn {
 1117:     my ($target,$token) = @_;
 1118:     my $currentstring = '';
 1119:     if ($target eq 'web' || $target eq 'webgrade') {
 1120: 	$currentstring .= $token->[4];
 1121:     } elsif ($target eq 'tex') {
 1122: 	$currentstring .= '\textit{';
 1123:     } 
 1124:     return $currentstring;
 1125: }
 1126: 
 1127: sub end_dfn {
 1128:     my ($target,$token) = @_;
 1129:     my $currentstring = '';
 1130:     if ($target eq 'web' || $target eq 'webgrade') {
 1131: 	$currentstring .= $token->[2];
 1132:     } elsif ($target eq 'tex') {
 1133: 	$currentstring .= '}';
 1134:     }
 1135:     return $currentstring;
 1136: }
 1137: 
 1138: #-- <tt> tag (end tag required)
 1139: sub start_tt {
 1140:     my ($target,$token) = @_;
 1141:     my $currentstring = '';
 1142:     if ($target eq 'web' || $target eq 'webgrade') {
 1143: 	$currentstring .= $token->[4];
 1144:     } elsif ($target eq 'tex') {
 1145: 	$currentstring .= '\texttt{';
 1146:     }
 1147:     return $currentstring;
 1148: }
 1149: 
 1150: sub end_tt {
 1151:     my ($target,$token) = @_;
 1152:     my $currentstring = '';
 1153:     if ($target eq 'web' || $target eq 'webgrade') {
 1154: 	$currentstring .= $token->[2];
 1155:     } elsif ($target eq 'tex') {
 1156: 	$currentstring .= '}';
 1157:     }
 1158:     return $currentstring;
 1159: }
 1160: 
 1161: #-- <kbd> tag (end tag required)
 1162: sub start_kbd {
 1163:     my ($target,$token) = @_;
 1164:     my $currentstring = '';
 1165:     if ($target eq 'web' || $target eq 'webgrade') {
 1166: 	$currentstring .= $token->[4];
 1167:     } elsif ($target eq 'tex') {
 1168: 	$currentstring .= '\texttt{';
 1169:     }
 1170:     return $currentstring;
 1171: }
 1172: 
 1173: sub end_kbd {
 1174:     my ($target,$token) = @_;
 1175:     my $currentstring = '';
 1176:     if ($target eq 'web' || $target eq 'webgrade') {
 1177: 	$currentstring .= $token->[2];
 1178:     } elsif ($target eq 'tex') {
 1179: 	$currentstring .= '}';
 1180:     }
 1181:     return $currentstring;
 1182: }
 1183: 
 1184: #-- <code> tag (end tag required)
 1185: sub start_code {
 1186:     my ($target,$token) = @_;
 1187:     my $currentstring = '';
 1188:     if ($target eq 'web' || $target eq 'webgrade') {
 1189: 	$currentstring .= $token->[4];
 1190:     } elsif ($target eq 'tex') {
 1191: 	$currentstring .= '\texttt{';
 1192:     } 
 1193:     return $currentstring;
 1194: }
 1195: 
 1196: sub end_code {
 1197:     my ($target,$token) = @_;
 1198:     my $currentstring = '';
 1199:     if ($target eq 'web' || $target eq 'webgrade') {
 1200: 	$currentstring .= $token->[2];
 1201:     } elsif ($target eq 'tex') {
 1202: 	$currentstring .= '}';
 1203:     } 
 1204:     return $currentstring;
 1205: }
 1206: 
 1207: #-- <em> tag (end tag required)
 1208: sub start_em {
 1209:     my ($target,$token) = @_;
 1210:     my $currentstring = '';
 1211:     if ($target eq 'web' || $target eq 'webgrade') {
 1212: 	$currentstring .= $token->[4];
 1213:     } elsif ($target eq 'tex') {
 1214: 	$currentstring .= '\emph{';
 1215:     }
 1216:     return $currentstring;
 1217: }
 1218: 
 1219: sub end_em {
 1220:     my ($target,$token) = @_;
 1221:     my $currentstring = '';
 1222:     if ($target eq 'web' || $target eq 'webgrade') {
 1223: 	$currentstring .= $token->[2];
 1224:     } elsif ($target eq 'tex') {
 1225: 	$currentstring .= '}';
 1226:     } 
 1227:     return $currentstring;
 1228: }
 1229: 
 1230: #-- <q> tag (end tag required)
 1231: sub start_q {
 1232:     my ($target,$token) = @_;
 1233:     my $currentstring = '';
 1234:     if ($target eq 'web' || $target eq 'webgrade') {
 1235: 	$currentstring .= $token->[4];
 1236:     } elsif ($target eq 'tex') {
 1237: 	$currentstring .= '\emph{';
 1238:     }
 1239:     return $currentstring;
 1240: }
 1241: 
 1242: sub end_q {
 1243:     my ($target,$token) = @_;
 1244:     my $currentstring = '';
 1245:     if ($target eq 'web' || $target eq 'webgrade') {
 1246: 	$currentstring .= $token->[2];
 1247:     } elsif ($target eq 'tex') {
 1248: 	$currentstring .= '}';
 1249:     } 
 1250:     return $currentstring;
 1251: }
 1252: 
 1253: #  <p> is a bit strange since it does not require a closing </p>
 1254: #  However in latex, we must often output closing stuff to end
 1255: #  environments and {}'s etc.  Therefore we do all the work
 1256: #  of figuring out the ending strings in the start tag processing,
 1257: #  and provide a mechanism to output the stop text external
 1258: #  to tag processing.
 1259: #
 1260: {
 1261: 
 1262:     my $closing_string = '';		# String required to close <p>
 1263: 
 1264: #   Some tags are <p> fragile meaning that <p> inside of them
 1265: #   does not work within TeX mode.  This is managed via the 
 1266: #   counter below:
 1267: #
 1268: 
 1269:     my $para_disabled = 0;
 1270: 
 1271: sub disable_para {
 1272:     $para_disabled++;
 1273: }
 1274: sub enable_para {
 1275:     $para_disabled--;
 1276: }
 1277: 
 1278: 
 1279: #-- <p> tag (end tag optional)
 1280: #optional attribute - align="center|left|right"
 1281: sub start_p {
 1282:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1283:     my $currentstring = '';
 1284:     if ($target eq 'web' || $target eq 'webgrade') {
 1285: 	$currentstring .= &end_p();	# close off prior para if in progress.
 1286: 	$currentstring .= $token->[4];
 1287: 	if (! ($currentstring =~ /\//)) {
 1288: 	    $closing_string = '</p>'; # Deal correctly with <p /> e.g.
 1289: 	}
 1290:     } elsif ($target eq 'tex' && !$para_disabled) {
 1291: 
 1292: 	$currentstring .= &end_p();	# close off prior para if in progress.
 1293: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
 1294: 	if ($align eq 'center') {
 1295: 	    $currentstring .='\begin{center}\par ';
 1296: 	    $closing_string = '\end{center}';
 1297: 	    if (&is_inside_of($tagstack, "table")) {
 1298: 		$currentstring = &center_correction().$currentstring;
 1299: 	    }
 1300: 	} elsif ($align eq 'right') {
 1301: 	    $currentstring.="\n".'{\flushright ';
 1302: #	    $currentstring.='\makebox['.$env{'form.textwidth'}.']{\hfill\llap{';
 1303: 	    $closing_string= "}\n";
 1304: 	} elsif ($align eq 'left') {
 1305: 	    $currentstring.= "\n".'{\flushleft ';
 1306: #	    $currentstring.='\noindent\makebox['.$env{'form.textwidth'}.']{{';
 1307: 	    $closing_string = "}\n";
 1308: 	} else {
 1309:             $currentstring.='\par ';
 1310: 	    if (&is_inside_of($tagstack, 'table')) {
 1311: 		$closing_string = '\vskip 0pt'; # Seems to be consistent with <p> in tables.
 1312: 	    } else {
 1313: 		$closing_string = '\strut\\\\\strut ';
 1314: 	    }
 1315:         }
 1316: 
 1317:     }
 1318:     return $currentstring;
 1319: }
 1320: #
 1321: #  End paragraph processing just requires that we output the
 1322: #  closing string that was saved and blank it.
 1323: sub end_p {
 1324:     #  Note only 'tex' mode uses disable_para and enable_para
 1325:     #  so we don't need to know the target in the check below:
 1326: 
 1327:     if (!$para_disabled) {
 1328: 	my $current_string = $closing_string;
 1329: 	$closing_string = '';	# Not in a para anymore.
 1330: 	return $current_string;
 1331:     } else {
 1332: 	return '';
 1333:     }
 1334: 
 1335: }
 1336: }
 1337: #-- <br> tag (end tag forbidden)
 1338: sub start_br {
 1339:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1340:     my $currentstring = '';
 1341:     if ($target eq 'web' || $target eq 'webgrade') {
 1342: 	$currentstring .= $token->[4];
 1343:     } elsif ($target eq 'tex') {
 1344: 	my @tempo=@$tagstack;
 1345: 	my $signal=0;
 1346: 	#  Not going to factor this to is_inside_of since that would require
 1347:         #  multiple stack traversals.
 1348: 	#
 1349: 	for (my $i=$#tempo;$i>=0;$i--) {
 1350: 	    if (($tempo[$i] eq 'b') || ($tempo[$i] eq 'strong') ||
 1351:                 ($tempo[$i] eq 'ol') || ($tempo[$i] eq 'ul'))  {
 1352: 		$signal=1;
 1353: 	    }
 1354: 	    if (($tempo[$i] eq 'td') || ($tempo[$i] eq 'th')) {
 1355: 		$signal = 1;
 1356: 	    }
 1357: 	}
 1358: 	if ($signal != 1) {
 1359: 	    $currentstring .= '\strut \\\\ \strut ';
 1360: 	}
 1361:     
 1362:     }
 1363:     return $currentstring;
 1364: }
 1365: 
 1366: sub end_br {
 1367:     my ($target,$token) = @_;
 1368:     my $currentstring = '';
 1369:     if ($target eq 'web' || $target eq 'webgrade') {
 1370: 	$currentstring .= $token->[2];
 1371:     }
 1372:     return $currentstring;
 1373: }
 1374: 
 1375: #-- <big> tag (end tag required)
 1376: sub start_big {
 1377:     my ($target,$token) = @_;
 1378:     my $currentstring = '';
 1379:     if ($target eq 'web' || $target eq 'webgrade') {
 1380: 	$currentstring .= $token->[4];
 1381:     } elsif ($target eq 'tex') {
 1382: 	$currentstring .= '{\large ';
 1383:     } 
 1384:     return $currentstring;
 1385: }
 1386: 
 1387: sub end_big {
 1388:     my ($target,$token) = @_;
 1389:     my $currentstring = '';
 1390:     if ($target eq 'web' || $target eq 'webgrade') {
 1391: 	$currentstring .= $token->[2];
 1392:     } elsif ($target eq 'tex') {
 1393: 	$currentstring .= '}';
 1394:     }
 1395:     return $currentstring;
 1396: }
 1397: 
 1398: #-- <small> tag (end tag required)
 1399: sub start_small {
 1400:     my ($target,$token) = @_;
 1401:     my $currentstring = '';
 1402:     if ($target eq 'web' || $target eq 'webgrade') {
 1403: 	$currentstring .= $token->[4];
 1404:     } elsif ($target eq 'tex') {
 1405: 	$currentstring .= '{\footnotesize ';
 1406:     }
 1407:     return $currentstring;
 1408: }
 1409: 
 1410: sub end_small {
 1411:     my ($target,$token) = @_;
 1412:     my $currentstring = '';
 1413:     if ($target eq 'web' || $target eq 'webgrade') {
 1414: 	$currentstring .= $token->[2];
 1415:     } elsif ($target eq 'tex') {
 1416: 	$currentstring .= '}';
 1417:     }
 1418:     return $currentstring;
 1419: }
 1420: 
 1421: #-- <basefont> tag (end tag forbidden)
 1422: sub start_basefont {
 1423:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1424:     my $currentstring = '';
 1425:     if ($target eq 'web' || $target eq 'webgrade') {
 1426: 	$currentstring = $token->[4];     
 1427:     } elsif ($target eq 'tex') {
 1428: 	my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
 1429: 	if (defined $basesize) {
 1430: 	    $currentstring = '{\\'.$basesize.' ';
 1431: 	}
 1432:     }
 1433:     return $currentstring;
 1434: }
 1435: 
 1436: sub end_basefont {
 1437:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1438:     my $currentstring = '';
 1439:     if ($target eq 'web' || $target eq 'webgrade') {
 1440: 	$currentstring = $token->[4];     
 1441:     } elsif ($target eq 'tex') {
 1442: 	my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
 1443: 	if (defined $basesize) {
 1444: 	    $currentstring = '}';
 1445: 	}
 1446:     }
 1447:     return $currentstring;
 1448: }
 1449: 
 1450: #-- <font> tag (end tag required)
 1451: sub start_font {
 1452:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1453:     my $currentstring = '';
 1454:     if ($target eq 'web' || $target eq 'webgrade') {
 1455: 	my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
 1456: 	$currentstring = $token->[4];     
 1457:     }  elsif ($target eq 'tex') {
 1458: 	my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
 1459: 	if (defined $fontsize) {
 1460: 	    $currentstring = '{\\'.$fontsize.' ';
 1461: 	}
 1462:     }
 1463:     return $currentstring;
 1464: }
 1465: 
 1466: sub end_font {
 1467:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1468:     my $currentstring = '';
 1469:     if ($target eq 'web' || $target eq 'webgrade') {
 1470: 	$currentstring = $token->[2];    
 1471:     }  elsif ($target eq 'tex') {
 1472: 	my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
 1473: 	if (defined $fontsize) {
 1474: 	    $currentstring = '}';
 1475: 	}
 1476:     }
 1477:     return $currentstring;
 1478: }
 1479:  
 1480: #-- <strike> tag (end tag required)
 1481: sub start_strike {
 1482:     my ($target,$token) = @_;
 1483:     my $currentstring = '';
 1484:     if ($target eq 'web' || $target eq 'webgrade') {
 1485: 	$currentstring .= $token->[4];
 1486:     } elsif ($target eq 'tex') {
 1487: 	&Apache::lonxml::startredirection();
 1488:     } 
 1489:     return $currentstring;
 1490: }
 1491: 
 1492: sub end_strike {
 1493:     my ($target,$token) = @_;
 1494:     my $currentstring = '';
 1495:     if ($target eq 'web' || $target eq 'webgrade') {
 1496: 	$currentstring .= $token->[2];
 1497:     } elsif ($target eq 'tex') {
 1498: 	$currentstring=&Apache::lonxml::endredirection();
 1499: 	$currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g; 
 1500: 	$currentstring=~s/^\s*(\S)/\\underline\{$1/; 
 1501: 	$currentstring=~s/(\S)\s*$/$1\}/;
 1502:     }
 1503:     return $currentstring;
 1504: }
 1505: 
 1506: #-- <s> tag (end tag required)
 1507: sub start_s {
 1508:     my ($target,$token) = @_;
 1509:     my $currentstring = '';
 1510:     if ($target eq 'web' || $target eq 'webgrade') {
 1511: 	$currentstring .= $token->[4];
 1512:     } elsif ($target eq 'tex') {
 1513: 	&Apache::lonxml::startredirection();
 1514:     } 
 1515:     return $currentstring;
 1516: }
 1517: 
 1518: sub end_s {
 1519:     my ($target,$token) = @_;
 1520:     my $currentstring = '';
 1521:     if ($target eq 'web' || $target eq 'webgrade') {
 1522: 	$currentstring .= $token->[2];
 1523:     } elsif ($target eq 'tex') {
 1524: 	$currentstring=&Apache::lonxml::endredirection();
 1525: 	$currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
 1526: 	$currentstring=~s/^\s*(\S)/\\underline\{$1/;
 1527: 	$currentstring=~s/(\S)\s*$/$1\}/;	
 1528:     }
 1529:     return $currentstring;
 1530: }
 1531: 
 1532: #-- <sub> tag (end tag required)
 1533: sub start_sub {
 1534:     my ($target,$token) = @_;
 1535:     my $currentstring = '';
 1536:     if ($target eq 'web' || $target eq 'webgrade') {
 1537: 	$currentstring .= $token->[4];
 1538:     } elsif ($target eq 'tex') {
 1539: 	$currentstring .= '\raisebox{-\smallskipamount}{\scriptsize{';
 1540:     } 
 1541:     return $currentstring;
 1542: }
 1543: 
 1544: sub end_sub {
 1545:     my ($target,$token) = @_;
 1546:     my $currentstring = '';
 1547:     if ($target eq 'web' || $target eq 'webgrade') {
 1548: 	$currentstring .= $token->[2];
 1549:     } elsif ($target eq 'tex') {
 1550: 	$currentstring .= '}}';
 1551:     }
 1552:     return $currentstring;
 1553: }
 1554: 
 1555: #-- <sup> tag (end tag required)
 1556: sub start_sup {
 1557:     my ($target,$token) = @_;
 1558:     my $currentstring = '';
 1559:     if ($target eq 'web' || $target eq 'webgrade') {
 1560: 	$currentstring .= $token->[4];
 1561:     } elsif ($target eq 'tex') {
 1562: 	$currentstring .= '\raisebox{\smallskipamount}{\scriptsize{';
 1563:     } 
 1564:     return $currentstring;
 1565: }
 1566: 
 1567: sub end_sup {
 1568:     my ($target,$token) = @_;
 1569:     my $currentstring = '';
 1570:     if ($target eq 'web' || $target eq 'webgrade') {
 1571: 	$currentstring .= $token->[2];
 1572:     } elsif ($target eq 'tex') {
 1573: 	$currentstring .= '}}';
 1574:     }
 1575:     return $currentstring;
 1576: }
 1577: 
 1578: #-- <hr> tag (end tag forbidden)
 1579: sub start_hr {
 1580:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1581:     my $currentstring = &end_p();	# End enclosing para.
 1582:     if ($target eq 'web' || $target eq 'webgrade') {
 1583: 	$currentstring .= $token->[4];
 1584:     } elsif ($target eq 'tex') {
 1585: 
 1586: 	# <hr /> can't be inside of <sup><sub> thank you LaTeX.
 1587: 	# 
 1588: 	my $restart_sub = 0;
 1589: 	my $restart_sup = 0;
 1590: 
 1591: 	# Since <sub> and <sup> are simple tags it's ok to turn off/on
 1592: 	# using the start_ stop_ functions.. those tags only care about
 1593: 	# $target.
 1594: 
 1595: 	if (&is_inside_of($tagstack, "sub")) {
 1596: 	    $restart_sub = 1;
 1597: 	    $currentstring .= &end_sub($target, $token, $tagstack, 
 1598: 				       $parstack, $parser, $safeeval);
 1599: 	}
 1600: 	if (&is_inside_of($tagstack, "sup")) {
 1601: 	    $restart_sup = 1;
 1602: 	    $currentstring .= &end_sup($target, $token, $tagstack,
 1603: 				       $parstack, $parser, $safeeval);
 1604: 	}	
 1605: 
 1606: 	my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
 1607: 	if (defined $LaTeXwidth) {
 1608: 	    if ($LaTeXwidth=~/^%/) {
 1609: 		substr($LaTeXwidth,0,1)='';
 1610: 		$LaTeXwidth=($LaTeXwidth/100).'\textwidth';
 1611: 	    }
 1612: 	} else {
 1613: 	    $LaTeXwidth ='0.9\textwidth';
 1614: 	}
 1615: 	my ($pre,$post);
 1616: 	my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
 1617: 	if (($align eq 'center') || (not defined $align)) {
 1618: 	    $pre=''; $post='';
 1619: 	} elsif ($align eq 'left') {
 1620: 	    $pre='\rlap{'; $post='} \hfill';
 1621: 	} elsif ($align eq 'right') {
 1622: 	    $pre=' \hfill \llap{'; $post='}';
 1623: 	}
 1624: 	$currentstring .= ' \vskip 0 mm \noindent\makebox['.$LaTeXwidth.']{'.$pre.'\makebox['.
 1625:                                     $LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm ';
 1626: 	# Turn stuff back on that we can't be inside of.
 1627: 
 1628: 	if ($restart_sub) {
 1629: 	    $currentstring .= &start_sub($target, $token, $tagstack,
 1630: 					$parstack, $parser, $safeeval);
 1631: 	}
 1632: 	if ($restart_sup) {
 1633: 	    $currentstring .= &start_sup($target, $token, $tagstack,
 1634: 					 $parstack, $parser, $safeeval);
 1635: 	}	
 1636:     } 
 1637:     return $currentstring;
 1638: }
 1639: 
 1640: sub end_hr {
 1641:     my ($target,$token) = @_;
 1642:     my $currentstring = '';
 1643:     if ($target eq 'web' || $target eq 'webgrade') {
 1644: 	$currentstring .= $token->[2];
 1645:     }
 1646:     return $currentstring;
 1647: }
 1648: 
 1649: #-- <div> tag (end tag required)
 1650: {
 1651: 
 1652: #  Since div can be nested, the stack below is used
 1653: #  in 'tex' mode to store the ending strings
 1654: #  for the div stack.
 1655: 
 1656:     my @div_end_stack;
 1657: 
 1658: sub start_div {
 1659:     my ($target,$token, $tagstack, $parstack, $parser, $safeeval) = @_;
 1660:     my $currentstring = &end_p();	# Close enclosing para.
 1661:     if ($target eq 'web' || $target eq 'webgrade') {
 1662: 	$currentstring .= $token->[4];
 1663:     } 
 1664:     if ($target eq 'tex') {
 1665: 	# 4 possible alignments: left, right, center, and -missing-.
 1666:         # If inside a table row, we must let the table logic
 1667: 	# do the alignment, however.
 1668: 	# 
 1669: 
 1670: 	my $endstring = '';
 1671: 
 1672: 	my $align = lc(&Apache::lonxml::get_param('align', $parstack,
 1673: 						  $safeeval, undef, 1));
 1674: 	if ($align eq 'center') {
 1675: 	    $currentstring .= '\begin{center}';
 1676: 	    $endstring      = '\end{center}';
 1677: 	    if (&is_inside_of($tagstack, "table")) {
 1678: 		$currentstring = &center_correction().$currentstring;
 1679: 		$endstring    .= &center_end_correction(); 
 1680: 	    }
 1681: 	}
 1682: 	elsif ($align eq 'right') {
 1683: 	    $currentstring .= '\begin{flushright}';
 1684: 	    $endstring     .= '\end{flushright}';
 1685: 	} elsif ($align eq 'left') {
 1686: 	    $currentstring .= '\begin{flushleft}';
 1687: 	    $endstring     = '\end{flushleft}';
 1688: 	} else {
 1689: 	
 1690: 	}
 1691: 	$currentstring .= "\n";   # For human readability.
 1692: 	$endstring       = "\n$endstring\n"; # For human readability
 1693: 	push(@div_end_stack, $endstring);
 1694:     }
 1695:     return $currentstring;
 1696: }
 1697: 
 1698: sub end_div {
 1699:     my ($target,$token) = @_;
 1700:     my $currentstring = '';
 1701:     if ($target eq 'web' || $target eq 'webgrade') {
 1702: 	$currentstring .= $token->[2];
 1703:     }
 1704:     if ($target eq 'tex') {
 1705: 	my $endstring = pop @div_end_stack;
 1706: 	$currentstring .= $endstring;
 1707:     }
 1708:     return $currentstring;
 1709: }
 1710: }
 1711: 
 1712: #-- <a> tag (end tag required)
 1713: sub start_a {
 1714:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1715:     my $currentstring = '';
 1716:     if ($target eq 'web' || $target eq 'webgrade') {
 1717: 	my $href=&Apache::lonxml::get_param('href',$parstack,$safeeval,
 1718: 					    undef,1);
 1719: 	$currentstring=&Apache::lonenc::encrypt_ref($token,{'href'=>$href});
 1720:         if ($href =~ /\S/) {
 1721:             if ($href !~ m{^https?://}) {
 1722:                 my $url=&Apache::lonnet::hreflocation('',$env{'request.filename'});
 1723:                 my $linkurl;
 1724:                 if ($href =~ m{^/uploaded/}) {
 1725:                     $linkurl = $href;
 1726:                 } elsif ($href =~ m{^[^/]}) {
 1727:                     my $path = $url;
 1728:                     $path  =~ s{[^/]*$}{};
 1729:                     $linkurl = $path.$href;
 1730:                 }
 1731:                 if ($linkurl =~ m{^/uploaded/}) {
 1732:                     if (!&Apache::lonnet::allowed('bre',$linkurl)) {
 1733:                         if (&Apache::lonnet::is_on_map($url)) {
 1734:                             &Apache::lonxml::extlink($linkurl);
 1735:                         } elsif ($env{'request.course.id'}) {
 1736:                             my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1737:                             my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1738:                             if ($linkurl =~ m{^([^/]|/uploaded/$cdom/$cnum/docs/)}) {
 1739:                                 my $cleanhref = &clean_docs_httpref($linkurl,$url,$cdom,$cnum);
 1740:                                 if ($cleanhref) {
 1741:                                     &Apache::lonxml::extlink($cleanhref);
 1742:                                 }
 1743:                             }
 1744:                         }
 1745:                     }
 1746:                 }
 1747:             }
 1748:         }
 1749:     }
 1750:     return $currentstring;
 1751: }
 1752: 
 1753: sub end_a {
 1754:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1755:     my $currentstring = '';
 1756:     if ($target eq 'web' || $target eq 'webgrade') {
 1757: 	$currentstring .= $token->[2];
 1758:     }
 1759:     if ($target eq 'tex') {
 1760: 	my $href =
 1761: 	    &Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1);
 1762: 	my $name =
 1763: 	    &Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1);
 1764:         my $uriprint =
 1765:             &Apache::lonxml::get_param('uriprint',$parstack,$safeeval,undef,1);
 1766:         my $anchorprint =
 1767:             &Apache::lonxml::get_param('anchorprint',$parstack,$safeeval,undef,1);
 1768: 	if (($href =~ /\S/) && ($uriprint=~/^on|uriprint|yes|1$/i)) {
 1769: 	    $href =~ s/([^\\])%/$1\\\%/g;
 1770: 	    # Substitute special symbols... and allow line breaks at each /
 1771: 	    #
 1772: 	    $href = &Apache::lonxml::latex_special_symbols($href);
 1773: 	    $href =~ s/\//\/\\-/g;              # Map / to /\- to allow hyphenation.
 1774: 	    $currentstring .= ' ({\tt URI:'.$href.'})';
 1775: 	} elsif (($name =~ /\S/) && ($anchorprint=~/^on|anchorprint|yes|1$/i)) {
 1776: 	    $currentstring .= ' ({\tt Anchor:'.&Apache::lonxml::latex_special_symbols($name).'})';
 1777: 	} else {
 1778: 	    $currentstring.='';
 1779: 	}	
 1780:     }
 1781:     return $currentstring;
 1782: }
 1783: 
 1784: #-- <li> tag (end tag optional)
 1785: sub start_li {
 1786:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1787:     my $currentstring = '';
 1788:     if ($target eq 'web' || $target eq 'webgrade') {
 1789: 	$currentstring = $token->[4];     
 1790:     } elsif ($target eq 'tex') {
 1791: 	my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
 1792: 	my $value=&Apache::lonxml::get_param('value',$parstack,$safeeval,undef,0);
 1793: 	#FIXME need to support types i and I 
 1794: 	if ($type=~/disc/) {
 1795: 	    $currentstring .= ' \item[$\bullet$] ';
 1796: 	} elsif ($type=~/circle/) {
 1797: 	    $currentstring .= ' \item[$\circ$] ';
 1798: 	} elsif ($type=~/square/) {
 1799: 	    $currentstring .= ' \item[$\diamond$] ';
 1800: 	} elsif ($type eq '1') {
 1801: 	    $currentstring .= ' \item['.($Apache::londefdef::list_index+1).'.]';
 1802: 	} elsif ($type eq 'A') {
 1803: 	    $currentstring .= ' \item['.('A'..'Z')[$Apache::londefdef::list_index].'.]';
 1804: 	} elsif ($type eq 'a') {
 1805: 	    $currentstring .= ' \item['.('a'..'z')[$Apache::londefdef::list_index].'.]';
 1806: 	} elsif ($value ne '') {
 1807: 	    $currentstring .= ' \item['.$value.'] ';
 1808: 	} else {
 1809: 	    $currentstring .= ' \item ';
 1810: 	}  
 1811: 	$Apache::londefdef::list_index++;
 1812:     }
 1813:     return $currentstring;
 1814: }
 1815: 
 1816: sub end_li {
 1817:     my ($target,$token) = @_;
 1818:     my $currentstring = &end_p();	# In case there's a <p> in the <li>
 1819:     if ($target eq 'web' || $target eq 'webgrade') {
 1820: 	$currentstring .= $token->[2];     
 1821:     } 
 1822:     return $currentstring;
 1823: }
 1824: 
 1825: #-- <u> tag (end tag required)
 1826: sub start_u {
 1827:     my ($target,$token) = @_;
 1828:     my $currentstring = '';
 1829:     if ($target eq 'web' || $target eq 'webgrade') {
 1830: 	$currentstring .= $token->[4];
 1831:     } elsif ($target eq 'tex') {
 1832: 	&Apache::lonxml::startredirection();
 1833:     } 
 1834:     return $currentstring;
 1835: }
 1836: 
 1837: sub end_u {
 1838:     my ($target,$token) = @_;
 1839:     my $currentstring = '';
 1840:     if ($target eq 'web' || $target eq 'webgrade') {
 1841: 	$currentstring .= $token->[2];
 1842:     } elsif ($target eq 'tex') {
 1843: 	$currentstring=&Apache::lonxml::endredirection();
 1844: 	$currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
 1845: 	$currentstring=~s/^\s*(\S)/\\underline\{$1/;
 1846: 	$currentstring=~s/(\S)\s*$/$1\}/;		
 1847:     }
 1848:     return $currentstring;
 1849: }
 1850: 
 1851: #-- <ul> tag (end tag required)
 1852: sub start_ul {
 1853:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1854:     my $currentstring = &end_p();	# Close off enclosing list.
 1855:     if ($target eq 'web' || $target eq 'webgrade') {
 1856: 	$currentstring .= $token->[4];     
 1857:     } elsif ($target eq 'tex') {
 1858: 	my $TeXtype=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
 1859: 	$Apache::londefdef::list_index=0;
 1860: 	if ($TeXtype eq 'disc') {
 1861: 	    $currentstring .= '\renewcommand{\labelitemi}{$\bullet$}'.
 1862:                               '\renewcommand{\labelitemii}{$\bullet$}'. 
 1863:                               '\renewcommand{\labelitemiii}{$\bullet$}'.
 1864:                               '\renewcommand{\labelitemiv}{$\bullet$}';
 1865: 	} elsif ($TeXtype eq 'circle') {
 1866: 	    $currentstring .= '\renewcommand{\labelitemi}{$\circ$}'.
 1867:                               '\renewcommand{\labelitemii}{$\circ$}'. 
 1868:                               '\renewcommand{\labelitemiii}{$\circ$}'.
 1869:                               '\renewcommand{\labelitemiv}{$\circ$}';
 1870: 	} elsif ($TeXtype eq 'square') {
 1871: 	    $currentstring .= '\renewcommand{\labelitemi}{$\diamond$}'.
 1872:                               '\renewcommand{\labelitemii}{$\diamond$}'. 
 1873:                               '\renewcommand{\labelitemiii}{$\diamond$}'.
 1874:                               '\renewcommand{\labelitemiv}{$\diamond$}';
 1875: 	}
 1876: 	$currentstring .= '\strut \begin{itemize}';  
 1877:     } 
 1878:     return $currentstring;
 1879: }
 1880: 
 1881: sub end_ul {
 1882:     my ($target,$token) = @_;
 1883:     my $currentstring = '';
 1884:     if ($target eq 'web' || $target eq 'webgrade') {
 1885: 	$currentstring = $token->[2];     
 1886:     } elsif ($target eq 'tex') {
 1887: 	$currentstring = '\end{itemize} \renewcommand{\labelitemi}{$\bullet$}'.
 1888:                                '\renewcommand{\labelitemii}{$\bullet$}'. 
 1889:                                '\renewcommand{\labelitemiii}{$\bullet$}'.
 1890:                                '\renewcommand{\labelitemiv}{$\bullet$}\strut ';  
 1891:     } 
 1892:     return $currentstring;
 1893: }
 1894: 
 1895: #-- <menu> tag (end tag required)
 1896: sub start_menu {
 1897:     my ($target,$token) = @_;
 1898:     my $currentstring = '';
 1899:     if ($target eq 'web' || $target eq 'webgrade') {
 1900: 	$currentstring = $token->[4];     
 1901:     } elsif ($target eq 'tex') {
 1902: 	$currentstring = " \\begin{itemize} ";  
 1903:     } 
 1904:     return $currentstring;
 1905: }
 1906: 
 1907: sub end_menu {
 1908:     my ($target,$token) = @_;
 1909:     my $currentstring = '';
 1910:     if ($target eq 'web' || $target eq 'webgrade') {
 1911: 	$currentstring = $token->[2];     
 1912:     } elsif ($target eq 'tex') {
 1913: 	$currentstring = " \\end{itemize}";  
 1914:     } 
 1915:     return $currentstring;
 1916: }
 1917: 
 1918: #-- <dir> tag (end tag required)
 1919: sub start_dir {
 1920:     my ($target,$token) = @_;
 1921:     my $currentstring = &end_p();	# In case there's a <p> prior to the list.
 1922:     if ($target eq 'web' || $target eq 'webgrade') {
 1923: 	$currentstring .= $token->[4];     
 1924:     } elsif ($target eq 'tex') {
 1925: 	$currentstring .= " \\begin{itemize} ";  
 1926:     } 
 1927:     return $currentstring;
 1928: }
 1929: 
 1930: sub end_dir {
 1931:     my ($target,$token) = @_;
 1932:     my $currentstring = '';
 1933:     if ($target eq 'web' || $target eq 'webgrade') {
 1934: 	$currentstring = $token->[2];     
 1935:     } elsif ($target eq 'tex') {
 1936: 	$currentstring = " \\end{itemize}";  
 1937:     } 
 1938:     return $currentstring;
 1939: }
 1940: 
 1941: #-- <ol> tag (end tag required)
 1942: sub start_ol {
 1943:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 1944:     my $currentstring = &end_p();	# In case there's a <p> prior to the list.
 1945:     if ($target eq 'web' || $target eq 'webgrade') {
 1946: 	$currentstring .= $token->[4];     
 1947:     } elsif ($target eq 'tex') {
 1948: 	$Apache::londefdef::list_index=0;
 1949: 	my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
 1950: 	if ($type eq '1') {
 1951: 	    $currentstring .= '\renewcommand{\labelenumi}{\arabic{enumi}.}'.
 1952:                               '\renewcommand{\labelenumii}{\arabic{enumii}.}'. 
 1953:                               '\renewcommand{\labelenumiii}{\arabic{enumiii}.}'.
 1954:                               '\renewcommand{\labelenumiv}{\arabic{enumiv}.}';
 1955: 	} elsif ($type eq 'A') {
 1956: 	    $currentstring .= '\renewcommand{\labelenumi}{\Alph{enumi}.}'.
 1957:                               '\renewcommand{\labelenumii}{\Alph{enumii}.}'. 
 1958:                               '\renewcommand{\labelenumiii}{\Alph{enumiii}.}'.
 1959:                               '\renewcommand{\labelenumiv}{\Alph{enumiv}.}';
 1960: 	} elsif ($type eq 'a') {
 1961: 	    $currentstring .= '\renewcommand{\labelenumi}{\alph{enumi}.}'.
 1962:                               '\renewcommand{\labelenumii}{\alph{enumii}.}'.
 1963:                               '\renewcommand{\labelenumiii}{\alph{enumiii}.}'.
 1964:                               '\renewcommand{\labelenumiv}{\alph{enumiv}.}';
 1965: 	} elsif ($type eq 'i') {
 1966: 	    $currentstring .= '\renewcommand{\labelenumi}{\roman{enumi}.}'.
 1967:                               '\renewcommand{\labelenumii}{\roman{enumii}.}'.
 1968:                               '\renewcommand{\labelenumiii}{\roman{enumiii}.}'.
 1969:                               '\renewcommand{\labelenumiv}{\roman{enumiv}.}';
 1970: 	} elsif ($type eq 'I') {
 1971: 	    $currentstring .= '\renewcommand{\labelenumi}{\Roman{enumi}.}'.
 1972:                               '\renewcommand{\labelenumii}{\Roman{enumii}.}'.
 1973:                               '\renewcommand{\labelenumiii}{\Roman{enumiii}.}'.
 1974:                               '\renewcommand{\labelenumiv}{\Roman{enumiv}.}';
 1975: 	}
 1976: 	$currentstring .= '\strut \begin{enumerate}';  
 1977:     } 
 1978:     return $currentstring;
 1979: }
 1980: 
 1981: sub end_ol {
 1982:     my ($target,$token) = @_;
 1983:     my $currentstring = '';
 1984:     if ($target eq 'web' || $target eq 'webgrade') {
 1985: 	$currentstring = $token->[2];     
 1986:     } elsif ($target eq 'tex') {
 1987: 	$currentstring = '\end{enumerate}\renewcommand{\labelenumi}{\arabic{enumi}.}'.
 1988:                                         '\renewcommand{\labelenumii}{\arabic{enumii}.}'.
 1989:                                         '\renewcommand{\labelenumiii}{\arabic{enumiii}.}'.
 1990:                                         '\renewcommand{\labelenumiv}{\arabic{enumiv}.}\strut ';  
 1991:     } 
 1992:     return $currentstring;
 1993: }
 1994: 
 1995: #-- <dl> tag (end tag required)
 1996: sub start_dl {
 1997:     my ($target,$token) = @_;
 1998:     my $currentstring = &end_p();	# In case there's a <p> unclosed prior to the list.
 1999:     if ($target eq 'web' || $target eq 'webgrade') {
 2000: 	$currentstring .= $token->[4];     
 2001:     } elsif ($target eq 'tex') {
 2002: 	$currentstring .= '\begin{description}';
 2003: 	$Apache::londefdef::DL++;
 2004: 	push(@Apache::londefdef::description,[]);
 2005: 	$Apache::londefdef::DD[$Apache::londefdef::DL]=0;
 2006: 	$Apache::londefdef::DT[$Apache::londefdef::DL]=0;
 2007: 	$Apache::londefdef::seenDT[$Apache::londefdef::DL]=0;
 2008:     } 
 2009:     return $currentstring;
 2010: }
 2011: 
 2012: sub end_dl {
 2013:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2014:     my $currentstring = '';
 2015:     if ($target eq 'web' || $target eq 'webgrade') {
 2016: 	$currentstring = $token->[2];     
 2017:     } elsif ($target eq 'tex') {
 2018: 	if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
 2019: 	if ($Apache::londefdef::DD[-1]) { &end_dd(@_); }
 2020: 	foreach my $element (@{$Apache::londefdef::description[-1]}) {
 2021: 	    $currentstring.=' '.$element.' ';
 2022: 	}
 2023: 	pop(@Apache::londefdef::description);
 2024: 	$currentstring.='\end{description}';  
 2025: 	delete($Apache::londefdef::DD[$Apache::londefdef::DL]);
 2026: 	delete($Apache::londefdef::DT[$Apache::londefdef::DL]);
 2027: 	delete($Apache::londefdef::seenDT[$Apache::londefdef::DL]);
 2028: 	$Apache::londefdef::DL--;
 2029:     } 
 2030:     return $currentstring;
 2031: }
 2032: 
 2033: #-- <dt> tag (end tag optional)
 2034: sub start_dt {
 2035:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2036:     my $currentstring='';
 2037:     if ($target eq 'web' || $target eq 'webgrade') {
 2038: 	$currentstring = $token->[4];     
 2039:     } elsif ($target eq 'tex') {
 2040: 	if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
 2041: 	if ($Apache::londefdef::DD[-1]) { &end_dd(@_); }
 2042: 	&Apache::lonxml::startredirection();
 2043: 	$Apache::londefdef::DT[-1]++;
 2044: 	$Apache::londefdef::seenDT[-1]=1;
 2045:     } 
 2046:     return $currentstring;
 2047: }
 2048: 
 2049: sub end_dt {
 2050:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2051:     my $currentstring = '';
 2052:     if ($target eq 'web' || $target eq 'webgrade') {
 2053: 	$currentstring = $token->[2];    
 2054:     } elsif ($target eq 'tex') {
 2055: 	if ($Apache::londefdef::DT[-1]) {
 2056: 	    my $data=&item_cleanup();
 2057: 	    push(@{$Apache::londefdef::description[-1]},'\item['.$data.'] \strut \vskip 0mm');
 2058: 	    $Apache::londefdef::DT[-1]--;
 2059: 	}
 2060:     } 
 2061:     return $currentstring;
 2062: }
 2063: 
 2064: sub item_cleanup {
 2065:     my $item=&Apache::lonxml::endredirection();
 2066:     $item=~s/\\begin{center}//g;
 2067:     $item=~s/\\end{center}//g;
 2068:     return $item;
 2069: }
 2070: 
 2071: #-- <dd> tag (end tag optional)
 2072: sub start_dd {
 2073:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2074:     my $currentstring = '';
 2075:     if ($target eq 'web' || $target eq 'webgrade') {
 2076: 	$currentstring = $token->[4];     
 2077:     } elsif ($target eq 'tex') {
 2078: 	if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
 2079: 	if ($Apache::londefdef::DD[-1]) { &end_dd(@_);}
 2080: 	if (!$Apache::londefdef::seenDT[-1]) {
 2081: 	    push(@{$Apache::londefdef::description[-1]},'\item[\strut] \strut \vskip 0mm ');
 2082: 	}
 2083: 	push(@{$Apache::londefdef::description[-1]},'');
 2084: 	$Apache::londefdef::description[-1]->[-1].=' \strut ';
 2085: 	$Apache::londefdef::DD[-1]++;
 2086: 	&Apache::lonxml::startredirection();
 2087:     } 
 2088:     return $currentstring;
 2089: }
 2090: 
 2091: sub end_dd {
 2092:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2093:     my $currentstring = '';
 2094:     if ($target eq 'web' || $target eq 'webgrade') {
 2095: 	$currentstring = $token->[2];    
 2096:     }  elsif ($target eq 'tex') {
 2097: 	$Apache::londefdef::description[-1]->[-1].=
 2098: 	    &Apache::lonxml::endredirection().' \vskip 0mm ';
 2099: 	$Apache::londefdef::DD[-1]--;
 2100:     }
 2101:     return $currentstring;
 2102: }
 2103: 
 2104: #-- <table> tag (end tag required)
 2105: #       <table> also ends any prior <p> that is not closed.
 2106: #               but, unless I allow <p>'s to nest, that's the
 2107: #               only way I could think of to allow <p> in 
 2108: #               <tr> <th> bodies
 2109: #
 2110: #list of supported attributes: border,width,TeXwidth,TeXtheme
 2111: #                              align
 2112: sub start_table {
 2113:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2114:     my $textwidth = '';
 2115:     my $currentstring = &end_p();
 2116:     if ($target eq 'web' || $target eq 'webgrade') {
 2117: 	$currentstring .= $token->[4];     
 2118:     } elsif ($target eq 'tex') {
 2119: 	&disable_para();	# Can't have paras in a table.
 2120: 
 2121: 	#  Get the parameters that we can do something about:
 2122: 
 2123: 	my $border = &Apache::lonxml::get_param('border', $parstack, $safeeval, undef, 0);
 2124: 	my $width  = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval, undef, 0);
 2125: 	my $theme  = &Apache::lonxml::get_param('TeXtheme', $parstack, $safeeval, undef, 0);
 2126: 	my $align  = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 0);
 2127: 	my $cell_border = &Apache::lonxml::get_param('rules', $parstack, $safeeval, undef, 0);
 2128: 
 2129: 	# The only thing that needs any figuring out is the width.. and then only if it is
 2130: 	# a percent. If not it's assumed to be some valid TeX measurement unit e.g. 3.0cm
 2131: 	#
 2132: 
 2133: 	my $table = new Apache::lontable();
 2134: 	if ((defined $border) && ($border > 0)) {
 2135: 	#    &Apache::lonnet::logthis("Turning on table borders: $border");
 2136: 	    $table->table_border(1);
 2137: 	    if (!defined $cell_border) {
 2138: 		$table->cell_border(1); # Default for rules is all if rules not defined.
 2139: 	    }
 2140: 	}
 2141: 
 2142: 	if ((defined $cell_border)) {
 2143: 	    if ($cell_border eq 'all') {
 2144: 		$table->cell_border(1);
 2145: 	    } elsif ($cell_border eq 'rows') {
 2146: 		$table->cell_border(2);
 2147: 	    } elsif ($cell_border eq 'cols') {
 2148: 		$table->cell_border(3);
 2149: 	    } elsif($cell_border eq 'groups') {
 2150: 		$table->cell_border(4);
 2151: 	    } else {
 2152: 		$table->cell_border(0);
 2153: 	    }
 2154: 	}
 2155: 	if (defined $theme) {
 2156: 	    $table->theme($theme);
 2157: 	}
 2158: 	if (defined $align) {
 2159: 	    $table->alignment($align);
 2160: 	}
 2161: 
 2162: 	# Missing width is most of page width
 2163: 
 2164: 	if (!(defined $width)) {
 2165: 	    $width = '70%';
 2166: 	}
 2167: 
 2168: 	# If a percentage, need to calculate what this means in terms of
 2169: 	# page width:
 2170: 	
 2171: 	if ($width =~ /%$/) {
 2172: 	    my $textwidth = &recalc($env{'form.textwidth'});  # Page width in mm.
 2173: 	    $width =~ s/%//;
 2174: 	    $width = $width * $textwidth / 100.0;
 2175: 	    $width .= " mm";
 2176: 	    $table->width($width);
 2177: 	}
 2178: 
 2179: 	push(@Apache::londefdef::table, $table);
 2180:         $currentstring.=' \keephidden{NEW TABLE ENTRY}';
 2181: 
 2182:     }
 2183:     return $currentstring;
 2184: }
 2185:  
 2186: sub end_table {
 2187:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2188:     my $currentstring = '';
 2189:     if ($target eq 'web' || $target eq 'webgrade') {
 2190: 	$currentstring = $token->[2];     
 2191:     } elsif ($target eq 'tex') {
 2192: 	
 2193: 	
 2194: 	my $table = pop(@Apache::londefdef::table);
 2195: 	my $t     = $table->generate();
 2196: 	# &Apache::lonnet::logthis("Generating string");
 2197: 	$currentstring = $t->generate_string();
 2198: 	# &Apache::lonnet::logthis("Generated: $currentstring");
 2199: 	&enable_para();
 2200: 	
 2201:     }
 2202:     return $currentstring;
 2203: }
 2204: 
 2205: #-- <tr> tag (end tag optional)
 2206: sub start_tr {
 2207:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2208:     my $currentstring = '';
 2209:     if ($target eq 'web' || $target eq 'webgrade') {
 2210: 	$currentstring = $token->[4];     
 2211:     } elsif ($target eq 'tex') {
 2212: 
 2213: 	my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 1);
 2214: 	$Apache::londefdef::table[-1]->start_row();
 2215: 	
 2216: 	if ($align ne '') {
 2217: 	    $Apache::londefdef::table[-1]->configure_row({default_halign => $align});
 2218: 	}
 2219: 
 2220: 	#---------------------------------------------------------------
 2221: 	# Old table code.
 2222: 	#---------------------------------------------------------------
 2223: 
 2224: 	if (0) {
 2225: 	$Apache::londefdef::table[-1]{'row_number'}++;
 2226: 	my $alignchar=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
 2227: 	if ($alignchar ne '') {
 2228: 	    push @ {$Apache::londefdef::table[-1]{'rows'} },substr($alignchar,0,1);
 2229: 	} else {
 2230: 	    push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l';
 2231: 	}
 2232: 	push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'});
 2233: 	#
 2234: 	#  Need to save the number of table columns to preserve the max # columns.
 2235: 	#
 2236: 	$Apache::londefdef::table[-1]{'prior_columns'}   = $Apache::londefdef::table[-1]{'counter_columns'};
 2237: 	$Apache::londefdef::table[-1]{'counter_columns'} = -1;
 2238: 	push @ {$Apache::londefdef::table[-1]{'TeXlen'}}, [];
 2239: 	push @ {$Apache::londefdef::table[-1]{'objectlen'}}, [];
 2240: 	push @ {$Apache::londefdef::table[-1]{'minlen'}}, [];
 2241: 	push @ {$Apache::londefdef::table[-1]{'maxlen'}}, [];
 2242: 	push @ {$Apache::londefdef::table[-1]{'content'}}, [];
 2243:     }
 2244:     } 
 2245:     return $currentstring;
 2246: }
 2247:         
 2248: sub end_tr {
 2249:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2250:     my $currentstring = &end_p();	# Close any pending <p> in the row.
 2251:     if ($target eq 'web' || $target eq 'webgrade') {
 2252: 	$currentstring .= $token->[2];     
 2253:     } elsif ($target eq 'tex') {
 2254: 
 2255: 	# In case the user is missing a </td> or </th> tag:
 2256: 
 2257: 	if ($Apache::londefdef::TD_redirection) {
 2258: 	    &end_td_tex($parstack,$parser,$safeeval);    
 2259: 	}
 2260: 	$Apache::londefdef::table[-1]->end_row();
 2261: 
 2262: 	#-----------------------------------------------
 2263: 	# Old table code
 2264: 	#-----------------------------------------------
 2265: 
 2266: 	if (0) {
 2267: 	if ($Apache::londefdef::TD_redirection) {
 2268: 	    &end_td_tex($parstack,$parser,$safeeval);    
 2269: 	}
 2270: 	# Counter columns must be the maximum number of columns seen
 2271: 	# in the table so far so:
 2272: 	if ($Apache::londefdef::table[-1]{'prior_columns'} > $Apache::londefdef::table[-1]{'counter_columns'}) {
 2273: 	    $Apache::londefdef::table[-1]{'counter_columns'} = $Apache::londefdef::table[-1]{'prior_columns'};
 2274: 	}
 2275:     }
 2276: 
 2277: 	
 2278:     }
 2279:     return $currentstring;
 2280: }
 2281: 
 2282: #-- <td> tag (end tag optional)
 2283: sub start_td {
 2284:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2285:     my $currentstring = '';
 2286:     if ($target eq 'web' || $target eq 'webgrade') {
 2287: 	$currentstring = $token->[4];     
 2288:     } elsif ($target eq 'tex') {
 2289: 	$Apache::londefdef::TD_redirection = 1;
 2290: 	&tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval);
 2291:     } 
 2292:     return $currentstring;
 2293: }   
 2294:     
 2295: sub tag_check {
 2296:     my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
 2297:     my @ar=@$parstack; 
 2298:     for (my $i=$#ar-1;$i>=0;$i--) {
 2299: 	if (lc($$tagstack[$i]) eq $good_tag) {
 2300: 	    &start_td_tex($parstack,$parser,$safeeval);
 2301: 	    last;
 2302: 	} elsif (lc($$tagstack[$i]) eq $bad_tag) {
 2303: 	    splice @ar, $i+1;
 2304: 	    &end_td_tex(\@ar,$parser,$safeeval);
 2305: 	    &start_td_tex($parstack,$parser,$safeeval);
 2306: 	    last;
 2307: 	}
 2308:     }
 2309:     return '';
 2310: }
 2311: 
 2312: #
 2313: #  Factor out cell configuration hash generation:
 2314: #
 2315: 
 2316: sub cell_config_hash {
 2317:     my ($align, $rowspan, $colspan, $width) = @_;
 2318:     if ($rowspan ne '') {
 2319:         $rowspan =~ s/^\s+|\s+$//g; 
 2320:     }
 2321:     if ($colspan ne '') {
 2322:         $colspan =~ s/^\s+|\s+$//g;
 2323:     }
 2324:     my %config;
 2325:     if ($align ne '') {
 2326: 	$config{'halign'} = $align;
 2327:     }
 2328:     if (($colspan =~ /^\d+$/) && ($colspan > 0)) {
 2329: 	$config{'colspan'} = $colspan;
 2330:     }
 2331:     if (($rowspan =~ /^\d+$/) && ($rowspan > 0)) {
 2332: 	$config{'rowspan'} = $rowspan;
 2333:     }
 2334:     if ($width ne '') {
 2335: 	$config{'width'} = $width;
 2336:     }
 2337:     return \%config;
 2338: }
 2339:  
 2340: sub start_td_tex {
 2341:     my ($parstack,$parser,$safeeval) = @_;
 2342: 
 2343:     # At this stage, an empty cell is created with the
 2344:     # appropriate rowspan/colspan and alignment
 2345:     # attributes, but empty of text.  end_td_tex will
 2346:     # fetch the contents from the recursive parse and
 2347:     # fill the cell with them:
 2348:     my $align   = &Apache::lonxml::get_param('align', $parstack, $safeeval);
 2349:     my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval);
 2350:     my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval);
 2351:     my $width   = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval);
 2352:     my $config = &cell_config_hash($align, $rowspan, $colspan, $width);
 2353: 
 2354:     my $table = $Apache::londefdef::table[-1];
 2355:     $table->add_cell('', $config);
 2356:     
 2357: 
 2358:     #------------------------------------------------
 2359:     #  Old table code.
 2360:     #------------------------------------------------
 2361: 
 2362:     if (0) {
 2363: 
 2364:     my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
 2365:     if ($alignchar eq '') {
 2366: 	$alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
 2367:     }
 2368:     push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
 2369:     $Apache::londefdef::table[-1]{'counter_columns'}++;
 2370:     my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
 2371:     if (defined $TeXwidth) {		
 2372: 	my $current_length=&recalc($TeXwidth);
 2373: 	$current_length=~/(\d+\.?\d*)/;
 2374: 	push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
 2375:     }
 2376:     }
 2377:     &Apache::lonxml::startredirection();
 2378:     return '';
 2379: }
 2380: 
 2381: sub end_td_tex {
 2382: 
 2383:     my $text = &Apache::lonxml::endredirection();
 2384:     my $table = $Apache::londefdef::table[-1];
 2385:     $table->append_cell_text($text);
 2386: 
 2387:     #-------------------------------------------------
 2388:     # Old table code
 2389:     #-------------------------------------------------
 2390: 
 2391:     if (0) {
 2392:     my ($parstack,$parser,$safeeval) = @_;
 2393:     my $current_row    = $Apache::londefdef::table[-1]{'row_number'};
 2394:     my $current_column = $Apache::londefdef::table[-1]{'counter_columns'}; 
 2395:     my $data = &Apache::lonxml::endredirection();
 2396: 
 2397:     #  The rowspan array of the table indicates which cells are part of a span.
 2398:     #  n indicates the start of a span set of n rows.
 2399:     #  ^ indicates a cell that continues a span set.
 2400:     #  _ indicates the cell is at the bottom of a span set.
 2401:     #  If this and subsequent cells are part of a rowspan, we must
 2402:     #  push along the row until we find one that is not.
 2403: 
 2404:     while ((defined $Apache::londefdef::table[-1]{'rowspan'}[$current_row] [$current_column]) 
 2405: 	   && ($Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column] =~ /[\^\_]/)) {
 2406: 	# Part of a span.
 2407: 	push @ {$Apache::londefdef::table[-1]{'content'}[-1]}, '';
 2408: 	$current_column++;
 2409:     }
 2410:     $Apache::londefdef::table[-1]{'counter_columns'} = $current_column;
 2411:    
 2412: 
 2413:     # Get the column and row spans.
 2414:     # Colspan can be done via \multicolumn if I can figure out the data structs.
 2415: 
 2416:     my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval, undef, 0);
 2417:     if (!$colspan) {
 2418: 	$colspan = 1;
 2419:     }
 2420: 
 2421:     my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval, undef, 0);
 2422:     if (!$rowspan) {
 2423: 	$rowspan = 1;
 2424:     }
 2425: 
 2426: 
 2427: 
 2428:     for (my $c = 0; $c < $colspan; $c++) {
 2429: 	$Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column+$c] = $rowspan;
 2430: 	for (my $i = 1; $i < $rowspan; $i++) {
 2431: 	    $Apache::londefdef::table[-1]{'rowspan'}[$current_row+$i][$current_column+$c] = '^';
 2432: 	    if ($i == ($rowspan-1)) {
 2433: 		$Apache::londefdef::table[-1]{'rowspan'}[$current_row+$i][$current_column+$c] = '_';
 2434: 	    }
 2435: 	}
 2436:     }
 2437: 
 2438:     my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
 2439:     if (defined $TeXwidth) {		
 2440: 	for (my $c = 0; $c < $colspan; $c++) {
 2441: 	    push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2442: 	    push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2443: 	    push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2444: 	}
 2445:     } else {
 2446: 	if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
 2447: 	    my $garbage_data=$data;
 2448: 	    my $fwidth=0;
 2449:             while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
 2450: 		my $current_length=&recalc($1);
 2451: 		$current_length=~/(\d+\.?\d*)/;
 2452: 		if ($fwidth<$1) {$fwidth=$1;}
 2453: 		$garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
 2454: 	    }
 2455:             while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
 2456: 		my $current_length=$1;
 2457: 		if ($fwidth<$current_length) {$fwidth=$current_length;}
 2458: 		$garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
 2459: 	    }
 2460: 	    for (my $c = 0; $c < $colspan; $c++) {
 2461: 		push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2462: 		push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
 2463: 		push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2464: 		push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2465: 	    }
 2466: 	} 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)*/) {
 2467: 	    my $garbage_data=$data;
 2468: 	    my $fwidth=0;
 2469:             while ($garbage_data=~/\\parbox\{\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)\s*\}/) {
 2470: 		my $current_length=&recalc($1);
 2471: 		$current_length=~/(\d+\.?\d*)/;
 2472: 		if ($fwidth<$1) {$fwidth=$1;}
 2473: 		$garbage_data=~s/\\parbox\{\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
 2474: 	    }
 2475:             while ($garbage_data=~/\\epsfxsize\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
 2476: 		my $current_length=&recalc($1);
 2477: 		$current_length=~/(\d+\.?\d*)/;
 2478: 		if ($fwidth<$1) {$fwidth=$1;}
 2479: 		$garbage_data=~s/\\epsfxsize\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
 2480: 	    }
 2481: 	    for (my $c = 0; $c < $colspan; $c++) {
 2482: 		push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2483: 		push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
 2484: 		push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2485: 		push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2486: 	    }
 2487: 	    $data=~s/\\\\\s*$//; 
 2488: 	} else {  
 2489: 	    $data=~s/^\s+(\S.*)/$1/; 
 2490: 	    $data=~s/(.*\S)\s+$/$1/;
 2491: 	    $data=~s/(\s)+/$1/;
 2492: 	    my ($current_length,$min_length)=(0,0);
 2493: 	    if ($data=~/\\vskip/) {
 2494:                 my $newdata=$data;
 2495: 		$newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
 2496: 		my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
 2497: 		foreach my $elementdata (@newdata) {
 2498: 		    my $lengthnewdata=2.5*&LATEX_length($elementdata);
 2499: 		    if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
 2500:                     my @words=split(/ /,$elementdata);
 2501: 		    foreach my $word (@words) {
 2502: 			my $lengthword=2.5*&LATEX_length($word);
 2503: 			if ($min_length<$lengthword) {$min_length=$lengthword;}
 2504: 		    }
 2505: 		}
 2506: 	    } else {
 2507: 		$current_length=2.5*&LATEX_length($data);
 2508:                     my @words=split(/ /,$data);
 2509: 		    foreach my $word (@words) {
 2510: 			my $lengthword=2*&LATEX_length($word);
 2511: 			if ($min_length<$lengthword) {$min_length=$lengthword;}
 2512: 		    }
 2513: 	    }
 2514: 	    for (my $c = 0; $c < $colspan; $c++) {
 2515: 		push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2516: 		push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2517: 		push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
 2518: 		push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
 2519: 	    }
 2520: 	}        
 2521:     }
 2522:     # Substitute all of the tables nested in this cell in their appropriate places.
 2523: 
 2524: 
 2525:     my $nested_count = $#{$Apache::londefdef::table[-1]{'include'}}; # This one is constant...
 2526:     for (my $in=0; $in<=$nested_count; $in++) {    
 2527: 	my $nested = shift @{$Apache::londefdef::table[-1]{'include'}};
 2528: 	$nested =~ s/\\end\{tabular\}\\strut\\\\/\\end\{tabular\}/;
 2529: 	# $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
 2530: 	$data =~ s/\\keephidden\{NEW TABLE ENTRY\}/$nested/;
 2531: 
 2532:     }
 2533:     # Should be be killing off the 'include' elements as they're used up?
 2534: 
 2535:     push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
 2536: 
 2537: 
 2538: 
 2539: 
 2540:     #  the colspan array will indicate how many columns will be spanned by this
 2541:     #  cell..this requires that counter_columns also be adjusted accordingly
 2542:     #  so that the next bunch of text goes in the right cell.  Note that since
 2543:     #  counter_columns is incremented in the start_td_tex, we adjust by colspan-1.
 2544:     #
 2545: 
 2546:     $Apache::londefdef::table[-1]{'counter_columns'} += $colspan -1;
 2547:     for (my $i = 0; $i < ($colspan -1); $i++) {
 2548: 	push @ {$Apache::londefdef::table[-1]{'content'}[-1] },'';
 2549:     }
 2550:     for (my $r = 0; $r < $rowspan; $r++) {
 2551: 	$Apache::londefdef::table[-1]{'colspan'}[$current_row+$r][$current_column] = $colspan;
 2552: 	# Put empty text in spanned cols.
 2553: 	
 2554:     }
 2555: 
 2556:     }
 2557: 
 2558:     return '';
 2559: }
 2560: 
 2561: sub end_td {
 2562:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2563:     my $currentstring = '';
 2564:     if ($target eq 'web' || $target eq 'webgrade') {
 2565: 	$currentstring = $token->[2];     
 2566:     } elsif ($target eq 'tex') {
 2567:         $Apache::londefdef::TD_redirection =0;
 2568: 	&end_td_tex($parstack,$parser,$safeeval);
 2569:     }
 2570:     return $currentstring;
 2571: }
 2572: 
 2573: #-- <th> tag (end tag optional)
 2574: sub start_th {
 2575:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2576:     my $currentstring = '';
 2577:     if ($target eq 'web' || $target eq 'webgrade') {
 2578: 	$currentstring = $token->[4];     
 2579:     } elsif ($target eq 'tex') {
 2580: 	$Apache::londefdef::TD_redirection = 1;
 2581: 	&tagg_check('tr','th',$tagstack,$parstack,$parser,$safeeval);
 2582:     } 
 2583:     return $currentstring;
 2584: }   
 2585:     
 2586: sub tagg_check {
 2587:     my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
 2588:     my @ar=@$parstack; 
 2589:     for (my $i=$#ar-1;$i>=0;$i--) {
 2590: 	if (lc($$tagstack[$i]) eq $good_tag) {
 2591: 	    &start_th_tex($parstack,$parser,$safeeval);
 2592: 	    last;
 2593: 	} elsif (lc($$tagstack[$i]) eq $bad_tag) {
 2594: 	    splice @ar, $i+1;
 2595: 	    &end_th_tex(\@ar,$parser,$safeeval);
 2596: 	    &start_th_tex($parstack,$parser,$safeeval);
 2597: 	    last;
 2598: 	}
 2599:     }
 2600:     return '';
 2601: }
 2602:  
 2603: sub start_th_tex {
 2604:     my ($parstack,$parser,$safeeval) = @_;
 2605: 
 2606:     my $alignment = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef,1);
 2607:     my $rowspan  =  &Apache::lonxml::get_param('rowspan', $parstack, $safeeval, undef, 1);
 2608:     my $colspan  =  &Apache::lonxml::get_param('colspan', $parstack, $safeeval, undef, 1);
 2609: 
 2610:     my $config   = cell_config_hash($alignment, $rowspan, $colspan);
 2611:     my $table    = $Apache::londefdef::table[-1];
 2612:     $table->add_cell('\textbf{', $config);
 2613: 
 2614:     #-------------------------------------------------------------------------------------
 2615:     #
 2616:     #  Old table code.
 2617:     #
 2618:     #--------------------------------------------------------------------------------------
 2619: 
 2620:     if (0) {
 2621: 
 2622: 
 2623:     my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
 2624:     if ($alignchar eq '') {
 2625: 	$alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
 2626:     }
 2627:     push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
 2628:     $Apache::londefdef::table[-1]{'counter_columns'}++;
 2629:     my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
 2630:     if (defined $TeXwidth) {		
 2631: 	my $current_length=&recalc($TeXwidth);
 2632: 	$current_length=~/(\d+\.?\d*)/;
 2633: 	push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
 2634:     }
 2635:     }
 2636: 
 2637:     # Accept xml until the </th> tag.
 2638: 
 2639:     &Apache::lonxml::startredirection();
 2640:     return '';
 2641: }
 2642: 
 2643: sub end_th_tex {
 2644:     my ($parstack,$parser,$safeeval) = @_;
 2645: 
 2646:     my $table = $Apache::londefdef::table[-1];
 2647:     my $text  = &Apache::lonxml::endredirection();
 2648:     $table->append_cell_text($text.'}');
 2649: 
 2650:     #-----------------------------------------------------------------------------
 2651:     #  Old table code:
 2652:     #-----------------------------------------------------------------------------
 2653: 
 2654:     if (0) {
 2655:     my $current_row = $Apache::londefdef::table[-1]{'row_number'};
 2656:     my $data=&Apache::lonxml::endredirection();
 2657:     my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
 2658:     if (defined $TeXwidth) {		
 2659: 	push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2660: 	push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2661: 	push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2662:     } else {
 2663: 	if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
 2664: 	    my $garbage_data=$data;
 2665: 	    my $fwidth=0;
 2666:             while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
 2667: 		my $current_length=&recalc($1);
 2668: 		$current_length=~/(\d+\.?\d*)/;
 2669: 		if ($fwidth<$1) {$fwidth=$1;}
 2670: 		$garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
 2671: 	    }
 2672:             while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
 2673: 		my $current_length=$1;
 2674: 		if ($fwidth<$current_length) {$fwidth=$current_length;}
 2675: 		$garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
 2676: 	    }
 2677: 	    push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2678: 	    push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
 2679: 	    push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2680: 	    push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2681: 	} else {  
 2682: 	    $data=~s/^\s+(\S.*)/$1/; 
 2683: 	    $data=~s/(.*\S)\s+$/$1/;
 2684: 	    $data=~s/(\s)+/$1/;
 2685: 	    my ($current_length,$min_length)=(0,0);
 2686: 	    if ($data=~/\\vskip/) {
 2687:                 my $newdata=$data;
 2688: 		$newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
 2689: 		my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
 2690: 		foreach my $elementdata (@newdata) {
 2691: 		    my $lengthnewdata=2.5*&LATEX_length($elementdata);
 2692: 		    if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
 2693:                     my @words=split(/ /,$elementdata);
 2694: 		    foreach my $word (@words) {
 2695: 			my $lengthword=2.5*&LATEX_length($word);
 2696: 			if ($min_length<$lengthword) {$min_length=$lengthword;}
 2697: 		    }
 2698: 		}
 2699: 	    } else {
 2700: 		$current_length=2.5*&LATEX_length($data);
 2701:                     my @words=split(/ /,$data);
 2702: 		    foreach my $word (@words) {
 2703: 			my $lengthword=2*&LATEX_length($word);
 2704: 			if ($min_length<$lengthword) {$min_length=$lengthword;}
 2705: 		    }
 2706: 	    }
 2707: 	    push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2708: 	    push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
 2709: 	    push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
 2710: 	    push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
 2711: 	}        
 2712:     }
 2713: 	for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {         
 2714: 	    $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
 2715: 	}
 2716:     #make data bold
 2717:     $data='\textbf{'.$data.'}';
 2718:     push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
 2719:     }
 2720:     return'';
 2721: }
 2722: 
 2723: sub end_th {
 2724:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2725:     my $currentstring = &end_p();	# Close any open <p> in the row.
 2726:     if ($target eq 'web' || $target eq 'webgrade') {
 2727: 	$currentstring .= $token->[2];     
 2728:     } elsif ($target eq 'tex') {
 2729:         $Apache::londefdef::TD_redirection =0;
 2730: 	&end_th_tex($parstack,$parser,$safeeval);
 2731:     }
 2732:     return $currentstring;
 2733: }
 2734:      
 2735: #-- <img> tag (end tag forbidden)
 2736: #
 2737: #  Render the <IMG> tag.
 2738: #     <IMG> has the following attributes (in addition to the 
 2739: #     standard HTML ones:
 2740: #      TeXwrap   - Governs how the tex target will try to wrap text around
 2741: #                  horizontally aligned images.
 2742: #      TeXwidth  - The width of the image when rendered for print (mm).
 2743: #      TeXheight - The height of the image when rendered for print (mm)
 2744: #         (Note there seems to also be support for this as a % of page size)
 2745: #      
 2746: sub start_img {
 2747:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
 2748:     my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,
 2749: 					 undef,1);
 2750:     if (! $src && 
 2751: 	($target eq 'web' || $target eq 'webgrade' || $target eq 'tex')
 2752: 	) { 
 2753: 	my $inside = &Apache::lonxml::get_all_text("/img",$parser,$style);
 2754: 	return '';
 2755:     }
 2756:     &Apache::lonxml::extlink($src);
 2757:     my $currentstring = '';
 2758:     my $scaling = .3;
 2759: 
 2760:    # Render unto browsers that which are the browser's...
 2761: 
 2762:     if ($target eq 'web' || $target eq 'webgrade') {
 2763:         my $enc = ('yes' eq 
 2764:                    lc(&Apache::lonxml::get_param('encrypturl',$parstack,
 2765:                       $safeeval)));
 2766:         $currentstring.=&Apache::lonenc::encrypt_ref($token,{'src'=>$src},
 2767:                          $enc);
 2768: 
 2769:     # and render unto TeX that which is LaTeX
 2770:     } elsif ($target eq 'tex') {
 2771: 	#
 2772: 	#  The alignment will require some superstructure to be put around
 2773: 	#  the \includegraphics stuff.  At present we can only partially
 2774: 	#  simulate the alignments offered by html.
 2775: 	#
 2776: 	#
 2777: 	my $align = lc(&Apache::lonxml::get_param('align', 
 2778: 						  $parstack,
 2779: 						  $safeeval,
 2780: 						  undef,1));
 2781: 	if(!$align) {
 2782: 		$align = "bottom";	# This is html's default so it's ours too.
 2783: 	}
 2784: 	#
 2785: 	&Apache::lonxml::debug("Alignemnt = $align");
 2786: 	#  LaTeX's image/text wrapping is really bad since it wants to
 2787: 	#  make figures float.  
 2788:         #   The user has the optional parameter (applicable only to l/r
 2789: 	# alignment to use the picins/parpic directive to get wrapped text
 2790: 	# this is also imperfect.. that's why we give them a choice...
 2791: 	# so they can't yell at us for our choice.
 2792: 	#
 2793: 	my $latex_rendering = &Apache::lonxml::get_param('TeXwrap',
 2794: 							    $parstack,
 2795: 							    $safeeval,
 2796: 							    undef,0);
 2797: 	# &Apache::lonxml::debug("LaTeX rendering = $latex_rendering");
 2798: 	if(!$latex_rendering) {
 2799: 		$latex_rendering = "texwrap";
 2800: 	}
 2801: 	# using texwrap inside a table does not work. So, if after all of this,
 2802: 	# texwrap is on, we turn it off if we detect we're in a table:
 2803: 	#
 2804: 	if (($latex_rendering eq 'texwrap') && &is_inside_of($tagstack, "table")) {
 2805: 	    $latex_rendering = 'parpic';
 2806: 	}
 2807: 
 2808: 	# &Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src");
 2809: 
 2810: 	#if original bmp/gif/jpg/png file exist do following:
 2811: 	my $origsrc=$src;
 2812: 	my ($path,$file) = &get_eps_image($src);
 2813: 	# &Apache::lonnet::logthis("Image source: $src result: $path $file");
 2814: 	$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
 2815: 	&Apache::lonxml::debug("path = $path file = $file src = $src");
 2816: 	if (-e $src) {
 2817: 	    &Apache::lonxml::debug("$src exists");
 2818: 	    my ($height_param,$width_param)=
 2819: 		&image_size($origsrc,0.3,$parstack,$safeeval);
 2820: 	    my $size;
 2821: 	    if ($width_param)  { $size.='width='.$width_param.' mm,'; }
 2822: 	    if ($height_param) { $size.='height='.$height_param.' mm]'; }
 2823: 	    # Default size if not able to extract that (e.g. eps image).
 2824: 	    
 2825: 	    # &Apache::lonnet::logthis("Size = $size");
 2826: 	    
 2827: 	    $size='['.$size;
 2828: 	    $size=~s/,$/]/; 
 2829: 	    $currentstring .= '\graphicspath{{'.$path.'}}'
 2830: 		.'\includegraphics'.$size.'{'.$file.'} ';
 2831: 	    my $closure;
 2832: 	    ($currentstring, $closure) = &align_latex_image($align, 
 2833: 							    $latex_rendering, 
 2834: 							    $currentstring, 
 2835: 							    $width_param, 
 2836: 							    $height_param);
 2837: 	    $currentstring .= $closure;
 2838: 						
 2839: 	} else {
 2840: 	    &Apache::lonxml::debug("$src does not exist");
 2841: 	    #original image file doesn't exist so check the alt attribute
 2842: 	    my $alt = 
 2843: 		&Apache::lonxml::get_param('alt',$parstack,$safeeval,undef,1);
 2844: 	    unless ($alt) {
 2845: 		$alt=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
 2846: 	    }
 2847: 
 2848: 	    if ($alt) { $currentstring .= ' '.$alt.' '; }
 2849: 	}
 2850: 
 2851: 	# And here's where the semi-quote breaks down: allow the user
 2852:         # to edit the beast as well by rendering the problem for edit:
 2853:     } elsif ($target eq 'edit') {
 2854:         my $only = join(',',&Apache::loncommon::filecategorytypes('Pictures'));
 2855: 	$currentstring .=&Apache::edit::tag_start($target,$token);
 2856: 	$currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70).
 2857: 	    &Apache::edit::browse('src',undef,'alt',$only).' '.
 2858: 	    &Apache::edit::search('src',undef,'alt').'<br />';
 2859: 	$currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'<br />';
 2860: 	$currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5);
 2861: 	$currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'<br />';
 2862: 	$currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5);
 2863: 	$currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5);
 2864: 	$currentstring .=&Apache::edit::select_arg('Alignment:','align',
 2865: 						   ['','bottom','middle','top','left','right'],$token,5);
 2866: 	$currentstring .=&Apache::edit::select_arg('TeXwrap:', 'TeXwrap',
 2867: 						   ['', 'none','parbox', 'parpic', 'wrapfigure'], $token, 2);
 2868:         my $alt=    &Apache::lonxml::get_param('alt',$parstack,$safeeval);
 2869:         my $enc=    &Apache::lonxml::get_param('encrypturl',$parstack,$safeeval);
 2870:  
 2871: 	$currentstring .=&Apache::edit::select_arg('Encrypt URL:','encrypturl',
 2872: 						   ['no','yes'], $token, 2);
 2873:         if (($alt=~/\S/) && (lc($enc) eq 'yes')) {
 2874:            $currentstring.='<br /><span class="LC_warning">'.&mt('Warning: the description "[_1]" will be available, even for encrypted URL',$alt).'</span><br />';
 2875:         }
 2876: 	$currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
 2877: 	my $src=    &Apache::lonxml::get_param('src',$parstack,$safeeval);
 2878: 	my $width=  &Apache::lonxml::get_param('width',$parstack,$safeeval);
 2879: 	my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
 2880: 
 2881:         if ($token->[2]{'src'}=~/\$/) {
 2882:            $currentstring.=&mt('Variable image source');
 2883:         } elsif ($token->[2]{'src'}=~/\S/) {
 2884: 	   $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
 2885: 	   if ($width) { $currentstring.=' width="'.$width.'" '; }
 2886: 	   if ($height) { $currentstring.=' height="'.$height.'" '; }
 2887: 	   $currentstring .= ' />';
 2888:         } else {
 2889:            $currentstring.=&mt("No image source specified");
 2890:         }
 2891:     } elsif ($target eq 'modified') {
 2892: 	my ($osrc,$owidth,$oheight)=
 2893: 	    ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
 2894: 	my $ctag=&Apache::edit::get_new_args($token,$parstack,
 2895: 					     $safeeval,'src','alt','align',
 2896: 					     'TeXwidth','TeXheight', 'TeXwrap',
 2897: 					     'width','height','encrypturl');
 2898: 	my ($nsrc,$nwidth,$nheight)=
 2899: 	    ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
 2900: 	my $loc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$nsrc);
 2901: 	&image_replication($loc);
 2902: 	my ($iwidth,$iheight);
 2903: 	if (-e $loc) {
 2904: 	    my $image = Image::Magick->new;
 2905: 	    $image->Read($loc);
 2906: 	    ($iwidth, $iheight) = ($image->Get('width'),
 2907: 				   $image->Get('height'));
 2908: 	}
 2909: 	if ($osrc ne $nsrc || (!$nwidth && !$nheight)) {
 2910: 	    # changed image or no size specified,
 2911:             # if they didn't explicitly change the 
 2912:             # width or height use the ones from the image
 2913: 	    if ($iwidth && $iheight) {
 2914: 		if ($owidth == $nwidth || (!$nwidth && !$nheight)) {
 2915: 		    $token->[2]{'width'} = $iwidth;$ctag=1;
 2916: 		}
 2917: 		if ($oheight == $nheight || (!$nwidth && !$nheight)) {
 2918: 		    $token->[2]{'height'}=$iheight;$ctag=1;
 2919: 		}
 2920: 	    }
 2921: 	}
 2922: 	my ($cwidth,$cheight)=($token->[2]{'width'},$token->[2]{'height'});
 2923: 	# if we don't have a width or height
 2924: 	if ($iwidth && $cwidth && !$cheight) {
 2925: 	    $token->[2]{'height'}=int(($cwidth/$iwidth)*$iheight);$ctag=1;
 2926: 	}
 2927: 	if ($iheight && $cheight && !$cwidth) {
 2928: 	    $token->[2]{'width'}=int(($cheight/$iheight)*$iwidth);$ctag=1;
 2929: 	}
 2930: 	if ($ctag) {$currentstring=&Apache::edit::rebuild_tag($token);}
 2931:     }
 2932: 
 2933:     return $currentstring;
 2934: }
 2935: 
 2936: sub end_img {
 2937:     my ($target,$token) = @_;
 2938:     my $currentstring = '';
 2939:     if ($target eq 'web' || $target eq 'webgrade') {
 2940: 	$currentstring = $token->[2];
 2941:     } elsif ($target eq 'tex') {
 2942: 	$currentstring = '';
 2943:     }
 2944:     return $currentstring;
 2945: }
 2946: 
 2947: #-- <applet> tag (end tag required)
 2948: sub start_applet {
 2949:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 2950:     
 2951:     my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,undef,1);
 2952:     &Apache::lonxml::extlink($code);
 2953:     my $archive=&Apache::lonxml::get_param('archive',$parstack,$safeeval,
 2954: 					   undef,1);
 2955:     &Apache::lonxml::extlink($archive);
 2956:     my $currentstring = '';
 2957:     if ($target eq 'web' || $target eq 'webgrade') {
 2958:         $currentstring = $token->[4];
 2959:     } elsif ($target eq 'tex') {
 2960:         # Turn off some stuff we can't be inside thank you LaTeX
 2961: 
 2962: 	my $restart_sub = 0;
 2963: 	my $restart_sup = 0;
 2964: 
 2965: 	# Since <sub> and <sup> are simple tags it's ok to turn off/on
 2966: 	# using the start_ stop_ functions.. those tags only care about
 2967: 	# $target.
 2968: 
 2969: 	if (&is_inside_of($tagstack, "sub")) {
 2970: 	    $restart_sub = 1;
 2971: 	    $currentstring .= &end_sub($target, $token, $tagstack, 
 2972: 				       $parstack, $parser, $safeeval);
 2973: 	}
 2974: 	if (&is_inside_of($tagstack, "sup")) {
 2975: 	    $restart_sup = 1;
 2976: 	    $currentstring .= &end_sup($target, $token, $tagstack,
 2977: 				       $parstack, $parser, $safeeval);
 2978: 	}
 2979: 
 2980: 	# Now process the applet; just replace it with its alt attribute.
 2981: 
 2982: 	my $alttag= &Apache::lonxml::get_param('alt',$parstack,
 2983: 					       $safeeval,undef,1);
 2984: 	unless ($alttag) {
 2985: 	    my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,
 2986: 						undef,1);
 2987: 	    $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
 2988: 					     $code);
 2989: 	}
 2990: 	$currentstring.='\begin{center} \fbox{Java Applet: '.$alttag.
 2991: 	    '.}\end{center}';
 2992: 
 2993: 	# Turn stuff back on that we can't be inside of.
 2994: 
 2995: 	if ($restart_sub) {
 2996: 	    $currentstring .= &start_sub($target, $token, $tagstack,
 2997: 					$parstack, $parser, $safeeval);
 2998: 	}
 2999: 	if ($restart_sup) {
 3000: 	    $currentstring .= &start_sup($target, $token, $tagstack,
 3001: 					 $parstack, $parser, $safeeval);
 3002: 	}
 3003:     } 
 3004:     return $currentstring;
 3005: }
 3006: 
 3007: sub end_applet {
 3008:     my ($target,$token) = @_;
 3009:     my $currentstring = '';
 3010:     if ($target eq 'web' || $target eq 'webgrade') {
 3011: 	$currentstring = $token->[2];
 3012:     } elsif ($target eq 'tex') {
 3013:     } 
 3014:     return $currentstring;
 3015: }
 3016: 
 3017: #-- <embed> tag (end tag optional/required)
 3018: sub start_embed {    
 3019:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 3020:     my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
 3021:     &Apache::lonxml::extlink($src);
 3022:     my $currentstring = '';
 3023:     if ($target eq 'web' || $target eq 'webgrade') {
 3024:     $currentstring=&Apache::lonenc::encrypt_ref($token,{'src'=>$src}); 
 3025:     } elsif ($target eq 'tex') {
 3026:     } 
 3027:     return $currentstring;
 3028: }
 3029: 
 3030: sub end_embed {
 3031:     my ($target,$token) = @_;
 3032:     my $currentstring = '';
 3033:     if ($target eq 'web' || $target eq 'webgrade') {
 3034:         $currentstring = $token->[2];
 3035:     } elsif ($target eq 'tex') {
 3036:         # ./.
 3037:     }
 3038:     return $currentstring;
 3039: }
 3040: 
 3041: #-- <param> tag (end tag forbidden)
 3042: sub start_param {
 3043:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 3044:     my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval,
 3045:                                           undef,1);
 3046:     if ($name =~/^cabbase$/i) {
 3047: 	my $value=&Apache::lonxml::get_param('value',$parstack,
 3048: 					     $safeeval,undef,1);
 3049: 	&Apache::lonxml::extlink($value);
 3050:     } elsif ($name eq 'flashvars') {
 3051:         if (lc(&Apache::lonxml::get_param('type',$parstack,$safeeval,-2,1))
 3052:             eq 'application/x-shockwave-flash') {
 3053:             my $launcher =
 3054:                 &Apache::lonxml::get_param('data',$parstack,$safeeval,-2,1);
 3055:             if ($launcher) {
 3056:                 &Apache::lonxml::extlink($launcher);
 3057:             }
 3058:             my $flashvars=&Apache::lonxml::get_param('value',$parstack,
 3059:                                                      $safeeval,undef,1);
 3060:             if ($flashvars ne '') {
 3061:                 foreach my $item (split(/\&/,$flashvars)) {
 3062:                     my ($key,$value)=split(/=/,$item,2);
 3063:                     if ($key eq 'content') {
 3064:                         if ($value ne '') {
 3065:                             my ($dir) = ($launcher =~ m{(.+/)[^/]+$});
 3066:                             &Apache::lonxml::extlink($dir.$value);
 3067:                         }
 3068:                     } elsif ($key eq 'thumb') {
 3069:                         if ($value ne '') {
 3070:                             &Apache::lonxml::extlink($value);
 3071:                         }
 3072:                     }
 3073:                 }
 3074:             }
 3075:         }
 3076:     }
 3077:     my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
 3078:     if ($src ne '') {
 3079:         &Apache::lonxml::extlink($src);
 3080:     }
 3081:     my $currentstring = '';
 3082:     if ($target eq 'web' || $target eq 'webgrade') {
 3083: 	my %toconvert;
 3084: 	if ($src) { $toconvert{'src'}= $src; }
 3085: 	if ($name=~/^cabbase$/i) {
 3086: 	    $toconvert{'value'}=&Apache::lonxml::get_param('value',$parstack,
 3087: 							   $safeeval,undef,1);
 3088: 	}
 3089: 	$currentstring = &Apache::lonenc::encrypt_ref($token,\%toconvert);
 3090:     } elsif ($target eq 'tex') {
 3091:     } 
 3092:     return $currentstring;
 3093: }
 3094: 
 3095: sub end_param {
 3096:     my ($target,$token) = @_;
 3097:     my $currentstring = '';
 3098:     if ($target eq 'web' || $target eq 'webgrade') {
 3099: 	$currentstring = $token->[2];     
 3100:     } elsif ($target eq 'tex') {
 3101:     } 
 3102:     return $currentstring;
 3103: }
 3104: 
 3105: #-- <allow> tag
 3106: sub start_allow {
 3107:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 3108:     my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
 3109:     &Apache::lonxml::extlink($src);
 3110: 
 3111:     if ($target eq 'tex') { &image_replication($src); }
 3112:     my $result;
 3113:     if ($target eq 'edit') {
 3114: 	$result .=&Apache::edit::tag_start($target,$token);
 3115: 	$result .=&Apache::edit::text_arg('File Spec:','src',$token,70);
 3116: 	$result .=&Apache::edit::end_row();#.&Apache::edit::start_spanning_row();
 3117:     } elsif ($target eq 'modified') {
 3118: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
 3119: 						     $safeeval,'src');
 3120: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
 3121:     }
 3122:     return $result;
 3123: }
 3124: 
 3125: sub end_allow {
 3126:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 3127:     if ( $target eq 'edit') { return (&Apache::edit::end_table()); }
 3128:     return '';
 3129: }
 3130: 
 3131: #-- Frames (end tag required)
 3132: #-- <frameset>
 3133: sub start_frameset {
 3134:     my ($target,$token) = @_;
 3135:     my $currentstring = '';	# Close any pending para.
 3136:     if ($target eq 'web' || $target eq 'webgrade') { 
 3137: 	$currentstring = 
 3138: 	    &Apache::loncommon::start_page($Apache::londefdef::title,
 3139: 					   $Apache::londefdef::head,
 3140: 					   {'add_entries'    => $token->[2],
 3141: #					    'no_title'       => 1,
 3142: 					    'force_register' => 1,
 3143: 					    'frameset'       => 1,});
 3144: 
 3145:     }
 3146:     return $currentstring;
 3147: }
 3148: 
 3149: sub end_frameset {
 3150:     my ($target,$token) = @_;
 3151:     my $currentstring = '';
 3152:     if ($target eq 'web' || $target eq 'webgrade') {
 3153: 	$currentstring = $token->[2];
 3154:     }
 3155:     return $currentstring;
 3156: }
 3157: 
 3158: #-- <xmp> (end tag required)
 3159: sub start_xmp {
 3160:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 3161:     my $currentstring = '';
 3162:     if ($target eq 'web' || $target eq 'webgrade') {
 3163: 	$currentstring .= $token->[4];
 3164:     } elsif ($target eq 'tex') {
 3165: 	$currentstring .= '\begin{verbatim}';
 3166:     } 
 3167:     return $currentstring;
 3168: }
 3169: 
 3170: sub end_xmp {
 3171:     my ($target,$token) = @_;
 3172:     my $currentstring = '';
 3173:     if ($target eq 'web' || $target eq 'webgrade') {
 3174: 	$currentstring .= $token->[2];
 3175:     } elsif ($target eq 'tex') {
 3176: 	$currentstring .= '\end{verbatim}';
 3177:     }
 3178:     return $currentstring;
 3179: }
 3180: 
 3181: #-- <pre> (end tag required)
 3182: sub start_pre {
 3183:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 3184:     my $currentstring = &end_p();	# close off pending <p>
 3185:     if ($target eq 'web' || $target eq 'webgrade') {
 3186: 	$currentstring .= $token->[4];
 3187:     } elsif ($target eq 'tex') {
 3188: 	$currentstring .= '\begin{verbatim}';
 3189: 	&Apache::lonxml::disable_LaTeX_substitutions();
 3190:     } 
 3191:     return $currentstring;
 3192: }
 3193: 
 3194: sub end_pre {
 3195:     my ($target,$token) = @_;
 3196:     my $currentstring = '';
 3197:     if ($target eq 'web' || $target eq 'webgrade') {
 3198: 	$currentstring .= $token->[2];
 3199:     } elsif ($target eq 'tex') {
 3200: 	$currentstring .= '\end{verbatim}';
 3201: 	&Apache::lonxml::enable_LaTeX_substitutions();
 3202:     }
 3203:     return $currentstring;
 3204: }
 3205: 
 3206: #-- <insert>
 3207: sub start_insert {
 3208:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 3209:     my $currentstring = '';
 3210:     if ($target eq 'web' || $target eq 'webgrade') {
 3211: 	my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
 3212: 	$currentstring .= '<b>'.$display.'</b>';;
 3213:     }
 3214:     return $currentstring;
 3215: }
 3216: 
 3217: sub end_insert {
 3218:     my ($target,$token) = @_;
 3219:     my $currentstring = '';
 3220:     if ($target eq 'web' || $target eq 'webgrade') {
 3221: 	$currentstring .= '';
 3222:     }
 3223:     return $currentstring;
 3224: }
 3225: 
 3226: #-- <externallink>
 3227: sub start_externallink {
 3228:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 3229:     my $currentstring = '';
 3230:     if ($target eq 'web' || $target eq 'webgrade') {
 3231: 	my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
 3232: 	$currentstring .= '<b>'.$display.'</b>';;
 3233:     }
 3234:     return $currentstring;
 3235: }
 3236: 
 3237: sub end_externallink {
 3238:     my ($target,$token) = @_;
 3239:     my $currentstring = '';
 3240:     if ($target eq 'web' || $target eq 'webgrade') {
 3241: 	$currentstring .= '';
 3242:     }
 3243:     return $currentstring;
 3244: }
 3245: 
 3246: #-- <blankspace heigth="">
 3247: sub start_blankspace {
 3248:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 3249:     my $currentstring = &end_p();	# closes off any unclosed <p>
 3250:     if ($target eq 'tex') {
 3251: 	my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval,undef,1);
 3252: 	$currentstring .= '\vskip '.$howmuch.' ';
 3253:     }
 3254:     return $currentstring;
 3255: }
 3256: 
 3257: sub end_blankspace {
 3258:     my ($target,$token) = @_;
 3259:     my $currentstring = '';
 3260:     if ($target eq 'tex') {
 3261: 	$currentstring .= '';
 3262:     }
 3263:     return $currentstring;
 3264: }
 3265: 
 3266: #-- <abbr> tag (end tag required)
 3267: sub start_abbr {
 3268:     my ($target,$token) = @_;
 3269:     my $currentstring = '';
 3270:     if ($target eq 'web' || $target eq 'webgrade') {
 3271: 	$currentstring = $token->[4];     
 3272:     } 
 3273:     return $currentstring;
 3274: }
 3275: 
 3276: sub end_abbr {
 3277:     my ($target,$token) = @_;
 3278:     my $currentstring = '';
 3279:     if ($target eq 'web' || $target eq 'webgrade') {
 3280: 	$currentstring = $token->[2];    
 3281:     } 
 3282:     return $currentstring;
 3283: }
 3284: 
 3285: #-- <acronym> tag (end tag required)
 3286: sub start_acronym {
 3287:     my ($target,$token) = @_;
 3288:     my $currentstring = '';
 3289:     if ($target eq 'web' || $target eq 'webgrade') {
 3290: 	$currentstring = $token->[4];     
 3291:     } 
 3292:     return $currentstring;
 3293: }
 3294: 
 3295: sub end_acronym {
 3296:     my ($target,$token) = @_;
 3297:     my $currentstring = '';
 3298:     if ($target eq 'web' || $target eq 'webgrade') {
 3299: 	$currentstring = $token->[2];    
 3300:     } 
 3301:     return $currentstring;
 3302: }
 3303: 
 3304: #-- <area> tag (end tag forbidden)
 3305: sub start_area {
 3306:     my ($target,$token) = @_;
 3307:     my $currentstring = '';
 3308:     if ($target eq 'web' || $target eq 'webgrade') {
 3309: 	$currentstring = $token->[4];     
 3310:     } 
 3311:     return $currentstring;
 3312: }
 3313: 
 3314: sub end_area {
 3315:     my ($target,$token) = @_;
 3316:     my $currentstring = '';
 3317:     if ($target eq 'web' || $target eq 'webgrade') {
 3318: 	$currentstring = $token->[2];    
 3319:     } 
 3320:     return $currentstring;
 3321: }
 3322: 
 3323: #-- <base> tag (end tag forbidden)
 3324: sub start_base {
 3325:     my ($target,$token) = @_;
 3326:     my $currentstring = '';
 3327:     if ($target eq 'web' || $target eq 'webgrade') {
 3328: 	$currentstring = $token->[4];     
 3329:     }
 3330:     return $currentstring;
 3331: }
 3332: 
 3333: sub end_base {
 3334:     my ($target,$token) = @_;
 3335:     my $currentstring = '';
 3336:     if ($target eq 'web' || $target eq 'webgrade') {
 3337: 	$currentstring = $token->[2];    
 3338:     } 
 3339:     return $currentstring;
 3340: }
 3341: 
 3342: #-- <bdo> tag (end tag required)
 3343: sub start_bdo {
 3344:     my ($target,$token) = @_;
 3345:     my $currentstring = '';
 3346:     if ($target eq 'web' || $target eq 'webgrade') {
 3347: 	$currentstring = $token->[4];     
 3348:     } 
 3349:     return $currentstring;
 3350: }
 3351: 
 3352: sub end_bdo {
 3353:     my ($target,$token) = @_;
 3354:     my $currentstring = '';
 3355:     if ($target eq 'web' || $target eq 'webgrade') {
 3356: 	$currentstring = $token->[2];    
 3357:     } 
 3358:     return $currentstring;
 3359: }
 3360: 
 3361: #-- <bgsound> tag (end tag optional)
 3362: sub start_bgsound {
 3363:     my ($target,$token) = @_;
 3364:     my $currentstring = '';
 3365:     if ($target eq 'web' || $target eq 'webgrade') {
 3366: 	$currentstring = $token->[4];     
 3367:     } 
 3368:     return $currentstring;
 3369: }
 3370: 
 3371: sub end_bgsound {
 3372:     my ($target,$token) = @_;
 3373:     my $currentstring = '';
 3374:     if ($target eq 'web' || $target eq 'webgrade') {
 3375: 	$currentstring = $token->[2];    
 3376:     } 
 3377:     return $currentstring;
 3378: }
 3379: 
 3380: #-- <blink> tag (end tag required)
 3381: sub start_blink {
 3382:     my ($target,$token) = @_;
 3383:     my $currentstring = '';
 3384:     if ($target eq 'web' || $target eq 'webgrade') {
 3385: 	$currentstring = $token->[4];     
 3386:     } 
 3387:     return $currentstring;
 3388: }
 3389: 
 3390: sub end_blink {
 3391:     my ($target,$token) = @_;
 3392:     my $currentstring = '';
 3393:     if ($target eq 'web' || $target eq 'webgrade') {
 3394: 	$currentstring = $token->[2];    
 3395:     } 
 3396:     return $currentstring;
 3397: }
 3398: 
 3399: #-- <blockquote> tag (end tag required)
 3400: sub start_blockquote {
 3401:     my ($target,$token) = @_;
 3402:     my $currentstring = &end_p();	# Close any unclosed <p>
 3403:     if ($target eq 'web' || $target eq 'webgrade') {
 3404: 	$currentstring .= $token->[4];     
 3405:     } 
 3406:     if ($target eq 'tex') {
 3407: 	$currentstring .= '\begin{quote}';
 3408:     }
 3409:     return $currentstring;
 3410: }
 3411: 
 3412: sub end_blockquote {
 3413:     my ($target,$token) = @_;
 3414:     my $currentstring = '';
 3415:     if ($target eq 'web' || $target eq 'webgrade') {
 3416: 	$currentstring = $token->[2];    
 3417:     } 
 3418:     if ($target eq 'tex') {
 3419: 	$currentstring = '\end{quote}';
 3420:     }
 3421:     return $currentstring;
 3422: }
 3423: 
 3424: #-- <button> tag (end tag required)
 3425: sub start_button {
 3426:     my ($target,$token) = @_;
 3427:     my $currentstring = '';
 3428:     if ($target eq 'web' || $target eq 'webgrade') {
 3429: 	$currentstring = $token->[4];     
 3430:     } 
 3431:     return $currentstring;
 3432: }
 3433: 
 3434: sub end_button {
 3435:     my ($target,$token) = @_;
 3436:     my $currentstring = '';
 3437:     if ($target eq 'web' || $target eq 'webgrade') {
 3438: 	$currentstring = $token->[2];    
 3439:     } 
 3440:     return $currentstring;
 3441: }
 3442: 
 3443: #-- <caption> tag (end tag required)
 3444: sub start_caption {
 3445:     my ($target,$token) = @_;
 3446:     my $currentstring = '';
 3447:     if ($target eq 'web' || $target eq 'webgrade') {
 3448: 	$currentstring = $token->[4];     
 3449:     } 
 3450:     return $currentstring;
 3451: }
 3452: 
 3453: sub end_caption {
 3454:     my ($target,$token) = @_;
 3455:     my $currentstring = '';
 3456:     if ($target eq 'web' || $target eq 'webgrade') {
 3457: 	$currentstring = $token->[2];    
 3458:     } 
 3459:     return $currentstring;
 3460: }
 3461: 
 3462: #-- <col> tag (end tag forbdden)
 3463: sub start_col {
 3464:     my ($target,$token) = @_;
 3465:     my $currentstring = '';
 3466:     if ($target eq 'web' || $target eq 'webgrade') {
 3467: 	$currentstring = $token->[4];     
 3468:     } 
 3469:     return $currentstring;
 3470: }
 3471: 
 3472: sub end_col {
 3473:     my ($target,$token) = @_;
 3474:     my $currentstring = '';
 3475:     if ($target eq 'web' || $target eq 'webgrade') {
 3476: 	$currentstring = $token->[2];    
 3477:     } 
 3478:     return $currentstring;
 3479: }
 3480: 
 3481: #-- <colgroup tag (end tag optional)
 3482: sub start_colgroup {
 3483:     my ($target,$token,$tagstack, $parstack, $parser, $safeeval, $style) = @_;
 3484:     my $currentstring = '';
 3485:     if ($target eq 'web' || $target eq 'webgrade') {
 3486: 	$currentstring = $token->[4];     
 3487:     } 
 3488:     if ($target eq 'tex') {
 3489: 	# TODO: Ensure this tag is in a table:
 3490: 
 3491: 	# Fetch the attributes and build the hash for the
 3492: 	# call to define_colgroup.
 3493: 
 3494: 	my $span    = &Apache::lonxml::get_param('span',   $parstack, $safeeval);
 3495: 	my $halign  = &Apache::lonxml::get_param('halign', $parstack, $safeeval);
 3496: 
 3497: 	my %colgroup_params;
 3498: 	if ($span ne '') {
 3499: 	    $colgroup_params{'span'} = $span;
 3500: 	}
 3501: 	if ($halign ne '') {
 3502: 	    $colgroup_params{'halign'} = $halign;
 3503: 	}
 3504: 	
 3505: 	my $table = $Apache::londefdef::table[-1];
 3506: 	$table->define_colgroup(\%colgroup_params);
 3507: 
 3508:     }
 3509:     return $currentstring;
 3510: }
 3511: 
 3512: sub end_colgroup {
 3513:     my ($target,$token) = @_;
 3514:     my $currentstring = '';
 3515:     if ($target eq 'web' || $target eq 'webgrade') {
 3516: 	$currentstring = $token->[2];    
 3517:     } 
 3518:     return $currentstring;
 3519: }
 3520: 
 3521: 
 3522: #-- <del> tag (end tag required)
 3523: sub start_del {
 3524:     my ($target,$token) = @_;
 3525:     my $currentstring = '';
 3526:     if ($target eq 'web' || $target eq 'webgrade') {
 3527: 	$currentstring = $token->[4];     
 3528:     } elsif ($target eq 'tex') {
 3529: 	&disable_para();
 3530: 	$currentstring .= '\st{';  
 3531:     } 
 3532:     return $currentstring;
 3533: }
 3534: 
 3535: sub end_del {
 3536:     my ($target,$token) = @_;
 3537:     my $currentstring = '';
 3538:     if ($target eq 'web' || $target eq 'webgrade') {
 3539: 	$currentstring = $token->[2];     
 3540:     } elsif ($target eq 'tex') {
 3541: 	&enable_para();
 3542: 	$currentstring = '}';
 3543:     } 
 3544:     return $currentstring;
 3545: }
 3546: 
 3547: #-- <fieldset> tag (end tag required)
 3548: sub start_fieldset {
 3549:     my ($target,$token) = @_;
 3550:     my $currentstring = '';
 3551:     if ($target eq 'web' || $target eq 'webgrade') {
 3552: 	$currentstring = $token->[4];     
 3553:     } 
 3554:     return $currentstring;
 3555: }
 3556: 
 3557: sub end_fieldset {
 3558:     my ($target,$token) = @_;
 3559:     my $currentstring = '';
 3560:     if ($target eq 'web' || $target eq 'webgrade') {
 3561: 	$currentstring = $token->[2];    
 3562:     } 
 3563:     return $currentstring;
 3564: }
 3565: 
 3566: #-- <frame> tag (end tag forbidden)
 3567: sub start_frame {
 3568:     my ($target,$token) = @_;
 3569:     my $currentstring = '';
 3570:     if ($target eq 'web' || $target eq 'webgrade') {
 3571: 	$currentstring = $token->[4];     
 3572:     } 
 3573:     return $currentstring;
 3574: }
 3575: 
 3576: sub end_frame {
 3577:     my ($target,$token) = @_;
 3578:     my $currentstring = '';
 3579:     if ($target eq 'web' || $target eq 'webgrade') {
 3580: 	$currentstring = $token->[2];    
 3581:     } 
 3582:     return $currentstring;
 3583: }
 3584: 
 3585: #-- <iframe> tag (end tag required)
 3586: sub start_iframe {
 3587:     my ($target,$token) = @_;
 3588:     my $currentstring = '';
 3589:     if ($target eq 'web' || $target eq 'webgrade') {
 3590:         my ($src,$url,$query);
 3591:         if ($token->[2]->{'src'}) {
 3592:             $src = $token->[2]->{'src'};
 3593:         } elsif ($token->[2]->{'SRC'}) {
 3594:             $src = $token->[2]->{'SRC'};
 3595:         }
 3596:         if ($src) {
 3597:             ($url,$query) = ($src =~ /^([^?]+)\??([^?]*)$/);
 3598:             if ($query =~ /inhibitmenu=yes/) {
 3599:                 $currentstring = $token->[4];
 3600:             } else {
 3601:                 my $inhibit;
 3602:                 if ($url =~ m{^[^/.].*\.x?html?$}) {
 3603:                     $inhibit = 1;
 3604:                 } elsif ($url =~ m{^/(uploaded|res)/.*\.x?html?$}) {
 3605:                     $inhibit = 1;
 3606:                 }
 3607:                 if ($inhibit) {
 3608:                     $currentstring = '<iframe ';
 3609:                     foreach my $attrib (@{$token->[3]}) {
 3610:                         if (lc($attrib) eq 'src') {
 3611:                             if ($query) {
 3612:                                 $query.='&amp;inhibitmenu=yes';
 3613:                             } else {
 3614:                                 $query = 'inhibitmenu=yes';
 3615:                             } 
 3616:                             $currentstring .= 'src="'.$url.'?'.$query.'" ';
 3617:                         } else {
 3618:                             $currentstring .= lc($attrib).'="'.$token->[2]->{$attrib}.'" ';
 3619:                         }
 3620:                     }
 3621:                     $currentstring =~ s/\s+$//;
 3622:                     if ($token->[4] =~ m{/>$}) {
 3623:                         $currentstring .= ' />';
 3624:                     } else {
 3625:                         $currentstring .= '>';
 3626:                     }
 3627:                 } else {
 3628:                     $currentstring = $token->[4];
 3629:                 }
 3630:             }
 3631:             if (($url !~ m{^https?://}) && ($env{'request.course.id'})) {
 3632:                 my $docuri = &Apache::lonnet::hreflocation('',$env{'request.filename'});
 3633:                 my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 3634:                 my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 3635:                 if ($url =~ m{^([^/]|/uploaded/)}) {
 3636:                     my $cleanhref = &clean_docs_httpref($url,$docuri,$cdom,$cnum);
 3637:                     if ($cleanhref) {
 3638:                         &Apache::lonxml::extlink($cleanhref);
 3639:                     }
 3640:                 } elsif (($url =~ m{/res/$LONCAPA::domain_re/}) && ($docuri =~ m{^\Q/uploaded/$cdom/$cnum/docs/\E})) {
 3641:                     if (!&Apache::lonnet::allowed('bre',$url)) {
 3642:                         if (&Apache::lonnet::is_on_map($url)) {
 3643:                             &Apache::lonxml::extlink($url);
 3644:                         }
 3645:                     }
 3646:                 }
 3647:             }
 3648:         } else {
 3649:             $currentstring = $token->[4];
 3650:         }
 3651:     }
 3652:     return $currentstring;
 3653: }
 3654: 
 3655: sub end_iframe {
 3656:     my ($target,$token) = @_;
 3657:     my $currentstring = '';
 3658:     if ($target eq 'web' || $target eq 'webgrade') {
 3659: 	$currentstring = $token->[2];    
 3660:     } 
 3661:     return $currentstring;
 3662: }
 3663: 
 3664: #-- <ins> tag (end tag required)
 3665: sub start_ins {
 3666:     my ($target,$token) = @_;
 3667:     my $currentstring = '';
 3668:     if ($target eq 'web' || $target eq 'webgrade') {
 3669: 	$currentstring = $token->[4];     
 3670:     } 
 3671:     return $currentstring;
 3672: }
 3673: 
 3674: sub end_ins {
 3675:     my ($target,$token) = @_;
 3676:     my $currentstring = '';
 3677:     if ($target eq 'web' || $target eq 'webgrade') {
 3678: 	$currentstring = $token->[2];    
 3679:     } 
 3680:     return $currentstring;
 3681: }
 3682: 
 3683: #-- <isindex> tag (end tag forbidden)
 3684: sub start_isindex {
 3685:     my ($target,$token) = @_;
 3686:     my $currentstring = '';
 3687:     if ($target eq 'web' || $target eq 'webgrade') {
 3688: 	$currentstring = $token->[4];     
 3689:     } 
 3690:     return $currentstring;
 3691: }
 3692: 
 3693: sub end_isindex {
 3694:     my ($target,$token) = @_;
 3695:     my $currentstring = '';
 3696:     if ($target eq 'web' || $target eq 'webgrade') {
 3697: 	$currentstring = $token->[2];    
 3698:     } 
 3699:     return $currentstring;
 3700: }
 3701: 
 3702: #-- <keygen> tag (end tag forbidden)
 3703: sub start_keygen {
 3704:     my ($target,$token) = @_;
 3705:     my $currentstring = '';
 3706:     if ($target eq 'web' || $target eq 'webgrade') {
 3707: 	$currentstring = $token->[4];     
 3708:     } 
 3709:     return $currentstring;
 3710: }
 3711: 
 3712: sub end_keygen {
 3713:     my ($target,$token) = @_;
 3714:     my $currentstring = '';
 3715:     if ($target eq 'web' || $target eq 'webgrade') {
 3716: 	$currentstring = $token->[2];    
 3717:     } 
 3718:     return $currentstring;
 3719: }
 3720: 
 3721: #-- <label> tag
 3722: sub start_label {
 3723:     my ($target,$token) = @_;
 3724:     my $currentstring = '';
 3725:     if ($target eq 'web' || $target eq 'webgrade') {
 3726: 	$currentstring = $token->[4];     
 3727:     } 
 3728:     return $currentstring;
 3729: }
 3730: 
 3731: sub end_label {
 3732:     my ($target,$token) = @_;
 3733:     my $currentstring = '';
 3734:     if ($target eq 'web' || $target eq 'webgrade') {
 3735: 	$currentstring = $token->[2];    
 3736:     } 
 3737:     return $currentstring;
 3738: }
 3739: 
 3740: #-- <layer> tag (end tag required)
 3741: sub start_layer {
 3742:     my ($target,$token) = @_;
 3743:     my $currentstring = '';
 3744:     if ($target eq 'web' || $target eq 'webgrade') {
 3745: 	$currentstring = $token->[4];     
 3746:     } 
 3747:     return $currentstring;
 3748: }
 3749: 
 3750: sub end_layer {
 3751:     my ($target,$token) = @_;
 3752:     my $currentstring = '';
 3753:     if ($target eq 'web' || $target eq 'webgrade') {
 3754: 	$currentstring = $token->[2];    
 3755:     } 
 3756:     return $currentstring;
 3757: }
 3758: 
 3759: #-- <legend> tag (end tag required)
 3760: sub start_legend {
 3761:     my ($target,$token) = @_;
 3762:     my $currentstring = '';
 3763:     if ($target eq 'web' || $target eq 'webgrade') {
 3764: 	$currentstring = $token->[4];     
 3765:     } 
 3766:     return $currentstring;
 3767: }
 3768: 
 3769: sub end_legend {
 3770:     my ($target,$token) = @_;
 3771:     my $currentstring = '';
 3772:     if ($target eq 'web' || $target eq 'webgrade') {
 3773: 	$currentstring = $token->[2];    
 3774:     } 
 3775:     return $currentstring;
 3776: }
 3777: 
 3778: #-- <link> tag (end tag forbidden)
 3779: sub start_link {
 3780:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
 3781:     my $currentstring = '';
 3782:     if ($target eq 'web' || $target eq 'webgrade') {
 3783: 	my $href=&Apache::lonxml::get_param('href',$parstack,$safeeval,
 3784: 					    undef,1);
 3785: 	&Apache::lonxml::extlink($href);
 3786: 	$currentstring = $token->[4];     
 3787:     } 
 3788:     return $currentstring;
 3789: }
 3790: 
 3791: sub end_link {
 3792:     my ($target,$token) = @_;
 3793:     my $currentstring = '';
 3794:     if ($target eq 'web' || $target eq 'webgrade') {
 3795: 	$currentstring = $token->[2];    
 3796:     } 
 3797:     return $currentstring;
 3798: }
 3799: 
 3800: #-- <marquee> tag (end tag optional)
 3801: sub start_marquee {
 3802:     my ($target,$token) = @_;
 3803:     my $currentstring = '';
 3804:     if ($target eq 'web' || $target eq 'webgrade') {
 3805: 	$currentstring = $token->[4];     
 3806:     } 
 3807:     return $currentstring;
 3808: }
 3809: 
 3810: sub end_marquee {
 3811:     my ($target,$token) = @_;
 3812:     my $currentstring = '';
 3813:     if ($target eq 'web' || $target eq 'webgrade') {
 3814: 	$currentstring = $token->[2];    
 3815:     } 
 3816:     return $currentstring;
 3817: }
 3818: 
 3819: #-- <multicol> tag (end tag required)
 3820: sub start_multicol {
 3821:     my ($target,$token) = @_;
 3822:     my $currentstring = &end_p();	# Close any pending <p>
 3823:     if ($target eq 'web' || $target eq 'webgrade') {
 3824: 	$currentstring .= $token->[4];     
 3825:     } 
 3826:     return $currentstring;
 3827: }
 3828: 
 3829: sub end_multicol {
 3830:     my ($target,$token) = @_;
 3831:     my $currentstring = '';
 3832:     if ($target eq 'web' || $target eq 'webgrade') {
 3833: 	$currentstring = $token->[2];    
 3834:     } 
 3835:     return $currentstring;
 3836: }
 3837: 
 3838: #-- <nobr> tag (end tag required)
 3839: sub start_nobr {
 3840:     my ($target,$token) = @_;
 3841:     my $currentstring = '';
 3842:     if ($target eq 'web' || $target eq 'webgrade') {
 3843: 	$currentstring = $token->[4];     
 3844:     }  elsif ($target eq 'tex') {
 3845: 	$currentstring='\mbox{';
 3846:     }
 3847:     return $currentstring;
 3848: }
 3849: 
 3850: sub end_nobr {
 3851:     my ($target,$token) = @_;
 3852:     my $currentstring = '';
 3853:     if ($target eq 'web' || $target eq 'webgrade') {
 3854: 	$currentstring = $token->[2];    
 3855:     }   elsif ($target eq 'tex') {
 3856: 	$currentstring='}';
 3857:     }
 3858:     return $currentstring;
 3859: }
 3860: 
 3861: #-- <noembed> tag (end tag required)
 3862: sub start_noembed {
 3863:     my ($target,$token) = @_;
 3864:     my $currentstring = '';
 3865:     if ($target eq 'web' || $target eq 'webgrade') {
 3866: 	$currentstring = $token->[4];     
 3867:     } 
 3868:     return $currentstring;
 3869: }
 3870: 
 3871: sub end_noembed {
 3872:     my ($target,$token) = @_;
 3873:     my $currentstring = '';
 3874:     if ($target eq 'web' || $target eq 'webgrade') {
 3875: 	$currentstring = $token->[2];    
 3876:     } 
 3877:     return $currentstring;
 3878: }
 3879: 
 3880: #-- <noframes> tag (end tag required)
 3881: sub start_noframes {
 3882:     my ($target,$token) = @_;
 3883:     my $currentstring = '';
 3884:     if ($target eq 'web' || $target eq 'webgrade') {
 3885: 	$currentstring = $token->[4];     
 3886:     } 
 3887:     return $currentstring;
 3888: }
 3889: 
 3890: sub end_noframes {
 3891:     my ($target,$token) = @_;
 3892:     my $currentstring = '';
 3893:     if ($target eq 'web' || $target eq 'webgrade') {
 3894: 	$currentstring = $token->[2];    
 3895:     } 
 3896:     return $currentstring;
 3897: }
 3898: 
 3899: #-- <nolayer> tag (end tag required)
 3900: sub start_nolayer {
 3901:     my ($target,$token) = @_;
 3902:     my $currentstring = '';
 3903:     if ($target eq 'web' || $target eq 'webgrade') {
 3904: 	$currentstring = $token->[4];     
 3905:     } 
 3906:     return $currentstring;
 3907: }
 3908: 
 3909: sub end_nolayer {
 3910:     my ($target,$token) = @_;
 3911:     my $currentstring = '';
 3912:     if ($target eq 'web' || $target eq 'webgrade') {
 3913: 	$currentstring = $token->[2];    
 3914:     } 
 3915:     return $currentstring;
 3916: }
 3917: 
 3918: #-- <noscript> tag (end tag required)
 3919: sub start_noscript {
 3920:     my ($target,$token) = @_;
 3921:     my $currentstring = '';
 3922:     if ($target eq 'web' || $target eq 'webgrade') {
 3923: 	$currentstring = $token->[4];     
 3924:     } 
 3925:     return $currentstring;
 3926: }
 3927: 
 3928: sub end_noscript {
 3929:     my ($target,$token) = @_;
 3930:     my $currentstring = '';
 3931:     if ($target eq 'web' || $target eq 'webgrade') {
 3932: 	$currentstring = $token->[2];    
 3933:     } 
 3934:     return $currentstring;
 3935: }
 3936: 
 3937: #-- <object> tag (end tag required)
 3938: sub start_object {
 3939:     my ($target,$token) = @_;
 3940:     my $currentstring = '';
 3941:     if ($target eq 'web' || $target eq 'webgrade') {
 3942: 	$currentstring = $token->[4];     
 3943:     } 
 3944:     return $currentstring;
 3945: }
 3946: 
 3947: sub end_object {
 3948:     my ($target,$token) = @_;
 3949:     my $currentstring = '';
 3950:     if ($target eq 'web' || $target eq 'webgrade') {
 3951: 	$currentstring = $token->[2];    
 3952:     } 
 3953:     return $currentstring;
 3954: }
 3955: 
 3956: #-- <optgroup> tag (end tag required)
 3957: sub start_optgroup {
 3958:     my ($target,$token) = @_;
 3959:     my $currentstring = '';
 3960:     if ($target eq 'web' || $target eq 'webgrade') {
 3961: 	$currentstring = $token->[4];     
 3962:     } 
 3963:     return $currentstring;
 3964: }
 3965: 
 3966: sub end_optgroup {
 3967:     my ($target,$token) = @_;
 3968:     my $currentstring = '';
 3969:     if ($target eq 'web' || $target eq 'webgrade') {
 3970: 	$currentstring = $token->[2];    
 3971:     } 
 3972:     return $currentstring;
 3973: }
 3974: 
 3975: #-- <samp> tag (end tag required)
 3976: sub start_samp {
 3977:     my ($target,$token) = @_;
 3978:     my $currentstring = '';
 3979:     if ($target eq 'web' || $target eq 'webgrade') {
 3980: 	$currentstring = $token->[4];     
 3981:     } elsif ($target eq 'tex') {
 3982: 	$currentstring='\texttt{';
 3983:     }
 3984:     return $currentstring;
 3985: }
 3986: 
 3987: sub end_samp {
 3988:     my ($target,$token) = @_;
 3989:     my $currentstring = '';
 3990:     if ($target eq 'web' || $target eq 'webgrade') {
 3991: 	$currentstring = $token->[2];    
 3992:     } elsif ($target eq 'tex') {
 3993: 	$currentstring='}';
 3994:     }
 3995:     return $currentstring;
 3996: }
 3997: 
 3998: #-- <server> tag
 3999: sub start_server {
 4000:     my ($target,$token) = @_;
 4001:     my $currentstring = '';
 4002:     if ($target eq 'web' || $target eq 'webgrade') {
 4003: 	$currentstring = $token->[4];     
 4004:     } 
 4005:     return $currentstring;
 4006: }
 4007: 
 4008: sub end_server {
 4009:     my ($target,$token) = @_;
 4010:     my $currentstring = '';
 4011:     if ($target eq 'web' || $target eq 'webgrade') {
 4012: 	$currentstring = $token->[2];    
 4013:     } 
 4014:     return $currentstring;
 4015: }
 4016: 
 4017: #-- <spacer> tag (end tag forbidden)
 4018: sub start_spacer {
 4019:     my ($target,$token) = @_;
 4020:     my $currentstring = &end_p();	# Close off any open <p> tag.
 4021:     if ($target eq 'web' || $target eq 'webgrade') {
 4022: 	$currentstring .= $token->[4];     
 4023:     } 
 4024:     return $currentstring;
 4025: }
 4026: 
 4027: sub end_spacer {
 4028:     my ($target,$token) = @_;
 4029:     my $currentstring = '';
 4030:     if ($target eq 'web' || $target eq 'webgrade') {
 4031: 	$currentstring = $token->[2];    
 4032:     } 
 4033:     return $currentstring;
 4034: }
 4035: 
 4036: #-- <span> tag (end tag required)
 4037: sub start_span {
 4038:     my ($target,$token) = @_;
 4039:     my $currentstring = '';
 4040:     if ($target eq 'web' || $target eq 'webgrade') {
 4041: 	$currentstring = $token->[4];     
 4042:     } 
 4043:     return $currentstring;
 4044: }
 4045: 
 4046: sub end_span {
 4047:     my ($target,$token) = @_;
 4048:     my $currentstring = '';
 4049:     if ($target eq 'web' || $target eq 'webgrade') {
 4050: 	$currentstring = $token->[2];    
 4051:     } 
 4052:     return $currentstring;
 4053: }
 4054: 
 4055: #-- <tbody> tag (end tag optional)
 4056: sub start_tbody {
 4057:     my ($target,$token) = @_;
 4058:     my $currentstring = '';
 4059:     if ($target eq 'web' || $target eq 'webgrade') {
 4060: 	$currentstring = $token->[4];     
 4061:     } 
 4062:     if ($target eq 'tex') {
 4063: 	# TODO: Ensure this tag is within a table:
 4064: 
 4065: 	my $table = $Apache::londefdef::table[-1];
 4066: 	$table->start_body();
 4067:     }
 4068:     return $currentstring;
 4069: }
 4070: 
 4071: sub end_tbody {
 4072:     my ($target,$token) = @_;
 4073:     my $currentstring = '';
 4074:     if ($target eq 'web' || $target eq 'webgrade') {
 4075: 	$currentstring = $token->[2];    
 4076:     } 
 4077:     if($target eq 'tex') {
 4078: 	# TODO: Ensure this tag is within a table:
 4079: 
 4080: 	my $table = $Apache::londefdef::table[-1];
 4081: 	$table->end_body();
 4082:     }
 4083:     return $currentstring;
 4084: }
 4085: 
 4086: #-- <tfoot> tag (end tag optional)
 4087: sub start_tfoot {
 4088:     my ($target,$token) = @_;
 4089:     my $currentstring = '';
 4090:     if ($target eq 'web' || $target eq 'webgrade') {
 4091: 	$currentstring = $token->[4];     
 4092:     } 
 4093:     if ($target eq 'tex') {
 4094:         # TODO: ensure this is within a table tag.
 4095: 	my $table = $Apache::londefdef::table[-1];
 4096: 	$table->start_foot();
 4097:     }
 4098:     return $currentstring;
 4099: }
 4100: 
 4101: sub end_tfoot {
 4102:     my ($target,$token) = @_;
 4103:     my $currentstring = '';
 4104:     if ($target eq 'web' || $target eq 'webgrade') {
 4105: 	$currentstring = $token->[2];    
 4106:     } 
 4107:     if ($target eq 'tex') {
 4108: 	#  TODO: Ensure this is in side a table 
 4109: 	my $table = $Apache::londefdef::table[-1];
 4110: 	$table->end_foot();
 4111:     }
 4112:     return $currentstring;
 4113: }
 4114: 
 4115: #-- <thead> tag (end tag optional)
 4116: sub start_thead {
 4117:     my ($target,$token) = @_;
 4118:     my $currentstring = '';
 4119:     if ($target eq 'web' || $target eq 'webgrade') {
 4120: 	$currentstring = $token->[4];     
 4121:     } 
 4122:     if ($target eq 'tex') {
 4123: 	# Assume we're in a table... TODO: Verify that and ignore tag if not.
 4124: 	my $table = $Apache::londefdef::table[-1];
 4125: 	$table->start_head();
 4126:     }
 4127:     return $currentstring;
 4128: }
 4129: 
 4130: sub end_thead {
 4131:     my ($target,$token) = @_;
 4132:     my $currentstring = '';
 4133:     if ($target eq 'web' || $target eq 'webgrade') {
 4134: 	$currentstring = $token->[2];    
 4135:     } 
 4136:     if ($target eq 'tex') {
 4137:      	# TODO: Verify we are in a table and ignore tag if not.
 4138: 
 4139: 	my $table = $Apache::londefdef::table[-1];
 4140: 	$table->end_head();
 4141:     }
 4142:     return $currentstring;
 4143: }
 4144: 
 4145: #-- <var> tag
 4146: sub start_var {
 4147:     my ($target,$token) = @_;
 4148:     my $currentstring = '';
 4149:     if ($target eq 'web' || $target eq 'webgrade') {
 4150: 	$currentstring = $token->[4];     
 4151:     } elsif ($target eq 'tex') {
 4152: 	$currentstring = '\textit{'; 
 4153:     }
 4154:     return $currentstring;
 4155: }
 4156: 
 4157: sub end_var {
 4158:     my ($target,$token) = @_;
 4159:     my $currentstring = '';
 4160:     if ($target eq 'web' || $target eq 'webgrade') {
 4161: 	$currentstring = $token->[2];
 4162:     } elsif ($target eq 'tex') {
 4163: 	$currentstring = '}'; 
 4164:     } 
 4165:     return $currentstring;
 4166: }
 4167: 
 4168: #-- <wbr> tag (end tag forbidden)
 4169: sub start_wbr {
 4170:     my ($target,$token) = @_;
 4171:     my $currentstring = '';
 4172:     if ($target eq 'web' || $target eq 'webgrade') {
 4173: 	$currentstring = $token->[4];     
 4174:     } 
 4175:     return $currentstring;
 4176: }
 4177: 
 4178: sub end_wbr {
 4179:     my ($target,$token) = @_;
 4180:     my $currentstring = '';
 4181:     if ($target eq 'web' || $target eq 'webgrade') {
 4182: 	$currentstring = $token->[2];    
 4183:     } 
 4184:     return $currentstring;
 4185: }
 4186: 
 4187: #-- <hideweboutput> tag
 4188: sub start_hideweboutput {
 4189:     my ($target,$token) = @_;
 4190:     if ($target eq 'web' || $target eq 'webgrade') {
 4191: 	&Apache::lonxml::startredirection();     
 4192:     } 
 4193:     return '';
 4194: }
 4195: 
 4196: sub end_hideweboutput {
 4197:     my ($target,$token) = @_;
 4198:     my $currentstring = '';
 4199:     if ($target eq 'web' || $target eq 'webgrade') {
 4200: 	$currentstring = &Apache::lonxml::endredirection();    
 4201:     } 
 4202:     return '';
 4203: }
 4204: 
 4205: 
 4206: sub image_replication {
 4207:     my $src = shift;
 4208:     if (not -e $src) { &Apache::lonnet::repcopy($src); }
 4209:     #replicates eps or ps 
 4210:     my $epssrc = my $pssrc = $src;
 4211:     $epssrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i;
 4212:     $pssrc  =~ s/\.(gif|jpg|jpeg|png)$/.ps/i;
 4213:     if (not -e $epssrc && not -e $pssrc) {
 4214: 	my $result=&Apache::lonnet::repcopy($epssrc);
 4215: 	if ($result ne 'ok') { &Apache::lonnet::repcopy($pssrc); }
 4216:     }
 4217:     return '';
 4218: }
 4219: 
 4220: 
 4221: 
 4222: sub resize_image {
 4223:     my ($height_param, $width_param, $scaling,
 4224: 	$parstack, $safeeval, $depth, $cis) = @_;
 4225: 
 4226:     # First apply the scaling...
 4227: 
 4228:     $height_param = $height_param * $scaling;
 4229:     $width_param  = $width_param  * $scaling;
 4230: 
 4231:     #do we have any specified LaTeX size of the picture?
 4232:     my $toget='TeXwidth'; 
 4233:     if ($cis) { 
 4234: 	$toget=lc($toget); 
 4235:     }
 4236:     my $TeXwidth = &Apache::lonxml::get_param($toget,$parstack,
 4237: 					      $safeeval,$depth,$cis);
 4238:     $toget='TeXheight'; if ($cis) { $toget=lc($toget); }
 4239:     my $TeXheight = &Apache::lonxml::get_param($toget,$parstack,
 4240: 					       $safeeval,$depth,$cis);
 4241:     #do we have any specified web size of the picture?
 4242:     my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval,
 4243: 					   $depth,1);
 4244:     if ($TeXwidth) { 
 4245: 	my $old_width_param=$width_param;
 4246: 	if ($TeXwidth=~/(\d+)\s*\%/) {
 4247: 	    $width_param = $1*$env{'form.textwidth'}/100;
 4248: 	} else { 
 4249: 	    $width_param = $TeXwidth;
 4250: 	}
 4251: 	if ($TeXheight) {
 4252: 	    $height_param = $TeXheight;
 4253: 	} elsif ($old_width_param) {
 4254: 	    $height_param=$TeXwidth/$old_width_param*$height_param;
 4255: 	}
 4256:     } elsif ($TeXheight) {
 4257: 	$height_param = $TeXheight;
 4258: 	if ($height_param) {
 4259: 	    $width_param  = $TeXheight/$height_param*$width_param;
 4260: 	}
 4261:     } elsif ($width) {
 4262: 	my $old_width_param=$width_param;
 4263: 	$width_param = $width*$scaling;
 4264: 	if ($old_width_param) {
 4265: 	    $height_param=$width_param/$old_width_param*$height_param;
 4266: 	}
 4267:     }
 4268:     if ($width_param > $env{'form.textwidth'}) {
 4269:         my $old_width_param=$width_param;
 4270: 	$width_param =0.95*$env{'form.textwidth'};
 4271: 	if ($old_width_param) {
 4272: 	    $height_param=$width_param/$old_width_param*$height_param;
 4273: 	}
 4274:     }
 4275: 
 4276:     return ($height_param, $width_param);
 4277: }
 4278: 
 4279: sub image_size {
 4280:     my ($src,$scaling,$parstack,$safeeval,$depth,$cis)=@_;
 4281: 
 4282:     #size of image from gif/jpg/jpeg/png 
 4283:     my $ressrc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
 4284:     if (-e $ressrc) {
 4285: 	$src = $ressrc;
 4286:     }
 4287:     my $image = Image::Magick->new;
 4288:     my $current_figure = $image->Read($src);
 4289:     my $width_param = $image->Get('width');
 4290:     my $height_param = $image->Get('height');
 4291:     &Apache::lonxml::debug("Image magick says: $src :  Height = $height_param width = $width_param");
 4292:     undef($image);
 4293: 
 4294:     ($height_param, $width_param) = &resize_image($height_param, $width_param,
 4295: 						  $scaling, $parstack, $safeeval, 
 4296: 						  $depth, $cis);
 4297: 
 4298:     return ($height_param, $width_param);
 4299: }
 4300: 
 4301: sub image_width {
 4302:     my ($height, $width) = &image_size(@_);
 4303:     return $width;
 4304: }
 4305: #  Not yet 100% sure this is correct in all circumstances..
 4306: #  due to my uncertainty about mods to image_size.
 4307: #
 4308: sub image_height {
 4309:     my ($height, $width) = &image_size(@_);
 4310:     return $height;
 4311: }
 4312: 
 4313: sub get_eps_image {
 4314:     my ($src)=@_;
 4315:     my $orig_src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1], $src);
 4316: 
 4317:     # In order to prevent the substitution of the alt text, we need to
 4318:     # be sure the orig_src file is on system now so:
 4319: 
 4320:     if (! -e $orig_src) {
 4321: 	&Apache::lonnet::repcopy($orig_src); # Failure is not completely fatal.
 4322:     }
 4323:     &Apache::lonxml::debug("get_eps_image: Original image: $orig_src");
 4324:     my ($spath, $sname, $sext) = &fileparse($src, qr/\.(bmp|gif|png|jpg|jpeg)/i);
 4325:     $src=~s/\.(bmp|gif|png|jpg|jpeg)$/\.eps/i;
 4326:     $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
 4327:     &Apache::lonxml::debug("Filelocation gives: $src");
 4328:     if (! -e $src) {
 4329: 	&Apache::lonxml::debug("$src does not exist");
 4330: 	if (&Apache::lonnet::repcopy($src) ne 'ok' ) {
 4331: 	    &Apache::lonxml::debug("Repcopy of $src failed (1)");
 4332: 	    #if replication failed try to find ps file
 4333: 	    $src=~s/\.eps$/\.ps/;
 4334: 	    &Apache::lonxml::debug("Now looking for $src");
 4335: 	    #if no ps file try to replicate it.
 4336: 	    my $didrepcopy = &Apache::lonnet::repcopy($src);
 4337: 	    &Apache::lonxml::debug("repcopy of $src ... $didrepcopy");
 4338: 	    if ( (not -e $src) ||
 4339: 		($didrepcopy ne 'ok')) {
 4340: 		&Apache::lonxml::debug("Failed to find or replicate $src");
 4341: 
 4342: 		#if replication failed try to produce eps file dynamically
 4343: 		$src=~s/\.ps$/\.eps/;
 4344: 		if (open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat")) {
 4345: 		    my $newsrc=$orig_src;
 4346: 		    $newsrc =~ s|(.*)/res/|/home/httpd/html/res/|;
 4347: 		    &Apache::lonxml::debug("queueing $newsrc for dynamic eps production.");
 4348: 		    print FILE ("$newsrc\n");
 4349: 		    close(FILE);
 4350:                 }
 4351: 		$src=~s|/home/httpd/html/res|/home/httpd/prtspool|;
 4352: 		$src=~s|/home/httpd/html/priv/[^/]+/([^/]*)/|/home/httpd/prtspool/$1/|;
 4353: 		if ($sext ne "") {	 # Put the ext. back in to uniquify.
 4354: 		    $src =~ s/\.eps$/$sext.eps/;
 4355: 		}
 4356: 
 4357: 	    }
 4358: 
 4359: 	}
 4360:     } else {
 4361: 	# If the postscript file has spaces in its name,
 4362: 	# LaTeX will gratuitiously vomit.  Therefore
 4363: 	# queue such files for copy with " " replaced by "_".
 4364: 	# printout.pm will know them by their .ps  or .eps extensions.
 4365: 	my $newsrc = $orig_src;
 4366: 	$newsrc    =~  s|(.*)/res/|/home/httpd/html/res/|;
 4367: 	open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat");
 4368: 	print FILE "$src\n";
 4369: 	close FILE;
 4370: 	$src=~s|/home/httpd/html/res|/home/httpd/prtspool|;
 4371: 	$src=~s|/home/httpd/html/priv/[^/]+/([^/]*)/|/home/httpd/prtspool/$1/|;
 4372:     }
 4373:     my ($path,$file)=($src=~m|(.*)/([^/]*)$|);
 4374:     $path =~ s/ /\_/g;
 4375:     $file =~ s/ /\_/g;
 4376:     &Apache::lonxml::debug("get_eps_image returning: $path / $file<BR />");
 4377:     return ($path.'/',$file);
 4378: }
 4379: 
 4380: sub eps_generation {
 4381:     my ($src,$file,$width_param) = @_;	     
 4382:     my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat";
 4383:     if (open(my $tmpfile,">>$filename")) { 
 4384:         print $tmpfile "$src\n";
 4385:         close($tmpfile);
 4386:     }
 4387:     my $newsrc = $src;
 4388:     $newsrc =~ s/(\.bmp|\.gif|\.jpg|\.jpeg)$/\.eps/i;
 4389:     $newsrc=~s{/home/httpd/html/res}{};
 4390:     $newsrc=~s{/home/httpd/html/priv/[^/]+/($LONCAPA::username_re)/}{/$1/};
 4391:     $newsrc=~s{/\./}{/};
 4392:     $newsrc=~s{/([^/]+)\.(ps|eps)}{/};
 4393:     if ($newsrc=~m{/home/httpd/lonUsers/}) {
 4394: 	$newsrc=~s{/home/httpd/lonUsers}{};
 4395: 	$newsrc=~s{/($LONCAPA::domain_re)/./././}{/$1/};
 4396:     }
 4397:     if ($newsrc=~m{/userfiles/}) {
 4398: 	return ' \graphicspath{{'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
 4399:     } else {
 4400: 	return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
 4401:     }
 4402: }
 4403: 
 4404: sub file_path {     
 4405:     my $src=shift;
 4406:     my ($file,$path); 
 4407:     if ($src =~ m!(.*)/([^/]*)$!) {
 4408: 	$file = $2; 
 4409: 	$path = $1.'/'; 
 4410:     } 
 4411:     return $file,$path;
 4412: }
 4413: 
 4414: 
 4415: sub recalc {
 4416:     my $argument = shift;
 4417:     if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}
 4418:     $argument=~/\s*(\d+\.?\d*)\s*(mm|cm|in|pc|pt)/;
 4419:     my $value=$1;
 4420:     my $units=$2;
 4421:     if ($units eq 'cm') {
 4422: 	$value*=10;
 4423:     } elsif ($units eq 'in') {
 4424: 	$value*=25.4;
 4425:     } elsif ($units eq 'pc') {
 4426: 	$value*=(25.4*12/72.27);
 4427:     } elsif ($units eq 'pt') {
 4428: 	$value*=(25.4/72.27);
 4429:     }
 4430:     return $value.' mm';
 4431: }
 4432: 
 4433: sub LATEX_length {
 4434:     my $garbage=shift;
 4435:     $garbage=~s/^\s+$//;
 4436:     $garbage=~s/^\s+(\S.*)/$1/;#space before 
 4437:     $garbage=~s/(.*\S)\s+$/$1/;#space after 
 4438:     $garbage=~s/(\s)+/$1/;#only one space
 4439:     $garbage=~s/(\\begin{([^\}]+)}|\\end{([^\}]+)})//g;#remove LaTeX \begin{...} and \end{...}
 4440:     $garbage=~s/(\$\_\{|\$\_|\$\^{|\$\^|\}\$)//g;#remove $_{,$_,$^{,$^,}$
 4441:     $garbage=~s/([^\\])\$/$1/g;#$
 4442:     $garbage=~s/(\\ensuremath\{\_\{|\\ensuremath\{\_|\\ensuremath\{\^{|\\ensuremath\{\^|\})//g;#remove \ensuremath{...}
 4443:    $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;
 4444:     $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;
 4445:     $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;
 4446:     $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;
 4447:     $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;
 4448:     $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;
 4449:     $garbage=~s/(\\hat{([^}]+)}|\\check{([^}]+)}|\\dot{([^}]+)}|\\breve{([^}]+)}|\\acute{([^}]+)}|\\ddot{([^}]+)}|\\grave{([^}]+)}|\\tilde{([^}]+)}|\\mathring{([^}]+)}|\\bar{([^}]+)}|\\vec{([^}]+)})/$1/g;
 4450:     #remove some other LaTeX command
 4451:     $garbage=~s|\\(\w+)\\|\\|g;	 
 4452:     $garbage=~s|\\(\w+)(\s*)|$2|g;	 	 
 4453:     $garbage=~s|\+|11|g;
 4454:     my  $value=length($garbage);
 4455:     return $value;
 4456: }
 4457: 
 4458: 
 4459: sub align_latex_image {
 4460:     my ($align, $latex_rendering, $image, $width, $height) = @_;
 4461:     my $currentstring;        # The 1/2 wrapped image.
 4462:     my $closure;              # The closure of the wrappage.
 4463: 
 4464:     # if it's none just return it back
 4465:     if ($latex_rendering eq 'none') {
 4466: 	return ($image,'');
 4467:     }
 4468: 
 4469:     #    If there's an alignment specification we need to honor it here.
 4470:     #    For the horizontal alignments, we will also honor the
 4471:     #    value of the latex specfication.  The default is parbox,
 4472:     #    and that's used for illegal values too.  
 4473:     #    
 4474:     #    Even though we set a default alignment value, the user
 4475:     #    could have given us an illegal value.  In that case we
 4476:     #    just use the default alignment of bottom..
 4477:     $currentstring = '';
 4478:     if      ($align eq "top")    {
 4479: 	$currentstring .= '\raisebox{-'.$height.'mm}{'.$image;
 4480: 	$closure = '}';
 4481:     } elsif (($align eq "center") || ($align eq "middle")) { # Being kind
 4482: 	my $offset = $height/2;
 4483: 	$currentstring .= '\raisebox{-'.$offset.'mm}{'.$image;
 4484: 	$closure       = '}';
 4485:     } elsif ($align eq "left")   { 
 4486: 	if ($latex_rendering eq "parpic") { 
 4487: 	    $currentstring .= '\parpic[l]{'.$image;
 4488: 	    $closure       = '}';
 4489: 	} elsif ($latex_rendering eq "parbox") {
 4490: 	    $currentstring .= '\begin{minipage}[l]{'.$width.'mm}'
 4491: 		.$image;
 4492: 	    $closure = '\end{minipage}';
 4493: 	} elsif ($latex_rendering eq "wrapfigure"
 4494: 		 || $latex_rendering ne 'none') {  # wrapfig render
 4495: 	    $currentstring .= 
 4496: 		'\begin{wrapfigure}{l}{'.$width.'mm}'
 4497: 		.'\scalebox{1.0}{'.$image;
 4498: 	    $closure = '}\end{wrapfigure}';
 4499: 	}
 4500:     } elsif ($align eq "right")  {   
 4501: 	if ($latex_rendering eq "parpic") {
 4502: 	    $currentstring .= '\parpic[r]{'.$image;
 4503: 	    $closure = '}';
 4504: 	} elsif ($latex_rendering eq "parbox") {
 4505: 	    $currentstring .=  '\begin{minipage}[r]{'.$width.'mm}'
 4506: 		.$image;
 4507: 	    $closure = '\end{minipage}';
 4508: 	} elsif ($latex_rendering eq "wrapfigure"
 4509: 		 || $latex_rendering ne 'none') {  # wrapfig render
 4510: 	    $currentstring .= 
 4511: 		'\begin{wrapfigure}{r}{'.$width.'mm}'
 4512: 		.'\scalebox{1.0}{'.$image;
 4513: 	    $closure = '}\end{wrapfigure}';
 4514: 	}
 4515:     } else {		# Bottom is also default.
 4516: 	# $currentstring = '\raisebox{'.$height.'mm}{'.$image.'}';
 4517: 	$currentstring .= "{$image";
 4518: 	$closure       = '}';
 4519:     }
 4520:     return ($currentstring, $closure);
 4521: }
 4522: 
 4523: 
 4524: sub is_inside_of {
 4525:     my ($tagstack, $tag) = @_;
 4526:     my @stack = @$tagstack;
 4527:     for (my $i = ($#stack - 1); $i >= 0; $i--) {
 4528: 	if ($stack[$i] eq $tag) {
 4529: 	    return 1;
 4530: 	}
 4531:     }
 4532:     return 0;
 4533: }
 4534: 
 4535: 
 4536: #
 4537: #   This sub provides the typical LaTeX prefix matter for tex output:
 4538: #
 4539: sub latex_header {
 4540:     my ($mode) = @_;
 4541:     my $currentstring = '';
 4542: 
 4543:     $currentstring .= 
 4544: 	"\n% &Apache::lonxml::londefdef \n" .
 4545: 	'\documentclass[letterpaper,twoside]{article}\raggedbottom';
 4546:     if (($env{'form.latex_type'}=~'batchmode') ||
 4547: 	(!$env{'request.role.adv'}) || 
 4548: 	($mode eq 'batchmode')) {$currentstring .='\batchmode';} 
 4549:     $currentstring .= '\newcommand{\keephidden}[1]{}'.
 4550: 	'\renewcommand{\deg}{$^{\circ}$}'.
 4551: 	'\usepackage{multirow}'.
 4552: 	'\usepackage{longtable}'.
 4553: 	'\usepackage{textcomp}'.
 4554: 	'\usepackage{makeidx}'.
 4555: 	'\usepackage[dvips]{graphicx}'.
 4556: 	'\usepackage{wrapfig}'.
 4557: 	'\usepackage{picins}'.
 4558: 	'\usepackage[T1]{fontenc}'."\n".
 4559: 	'\usepackage{lmodern}'."\n".
 4560: 	'\usepackage[postscript]{ucs}'."\n".
 4561: 	'\usepackage[utf8x]{inputenc}'."\n".
 4562: 	'\usepackage{pifont}' ."\n".
 4563: 	'\usepackage{latexsym}'."\n".
 4564: 	'\usepackage{epsfig}'.
 4565: 	"\\usepackage{xtab}\n".
 4566: 	"\\usepackage{tabularx}\n".
 4567: 	"\\usepackage{booktabs}\n".
 4568: 	"\\usepackage{array}\n".
 4569: 	"\\usepackage{colortbl}\n".
 4570: 	"\\usepackage{xcolor}\n".
 4571: 	'\usepackage{calc}'.
 4572: 	'\usepackage{amsmath}'.
 4573: 	'\usepackage{soul}'.
 4574: 	'\usepackage{amssymb}'.
 4575: 	'\usepackage{amsfonts}'.
 4576: 	'\usepackage{amsthm}'.
 4577: 	'\usepackage{amscd}'
 4578:         .'\usepackage{picins}\usepackage{calc}'."\n". # From lonprintout.pm
 4579: 	'\usepackage[T1]{fontenc}'."\n".
 4580: 	'\usepackage{lmodern}'."\n".
 4581: 	'\usepackage[postscript]{ucs}'."\n".
 4582: 	'\usepackage[utf8x]{inputenc}'."\n".
 4583: 	'\usepackage{pifont}'  . "\n";
 4584: 	
 4585:     if($env{'form.pdfFormFields'} eq 'yes') {
 4586: 	$currentstring .= '\usepackage{hyperref}'.
 4587: 	    '\usepackage{eforms}'.
 4588: 	    '\usepackage{tabularx}';
 4589:     } 
 4590:     
 4591:         $currentstring .= '\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}}'.
 4592:                           '\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}}';
 4593:     $currentstring .= '\begin{document}';
 4594:     
 4595:     return $currentstring;
 4596: 
 4597: }
 4598: 
 4599: sub clean_docs_httpref {
 4600:     my ($href,$docuri,$cdom,$cnum) = @_;
 4601:     if ($docuri eq '') {
 4602:         $docuri = &Apache::lonnet::hreflocation('',$env{'request.filename'});
 4603:     }
 4604:     if ($cdom eq '') {
 4605:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 4606:     }
 4607:     if ($cnum eq '') {
 4608:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 4609:     }
 4610:     my $cleanhref;
 4611:     if ($docuri =~ m{^(\Q/uploaded/$cdom/$cnum/docs/\E)(.+/)[^/]+$}) {
 4612:         my $prefix = $1;
 4613:         my $relpath = $2;
 4614:         my ($hrefpath,$fname);
 4615:         if ($href =~ m{^/}) {
 4616:             if ($href =~ m{^\Q$prefix\E(.+/)([^/]+)$}) {
 4617:                 $hrefpath = $1;
 4618:                 $fname = $2;
 4619:             } else {
 4620:                 return $cleanhref;
 4621:             }
 4622:         } else {
 4623:             if ($href =~ m{/}) {  
 4624:                 (my $path,$fname) = ($href =~ m{^(.*)/([^/]*)$});
 4625:                 $hrefpath = $relpath.$path;
 4626:                 if ($path eq '') {
 4627:                     $hrefpath =~ s{/$}{};
 4628:                 }
 4629:             } else {
 4630:                 $fname = $href;
 4631:                 $hrefpath = $relpath;
 4632:                 $hrefpath =~ s{/$}{};
 4633:             }
 4634:         }
 4635:         if ($fname ne '') {
 4636:             my $cleanrelpath;
 4637:             foreach my $dir (split(/\//,$hrefpath)) {
 4638:                 next if ($dir eq '.');
 4639:                 if ($dir eq '..') {
 4640:                     $cleanrelpath =~ s{([^/]+/)$}{};
 4641:                 } else {
 4642:                     $cleanrelpath .= $dir.'/';
 4643:                 }
 4644:             }
 4645:             if ($cleanrelpath ne '') {
 4646:                 $cleanhref = $prefix.$cleanrelpath.$fname;
 4647:             } else {
 4648:                 $cleanhref = $prefix.$fname;
 4649:             }
 4650:         }
 4651:     }
 4652:     return $cleanhref;
 4653: }
 4654: 
 4655: =pod
 4656: 
 4657: =head1 NAME
 4658: 
 4659: Apache::londefdef.pm
 4660: 
 4661: =head1 SYNOPSIS
 4662: 
 4663: Tags Default Definition Module
 4664: 
 4665: This is part of the LearningOnline Network with CAPA project
 4666: described at http://www.lon-capa.org.
 4667: 
 4668: 
 4669: =head1 NOTABLE SUBROUTINES
 4670: 
 4671: =over
 4672: 
 4673: =item start_hideweboutput()
 4674: 
 4675: =item end_hideweboutput()
 4676: 
 4677: =item image_replication()
 4678: 
 4679: =item resize_image()
 4680: 
 4681: 	Get correct sizing parameter for an image given
 4682: 	it's initial ht. and wid.  This allows sizing of
 4683: 	images that are generated on-the-fly (e.g. gnuplot)
 4684: 	as well as serving as a utility for image_size.
 4685:  
 4686: 	Parameter:
 4687:         height_param
 4688:         width_param    - Initial picture dimensions.
 4689:         scaling        - A scale factor.
 4690:         parstack,      - the current stack of tag attributes 
 4691:                          from the xml parser
 4692:         safeeval,      - pointer to the safespace
 4693:         depth,         - from what level in the stack to look for attributes
 4694:                          (assumes -1 if unspecified)
 4695:         cis            - look for attrubutes case insensitively
 4696:                          (assumes false)
 4697: 
 4698: 	Returns:
 4699: 		height, width   - new dimensions.
 4700: 
 4701: =item image_size()
 4702: 
 4703: =item image_width()
 4704: 
 4705: =item image_height()
 4706: 
 4707: =item get_eps_image()
 4708: 
 4709: =item eps_generation()
 4710: 
 4711: =item file_path()
 4712: 
 4713: =item recalc()
 4714: 
 4715: 	Converts a measurement in to mm from any of 
 4716: 	the other valid LaTeX units of measure.
 4717: 	If the units of measure are missing from the 
 4718: 	parameter, it is assumed to be in and returned
 4719: 	with mm units of measure
 4720: 
 4721: =item LATEX_length()
 4722: 
 4723: =item align_latex_image()
 4724: 
 4725:   	Wrap image 'stuff' inside of the LaTeX required to implement 
 4726:    	alignment:
 4727:      	align_tex_image(align, latex_rendering, image)
 4728:    	Where:
 4729:      	align   - The HTML alignment specification.
 4730:      	latex_rendering - rendering hint for latex.
 4731:      	image   - The LaTeX needed to insert the image itsef.
 4732:      	width,height - dimensions of the image.
 4733:  	Returns:
 4734:     	The 1/2 wrapped image and the stuff required to close the
 4735:     	wrappage.  This allows e.g. randomlabel to insert more stuff
 4736:     	into the closure.
 4737: 
 4738: 
 4739: =item is_inside_of($tagstack, $tag)
 4740:    	This sub returns true if the current state of Xml processing is inside of the tag.   
 4741: 	Parameters:
 4742:     	tagstack   - The tagstack from the parser.
 4743:     	tag        - The tag (without the <>'s.).
 4744: 	Sample usage:
 4745:     	if (is_inside_of($tagstack "table")) {
 4746:      	   I'm in a table....
 4747:      	}
 4748: 
 4749: =item clean_docs_httpref($href,$docuri,$cdom,$cnum)
 4750:         HTML pages uploaded to a course which contain dependencies either from iframes,
 4751:         javascript files or objects (FlashPlayerSwf, MediaSrc, XMPSrc, ConfigurationSrc,
 4752:         and PosterImageSrc) for which dependency is another file uploaded to the same
 4753:         course.
 4754: 
 4755:         Required input: 
 4756:         href - dependency (either a relative URL, or an absolute URL)
 4757:         Optional inputs:
 4758:         docuri - URL of HTML page containing the dependency
 4759:         cdom - Course domain
 4760:         cnum - CourseID
 4761: 
 4762:         Output:
 4763:         returns an absolute URL constructed from the href provided, and the calling context.
 4764:         (this will be null, if the URL does not begin: /uploaded/$cdom/$cnum/docs/).
 4765: 
 4766: =back
 4767: 
 4768: =cut
 4769: 
 4770: 
 4771: 1;
 4772: __END__

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