File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.456.2.4: download - view: text, annotated - select for diffs
Fri May 17 15:41:32 2019 UTC (4 years, 11 months ago) by raeburn
Branches: version_2_11_X
Diff to branchpoint 1.456: preferred, unified
- For 2.11
  Backport 1.458

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

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