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

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

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