File:  [LON-CAPA] / loncom / xml / londefdef.pm
Revision 1.472: download - view: text, annotated - select for diffs
Thu Jul 13 19:07:27 2023 UTC (10 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Breadcrumbs text when displaying/editing resource in Course Authoring Space.

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

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