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