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

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

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