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

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

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