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

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

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