File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.457: download - view: text, annotated - select for diffs
Wed Jan 6 16:44:37 2016 UTC (8 years, 4 months ago) by damieng
Branches: MAIN
CVS tags: HEAD
Added Daxe editing for HTML documents, fixed issues with case mixing in task documents

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

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