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