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

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

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