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

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

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