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