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

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

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