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