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

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

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