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