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