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