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

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

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