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

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

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