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