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