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