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

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

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