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

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

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