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

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

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