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

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

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