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

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

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