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

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

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