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

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

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