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

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

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