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

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

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