File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.458: download - view: text, annotated - select for diffs
Thu Jan 14 19:40:26 2016 UTC (8 years, 4 months ago) by damieng
Branches: MAIN
CVS tags: HEAD
added a warning for the use of <m> without math delimiters

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

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