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