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

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

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