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

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

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