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

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

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