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