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

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

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