1: # The LearningOnline Network with CAPA
2: # Tags Default Definition Module
3: #
4: # $Id: londefdef.pm,v 1.73 2002/07/12 16:37:38 albertel 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: #
29: # Copyright for TtHfunc and TtMfunc by Ian Hutchinson.
30: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into
31: # binary executable programs or libraries distributed by the
32: # Michigan State University (the "Licensee"), but any binaries so
33: # distributed are hereby licensed only for use in the context
34: # of a program or computational system for which the Licensee is the
35: # primary author or distributor, and which performs substantial
36: # additional tasks beyond the translation of (La)TeX into HTML.
37: # The C source of the Code may not be distributed by the Licensee
38: # to any other parties under any circumstances.
39: #
40: #
41: # last modified 06/26/00 by Alexander Sakharuk
42: # 11/6,11/30,02/01/01,5/4 Gerd Kortemeyer
43: # 01/18 Alex Sakharuk
44:
45: package Apache::londefdef;
46:
47: use Apache::lonnet;
48: use strict;
49: use Apache::lonxml;
50: use Apache::File();
51: use Image::Magick;
52:
53: BEGIN {
54:
55: &Apache::lonxml::register('Apache::londefdef',('m','html','head','map','select','option','input','textarea','form','meta','title','body','center','b','strong','dt','h1','h2','h3','h4','h5','h6','cite','i','address','dd','dl','dir','ol','ul','menu','dfn','kbd','tt','code','em','q','p','br','big','small','basefont','font','s','sub','strike','sup','hr','a','li','u','output','param','applet','img','embed','allow','frameset','pre','insert','externallink','table','tr','th','td','blankspace','bubble','bubbles','bubbleline'));
56:
57: }
58:
59: #======================= TAG SUBROUTINES =====================
60: #-- <output>
61: sub start_output {
62: my ($target) = @_;
63: if ($target eq 'meta') { $Apache::lonxml::metamode--; }
64: return '';
65: }
66: sub end_output {
67: my ($target) = @_;
68: if ($target eq 'meta') { $Apache::lonxml::metamode++; }
69: return '';
70: }
71: #-- <m> tag
72: sub start_m {
73: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
74: my $currentstring = '';
75: if ($target eq 'web') {
76: $Apache::lonxml::prevent_entity_encode++;
77: my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser);
78: $inside ='\\documentstyle{article}'.$inside;
79: &Apache::lonxml::debug("M is starting with:$inside:");
80: my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
81: if ($eval eq 'on') {
82: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
83: #&Apache::lonxml::debug("M is evaulated to:$inside:");
84: }
85: $currentstring = &Apache::lontexconvert::converted(\$inside);
86: if ($Apache::lontexconvert::errorstring) {
87: &Apache::lonxml::warning("tth error: ".
88: $Apache::lontexconvert::errorstring);
89: $Apache::lontexconvert::errorstring='';
90: }
91: #&Apache::lonxml::debug("M is ends with:$currentstring:");
92: } elsif ($target eq 'tex') {
93: $currentstring = &Apache::lonxml::get_all_text_unbalanced("/m",$parser);
94: } else {
95: my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser);
96: }
97: return $currentstring;
98: }
99: sub end_m {
100: my ($target,$token) = @_;
101: my $currentstring = '';
102: if ($target eq 'web') {
103: $Apache::lonxml::prevent_entity_encode--;
104: } elsif ($target eq 'tex') {
105: $currentstring = "";
106: } elsif ($target eq 'meta') {
107: }
108: return $currentstring;
109: }
110: #-- <html> tag
111: sub start_html {
112: my ($target,$token) = @_;
113: my $currentstring = '';
114: if ($ENV{'browser.mathml'}) {
115: &tth::ttminit();
116: } else {
117: &tth::tthinit();
118: }
119: if ($target eq 'web') {
120: $currentstring = &Apache::lonxml::xmlbegin().
121: &Apache::lonxml::fontsettings();
122: } elsif ($target eq 'tex') {
123: @Apache::londefdef::table = ();
124: $currentstring .= '\documentclass[letterpaper]{article}
125: \newcommand{\keephidden}[1]{}
126: \usepackage[dvips]{graphicx}
127: \usepackage{epsfig}\usepackage{calc}';
128: }
129: return $currentstring;
130: }
131: sub end_html {
132: my ($target,$token) = @_;
133: my $currentstring = '';
134: if ($target eq 'web') {
135: $currentstring = &Apache::lonxml::xmlend();
136: }
137: return $currentstring;
138: }
139: #-- <head> tag
140: sub start_head {
141: my ($target,$token) = @_;
142: my $currentstring = '';
143: if ($target eq 'web') {
144: $currentstring = $token->[4];
145: }
146: return $currentstring;
147: }
148: sub end_head {
149: my ($target,$token) = @_;
150: my $currentstring = '';
151: if ($target eq 'web') {
152: $currentstring = &Apache::lonxml::registerurl(undef,$target).
153: $token->[2];
154: }
155: return $currentstring;
156: }
157: #-- <map> tag
158: sub start_map {
159: my ($target,$token) = @_;
160: my $currentstring = '';
161: if ($target eq 'web') {
162: $currentstring = $token->[4];
163: }
164: return $currentstring;
165: }
166: sub end_map {
167: my ($target,$token) = @_;
168: my $currentstring = '';
169: if ($target eq 'web') {
170: $currentstring = $token->[2];
171: }
172: return $currentstring;
173: }
174: #-- <select> tag
175: sub start_select {
176: my ($target,$token) = @_;
177: my $currentstring = '';
178: if ($target eq 'web') {
179: $currentstring = $token->[4];
180: }
181: return $currentstring;
182: }
183: sub end_select {
184: my ($target,$token) = @_;
185: my $currentstring = '';
186: if ($target eq 'web') {
187: $currentstring = $token->[2];
188: }
189: return $currentstring;
190: }
191: #-- <option> tag
192: sub start_option {
193: my ($target,$token) = @_;
194: my $currentstring = '';
195: if ($target eq 'web') {
196: $currentstring = $token->[4];
197: }
198: return $currentstring;
199: }
200: sub end_option {
201: my ($target,$token) = @_;
202: my $currentstring = '';
203: if ($target eq 'web') {
204: $currentstring = $token->[2];
205: }
206: return $currentstring;
207: }
208: #-- <input> tag
209: sub start_input {
210: my ($target,$token) = @_;
211: my $currentstring = '';
212: if ($target eq 'web') {
213: $currentstring = $token->[4];
214: }
215: return $currentstring;
216: }
217: sub end_input {
218: my ($target,$token) = @_;
219: my $currentstring = '';
220: if ($target eq 'web') {
221: $currentstring = $token->[2];
222: }
223: return $currentstring;
224: }
225: #-- <textarea> tag
226: sub start_textarea {
227: my ($target,$token) = @_;
228: my $currentstring = '';
229: if ($target eq 'web') {
230: $currentstring = $token->[4];
231: }
232: return $currentstring;
233: }
234: sub end_textarea {
235: my ($target,$token) = @_;
236: my $currentstring = '';
237: if ($target eq 'web') {
238: $currentstring = $token->[2];
239: }
240: return $currentstring;
241: }
242: #-- <form> tag
243: sub start_form {
244: my ($target,$token) = @_;
245: my $currentstring = '';
246: if ($target eq 'web') {
247: $currentstring = $token->[4];
248: }
249: return $currentstring;
250: }
251: sub end_form {
252: my ($target,$token) = @_;
253: my $currentstring = '';
254: if ($target eq 'web') {
255: $currentstring = $token->[2];
256: }
257: return $currentstring;
258: }
259: #-- <title> tag
260: sub start_title {
261: my ($target,$token) = @_;
262: my $currentstring = '';
263: if ($target eq 'web') {
264: $currentstring = $token->[4];
265: } elsif ($target eq 'tex') {
266: $currentstring .= '\keephidden{'
267: }
268: if ($target eq 'meta') {
269: $currentstring='<title>';
270: &start_output();
271: }
272: return $currentstring;
273: }
274: sub end_title {
275: my ($target,$token) = @_;
276: my $currentstring = '';
277: if ($target eq 'web') {
278: $currentstring = $token->[2];
279: } elsif ($target eq 'tex') {
280: $currentstring .= '}';
281: }
282: if ($target eq 'meta') {
283: &end_output();
284: $currentstring='</title>';
285: }
286: return $currentstring;
287: }
288: #-- <meta> tag
289: sub start_meta {
290: my ($target,$token,$tagstack,$parstack,$parser) = @_;
291: my $currentstring = '';
292: if ($target eq 'web') {
293: my $args='';
294: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
295: if ($args eq '') {
296: &Apache::lonxml::get_all_text("/meta",$$parser[$#$parser]);
297: } else {
298: $currentstring = $token->[4];
299: }
300: }
301: if ($target eq 'meta') {
302: unless ($token->[2]->{'http-equiv'}) {
303: my $name=$token->[2]->{'name'};
304: $name=~tr/A-Z/a-z/;
305: $name=~s/\s/\_/g;
306: if ($name) {
307: $currentstring='<'.$name.'>'.
308: $token->[2]->{'content'}.
309: '</'.$name.'>';
310: }
311: }
312: }
313: return $currentstring;
314: }
315: sub end_meta {
316: my ($target,$token,$tagstack,$parstack,$parser) = @_;
317: my $currentstring = '';
318: if ($target eq 'web') {
319: my $args='';
320: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
321: if ($args ne '') {
322: $currentstring = $token->[4];
323: }
324: }
325: return $currentstring;
326: }
327: #-- <body> tag
328: sub start_body {
329: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
330: # my ($target,$token) = @_;
331: my $currentstring = '';
332: if ($target eq 'web') {
333: if (!$Apache::lonxml::registered) {
334: $currentstring.='<head>'.
335: &Apache::lonxml::registerurl(undef,$target).'</head>';
336: }
337: my $onLoad='';
338: foreach my $key (keys(%{$token->[2]})) {
339: if ($key =~ /^onload$/i) {
340: $onLoad.=$token->[2]->{$key}.';';
341: delete($token->[2]->{$key});
342: }
343: }
344: $token->[2]->{'onLoad'}=&Apache::lonxml::loadevents().
345: ';'.$onLoad;
346: my $onUnload='';
347: foreach my $key (keys(%{$token->[2]})) {
348: if ($key =~ /^onunload$/i) {
349: $onUnload.=$token->[2]->{$key}.';';
350: delete($token->[2]->{$key});
351: }
352: }
353: $token->[2]->{'onUnload'}=&Apache::lonxml::unloadevents().
354: ';'.$onUnload;
355:
356: $currentstring .= '<'.$token->[1];
357: foreach (keys %{$token->[2]}) {
358: $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
359: }
360: $currentstring.='>';
361: if ($ENV{'request.state'} ne 'published') {
362: $currentstring.=(<<EDITBUTTON);
363: <form method="post">
364: <input type="submit" name="editmode" value="Edit" />
365: </form>
366: EDITBUTTON
367: }
368: } elsif ($target eq 'tex') {
369: $currentstring = '\begin{document}';
370: }
371: return $currentstring;
372: }
373: sub end_body {
374: my ($target,$token) = @_;
375: my $currentstring = '';
376: if ($target eq 'web') {
377: $currentstring = $token->[2];
378: } elsif ($target eq 'tex') {
379: $currentstring = '\end{document}';
380: }
381: return $currentstring;
382: }
383: #-- <center> tag
384: sub start_center {
385: my ($target,$token) = @_;
386: my $currentstring = '';
387: if ($target eq 'web') {
388: $currentstring = $token->[4];
389: } elsif ($target eq 'tex') {
390: $currentstring = '\begin{center}';
391: } elsif ($target eq 'latexsource') {
392: $currentstring = '\begin{center}';
393: }
394: return $currentstring;
395: }
396: sub end_center {
397: my ($target,$token) = @_;
398: my $currentstring = '';
399: if ($target eq 'web') {
400: $currentstring = $token->[2];
401: } elsif ($target eq 'tex') {
402: $currentstring = '\end{center}';
403: } elsif ($target eq 'latexsource') {
404: $currentstring = '\end{center}';
405: }
406: return $currentstring;
407: }
408: #-- <b> tag
409: sub start_b {
410: my ($target,$token) = @_;
411: my $currentstring = '';
412: if ($target eq 'web') {
413: $currentstring = $token->[4];
414: } elsif ($target eq 'tex') {
415: $currentstring = '\textbf{';
416: } elsif ($target eq 'latexsource') {
417: $currentstring = '\textbf{';
418: }
419: return $currentstring;
420: }
421: sub end_b {
422: my ($target,$token) = @_;
423: my $currentstring = '';
424: if ($target eq 'web') {
425: $currentstring = $token->[2];
426: } elsif ($target eq 'tex') {
427: $currentstring = '}';
428:
429: } elsif ($target eq 'latexsource') {
430: $currentstring = '}';
431: }
432: return $currentstring;
433: }
434: #-- <strong> tag
435: sub start_strong {
436: my ($target,$token) = @_;
437: my $currentstring = '';
438: if ($target eq 'web') {
439: $currentstring = $token->[4];
440: } elsif ($target eq 'tex') {
441: $currentstring = '\textbf{';
442: } elsif ($target eq 'latexsource') {
443: $currentstring = '\textbf{';
444: }
445: return $currentstring;
446: }
447: sub end_strong {
448: my ($target,$token) = @_;
449: my $currentstring = '';
450: if ($target eq 'web') {
451:
452: $currentstring = $token->[2];
453: } elsif ($target eq 'tex') {
454: $currentstring = '}';
455: } elsif ($target eq 'latexsource') {
456: $currentstring = '}';
457: }
458: return $currentstring;
459: }
460: #-- <h1> tag
461: sub start_h1 {
462: my ($target,$token) = @_;
463: my $currentstring = '';
464: if ($target eq 'web') {
465: $currentstring .= $token->[4];
466: } elsif ($target eq 'tex') {
467: $currentstring .= '\large{\textbf{';
468: } elsif ($target eq 'meta') {
469: $currentstring='<subject>';
470: &start_output();
471: }
472: return $currentstring;
473: }
474: sub end_h1 {
475: my ($target,$token) = @_;
476: my $currentstring = '';
477: if ($target eq 'web') {
478: $currentstring .= $token->[2];
479: } elsif ($target eq 'tex') {
480: $currentstring .= '}}';
481: } elsif ($target eq 'meta') {
482: &end_output();
483: $currentstring='</subject>';
484: }
485: return $currentstring;
486: }
487: #-- <h2> tag
488: sub start_h2 {
489: my ($target,$token) = @_;
490: my $currentstring = '';
491: if ($target eq 'web') {
492: $currentstring .= $token->[4];
493: } elsif ($target eq 'tex') {
494: $currentstring .= '\large{\textbf{';
495: }
496: return $currentstring;
497: }
498: sub end_h2 {
499: my ($target,$token) = @_;
500: my $currentstring = '';
501: if ($target eq 'web') {
502: $currentstring .= $token->[2];
503: } elsif ($target eq 'tex') {
504: $currentstring .= '}}';
505: }
506: return $currentstring;
507: }
508: #-- <h3> tag
509: sub start_h3 {
510: my ($target,$token) = @_;
511: my $currentstring = '';
512: if ($target eq 'web') {
513: $currentstring .= $token->[4];
514: } elsif ($target eq 'tex') {
515: $currentstring .= '\large{\textbf{';
516: }
517: return $currentstring;
518: }
519: sub end_h3 {
520: my ($target,$token) = @_;
521: my $currentstring = '';
522: if ($target eq 'web') {
523: $currentstring .= $token->[2];
524: } elsif ($target eq 'tex') {
525: $currentstring .= '}}';
526: }
527: return $currentstring;
528: }
529: #-- <h4> tag
530: sub start_h4 {
531: my ($target,$token) = @_;
532: my $currentstring = '';
533: if ($target eq 'web') {
534: $currentstring .= $token->[4];
535: } elsif ($target eq 'tex') {
536: $currentstring .= '\large{\textbf{';
537: }
538: return $currentstring;
539: }
540: sub end_h4 {
541: my ($target,$token) = @_;
542: my $currentstring = '';
543: if ($target eq 'web') {
544: $currentstring .= $token->[2];
545: } elsif ($target eq 'tex') {
546: $currentstring .= '}}';
547: }
548: return $currentstring;
549: }
550: #-- <h5> tag
551: sub start_h5 {
552: my ($target,$token) = @_;
553: my $currentstring = '';
554: if ($target eq 'web') {
555: $currentstring .= $token->[4];
556: } elsif ($target eq 'tex') {
557: $currentstring .= '\large{\textbf{';
558: }
559: return $currentstring;
560: }
561: sub end_h5 {
562: my ($target,$token) = @_;
563: my $currentstring = '';
564: if ($target eq 'web') {
565: $currentstring .= $token->[2];
566: } elsif ($target eq 'tex') {
567: $currentstring .= '}}';
568: }
569: return $currentstring;
570: }
571: #-- <h6> tag
572: sub start_h6 {
573: my ($target,$token) = @_;
574: my $currentstring = '';
575: if ($target eq 'web') {
576: $currentstring .= $token->[4];
577: } elsif ($target eq 'tex') {
578: $currentstring .= '\large{\textbf{';
579: }
580: return $currentstring;
581: }
582: sub end_h6 {
583: my ($target,$token) = @_;
584: my $currentstring = '';
585: if ($target eq 'web') {
586: $currentstring .= $token->[2];
587: } elsif ($target eq 'tex') {
588: $currentstring .= '}}';
589: }
590: return $currentstring;
591: }
592: #--- <cite> tag
593: sub start_cite {
594: my ($target,$token) = @_;
595: my $currentstring = '';
596: if ($target eq 'web') {
597: $currentstring .= $token->[4];
598: } elsif ($target eq 'tex') {
599: $currentstring .= "\\textit{";
600: } elsif ($target eq 'latexsource') {
601: $currentstring .= "\\textit{";
602: }
603: return $currentstring;
604: }
605: sub end_cite {
606: my ($target,$token) = @_;
607: my $currentstring = '';
608: if ($target eq 'web') {
609: $currentstring .= $token->[2];
610: } elsif ($target eq 'tex') {
611: $currentstring .= "}";
612: } elsif ($target eq 'latexsource') {
613: $currentstring .= "}";
614: }
615: return $currentstring;
616: }
617: #-- <i> tag
618: sub start_i {
619: my ($target,$token) = @_;
620: my $currentstring = '';
621: if ($target eq 'web') {
622: $currentstring .= $token->[4];
623: } elsif ($target eq 'tex') {
624: $currentstring .= '\textit{';
625: } elsif ($target eq 'latexsource') {
626: $currentstring .= '\textit{';
627: }
628: return $currentstring;
629: }
630: sub end_i {
631: my ($target,$token) = @_;
632: my $currentstring = '';
633: if ($target eq 'web') {
634: $currentstring .= $token->[2];
635: } elsif ($target eq 'tex') {
636: $currentstring .= '}';
637: } elsif ($target eq 'latexsource') {
638: $currentstring .= '}';
639: }
640: return $currentstring;
641: }
642: #-- <address> tag
643: sub start_address {
644: my ($target,$token) = @_;
645: my $currentstring = '';
646: if ($target eq 'web') {
647: $currentstring .= $token->[4];
648: } elsif ($target eq 'tex') {
649: $currentstring .= "\\textit{";
650: } elsif ($target eq 'latexsource') {
651: $currentstring .= "\\textit{";
652: }
653: return $currentstring;
654: }
655: sub end_address {
656: my ($target,$token) = @_;
657: my $currentstring = '';
658: if ($target eq 'web') {
659: $currentstring .= $token->[2];
660: } elsif ($target eq 'tex') {
661: $currentstring .= "}";
662: } elsif ($target eq 'latexsource') {
663: $currentstring .= "}";
664: }
665: return $currentstring;
666: }
667: #-- <dfn> tag
668: sub start_dfn {
669: my ($target,$token) = @_;
670: my $currentstring = '';
671: if ($target eq 'web') {
672: $currentstring .= $token->[4];
673: } elsif ($target eq 'tex') {
674: $currentstring .= "\\textit{";
675: } elsif ($target eq 'latexsource') {
676: $currentstring .= "\\textit{";
677: }
678: return $currentstring;
679: }
680: sub end_dfn {
681: my ($target,$token) = @_;
682: my $currentstring = '';
683: if ($target eq 'web') {
684: $currentstring .= $token->[2];
685: } elsif ($target eq 'tex') {
686: $currentstring .= "}";
687: } elsif ($target eq 'latexsource') {
688: $currentstring .= "}";
689: }
690: return $currentstring;
691: }
692: #-- <tt> tag
693: sub start_tt {
694: my ($target,$token) = @_;
695: my $currentstring = '';
696: if ($target eq 'web') {
697: $currentstring .= $token->[4];
698: } elsif ($target eq 'tex') {
699: $currentstring .= '\texttt{';
700: } elsif ($target eq 'latexsource') {
701: $currentstring .= '\texttt{';
702: }
703: return $currentstring;
704: }
705: sub end_tt {
706: my ($target,$token) = @_;
707: my $currentstring = '';
708: if ($target eq 'web') {
709: $currentstring .= $token->[2];
710: } elsif ($target eq 'tex') {
711: $currentstring .= '}';
712: } elsif ($target eq 'latexsource') {
713: $currentstring .= '}';
714: }
715: return $currentstring;
716: }
717: #-- <kbd> tag
718: sub start_kbd {
719: my ($target,$token) = @_;
720: my $currentstring = '';
721: if ($target eq 'web') {
722: $currentstring .= $token->[4];
723: } elsif ($target eq 'tex') {
724: $currentstring .= "\\texttt";
725: } elsif ($target eq 'latexsource') {
726: $currentstring .= "\\texttt{";
727: }
728: return $currentstring;
729: }
730: sub end_kbd {
731: my ($target,$token) = @_;
732: my $currentstring = '';
733: if ($target eq 'web') {
734: $currentstring .= $token->[2];
735: } elsif ($target eq 'tex') {
736: $currentstring .= "}";
737: } elsif ($target eq 'latexsource') {
738: $currentstring .= "}";
739: }
740: return $currentstring;
741: }
742: #-- <code> tag
743: sub start_code {
744: my ($target,$token) = @_;
745: my $currentstring = '';
746: if ($target eq 'web') {
747: $currentstring .= $token->[4];
748: } elsif ($target eq 'tex') {
749: $currentstring .= '\texttt{';
750: }
751: return $currentstring;
752: }
753: sub end_code {
754: my ($target,$token) = @_;
755: my $currentstring = '';
756: if ($target eq 'web') {
757: $currentstring .= $token->[2];
758: } elsif ($target eq 'tex') {
759: $currentstring .= '}';
760: }
761: return $currentstring;
762: }
763: #-- <em> tag
764: sub start_em {
765: my ($target,$token) = @_;
766: my $currentstring = '';
767: if ($target eq 'web') {
768: $currentstring .= $token->[4];
769: } elsif ($target eq 'tex') {
770: $currentstring .= '\emph{';
771: } elsif ($target eq 'latexsource') {
772: $currentstring .= '\emph{';
773: }
774: return $currentstring;
775: }
776: sub end_em {
777: my ($target,$token) = @_;
778: my $currentstring = '';
779: if ($target eq 'web') {
780: $currentstring .= $token->[2];
781: } elsif ($target eq 'tex') {
782: $currentstring .= '}';
783: } elsif ($target eq 'latexsource') {
784: $currentstring .= '}';
785: }
786: return $currentstring;
787: }
788: #-- <q> tag
789: sub start_q {
790: my ($target,$token) = @_;
791: my $currentstring = '';
792: if ($target eq 'web') {
793: $currentstring .= $token->[4];
794: } elsif ($target eq 'tex') {
795: $currentstring .= "\\emph{";
796: } elsif ($target eq 'latexsource') {
797: $currentstring .= "\\emph{";
798: }
799: return $currentstring;
800: }
801: sub end_q {
802: my ($target,$token) = @_;
803: my $currentstring = '';
804: if ($target eq 'web') {
805: $currentstring .= $token->[2];
806: } elsif ($target eq 'tex') {
807: $currentstring .= "}";
808: } elsif ($target eq 'latexsource') {
809: $currentstring .= "}";
810: }
811: return $currentstring;
812: }
813: #-- <p> tag
814: sub start_p {
815: my ($target,$token) = @_;
816: my $currentstring = '';
817: if ($target eq 'web') {
818: $currentstring .= $token->[4];
819: } elsif ($target eq 'tex') {
820: $currentstring .= '{\par ';
821: } elsif ($target eq 'latexsource') {
822: $currentstring .= '{\par ';
823: }
824: return $currentstring;
825: }
826: sub end_p {
827: my ($target,$token) = @_;
828: my $currentstring = '';
829: if ($target eq 'web') {
830: $currentstring .= $token->[2];
831: } elsif ($target eq 'tex') {
832: $currentstring .= '}';
833: } elsif ($target eq 'latexsource') {
834: $currentstring .= '}';
835: }
836: return $currentstring;
837: }
838: #-- <br> tag
839: sub start_br {
840: my ($target,$token) = @_;
841: my $currentstring = '';
842: if ($target eq 'web') {
843: $currentstring .= $token->[4];
844: } elsif ($target eq 'tex') {
845: $currentstring .= '\vskip 0 mm';
846: } elsif ($target eq 'latexsource') {
847: $currentstring .= '\\';
848: }
849: return $currentstring;
850: }
851: sub end_br {
852: my ($target,$token) = @_;
853: my $currentstring = '';
854: if ($target eq 'web') {
855: $currentstring .= $token->[2];
856: }
857: return $currentstring;
858: }
859: #-- <big> tag
860: sub start_big {
861: my ($target,$token) = @_;
862: my $currentstring = '';
863: if ($target eq 'web') {
864: $currentstring .= $token->[4];
865: } elsif ($target eq 'tex') {
866: $currentstring .= '\large{';
867: } elsif ($target eq 'latexsource') {
868: $currentstring .= '{\Large ';
869: }
870: return $currentstring;
871: }
872: sub end_big {
873: my ($target,$token) = @_;
874: my $currentstring = '';
875: if ($target eq 'web') {
876: $currentstring .= $token->[2];
877: } elsif ($target eq 'tex') {
878: $currentstring .= '}';
879: } elsif ($target eq 'latexsource') {
880: $currentstring .= '}';
881: }
882: return $currentstring;
883: }
884: #-- <small> tag
885: sub start_small {
886: my ($target,$token) = @_;
887: my $currentstring = '';
888: if ($target eq 'web') {
889: $currentstring .= $token->[4];
890: } elsif ($target eq 'tex') {
891: $currentstring .= '{\footnotesize ';
892: } elsif ($target eq 'latexsource') {
893: $currentstring .= '{\footnotesize ';
894: }
895: return $currentstring;
896: }
897: sub end_small {
898: my ($target,$token) = @_;
899: my $currentstring = '';
900: if ($target eq 'web') {
901: $currentstring .= $token->[2];
902: } elsif ($target eq 'tex') {
903: $currentstring .= '}';
904: } elsif ($target eq 'latexsource') {
905: $currentstring .= '}';
906: }
907: return $currentstring;
908: }
909: #-- <basefont> tag
910: sub start_basefont {
911: my ($target,$token) = @_;
912: my $currentstring = '';
913: if ($target eq 'web') {
914: $currentstring = $token->[4];
915: }
916: return $currentstring;
917: }
918: sub end_basefont {
919: my ($target,$token) = @_;
920: my $currentstring = '';
921: if ($target eq 'web') {
922: $currentstring = $token->[4];
923: }
924: return $currentstring;
925: }
926: #-- <font> tag
927: sub start_font {
928: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
929: my $currentstring = '';
930: if ($target eq 'web') {
931: my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
932: if ($face=~/symbol/i) {$Apache::lonxml::prevent_entity_encode++;}
933: $currentstring = $token->[4];
934: }
935: return $currentstring;
936: }
937: sub end_font {
938: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
939: my $currentstring = '';
940: if ($target eq 'web') {
941: my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
942: if ($face=~/symbol/i) {$Apache::lonxml::prevent_entity_encode--;}
943: $currentstring = $token->[2];
944: }
945: return $currentstring;
946: }
947: #-- <strike> tag
948: sub start_strike {
949: my ($target,$token) = @_;
950: my $currentstring = '';
951: if ($target eq 'web') {
952: $currentstring .= $token->[4];
953: } elsif ($target eq 'tex') {
954: $currentstring .= "{\\underline ";
955: }
956: return $currentstring;
957: }
958: sub end_strike {
959: my ($target,$token) = @_;
960: my $currentstring = '';
961: if ($target eq 'web') {
962: $currentstring .= $token->[2];
963: } elsif ($target eq 'tex') {
964: $currentstring .= " }";
965: }
966: return $currentstring;
967: }
968: #-- <s> tag
969: sub start_s {
970: my ($target,$token) = @_;
971: my $currentstring = '';
972: if ($target eq 'web') {
973: $currentstring .= $token->[4];
974: } elsif ($target eq 'tex') {
975: $currentstring .= "{\\underline ";
976: }
977: return $currentstring;
978: }
979: sub end_s {
980: my ($target,$token) = @_;
981: my $currentstring = '';
982: if ($target eq 'web') {
983: $currentstring .= $token->[2];
984: } elsif ($target eq 'tex') {
985: $currentstring .= " }";
986: }
987: return $currentstring;
988: }
989: #-- <sub> tag
990: sub start_sub {
991: my ($target,$token) = @_;
992: my $currentstring = '';
993: if ($target eq 'web') {
994: $currentstring .= $token->[4];
995: } elsif ($target eq 'tex') {
996: $currentstring .= "\$_{ ";
997: }
998: return $currentstring;
999: }
1000: sub end_sub {
1001: my ($target,$token) = @_;
1002: my $currentstring = '';
1003: if ($target eq 'web') {
1004: $currentstring .= $token->[2];
1005: } elsif ($target eq 'tex') {
1006: $currentstring .= " }\$";
1007: }
1008: return $currentstring;
1009: }
1010: #-- <sup> tag
1011: sub start_sup {
1012: my ($target,$token) = @_;
1013: my $currentstring = '';
1014: if ($target eq 'web') {
1015: $currentstring .= $token->[4];
1016: } elsif ($target eq 'tex') {
1017: $currentstring .= "\$^{ ";
1018: }
1019: return $currentstring;
1020: }
1021: sub end_sup {
1022: my ($target,$token) = @_;
1023: my $currentstring = '';
1024: if ($target eq 'web') {
1025: $currentstring .= $token->[2];
1026: } elsif ($target eq 'tex') {
1027: $currentstring .= " }\$";
1028: }
1029: return $currentstring;
1030: }
1031: #-- <hr> tag
1032: sub start_hr {
1033: my ($target,$token) = @_;
1034: my $currentstring = '';
1035: if ($target eq 'web') {
1036: $currentstring .= $token->[4];
1037: } elsif ($target eq 'tex') {
1038: $currentstring .= "\\hline ";
1039: }
1040: return $currentstring;
1041: }
1042: sub end_hr {
1043: my ($target,$token) = @_;
1044: my $currentstring = '';
1045: if ($target eq 'web') {
1046: $currentstring .= $token->[2];
1047: } elsif ($target eq 'tex') {
1048: }
1049: return $currentstring;
1050: }
1051: #-- <a> tag
1052: sub start_a {
1053: my ($target,$token) = @_;
1054: my $currentstring = '';
1055: if ($target eq 'web') {
1056: $currentstring .= $token->[4];
1057: } elsif ($target eq 'tex') {
1058: }
1059: return $currentstring;
1060: }
1061: sub end_a {
1062: my ($target,$token,$tagstack,$stackref) = @_;
1063: my $currentstring = '';
1064: if ($target eq 'web') {
1065: $currentstring .= $token->[2];
1066: } elsif ($target eq 'tex') {
1067: my $tempor_var = $stackref->[$#$stackref];
1068: if (index($tempor_var,'name') != -1 ) {
1069: $tempor_var =~ s/name=([^,]*),/$1/g;
1070: # $currentstring .= " \\label{$tempor_var}";
1071: } elsif (index($tempor_var,'href') != -1 ) {
1072: $tempor_var =~ s/href=([^,]*),/$1/g;
1073: $currentstring .= " \\ref{$tempor_var}";
1074: }
1075: }
1076: return $currentstring;
1077: }
1078: #-- <li> tag
1079: sub start_li {
1080: my ($target,$token,$tagstack,$stackref) = @_;
1081: my $currentstring = '';
1082: if ($target eq 'web') {
1083: $currentstring = $token->[4];
1084: } elsif ($target eq 'tex') {
1085: my $tempor_var = $stackref->[$#$stackref];
1086: if (index($tempor_var,'circle') != -1 ) {
1087: $currentstring .= " \\item[o] ";
1088: } elsif (index($tempor_var,'square') != -1 ) {
1089: $currentstring .= " \\item[$\Box$] ";
1090: } elsif ($tempor_var ne '') {
1091: $_ = $tempor_var;
1092: m/my\s*([^=]*)=/;
1093: $currentstring .= " \\item[$1] ";
1094: } else {
1095: $currentstring .= " \\item ";
1096: }
1097: }
1098: return $currentstring;
1099: }
1100: sub end_li {
1101: my ($target,$token) = @_;
1102: my $currentstring = '';
1103: if ($target eq 'web') {
1104: $currentstring = $token->[2];
1105: }
1106: return $currentstring;
1107: }
1108: #-- <u> tag
1109: sub start_u {
1110: my ($target,$token) = @_;
1111: my $currentstring = '';
1112: if ($target eq 'web') {
1113: $currentstring .= $token->[4];
1114: } elsif ($target eq 'tex') {
1115: $currentstring .= "{\\underline ";
1116: }
1117: return $currentstring;
1118: }
1119: sub end_u {
1120: my ($target,$token) = @_;
1121: my $currentstring = '';
1122: if ($target eq 'web') {
1123: $currentstring .= $token->[2];
1124: } elsif ($target eq 'tex') {
1125: $currentstring .= " }";
1126: }
1127: return $currentstring;
1128: }
1129: #-- <ul> tag
1130: sub start_ul {
1131: my ($target,$token) = @_;
1132: my $currentstring = '';
1133: if ($target eq 'web') {
1134: $currentstring = $token->[4];
1135: } elsif ($target eq 'tex') {
1136: $currentstring = '\begin{itemize}';
1137: }
1138: return $currentstring;
1139: }
1140: sub end_ul {
1141: my ($target,$token) = @_;
1142: my $currentstring = '';
1143: if ($target eq 'web') {
1144: $currentstring = $token->[2];
1145: } elsif ($target eq 'tex') {
1146: $currentstring = '\end{itemize}';
1147: }
1148: return $currentstring;
1149: }
1150: #-- <menu> tag
1151: sub start_menu {
1152: my ($target,$token) = @_;
1153: my $currentstring = '';
1154: if ($target eq 'web') {
1155: $currentstring = $token->[4];
1156: } elsif ($target eq 'tex') {
1157: $currentstring = " \\begin{itemize} ";
1158: }
1159: return $currentstring;
1160: }
1161: sub end_menu {
1162: my ($target,$token) = @_;
1163: my $currentstring = '';
1164: if ($target eq 'web') {
1165: $currentstring = $token->[2];
1166: } elsif ($target eq 'tex') {
1167: $currentstring = " \\end{itemize}";
1168: }
1169: return $currentstring;
1170: }
1171: #-- <dir> tag
1172: sub start_dir {
1173: my ($target,$token) = @_;
1174: my $currentstring = '';
1175: if ($target eq 'web') {
1176: $currentstring = $token->[4];
1177: } elsif ($target eq 'tex') {
1178: $currentstring = " \\begin{itemize} ";
1179: }
1180: return $currentstring;
1181: }
1182: sub end_dir {
1183: my ($target,$token) = @_;
1184: my $currentstring = '';
1185: if ($target eq 'web') {
1186: $currentstring = $token->[2];
1187: } elsif ($target eq 'tex') {
1188: $currentstring = " \\end{itemize}";
1189: }
1190: return $currentstring;
1191: }
1192: #-- <ol> tag
1193: sub start_ol {
1194: my ($target,$token) = @_;
1195: my $currentstring = '';
1196: if ($target eq 'web') {
1197: $currentstring = $token->[4];
1198: } elsif ($target eq 'tex') {
1199: $currentstring = '\begin{enumerate}';
1200: }
1201: return $currentstring;
1202: }
1203: sub end_ol {
1204: my ($target,$token) = @_;
1205: my $currentstring = '';
1206: if ($target eq 'web') {
1207: $currentstring = $token->[2];
1208: } elsif ($target eq 'tex') {
1209: $currentstring = '\end{enumerate}';
1210: }
1211: return $currentstring;
1212: }
1213: #-- <dl> tag
1214: sub start_dl {
1215: my ($target,$token) = @_;
1216: my $currentstring = '';
1217: if ($target eq 'web') {
1218: $currentstring = $token->[4];
1219: } elsif ($target eq 'tex') {
1220: $currentstring = '\begin{description}';
1221: }
1222: return $currentstring;
1223: }
1224: sub end_dl {
1225: my ($target,$token) = @_;
1226: my $currentstring = '';
1227: if ($target eq 'web') {
1228: $currentstring = $token->[2];
1229: } elsif ($target eq 'tex') {
1230: $currentstring = '\end{description}';
1231: }
1232: return $currentstring;
1233: }
1234: #-- <dt> tag
1235: sub start_dt {
1236: my ($target,$token) = @_;
1237: my $currentstring = '';
1238: if ($target eq 'web') {
1239: $currentstring = $token->[4];
1240: } elsif ($target eq 'tex') {
1241: $currentstring = '\item[';
1242: }
1243: return $currentstring;
1244: }
1245: sub end_dt {
1246: my ($target,$token) = @_;
1247: my $currentstring = '';
1248: if ($target eq 'web') {
1249: $currentstring = $token->[2];
1250: } elsif ($target eq 'tex') {
1251: $currentstring = ']';
1252: }
1253: return $currentstring;
1254: }
1255: #-- <dd> tag
1256: sub start_dd {
1257: my ($target,$token) = @_;
1258: my $currentstring = '';
1259: if ($target eq 'web') {
1260: $currentstring = $token->[4];
1261: }
1262: return $currentstring;
1263: }
1264: sub end_dd {
1265: my ($target,$token) = @_;
1266: my $currentstring = '';
1267: if ($target eq 'web') {
1268: $currentstring = $token->[2];
1269: }
1270: return $currentstring;
1271: }
1272: #-- <table> tag
1273: sub start_table {
1274: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1275: my $currentstring = '';
1276: if ($target eq 'web') {
1277: $currentstring = $token->[4];
1278: } elsif ($target eq 'tex') {
1279: my $aa = {};
1280: push @Apache::londefdef::table, $aa;
1281: $Apache::londefdef::table[-1]{'row_number'} = -1;
1282: $Apache::londefdef::table[-1]{'output'} = '\begin{tabular} ';
1283: my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval);
1284: unless (defined $border) { $border = 0; }
1285: if ($border) {
1286: $Apache::londefdef::table[-1]{'hinc'} = '\hline ';
1287: $Apache::londefdef::table[-1]{'vinc'} = '&';
1288: $Apache::londefdef::table[-1]{'vvinc'} = '|';
1289: } else {
1290: $Apache::londefdef::table[-1]{'hinc'} = '';
1291: $Apache::londefdef::table[-1]{'vinc'} = '&';
1292: $Apache::londefdef::table[-1]{'vvinc'} = '';
1293: }
1294: }
1295: return $currentstring;
1296: }
1297: sub end_table {
1298: my ($target,$token) = @_;
1299: my $currentstring = '';
1300: if ($target eq 'web') {
1301: $currentstring = $token->[2];
1302: } elsif ($target eq 'tex') {
1303: my $inmemory = '';
1304: my $output = '';
1305: my $header_of_table = '{'.$Apache::londefdef::table[-1]{'vvinc'};
1306: my $in;
1307: for ($in=0;$in<=$Apache::londefdef::table[-1]{'counter_columns'};$in++) {
1308: $header_of_table .= $Apache::londefdef::table[-1]{'columns'}[$in].$Apache::londefdef::table[-1]{'vvinc'};
1309: }
1310: $header_of_table .= '}';
1311: for ($in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1312: $output .= $Apache::londefdef::table[-1]{'rowdata'}[$in];
1313: chop $output;
1314: $output .= ' \\\\ ';
1315: }
1316: my @length = split(/,/,$Apache::londefdef::table[-1]{'length'});
1317: my $how_many_columns = $#length+1;
1318: my $parboxlength = '(\textwidth';
1319: for (my $io=0; $io<=$#length;$io++) {
1320: if ($length[$io] ne '') {
1321: $parboxlength .= ' - '.$length[$io].' ';
1322: }
1323: }
1324: $parboxlength .= ')/'.$how_many_columns.' - 7 mm';
1325: $output =~ s/\\parbox{}/\\parbox{$parboxlength}/g;
1326: $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$output.$Apache::londefdef::table[-1]{'hinc'}.'\end{tabular}\vskip 0 mm ';
1327: if ($#Apache::londefdef::table > 0) {
1328: $inmemory = $Apache::londefdef::table[-1]{'output'};
1329: pop @Apache::londefdef::table;
1330: $Apache::londefdef::table[-1]{'rowdata'}[$Apache::londefdef::table[-1]{'row_number'}] .= $inmemory;
1331: } else {
1332: $currentstring = $Apache::londefdef::table[-1]{'output'};
1333: $currentstring =~ s/\\\\\s+\\\\/\\\\/g;
1334: pop @Apache::londefdef::table;
1335: }
1336: }
1337: return $currentstring;
1338: }
1339: #-- <tr> tag
1340: sub start_tr {
1341: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1342: my $currentstring = '';
1343: if ($target eq 'web') {
1344: $currentstring = $token->[4];
1345: } elsif ($target eq 'tex') {
1346: $Apache::londefdef::table[-1]{'row_number'}++;
1347: my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval),0,1);
1348: if ($alignchar ne '') {
1349: push @ {$Apache::londefdef::table[-1]{'rows'} }, $alignchar;
1350: } else {
1351: push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l';
1352: }
1353: push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'});
1354: $Apache::londefdef::table[-1]{'counter_columns'} = -1;
1355: $Apache::londefdef::table[-1]{'length'} = ''; #just added
1356:
1357: }
1358: return $currentstring;
1359: }
1360: sub end_tr {
1361: my ($target,$token) = @_;
1362: my $currentstring = '';
1363: if ($target eq 'web') {
1364: $currentstring = $token->[2];
1365: } elsif ($target eq 'tex') {
1366: # $currentstring .= ' START ROW '. $Apache::londefdef::table[-1]{'rowdata'}[$Apache::londefdef::table[-1]{'row_number'}].' END ROW ';
1367: }
1368: return $currentstring;
1369: }
1370: #-- <td> tag
1371: sub start_td {
1372: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1373: my $currentstring = '';
1374: if ($target eq 'web') {
1375: $currentstring = $token->[4];
1376: } elsif ($target eq 'tex') {
1377: my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval),0,1);
1378: if ($what_to_push eq '') {
1379: $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);;
1380: }
1381: push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push;
1382: $Apache::londefdef::table[-1]{'counter_columns'}++;
1383: &Apache::lonxml::startredirection();
1384: ;
1385: }
1386: return $currentstring;
1387: }
1388: sub end_td {
1389: my ($target,$token) = @_;
1390: my $currentstring = '';
1391: if ($target eq 'web') {
1392: $currentstring = $token->[2];
1393: } elsif ($target eq 'tex') {
1394: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
1395: my $data=&Apache::lonxml::endredirection();
1396: if ($data=~m/width\s*=\s*(\d+\.*\d*\s*(mm|cm))/) { #just added
1397: $Apache::londefdef::table[-1]{'length'} .= $1.','; #just added
1398: } #just added
1399: @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{'.$1.'}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'};
1400: }
1401: return $currentstring;
1402: }
1403: #-- <th> tag
1404: sub start_th {
1405: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1406: my $currentstring = '';
1407: if ($target eq 'web') {
1408: $currentstring = $token->[4];
1409: } elsif ($target eq 'tex') {
1410: my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval),0,1);
1411: if ($what_to_push eq '') {
1412: $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);;
1413: }
1414: push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push;
1415: $Apache::londefdef::table[-1]{'counter_columns'}++;
1416: &Apache::lonxml::startredirection();
1417: ;
1418: }
1419: return $currentstring;
1420: }
1421: sub end_th {
1422: my ($target,$token) = @_;
1423: my $currentstring = '';
1424: if ($target eq 'web') {
1425: $currentstring = $token->[2];
1426: } elsif ($target eq 'tex') {
1427: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
1428: my $data=&Apache::lonxml::endredirection();
1429: if ($data=~m/width\s*=\s*(\d+\.*\d*\s*(mm|cm))/) { #just added
1430: $Apache::londefdef::table[-1]{'length'} .= $1.','; #just added
1431: } #just added
1432: @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{'.$1.'}{\textbf{'.$data.'}} '.$Apache::londefdef::table[-1]{'vinc'};
1433: }
1434: return $currentstring;
1435: }
1436: #-- <img> tag
1437: sub start_img {
1438: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1439: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
1440: $token->[2]->{'src'};
1441: my $currentstring = '';
1442: my $width_param = '';
1443: my $height_param = '';
1444: my $scaling = .3;
1445:
1446: if ($target eq 'web') {
1447: $currentstring = $token->[4];
1448: } elsif ($target eq 'tex') {
1449: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval);
1450: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
1451: my $image = Image::Magick->new;
1452: my $current_figure = $image->Read($src);
1453: $width_param = $image->Get('width') * $scaling;;
1454: $height_param = $image->Get('height') * $scaling;;
1455: undef $image;
1456: my $epssrc = $src;
1457: $epssrc =~ s/(\.gif|\.jpg)$/\.eps/i;
1458: if (not -e $epssrc) {
1459: my $localfile = $epssrc;
1460: $localfile =~ s/.*(\/res)/$1/;
1461: my $file;
1462: my $path;
1463: if ($localfile =~ m!(.*)/([^/]*)$!) {
1464: $file = $2;
1465: $path = $1.'/';
1466: }
1467: my $signal_eps = 0;
1468: my @content_directory = &Apache::lonnet::dirlist($path);
1469: for (my $iy=0;$iy<=$#content_directory;$iy++) {
1470: my @tempo_array = split(/&/,$content_directory[$iy]);
1471: $content_directory[$iy] = $tempo_array[0];
1472: if ($file eq $tempo_array[0]) {
1473: $signal_eps = 1;
1474: last;
1475: }
1476: }
1477: if ($signal_eps) {
1478: my $eps_file = &Apache::lonnet::getfile($localfile);
1479: } else {
1480: $localfile = $src;
1481: $localfile =~ s/.*(\/res)/$1/;
1482: my $as = &Apache::lonnet::getfile($src);
1483: }
1484: }
1485: my $file;
1486: my $path;
1487: if ($src =~ m!(.*)/([^/]*)$!) {
1488: $file = $2;
1489: $path = $1.'/';
1490: }
1491: my $newsrc = $src;
1492: $newsrc =~ s/(\.gif|\.jpg)$/\.eps/i;
1493: $file=~s/(\.gif|\.jpg)$/\.eps/i;
1494: #do we have any specified size of the picture?
1495: my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval);
1496: my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval);
1497: my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval);
1498: if ($TeXwidth ne '') {
1499: $width_param = $TeXwidth;
1500: } elsif ($TeXheight ne '') {
1501: $width_param = $TeXheight/$height_param*$width_param;
1502: } elsif ($width ne '') {
1503: $width_param = $width*$scaling;
1504: }
1505: #where can we find the picture?
1506: if (-e $newsrc) {
1507: if ($path) {
1508: $currentstring .= '\noindent\graphicspath{{'.$path.'}}\fbox{\includegraphics[width='.$width_param.' mm]{'.$file.'}} ';
1509: }
1510: } else {
1511: my $temp_file;
1512: my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat";
1513: $temp_file = Apache::File->new('>>'.$filename);
1514: print $temp_file "$src\n";
1515: $currentstring .= '\graphicspath{{/home/httpd/prtspool/}}\fbox{\includegraphics[width='.$width_param.' mm]{'.$file.'}} ';
1516: }
1517: }
1518: return $currentstring;
1519: }
1520: sub end_img {
1521: my ($target,$token) = @_;
1522: my $currentstring = '';
1523: if ($target eq 'web') {
1524: $currentstring = $token->[2];
1525: } elsif ($target eq 'tex') {
1526: $currentstring = '';
1527: }
1528: return $currentstring;
1529: }
1530: #-- <applet> tag
1531:
1532: sub start_applet {
1533: my ($target,$token) = @_;
1534: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
1535: $token->[2]->{'code'};
1536: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
1537: $token->[2]->{'archive'};
1538: my $currentstring = '';
1539: if ($target eq 'web') {
1540: $currentstring = $token->[4];
1541: } elsif ($target eq 'tex') {
1542: $currentstring = " \\begin{figure} ";
1543: }
1544: return $currentstring;
1545: }
1546: sub end_applet {
1547: my ($target,$token) = @_;
1548: my $currentstring = '';
1549: if ($target eq 'web') {
1550: $currentstring = $token->[2];
1551: } elsif ($target eq 'tex') {
1552: $currentstring = " \\end{figure}";
1553: }
1554: return $currentstring;
1555: }
1556:
1557: #-- <embed> tag
1558:
1559: sub start_embed {
1560: my ($target,$token) = @_;
1561: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
1562: $token->[2]->{'src'};
1563: my $currentstring = '';
1564: if ($target eq 'web') {
1565: $currentstring = $token->[4];
1566: } elsif ($target eq 'tex') {
1567: $currentstring = " \\begin{figure} ";
1568: }
1569: return $currentstring;
1570: }
1571: sub end_embed {
1572: my ($target,$token) = @_;
1573: my $currentstring = '';
1574: if ($target eq 'web') {
1575: $currentstring = $token->[2];
1576: } elsif ($target eq 'tex') {
1577: $currentstring = " \\end{figure}";
1578: }
1579: return $currentstring;
1580: }
1581:
1582: #-- <param> tag
1583:
1584: sub start_param {
1585: my ($target,$token) = @_;
1586: if ($token->[2]->{'name'} eq 'cabbase') {
1587: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
1588: $token->[2]->{'value'};
1589: }
1590: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
1591: $token->[2]->{'src'};
1592: my $currentstring = '';
1593: if ($target eq 'web') {
1594: $currentstring = $token->[4];
1595: } elsif ($target eq 'tex') {
1596: $currentstring = " \\begin{figure} ";
1597: }
1598: return $currentstring;
1599: }
1600: sub end_param {
1601: my ($target,$token) = @_;
1602: my $currentstring = '';
1603: if ($target eq 'web') {
1604: $currentstring = $token->[2];
1605: } elsif ($target eq 'tex') {
1606: $currentstring = " \\end{figure}";
1607: }
1608: return $currentstring;
1609: }
1610:
1611: #-- <allow> tag
1612:
1613: sub start_allow {
1614: my ($target,$token) = @_;
1615:
1616: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
1617: $token->[2]->{'src'};
1618:
1619: return '';
1620: }
1621: sub end_allow {
1622: return '';
1623: }
1624: #-- Frames
1625: sub start_frameset {
1626: my ($target,$token) = @_;
1627: my $currentstring = '';
1628: if ($target eq 'web') {
1629: if (!$Apache::lonxml::registered) {
1630: $currentstring.='<head>'.
1631: &Apache::lonxml::registerurl(undef,$target).'</head>';
1632: }
1633: $currentstring .= $token->[4];
1634: }
1635: return $currentstring;
1636: }
1637: sub end_frameset {
1638: my ($target,$token) = @_;
1639: my $currentstring = '';
1640: if ($target eq 'web') {
1641: $currentstring = $token->[2];
1642: }
1643: return $currentstring;
1644: }
1645: #-- <pre>
1646: sub start_pre {
1647: my ($target,$token) = @_;
1648: my $currentstring = '';
1649: if ($target eq 'web') {
1650: $currentstring .= $token->[4];
1651: } elsif ($target eq 'tex') {
1652: $currentstring .= '\begin{verbatim}';
1653: }
1654: return $currentstring;
1655: }
1656: sub end_pre {
1657: my ($target,$token) = @_;
1658: my $currentstring = '';
1659: if ($target eq 'web') {
1660: $currentstring .= $token->[2];
1661: } elsif ($target eq 'tex') {
1662: $currentstring .= '\end{verbatim}';
1663: }
1664: return $currentstring;
1665: }
1666: #-- <insert>
1667: sub start_insert {
1668: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1669: my $currentstring = '';
1670: if ($target eq 'web') {
1671: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval);
1672: $currentstring .= '<b>'.$display.'</b>';;
1673: }
1674: return $currentstring;
1675: }
1676: sub end_insert {
1677: my ($target,$token) = @_;
1678: my $currentstring = '';
1679: if ($target eq 'web') {
1680: $currentstring .= '';
1681: }
1682: return $currentstring;
1683: }
1684: #-- <externallink>
1685: sub start_externallink {
1686: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1687: my $currentstring = '';
1688: if ($target eq 'web') {
1689: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval);
1690: $currentstring .= '<b>'.$display.'</b>';;
1691: }
1692: return $currentstring;
1693: }
1694: sub end_externallink {
1695: my ($target,$token) = @_;
1696: my $currentstring = '';
1697: if ($target eq 'web') {
1698: $currentstring .= '';
1699: }
1700: return $currentstring;
1701: }
1702: #-- <blankspace heigth="">
1703: sub start_blankspace {
1704: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1705: my $currentstring = '';
1706: if ($target eq 'tex') {
1707: my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval);
1708: $currentstring .= '\vskip '.$howmuch.' ';
1709: }
1710: return $currentstring;
1711: }
1712: sub end_blankspace {
1713: my ($target,$token) = @_;
1714: my $currentstring = '';
1715: if ($target eq 'tex') {
1716: $currentstring .= '';
1717: }
1718: return $currentstring;
1719: }
1720:
1721: 1;
1722: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>