Annotation of loncom/xml/londefdef.pm, revision 1.415.4.3

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

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