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