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

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

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