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

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

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