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