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