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

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

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