File:
[LON-CAPA] /
loncom /
xml /
londefdef.pm
Revision
1.217:
download - view:
text,
annotated -
select for diffs
Wed May 26 15:13:56 2004 UTC (20 years ago) by
sakharuk
Branches:
MAIN
CVS tags:
HEAD
Bug 3020 (support for LaTeX packages) is partly solved. I've added the whole AMS package family. Before this I carefully check if there are conflicts between these packages and our old ones. As to the other packages I need to check how they will interact with our current pool. Nevertheless I am ready to add any additional package, of caurse after test.
1: # The LearningOnline Network with CAPA
2: # Tags Default Definition Module
3: #
4: # $Id: londefdef.pm,v 1.217 2004/05/26 15:13:56 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: ## Copyright for TtHfunc and TtMfunc by Ian Hutchinson.
29: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into
30: # binary executable programs or libraries distributed by the
31: # Michigan State University (the "Licensee"), but any binaries so
32: # distributed are hereby licensed only for use in the context
33: # of a program or computational system for which the Licensee is the
34: # primary author or distributor, and which performs substantial
35: # additional tasks beyond the translation of (La)TeX into HTML.
36: # The C source of the Code may not be distributed by the Licensee
37: # to any other parties under any circumstances.
38: #
39: #
40: # last modified 06/26/00 by Alexander Sakharuk
41: # 11/6,11/30,02/01/01,5/4 Gerd Kortemeyer
42: # 01/18 Alex Sakharuk
43:
44: package Apache::londefdef;
45:
46: use Apache::lonnet();
47: use strict;
48: use Apache::lonxml;
49: use Apache::File();
50: use Image::Magick;
51: use Apache::lonmenu();
52: use Apache::lonmeta();
53: use Apache::Constants qw(:common);
54:
55:
56: BEGIN {
57:
58: &Apache::lonxml::register('Apache::londefdef',('a','abbr','acronym','accessrule','address','allow','applet','area','b','base','basefont','bgo','bgsound','big','blink','blockquote','blankspace','body','br','button','caption','center','cite','code','col','colgroup','dd','del','dfn','dir','div','dl','dt','em','embed','externallink','fieldset','font','form','frame','frameset','h1','h2','h3','h4','h5','h6','head','hr','html','i','iframe','img','input','ins','insert','isindex','kbd','keygen','label','layer','legend','li','link','m','map','marquee','menu','meta','multicol','nobr','noembed','noframes','nolayer','noscript','object','ol','optgroup','option','output','p','param','pre','q','s','samp','select','server','small','spacer','span','strike','strong','sub','sup','table','tbody','td','textarea','tfoot','th','thead','title','tr','tt','tthoption','u','ul','var','wbr','hideweboutput'));
59:
60: }
61:
62: sub initialize_londefdef {
63: $Apache::londefdef::TD_redirection=0;
64: @Apache::londefdef::table = ();
65: $Apache::londefdef::select=0;
66: @Apache::londefdef::description=();
67: $Apache::londefdef::DD_redirection=0;
68: $Apache::londefdef::DT_redirection=0;
69: }
70:
71: #======================= TAG SUBROUTINES =====================
72: #-- <output>
73: sub start_output {
74: my ($target) = @_;
75: if ($target eq 'meta') { $Apache::lonxml::metamode--; }
76: return '';
77: }
78: sub end_output {
79: my ($target) = @_;
80: if ($target eq 'meta') { $Apache::lonxml::metamode++; }
81: return '';
82: }
83: #-- <m> tag
84: sub start_m {
85: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
86: my $currentstring = '';
87: my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser);
88: if ($target eq 'web' || $target eq 'analyze') {
89: $inside ='\\documentstyle{article}'.$inside;
90: &Apache::lonxml::debug("M is starting with:$inside:");
91: my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
92: if ($eval eq 'on') {
93: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
94: #&Apache::lonxml::debug("M is evaulated to:$inside:");
95: }
96: $currentstring = &Apache::lontexconvert::converted(\$inside);
97: if ($Apache::lontexconvert::errorstring) {
98: &Apache::lonxml::warning("tth error: ".
99: $Apache::lontexconvert::errorstring);
100: $Apache::lontexconvert::errorstring='';
101: }
102: #&Apache::lonxml::debug("M is ends with:$currentstring:");
103: $Apache::lonxml::post_evaluate=0;
104: } elsif ($target eq 'tex') {
105: $currentstring = $inside;
106: my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
107: if ($eval eq 'on') {
108: $currentstring=&Apache::run::evaluate($currentstring,$safeeval,$$parstack[-1]);
109: }
110: if ($currentstring=~/^(\s*\\\\\s*)*$/) {$currentstring = ' \vskip 0 mm ';}
111: $Apache::lonxml::post_evaluate=0;
112: }
113: return $currentstring;
114: }
115:
116: sub end_m {
117: my ($target,$token) = @_;
118: my $currentstring = '';
119: if ($target eq 'tex') {
120: $currentstring = "";
121: }
122: return $currentstring;
123: }
124:
125: sub start_tthoption {
126: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
127: my $result;
128: if ($target eq 'web') {
129: my $inside = &Apache::lonxml::get_all_text("/tthoption",$parser);
130: $inside=~s/^\s*//;
131: if ($ENV{'browser.mathml'}) {
132: &tth::ttmoptions($inside);
133: } else {
134: &tth::tthoptions($inside);
135: }
136: }
137: return $result;
138: }
139:
140: sub end_tthoption {
141: my ($target,$token) = @_;
142: my $result;
143: return $result;
144: }
145:
146: #-- <html> tag (end tag optional)
147: sub start_html {
148: my ($target,$token) = @_;
149: my $currentstring = '';
150: my $options=$ENV{'course.'.$ENV{'request.course.id'}.'.tthoptions'};
151: &Apache::lontexconvert::init_tth();
152: if ($target eq 'web' || $target eq 'edit') {
153: $currentstring = &Apache::lonxml::xmlbegin().
154: &Apache::lonxml::fontsettings();
155: } elsif ($target eq 'tex') {
156: @Apache::londefdef::table = ();
157: $currentstring .= '\documentclass[letterpaper]{article}';
158: if ($ENV{'form.latex_type'}=~'batchmode') {$currentstring .='\batchmode';}
159: $currentstring .= '\newcommand{\keephidden}[1]{}'.
160: '\renewcommand{\deg}{$^{\circ}$}'.
161: '\usepackage{longtable}'.
162: '\usepackage{textcomp}'.
163: '\usepackage{makeidx}'.
164: '\usepackage[dvips]{graphicx}'.
165: '\usepackage{epsfig}'.
166: '\usepackage{calc}'.
167: '\usepackage{amsmath}'.
168: '\usepackage{amssymb}'.
169: '\usepackage{amsfonts}'.
170: '\usepackage{amsthm}'.
171: '\usepackage{amscd}'.
172: '\newenvironment{choicelist}{\begin{list}{}{\setlength{\rightmargin}{0in}\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.05in}\setlength{\itemsep}{0.022in}\setlength{\parsep}{0in}\setlength{\belowdisplayskip}{0.04in}\setlength{\abovedisplayskip}{0.05in}\setlength{\abovedisplayshortskip}{-0.04in}\setlength{\belowdisplayshortskip}{0.04in}}}{\end{list}}'.
173: '\renewenvironment{theindex}{\begin{list}{}{{\vskip 1mm \noindent \large\textbf{Index}} \newline \setlength{\rightmargin}{0in}\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.01in}\setlength{\itemsep}{0.1in}\setlength{\parsep}{-0.02in}\setlength{\belowdisplayskip}{0.01in}\setlength{\abovedisplayskip}{0.01in}\setlength{\abovedisplayshortskip}{-0.04in}\setlength{\belowdisplayshortskip}{0.01in}}}{\end{list}}';
174: }
175: return $currentstring;
176: }
177:
178: sub end_html {
179: my ($target,$token) = @_;
180: my $currentstring = '';
181: if ($target eq 'web') {
182: $currentstring = &Apache::lonxml::xmlend();
183: }
184: return $currentstring;
185: }
186:
187: #-- <head> tag (end tag optional)
188: sub start_head {
189: my ($target,$token) = @_;
190: my $currentstring = '';
191: if ($target eq 'web') {
192: $currentstring = $token->[4];
193: }
194: return $currentstring;
195: }
196:
197: sub end_head {
198: my ($target,$token) = @_;
199: my $currentstring = '';
200: if ($target eq 'web' && $ENV{'request.state'} eq 'published') {
201: $currentstring = &Apache::lonmenu::registerurl(undef,$target).
202: $token->[2];
203: }
204: return $currentstring;
205: }
206:
207: #-- <map> tag (end tag required)
208: sub start_map {
209: my ($target,$token) = @_;
210: my $currentstring = '';
211: if ($target eq 'web') {
212: $currentstring = $token->[4];
213: }
214: return $currentstring;
215: }
216:
217: sub end_map {
218: my ($target,$token) = @_;
219: my $currentstring = '';
220: if ($target eq 'web') {
221: $currentstring = $token->[2];
222: }
223: return $currentstring;
224: }
225:
226: #-- <select> tag (end tag required)
227: sub start_select {
228: my ($target,$token) = @_;
229: my $currentstring = '';
230: if ($target eq 'web') {
231: $currentstring = $token->[4];
232: } elsif ($target eq 'tex') {
233: $Apache::londefdef::select=0;
234: }
235: return $currentstring;
236: }
237:
238: sub end_select {
239: my ($target,$token) = @_;
240: my $currentstring = '';
241: if ($target eq 'web') {
242: $currentstring = $token->[2];
243: }
244: return $currentstring;
245: }
246:
247: #-- <option> tag (end tag optional)
248: sub start_option {
249: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
250: my $currentstring = '';
251: if ($target eq 'web') {
252: $currentstring = $token->[4];
253: } elsif ($target eq 'tex') {
254: $Apache::londefdef::select++;
255: if ($Apache::londefdef::select == 1) {
256: $currentstring='\noindent\fbox{'.&Apache::lonxml::get_param('value',$parstack,$safeeval).'}\keephidden{';
257: } else {
258: $currentstring='\keephidden{';
259: }
260: }
261: return $currentstring;
262: }
263:
264: sub end_option {
265: my ($target,$token) = @_;
266: my $currentstring = '';
267: if ($target eq 'web') {
268: $currentstring = $token->[2];
269: } elsif ($target eq 'tex') {
270: $currentstring='}';
271: }
272: return $currentstring;
273: }
274:
275: #-- <input> tag (end tag forbidden)
276: sub start_input {
277: my ($target,$token) = @_;
278: my $currentstring = '';
279: if ($target eq 'web') {
280: $currentstring = $token->[4];
281: }
282: return $currentstring;
283: }
284:
285: sub end_input {
286: my ($target,$token) = @_;
287: my $currentstring = '';
288: if ($target eq 'web') {
289: $currentstring = $token->[2];
290: }
291: return $currentstring;
292: }
293:
294: #-- <textarea> tag (end tag required)
295: sub start_textarea {
296: my ($target,$token) = @_;
297: my $currentstring = '';
298: if ($target eq 'web') {
299: $currentstring = $token->[4];
300: }
301: return $currentstring;
302: }
303:
304: sub end_textarea {
305: my ($target,$token) = @_;
306: my $currentstring = '';
307: if ($target eq 'web') {
308: $currentstring = $token->[2];
309: }
310: return $currentstring;
311: }
312:
313: #-- <form> tag (end tag required)
314: sub start_form {
315: my ($target,$token) = @_;
316: my $currentstring = '';
317: if ($target eq 'web') {
318: $currentstring = $token->[4];
319: }
320: return $currentstring;
321: }
322:
323: sub end_form {
324: my ($target,$token) = @_;
325: my $currentstring = '';
326: if ($target eq 'web') {
327: $currentstring = $token->[2];
328: }
329: return $currentstring;
330: }
331:
332: #-- <title> tag (end tag required)
333: sub start_title {
334: my ($target,$token) = @_;
335: my $currentstring = '';
336: if ($target eq 'web') {
337: $currentstring = $token->[4];
338: } elsif ($target eq 'tex') {
339: $currentstring .= '\keephidden{Title of the document: '
340: }
341: if ($target eq 'meta') {
342: $currentstring='<title>';
343: &start_output($target);
344: }
345: return $currentstring;
346: }
347:
348: sub end_title {
349: my ($target,$token) = @_;
350: my $currentstring = '';
351: if ($target eq 'web') {
352: $currentstring = $token->[2];
353: } elsif ($target eq 'tex') {
354: $currentstring .= '}';
355: }
356: if ($target eq 'meta') {
357: &end_output($target);
358: $currentstring='</title>';
359: }
360: return $currentstring;
361: }
362:
363: #-- <meta> tag (end tag forbidden)
364: sub start_meta {
365: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
366: my $currentstring = '';
367: if ($target eq 'web') {
368: my $args='';
369: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
370: if ($args eq '') {
371: &Apache::lonxml::get_all_text("/meta",$parser);
372: } else {
373: $currentstring = $token->[4];
374: }
375: } elsif ($target eq 'meta') {
376: unless (&Apache::lonxml::get_param
377: ('http-equiv',$parstack,$safeeval,undef,1)) {
378: my $name=$token->[2]->{'name'};
379: $name=~tr/A-Z/a-z/;
380: $name=~s/\s/\_/gs;
381: $name=~s/\W//gs;
382: if ($name) {
383: $currentstring='<'.$name;
384: my $display=&Apache::lonxml::get_param
385: ('display',$parstack,$safeeval,undef,1);
386: if ($display) {
387: $display=~s/\"/\'/g;
388: $currentstring.=' display="'.$display.'"';
389: }
390: $currentstring.='>'.
391: &Apache::lonxml::get_param
392: ('content',$parstack,$safeeval,undef,1).
393: '</'.$name.'>';
394: }
395: my $display=&Apache::lonxml::get_param
396: ('display',$parstack,$safeeval,undef,1);
397: if ($display) {
398: $display=&HTML::Entities::encode($display,'<>&"');
399: $currentstring.='<'.$name.'.display>'.$display.
400: '</'.$name.'.display>';
401: }
402: }
403: } elsif ($target eq 'tex') {
404: my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval);
405: my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval);
406: if ((not defined $content) && (not defined $name)) {
407: &Apache::lonxml::startredirection();
408: }
409: }
410: return $currentstring;
411: }
412:
413: sub end_meta {
414: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
415: my $currentstring = '';
416: if ($target eq 'web') {
417: my $args='';
418: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
419: if ($args ne '') {
420: $currentstring = $token->[4];
421: }
422: } elsif ($target eq 'tex') {
423: my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval);
424: my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval);
425: if ((not defined $content) && (not defined $name)) {
426: &Apache::lonxml::endredirection();
427: }
428: }
429: return $currentstring;
430: }
431:
432: # accessrule
433: sub start_accessrule {
434: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
435: my $currentstring = '';
436: my $eff=&Apache::lonxml::get_param
437: ('effect',$parstack,$safeeval,undef,1);
438: my $realm=&Apache::lonxml::get_param
439: ('realm',$parstack,$safeeval,undef,1);
440: my $role=&Apache::lonxml::get_param
441: ('role',$parstack,$safeeval,undef,1);
442: $realm=~s/\s+//g;
443: $realm=~s/\//\_/g;
444: $realm=~s/^\_//;
445: $realm=~s/\W/\;/g;
446: $role=~s/\s+//g;
447: $role=~s/\//\_/g;
448: $role=~s/\W/\;/g;
449: if ($target eq 'web') {
450: my $args='';
451: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
452: if ($args eq '') {
453: &Apache::lonxml::get_all_text("/accessrule",$parser);
454: } else {
455: $currentstring = $token->[4];
456: }
457: }
458: if ($target eq 'meta') {
459: $currentstring='<rule>'.$eff.':'.$realm.':'.$role.'</rule>';
460: }
461: return $currentstring;
462: }
463:
464: sub end_accessrule {
465: my ($target,$token,$tagstack,$parstack,$parser) = @_;
466: my $currentstring = '';
467: if ($target eq 'web') {
468: my $args='';
469: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
470: if ($args ne '') {
471: $currentstring = $token->[4];
472: }
473: }
474: return $currentstring;
475: }
476:
477: #-- <body> tag (end tag required)
478: sub start_body {
479: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
480: my $currentstring = '';
481: if ($target eq 'web') {
482: if ($Apache::lonhomework::parsing_a_problem) {
483: &Apache::lonxml::warning("<body> tag found inside of <problem> tag this can cause problems.");
484: return '';
485: }
486: if (!$Apache::lonxml::registered &&
487: $ENV{'request.state'} eq 'published') {
488: $currentstring.='<head>'.
489: &Apache::lonmenu::registerurl(undef,$target).'</head>';
490: }
491: # Accessibility
492: if ($ENV{'browser.imagesuppress'} eq 'on') {
493: delete($token->[2]->{'background'});
494: }
495: if ($ENV{'browser.fontenhance'} eq 'on') {
496: my $style='';
497: foreach my $key (keys(%{$token->[2]})) {
498: if ($key =~ /^style$/i) {
499: $style.=$token->[2]->{$key}.';';
500: delete($token->[2]->{$key});
501: }
502: }
503: $token->[2]->{'style'}=$style.'; font-size: x-large;';
504: }
505: if ($ENV{'browser.blackwhite'} eq 'on') {
506: delete($token->[2]->{'font'});
507: delete($token->[2]->{'link'});
508: delete($token->[2]->{'alink'});
509: delete($token->[2]->{'vlink'});
510: delete($token->[2]->{'bgcolor'});
511: delete($token->[2]->{'background'});
512: }
513: # Overload loads
514: my $onLoad='';
515: foreach my $key (keys(%{$token->[2]})) {
516: if ($key =~ /^onload$/i) {
517: $onLoad.=$token->[2]->{$key}.';';
518: delete($token->[2]->{$key});
519: }
520: }
521: $token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad;
522: my $onUnload='';
523: foreach my $key (keys(%{$token->[2]})) {
524: if ($key =~ /^onunload$/i) {
525: $onUnload.=$token->[2]->{$key}.';';
526: delete($token->[2]->{$key});
527: }
528: }
529: $token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents().
530: ';'.$onUnload;
531:
532: $currentstring .= '<'.$token->[1];
533: foreach (keys %{$token->[2]}) {
534: $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
535: }
536: $currentstring.='>';
537: if ($ENV{'request.state'} ne 'published') {
538: $currentstring.=(<<EDITBUTTON);
539: <form method="post">
540: <input type="submit" name="editmode" accesskey="e" value="Edit" />
541: </form>
542: EDITBUTTON
543: } else {
544: $currentstring.=&Apache::lonmenu::menubuttons(undef,$target,1);
545: }
546: $currentstring.=&Apache::lonxml::message_location();
547: } elsif ($target eq 'tex') {
548: $currentstring = '\begin{document}';
549: }
550: return $currentstring;
551: }
552:
553: sub end_body {
554: my ($target,$token) = @_;
555: my $currentstring = '';
556: if ($target eq 'web') {
557: $currentstring = $token->[2];
558: } elsif ($target eq 'tex') {
559: $currentstring = '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}';
560: }
561: return $currentstring;
562: }
563:
564: #-- <center> tag (end tag required)
565: sub start_center {
566: my ($target,$token) = @_;
567: my $currentstring = '';
568: if ($target eq 'web') {
569: $currentstring = $token->[4];
570: } elsif ($target eq 'tex') {
571: $currentstring = '\begin{center}';
572: }
573: return $currentstring;
574: }
575:
576: sub end_center {
577: my ($target,$token) = @_;
578: my $currentstring = '';
579: if ($target eq 'web') {
580: $currentstring = $token->[2];
581: } elsif ($target eq 'tex') {
582: $currentstring = '\end{center}';
583: }
584: return $currentstring;
585: }
586:
587: #-- <b> tag (end tag required)
588: sub start_b {
589: my ($target,$token) = @_;
590: my $currentstring = '';
591: if ($target eq 'web') {
592: $currentstring = $token->[4];
593: } elsif ($target eq 'tex') {
594: $currentstring = '\textbf{';
595: }
596: return $currentstring;
597: }
598:
599: sub end_b {
600: my ($target,$token) = @_;
601: my $currentstring = '';
602: if ($target eq 'web') {
603: $currentstring = $token->[2];
604: } elsif ($target eq 'tex') {
605: $currentstring = '}';
606: }
607: return $currentstring;
608: }
609:
610: #-- <strong> tag (end tag required)
611: sub start_strong {
612: my ($target,$token) = @_;
613: my $currentstring = '';
614: if ($target eq 'web') {
615: $currentstring = $token->[4];
616: } elsif ($target eq 'tex') {
617: $currentstring = '\textbf{';
618: }
619: return $currentstring;
620: }
621:
622: sub end_strong {
623: my ($target,$token) = @_;
624: my $currentstring = '';
625: if ($target eq 'web') {
626: $currentstring = $token->[2];
627: } elsif ($target eq 'tex') {
628: $currentstring = '}';
629: }
630: return $currentstring;
631: }
632:
633: #-- <h1> tag (end tag required)
634: sub start_h1 {
635: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
636: my $currentstring = '';
637: if ($target eq 'web') {
638: $currentstring .= $token->[4];
639: } elsif ($target eq 'tex') {
640: my $pre;
641: my $align=lc(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1));
642: if ($align eq 'center') {
643: $pre='\begin{center}';
644: } elsif ($align eq 'left') {
645: $pre='\rlap{';
646: } elsif ($align eq 'right') {
647: $pre=' \hfill \llap{';
648: }
649: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
650: if (not defined $TeXsize) {$TeXsize="large";}
651: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
652: } elsif ($target eq 'meta') {
653: $currentstring='<subject>';
654: &start_output($target);
655: }
656: return $currentstring;
657: }
658:
659: sub end_h1 {
660: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
661: my $currentstring = '';
662: if ($target eq 'web') {
663: $currentstring .= $token->[2];
664: } elsif ($target eq 'tex') {
665: my $post='\vskip 0 mm ';
666: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
667: if ($align eq 'center') {
668: $post='\end{center}';
669: } elsif ($align eq 'left') {
670: $post='} \hfill'.'\vskip 0 mm ';
671: } elsif ($align eq 'right') {
672: $post='}'.'\vskip 0 mm ';
673: }
674: $currentstring .= '}}'.$post;
675: } elsif ($target eq 'meta') {
676: &end_output($target);
677: $currentstring='</subject>';
678: }
679: return $currentstring;
680: }
681:
682: #-- <h2> tag
683: sub start_h2 {
684: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
685: my $currentstring = '';
686: if ($target eq 'web') {
687: $currentstring .= $token->[4];
688: } elsif ($target eq 'tex') {
689: my $pre;
690: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
691: if ($align eq 'center') {
692: $pre='\begin{center}';
693: } elsif ($align eq 'left') {
694: $pre='\rlap{';
695: } elsif ($align eq 'right') {
696: $pre=' \hfill \llap{';
697: }
698: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
699: if (not defined $TeXsize) {$TeXsize="large";}
700: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
701: }
702: return $currentstring;
703: }
704:
705: sub end_h2 {
706: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
707: my $currentstring = '';
708: if ($target eq 'web') {
709: $currentstring .= $token->[2];
710: } elsif ($target eq 'tex') {
711: my $post='\vskip 0 mm ';
712: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
713: if ($align eq 'center') {
714: $post='\end{center}';
715: } elsif ($align eq 'left') {
716: $post='} \hfill'.'\vskip 0 mm ';
717: } elsif ($align eq 'right') {
718: $post='}'.'\vskip 0 mm ';
719: }
720: $currentstring .= '}}'.$post;
721: }
722: return $currentstring;
723: }
724:
725: #-- <h3> tag
726: sub start_h3 {
727: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
728: my $currentstring = '';
729: if ($target eq 'web') {
730: $currentstring .= $token->[4];
731: } elsif ($target eq 'tex') {
732: my $pre;
733: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
734: if ($align eq 'center') {
735: $pre='\begin{center}';
736: } elsif ($align eq 'left') {
737: $pre='\rlap{';
738: } elsif ($align eq 'right') {
739: $pre=' \hfill \llap{';
740: }
741: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
742: if (not defined $TeXsize) {$TeXsize="large";}
743: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
744: }
745: return $currentstring;
746: }
747:
748: sub end_h3 {
749: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
750: my $currentstring = '';
751: if ($target eq 'web') {
752: $currentstring .= $token->[2];
753: } elsif ($target eq 'tex') {
754: my $post='\vskip 0 mm ';
755: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
756: if ($align eq 'center') {
757: $post='\end{center}';
758: } elsif ($align eq 'left') {
759: $post='} \hfill'.'\vskip 0 mm ';
760: } elsif ($align eq 'right') {
761: $post='}'.'\vskip 0 mm ';
762: }
763: $currentstring .= '}}'.$post;
764: }
765: return $currentstring;
766: }
767:
768: #-- <h4> tag
769: sub start_h4 {
770: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
771: my $currentstring = '';
772: if ($target eq 'web') {
773: $currentstring .= $token->[4];
774: } elsif ($target eq 'tex') {
775: my $pre;
776: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
777: if ($align eq 'center') {
778: $pre='\begin{center}';
779: } elsif ($align eq 'left') {
780: $pre='\rlap{';
781: } elsif ($align eq 'right') {
782: $pre=' \hfill \llap{';
783: }
784: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
785: if (not defined $TeXsize) {$TeXsize="large";}
786: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
787: }
788: return $currentstring;
789: }
790:
791: sub end_h4 {
792: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
793: my $currentstring = '';
794: if ($target eq 'web') {
795: $currentstring .= $token->[2];
796: } elsif ($target eq 'tex') {
797: my $post='\vskip 0 mm ';
798: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
799: if ($align eq 'center') {
800: $post='\end{center}';
801: } elsif ($align eq 'left') {
802: $post='} \hfill'.'\vskip 0 mm ';
803: } elsif ($align eq 'right') {
804: $post='}'.'\vskip 0 mm ';
805: }
806: $currentstring .= '}}'.$post;
807: }
808: return $currentstring;
809: }
810:
811: #-- <h5> tag
812: sub start_h5 {
813: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
814: my $currentstring = '';
815: if ($target eq 'web') {
816: $currentstring .= $token->[4];
817: } elsif ($target eq 'tex') {
818: my $pre;
819: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
820: if ($align eq 'center') {
821: $pre='\begin{center}';
822: } elsif ($align eq 'left') {
823: $pre='\rlap{';
824: } elsif ($align eq 'right') {
825: $pre=' \hfill \llap{';
826: }
827: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
828: if (not defined $TeXsize) {$TeXsize="large";}
829: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
830: }
831: return $currentstring;
832: }
833:
834: sub end_h5 {
835: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
836: my $currentstring = '';
837: if ($target eq 'web') {
838: $currentstring .= $token->[2];
839: } elsif ($target eq 'tex') {
840: my $post='\vskip 0 mm ';
841: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
842: if ($align eq 'center') {
843: $post='\end{center}';
844: } elsif ($align eq 'left') {
845: $post='} \hfill'.'\vskip 0 mm ';
846: } elsif ($align eq 'right') {
847: $post='}'.'\vskip 0 mm ';
848: }
849: $currentstring .= '}}'.$post;
850: }
851: return $currentstring;
852: }
853:
854: #-- <h6> tag
855: sub start_h6 {
856: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
857: my $currentstring = '';
858: if ($target eq 'web') {
859: $currentstring .= $token->[4];
860: } elsif ($target eq 'tex') {
861: my $pre;
862: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
863: if ($align eq 'center') {
864: $pre='\begin{center}';
865: } elsif ($align eq 'left') {
866: $pre='\rlap{';
867: } elsif ($align eq 'right') {
868: $pre=' \hfill \llap{';
869: }
870: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
871: if (not defined $TeXsize) {$TeXsize="large";}
872: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
873: }
874: return $currentstring;
875: }
876:
877: sub end_h6 {
878: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
879: my $currentstring = '';
880: if ($target eq 'web') {
881: $currentstring .= $token->[2];
882: } elsif ($target eq 'tex') {
883: my $post='\vskip 0 mm ';
884: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
885: if ($align eq 'center') {
886: $post='\end{center}';
887: } elsif ($align eq 'left') {
888: $post='} \hfill'.'\vskip 0 mm ';
889: } elsif ($align eq 'right') {
890: $post='}'.'\vskip 0 mm ';
891: }
892: $currentstring .= '}}'.$post;
893: }
894: return $currentstring;
895: }
896:
897: #--- <cite> tag (end tag required)
898: sub start_cite {
899: my ($target,$token) = @_;
900: my $currentstring = '';
901: if ($target eq 'web') {
902: $currentstring .= $token->[4];
903: } elsif ($target eq 'tex') {
904: $currentstring .= '\textit{';
905: }
906: return $currentstring;
907: }
908:
909: sub end_cite {
910: my ($target,$token) = @_;
911: my $currentstring = '';
912: if ($target eq 'web') {
913: $currentstring .= $token->[2];
914: } elsif ($target eq 'tex') {
915: $currentstring .= '}';
916: }
917: return $currentstring;
918: }
919:
920: #-- <i> tag (end tag required)
921: sub start_i {
922: my ($target,$token) = @_;
923: my $currentstring = '';
924: if ($target eq 'web') {
925: $currentstring .= $token->[4];
926: } elsif ($target eq 'tex') {
927: $currentstring .= '\textit{';
928: }
929: return $currentstring;
930: }
931:
932: sub end_i {
933: my ($target,$token) = @_;
934: my $currentstring = '';
935: if ($target eq 'web') {
936: $currentstring .= $token->[2];
937: } elsif ($target eq 'tex') {
938: $currentstring .= '}';
939: }
940: return $currentstring;
941: }
942:
943: #-- <address> tag (end tag required)
944: sub start_address {
945: my ($target,$token) = @_;
946: my $currentstring = '';
947: if ($target eq 'web') {
948: $currentstring .= $token->[4];
949: } elsif ($target eq 'tex') {
950: $currentstring .= '\textit{';
951: }
952: return $currentstring;
953: }
954:
955: sub end_address {
956: my ($target,$token) = @_;
957: my $currentstring = '';
958: if ($target eq 'web') {
959: $currentstring .= $token->[2];
960: } elsif ($target eq 'tex') {
961: $currentstring .= '}';
962: }
963: return $currentstring;
964: }
965:
966: #-- <dfn> tag (end tag required)
967: sub start_dfn {
968: my ($target,$token) = @_;
969: my $currentstring = '';
970: if ($target eq 'web') {
971: $currentstring .= $token->[4];
972: } elsif ($target eq 'tex') {
973: $currentstring .= '\textit{';
974: }
975: return $currentstring;
976: }
977:
978: sub end_dfn {
979: my ($target,$token) = @_;
980: my $currentstring = '';
981: if ($target eq 'web') {
982: $currentstring .= $token->[2];
983: } elsif ($target eq 'tex') {
984: $currentstring .= '}';
985: }
986: return $currentstring;
987: }
988:
989: #-- <tt> tag (end tag required)
990: sub start_tt {
991: my ($target,$token) = @_;
992: my $currentstring = '';
993: if ($target eq 'web') {
994: $currentstring .= $token->[4];
995: } elsif ($target eq 'tex') {
996: $currentstring .= '\texttt{';
997: }
998: return $currentstring;
999: }
1000:
1001: sub end_tt {
1002: my ($target,$token) = @_;
1003: my $currentstring = '';
1004: if ($target eq 'web') {
1005: $currentstring .= $token->[2];
1006: } elsif ($target eq 'tex') {
1007: $currentstring .= '}';
1008: }
1009: return $currentstring;
1010: }
1011:
1012: #-- <kbd> tag (end tag required)
1013: sub start_kbd {
1014: my ($target,$token) = @_;
1015: my $currentstring = '';
1016: if ($target eq 'web') {
1017: $currentstring .= $token->[4];
1018: } elsif ($target eq 'tex') {
1019: $currentstring .= '\texttt{';
1020: }
1021: return $currentstring;
1022: }
1023:
1024: sub end_kbd {
1025: my ($target,$token) = @_;
1026: my $currentstring = '';
1027: if ($target eq 'web') {
1028: $currentstring .= $token->[2];
1029: } elsif ($target eq 'tex') {
1030: $currentstring .= '}';
1031: }
1032: return $currentstring;
1033: }
1034:
1035: #-- <code> tag (end tag required)
1036: sub start_code {
1037: my ($target,$token) = @_;
1038: my $currentstring = '';
1039: if ($target eq 'web') {
1040: $currentstring .= $token->[4];
1041: } elsif ($target eq 'tex') {
1042: $currentstring .= '\texttt{';
1043: }
1044: return $currentstring;
1045: }
1046:
1047: sub end_code {
1048: my ($target,$token) = @_;
1049: my $currentstring = '';
1050: if ($target eq 'web') {
1051: $currentstring .= $token->[2];
1052: } elsif ($target eq 'tex') {
1053: $currentstring .= '}';
1054: }
1055: return $currentstring;
1056: }
1057:
1058: #-- <em> tag (end tag required)
1059: sub start_em {
1060: my ($target,$token) = @_;
1061: my $currentstring = '';
1062: if ($target eq 'web') {
1063: $currentstring .= $token->[4];
1064: } elsif ($target eq 'tex') {
1065: $currentstring .= '\emph{';
1066: }
1067: return $currentstring;
1068: }
1069:
1070: sub end_em {
1071: my ($target,$token) = @_;
1072: my $currentstring = '';
1073: if ($target eq 'web') {
1074: $currentstring .= $token->[2];
1075: } elsif ($target eq 'tex') {
1076: $currentstring .= '}';
1077: }
1078: return $currentstring;
1079: }
1080:
1081: #-- <q> tag (end tag required)
1082: sub start_q {
1083: my ($target,$token) = @_;
1084: my $currentstring = '';
1085: if ($target eq 'web') {
1086: $currentstring .= $token->[4];
1087: } elsif ($target eq 'tex') {
1088: $currentstring .= '\emph{';
1089: }
1090: return $currentstring;
1091: }
1092:
1093: sub end_q {
1094: my ($target,$token) = @_;
1095: my $currentstring = '';
1096: if ($target eq 'web') {
1097: $currentstring .= $token->[2];
1098: } elsif ($target eq 'tex') {
1099: $currentstring .= '}';
1100: }
1101: return $currentstring;
1102: }
1103:
1104: #-- <p> tag (end tag optional)
1105: #optional attribute - align="center|left|right"
1106: sub start_p {
1107: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1108: my $currentstring = '';
1109: if ($target eq 'web') {
1110: $currentstring .= $token->[4];
1111: } elsif ($target eq 'tex') {
1112: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1113: if ($align eq 'center') {
1114: $currentstring='\begin{center}\par';
1115: } elsif ($align eq 'right') {
1116: $currentstring='\makebox['.$ENV{'form.textwidth'}.']{\hfill\llap{';
1117: } elsif ($align eq 'left') {
1118: $currentstring='\noindent\makebox['.$ENV{'form.textwidth'}.']{\rlap{';
1119: } else {
1120: $currentstring='\par ';
1121: }
1122: my $signal=1;#<p> does not work inside <b>...</b>
1123: foreach my $tag (@$tagstack) {if (lc($tag) eq 'b') {$signal=0;}
1124: if (!$signal) {$currentstring = '';}
1125: }
1126: }
1127: return $currentstring;
1128: }
1129:
1130: sub end_p {
1131: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1132: my $currentstring = '';
1133: if ($target eq 'web') {
1134: $currentstring .= $token->[2];
1135: } elsif ($target eq 'tex') {
1136: if ($$tagstack[-1] eq 'p') {
1137: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1138: if ($align eq 'center') {
1139: $currentstring .= '\end{center}';
1140: } elsif ($align eq 'right') {
1141: $currentstring .= '}}';
1142: } elsif ($align eq 'left') {
1143: $currentstring .= '}\hfill}';
1144: }
1145: }
1146: }
1147: return $currentstring;
1148: }
1149:
1150: #-- <br> tag (end tag forbidden)
1151: sub start_br {
1152: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1153: my $currentstring = '';
1154: if ($target eq 'web') {
1155: $currentstring .= $token->[4];
1156: } elsif ($target eq 'tex') {
1157: if ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') {
1158: $currentstring .= '\vskip 0.2 mm ';
1159: }
1160: }
1161: return $currentstring;
1162: }
1163:
1164: sub end_br {
1165: my ($target,$token) = @_;
1166: my $currentstring = '';
1167: if ($target eq 'web') {
1168: $currentstring .= $token->[2];
1169: }
1170: return $currentstring;
1171: }
1172:
1173: #-- <big> tag (end tag required)
1174: sub start_big {
1175: my ($target,$token) = @_;
1176: my $currentstring = '';
1177: if ($target eq 'web') {
1178: $currentstring .= $token->[4];
1179: } elsif ($target eq 'tex') {
1180: $currentstring .= '{\large ';
1181: }
1182: return $currentstring;
1183: }
1184:
1185: sub end_big {
1186: my ($target,$token) = @_;
1187: my $currentstring = '';
1188: if ($target eq 'web') {
1189: $currentstring .= $token->[2];
1190: } elsif ($target eq 'tex') {
1191: $currentstring .= '}';
1192: }
1193: return $currentstring;
1194: }
1195:
1196: #-- <small> tag (end tag required)
1197: sub start_small {
1198: my ($target,$token) = @_;
1199: my $currentstring = '';
1200: if ($target eq 'web') {
1201: $currentstring .= $token->[4];
1202: } elsif ($target eq 'tex') {
1203: $currentstring .= '{\footnotesize ';
1204: }
1205: return $currentstring;
1206: }
1207:
1208: sub end_small {
1209: my ($target,$token) = @_;
1210: my $currentstring = '';
1211: if ($target eq 'web') {
1212: $currentstring .= $token->[2];
1213: } elsif ($target eq 'tex') {
1214: $currentstring .= '}';
1215: }
1216: return $currentstring;
1217: }
1218:
1219: #-- <basefont> tag (end tag forbidden)
1220: sub start_basefont {
1221: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1222: my $currentstring = '';
1223: if ($target eq 'web') {
1224: $currentstring = $token->[4];
1225: } elsif ($target eq 'tex') {
1226: my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1227: if (defined $basesize) {
1228: $currentstring = '{\\'.$basesize.' ';
1229: }
1230: }
1231: return $currentstring;
1232: }
1233:
1234: sub end_basefont {
1235: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1236: my $currentstring = '';
1237: if ($target eq 'web') {
1238: $currentstring = $token->[4];
1239: } elsif ($target eq 'tex') {
1240: my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1241: if (defined $basesize) {
1242: $currentstring = '}';
1243: }
1244: }
1245: return $currentstring;
1246: }
1247:
1248: #-- <font> tag (end tag required)
1249: sub start_font {
1250: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1251: my $currentstring = '';
1252: if ($target eq 'web') {
1253: my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
1254: if ($face!~/symbol/i) {
1255: if (($ENV{'browser.fontenhance'} eq 'on') ||
1256: ($ENV{'browser.blackwhite'} eq 'on')) { return ''; }
1257: }
1258: $currentstring = $token->[4];
1259: } elsif ($target eq 'tex') {
1260: my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1261: if (defined $fontsize) {
1262: $currentstring = '{\\'.$fontsize.' ';
1263: }
1264: }
1265: return $currentstring;
1266: }
1267:
1268: sub end_font {
1269: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1270: my $currentstring = '';
1271: if ($target eq 'web') {
1272: $currentstring = $token->[2];
1273: } elsif ($target eq 'tex') {
1274: my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1275: if (defined $fontsize) {
1276: $currentstring = '}';
1277: }
1278: }
1279: return $currentstring;
1280: }
1281:
1282: #-- <strike> tag (end tag required)
1283: sub start_strike {
1284: my ($target,$token) = @_;
1285: my $currentstring = '';
1286: if ($target eq 'web') {
1287: $currentstring .= $token->[4];
1288: } elsif ($target eq 'tex') {
1289: &Apache::lonxml::startredirection();
1290: }
1291: return $currentstring;
1292: }
1293:
1294: sub end_strike {
1295: my ($target,$token) = @_;
1296: my $currentstring = '';
1297: if ($target eq 'web') {
1298: $currentstring .= $token->[2];
1299: } elsif ($target eq 'tex') {
1300: $currentstring=&Apache::lonxml::endredirection();
1301: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1302: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1303: $currentstring=~s/(\S)\s*$/$1\}/;
1304: }
1305: return $currentstring;
1306: }
1307:
1308: #-- <s> tag (end tag required)
1309: sub start_s {
1310: my ($target,$token) = @_;
1311: my $currentstring = '';
1312: if ($target eq 'web') {
1313: $currentstring .= $token->[4];
1314: } elsif ($target eq 'tex') {
1315: &Apache::lonxml::startredirection();
1316: }
1317: return $currentstring;
1318: }
1319:
1320: sub end_s {
1321: my ($target,$token) = @_;
1322: my $currentstring = '';
1323: if ($target eq 'web') {
1324: $currentstring .= $token->[2];
1325: } elsif ($target eq 'tex') {
1326: $currentstring=&Apache::lonxml::endredirection();
1327: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1328: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1329: $currentstring=~s/(\S)\s*$/$1\}/;
1330: }
1331: return $currentstring;
1332: }
1333:
1334: #-- <sub> tag (end tag required)
1335: sub start_sub {
1336: my ($target,$token) = @_;
1337: my $currentstring = '';
1338: if ($target eq 'web') {
1339: $currentstring .= $token->[4];
1340: } elsif ($target eq 'tex') {
1341: $currentstring .= '\ensuremath{_{';
1342: }
1343: return $currentstring;
1344: }
1345:
1346: sub end_sub {
1347: my ($target,$token) = @_;
1348: my $currentstring = '';
1349: if ($target eq 'web') {
1350: $currentstring .= $token->[2];
1351: } elsif ($target eq 'tex') {
1352: $currentstring .= '}}';
1353: }
1354: return $currentstring;
1355: }
1356:
1357: #-- <sup> tag (end tag required)
1358: sub start_sup {
1359: my ($target,$token) = @_;
1360: my $currentstring = '';
1361: if ($target eq 'web') {
1362: $currentstring .= $token->[4];
1363: } elsif ($target eq 'tex') {
1364: $currentstring .= '\ensuremath{^{';
1365: }
1366: return $currentstring;
1367: }
1368:
1369: sub end_sup {
1370: my ($target,$token) = @_;
1371: my $currentstring = '';
1372: if ($target eq 'web') {
1373: $currentstring .= $token->[2];
1374: } elsif ($target eq 'tex') {
1375: $currentstring .= '}}';
1376: }
1377: return $currentstring;
1378: }
1379:
1380: #-- <hr> tag (end tag forbidden)
1381: sub start_hr {
1382: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1383: my $currentstring = '';
1384: if ($target eq 'web') {
1385: $currentstring .= $token->[4];
1386: } elsif ($target eq 'tex') {
1387: my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
1388: if (defined $LaTeXwidth) {
1389: if ($LaTeXwidth=~/^%/) {
1390: substr($LaTeXwidth,0,1)='';
1391: $LaTeXwidth=($LaTeXwidth/100).'\textwidth';
1392: }
1393: } else {
1394: $LaTeXwidth ='0.9\textwidth';
1395: }
1396: my ($pre,$post);
1397: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1398: if (($align eq 'center') || (not defined $align)) {
1399: $pre=''; $post='';
1400: } elsif ($align eq 'left') {
1401: $pre='\rlap{'; $post='} \hfill';
1402: } elsif ($align eq 'right') {
1403: $pre=' \hfill \llap{'; $post='}';
1404: }
1405: $currentstring .= ' \vskip 0 mm \noindent\makebox['.$LaTeXwidth.']{'.$pre.'\makebox['.
1406: $LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm ';
1407: }
1408: return $currentstring;
1409: }
1410:
1411: sub end_hr {
1412: my ($target,$token) = @_;
1413: my $currentstring = '';
1414: if ($target eq 'web') {
1415: $currentstring .= $token->[2];
1416: }
1417: return $currentstring;
1418: }
1419:
1420: #-- <div> tag (end tag required)
1421: sub start_div {
1422: my ($target,$token) = @_;
1423: my $currentstring = '';
1424: if ($target eq 'web') {
1425: $currentstring .= $token->[4];
1426: }
1427: return $currentstring;
1428: }
1429:
1430: sub end_div {
1431: my ($target,$token) = @_;
1432: my $currentstring = '';
1433: if ($target eq 'web') {
1434: $currentstring .= $token->[2];
1435: }
1436: return $currentstring;
1437: }
1438:
1439: #-- <a> tag (end tag required)
1440: sub start_a {
1441: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1442: my $currentstring = '';
1443: if ($target eq 'web') {
1444: $currentstring .= $token->[4];
1445: } elsif ($target eq 'tex') {
1446: my $a=&Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1);
1447: my $b=&Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1);
1448: if ($a=~/\S/) {
1449: $a=~s/([^\\])%/$1\\\%/g;
1450: $currentstring .= '\ref{URI: '.$a.'}';
1451: } elsif ($b=~/\S/) {
1452: $currentstring .= '\ref{Anchor: '.$b.'}';
1453: } else {
1454: $currentstring.='';
1455: }
1456: }
1457: return $currentstring;
1458: }
1459:
1460: sub end_a {
1461: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1462: my $currentstring = '';
1463: if ($target eq 'web') {
1464: $currentstring .= $token->[2];
1465: }
1466: return $currentstring;
1467: }
1468:
1469: #-- <li> tag (end tag optional)
1470: sub start_li {
1471: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1472: my $currentstring = '';
1473: if ($target eq 'web') {
1474: $currentstring = $token->[4];
1475: } elsif ($target eq 'tex') {
1476: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,1);
1477: if ($type=~/circle/) {
1478: $currentstring .= ' \item[o] ';
1479: } elsif ($type=~/square/) {
1480: $currentstring .= ' \item[$\Box$] ';
1481: } elsif ($type ne '') {
1482: $currentstring .= ' \item['.$type.'] ';
1483: } else {
1484: $currentstring .= ' \item ';
1485: }
1486: }
1487: return $currentstring;
1488: }
1489:
1490: sub end_li {
1491: my ($target,$token) = @_;
1492: my $currentstring = '';
1493: if ($target eq 'web') {
1494: $currentstring = $token->[2];
1495: }
1496: return $currentstring;
1497: }
1498:
1499: #-- <u> tag (end tag required)
1500: sub start_u {
1501: my ($target,$token) = @_;
1502: my $currentstring = '';
1503: if ($target eq 'web') {
1504: $currentstring .= $token->[4];
1505: } elsif ($target eq 'tex') {
1506: &Apache::lonxml::startredirection();
1507: }
1508: return $currentstring;
1509: }
1510:
1511: sub end_u {
1512: my ($target,$token) = @_;
1513: my $currentstring = '';
1514: if ($target eq 'web') {
1515: $currentstring .= $token->[2];
1516: } elsif ($target eq 'tex') {
1517: $currentstring=&Apache::lonxml::endredirection();
1518: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1519: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1520: $currentstring=~s/(\S)\s*$/$1\}/;
1521: }
1522: return $currentstring;
1523: }
1524:
1525: #-- <ul> tag (end tag required)
1526: sub start_ul {
1527: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1528: my $currentstring = '';
1529: if ($target eq 'web') {
1530: $currentstring = $token->[4];
1531: } elsif ($target eq 'tex') {
1532: my $TeXtype=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1533: if ($TeXtype eq 'disc') {
1534: $currentstring .= ' \renewcommand{\labelitemi}{$\bullet$}
1535: \renewcommand{\labelitemii}{$\bullet$}
1536: \renewcommand{\labelitemiii}{$\bullet$}
1537: \renewcommand{\labelitemiv}{$\bullet$}';
1538: } elsif ($TeXtype eq 'circle') {
1539: $currentstring .= ' \renewcommand{\labelitemi}{$\circ$}
1540: \renewcommand{\labelitemii}{$\circ$}
1541: \renewcommand{\labelitemiii}{$\circ$}
1542: \renewcommand{\labelitemiv}{$\circ$}';
1543: } elsif ($TeXtype eq 'square') {
1544: $currentstring .= ' \renewcommand{\labelitemi}{$\diamond$}
1545: \renewcommand{\labelitemii}{$\diamond$}
1546: \renewcommand{\labelitemiii}{$\diamond$}
1547: \renewcommand{\labelitemiv}{$\diamond$}';
1548: }
1549: $currentstring .= '\begin{itemize}';
1550: }
1551: return $currentstring;
1552: }
1553:
1554: sub end_ul {
1555: my ($target,$token) = @_;
1556: my $currentstring = '';
1557: if ($target eq 'web') {
1558: $currentstring = $token->[2];
1559: } elsif ($target eq 'tex') {
1560: $currentstring = '\end{itemize} \renewcommand{\labelitemi}{$\bullet$}
1561: \renewcommand{\labelitemii}{$\bullet$}
1562: \renewcommand{\labelitemiii}{$\bullet$}
1563: \renewcommand{\labelitemiv}{$\bullet$}';
1564: }
1565: return $currentstring;
1566: }
1567:
1568: #-- <menu> tag (end tag required)
1569: sub start_menu {
1570: my ($target,$token) = @_;
1571: my $currentstring = '';
1572: if ($target eq 'web') {
1573: $currentstring = $token->[4];
1574: } elsif ($target eq 'tex') {
1575: $currentstring = " \\begin{itemize} ";
1576: }
1577: return $currentstring;
1578: }
1579:
1580: sub end_menu {
1581: my ($target,$token) = @_;
1582: my $currentstring = '';
1583: if ($target eq 'web') {
1584: $currentstring = $token->[2];
1585: } elsif ($target eq 'tex') {
1586: $currentstring = " \\end{itemize}";
1587: }
1588: return $currentstring;
1589: }
1590:
1591: #-- <dir> tag (end tag required)
1592: sub start_dir {
1593: my ($target,$token) = @_;
1594: my $currentstring = '';
1595: if ($target eq 'web') {
1596: $currentstring = $token->[4];
1597: } elsif ($target eq 'tex') {
1598: $currentstring = " \\begin{itemize} ";
1599: }
1600: return $currentstring;
1601: }
1602:
1603: sub end_dir {
1604: my ($target,$token) = @_;
1605: my $currentstring = '';
1606: if ($target eq 'web') {
1607: $currentstring = $token->[2];
1608: } elsif ($target eq 'tex') {
1609: $currentstring = " \\end{itemize}";
1610: }
1611: return $currentstring;
1612: }
1613:
1614: #-- <ol> tag (end tag required)
1615: sub start_ol {
1616: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1617: my $currentstring = '';
1618: if ($target eq 'web') {
1619: $currentstring = $token->[4];
1620: } elsif ($target eq 'tex') {
1621: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1622: if ($type eq '1') {
1623: $currentstring .= ' \renewcommand{\labelenumi}{\arabic{enumi}.}
1624: \renewcommand{\labelenumii}{\arabic{enumii}.}
1625: \renewcommand{\labelenumiii}{\arabic{enumiii}.}
1626: \renewcommand{\labelenumiv}{\arabic{enumiv}.}';
1627: } elsif ($type eq 'A') {
1628: $currentstring .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}
1629: \renewcommand{\labelenumii}{\Alph{enumii}.}
1630: \renewcommand{\labelenumiii}{\Alph{enumiii}.}
1631: \renewcommand{\labelenumiv}{\Alph{enumiv}.}';
1632: } elsif ($type eq 'a') {
1633: $currentstring .= ' \renewcommand{\labelenumi}{\alph{enumi}.}
1634: \renewcommand{\labelenumii}{\alph{enumii}.}
1635: \renewcommand{\labelenumiii}{\alph{enumiii}.}
1636: \renewcommand{\labelenumiv}{\alph{enumiv}.} ';
1637: } elsif ($type eq 'i') {
1638: $currentstring .= ' \renewcommand{\labelenumi}{\roman{enumi}.}
1639: \renewcommand{\labelenumii}{\roman{enumii}.}
1640: \renewcommand{\labelenumiii}{\roman{enumiii}.}
1641: \renewcommand{\labelenumiv}{\roman{enumiv}.} ';
1642: } elsif ($type eq 'I') {
1643: $currentstring .= ' \renewcommand{\labelenumi}{\Roman{enumi}.}
1644: \renewcommand{\labelenumii}{\Roman{enumii}.}
1645: \renewcommand{\labelenumiii}{\Roman{enumiii}.}
1646: \renewcommand{\labelenumiv}{\Roman{enumiv}.} ';
1647: }
1648: $currentstring .= '\begin{enumerate}';
1649: }
1650: return $currentstring;
1651: }
1652:
1653: sub end_ol {
1654: my ($target,$token) = @_;
1655: my $currentstring = '';
1656: if ($target eq 'web') {
1657: $currentstring = $token->[2];
1658: } elsif ($target eq 'tex') {
1659: $currentstring = '\end{enumerate} \renewcommand{\labelenumi}{\arabic{enumi}.}
1660: \renewcommand{\labelenumii}{\arabic{enumii}.}
1661: \renewcommand{\labelenumiii}{\arabic{enumiii}.}
1662: \renewcommand{\labelenumiv}{\arabic{enumiv}.}';
1663: }
1664: return $currentstring;
1665: }
1666:
1667: #-- <dl> tag (end tag required)
1668: sub start_dl {
1669: my ($target,$token) = @_;
1670: my $currentstring = '';
1671: if ($target eq 'web') {
1672: $currentstring = $token->[4];
1673: } elsif ($target eq 'tex') {
1674: $currentstring = '\begin{description}';
1675: @Apache::londefdef::description=();
1676: $Apache::londefdef::DD_redirection=0;
1677: $Apache::londefdef::DT_redirection=0;
1678: }
1679: return $currentstring;
1680: }
1681:
1682: sub end_dl {
1683: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1684: my $currentstring = '';
1685: if ($target eq 'web') {
1686: $currentstring = $token->[2];
1687: } elsif ($target eq 'tex') {
1688: if ($Apache::londefdef::DT_redirection) {
1689: my $data=&item_cleanup;
1690: push @Apache::londefdef::description,'\item['.$data.']';
1691: $Apache::londefdef::DT_redirection=0;
1692: } elsif ($Apache::londefdef::DD_redirection) {
1693: $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection();
1694: }
1695: foreach my $element (@Apache::londefdef::description) {
1696: $currentstring.=' '.$element.' ';
1697: }
1698: @Apache::londefdef::description=();
1699: $currentstring.='\end{description}';
1700: }
1701: return $currentstring;
1702: }
1703:
1704: #-- <dt> tag (end tag optional)
1705: sub start_dt {
1706: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1707: my $currentstring='';
1708: if ($target eq 'web') {
1709: $currentstring = $token->[4];
1710: } elsif ($target eq 'tex') {
1711: if ($Apache::londefdef::DT_redirection) {
1712: my $data=&item_cleanup;
1713: push @Apache::londefdef::description,'\item['.$data.']';
1714: $Apache::londefdef::DT_redirection=0;
1715: } elsif ($Apache::londefdef::DD_redirection) {
1716: $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection();
1717: $Apache::londefdef::DD_redirection=0;
1718: }
1719: &Apache::lonxml::startredirection();
1720: $Apache::londefdef::DT_redirection=1;
1721: }
1722: return $currentstring;
1723: }
1724:
1725: sub end_dt {
1726: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1727: my $currentstring = '';
1728: if ($target eq 'web') {
1729: $currentstring = $token->[2];
1730: } elsif ($target eq 'tex') {
1731: my $data=&item_cleanup;
1732: push @Apache::londefdef::description,'\item['.$data.']';
1733: $Apache::londefdef::DT_redirection=0;
1734: }
1735: return $currentstring;
1736: }
1737:
1738: sub item_cleanup {
1739: my $item=&Apache::lonxml::endredirection();
1740: $item=~s/\\begin{center}//g;
1741: $item=~s/\\end{center}//g;
1742: return $item;
1743: }
1744:
1745: #-- <dd> tag (end tag optional)
1746: sub start_dd {
1747: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1748: my $currentstring = '';
1749: if ($target eq 'web') {
1750: $currentstring = $token->[4];
1751: } elsif ($target eq 'tex') {
1752: if ($Apache::londefdef::DT_redirection) {
1753: my $data=&item_cleanup;
1754: push @Apache::londefdef::description,'\item['.$data.']';
1755: $Apache::londefdef::DT_redirection=0;
1756: }
1757: $Apache::londefdef::DD_redirection=1;
1758: &Apache::lonxml::startredirection();
1759: }
1760: return $currentstring;
1761: }
1762:
1763: sub end_dd {
1764: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1765: my $currentstring = '';
1766: if ($target eq 'web') {
1767: $currentstring = $token->[2];
1768: } elsif ($target eq 'tex') {
1769: $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection();
1770: $Apache::londefdef::DD_redirection=0;
1771: }
1772: return $currentstring;
1773: }
1774:
1775: #-- <table> tag (end tag required)
1776: #list of supported attributes: border,width,TeXwidth
1777: sub start_table {
1778: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1779: my ($textwidth,$currentstring)=('','');
1780: if ($target eq 'web') {
1781: $currentstring = $token->[4];
1782: } elsif ($target eq 'tex') {
1783: my $aa = {};
1784: push @Apache::londefdef::table, $aa;
1785: $Apache::londefdef::table[-1]{'row_number'} = -1;
1786: #table's width
1787: #default coincides with text line length
1788: if ($#Apache::londefdef::table==0) {
1789: $textwidth=&recalc($ENV{'form.textwidth'}); #result is always in mm
1790: $textwidth=~/(\d+\.?\d*)/;
1791: $textwidth=0.95*$1; #accounts "internal" LaTeX space for table frame
1792: } else {
1793: if ($Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]=~/\d/) {
1794: #the maximum width of nested table is determined by LATeX width of parent cell
1795: $textwidth=$Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}];
1796: } else {
1797: #try to use all space not used before (minus 5% for LaTeX table internal) - rather silly
1798: my $textwidth=$Apache::londefdef::table[-2]{'width'};
1799: for (my $i=0;$i<$Apache::londefdef::table[-2]{'counter_columns'};$i++) {
1800: $textwidth=$textwidth-$Apache::londefdef::table[-2]{'TeXlen'}[0][$i];
1801: }
1802: }
1803: }
1804: my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
1805: if (not defined $TeXwidth) {
1806: my $htmlwidth = &Apache::lonxml::get_param('width',$parstack,$safeeval,undef,1);
1807: if ($htmlwidth=~/%/) {
1808: $Apache::londefdef::table[-1]{'percent'}=1;
1809: $htmlwidth=~/(\d+)/;
1810: $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;;
1811: } else {
1812: $Apache::londefdef::table[-1]{'width'}=$textwidth;
1813: }
1814: } elsif ($TeXwidth=~/%/) {
1815: $Apache::londefdef::table[-1]{'percent'}=1;
1816: $TeXwidth=~/(\d+)/;
1817: $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;
1818: } else {
1819: $Apache::londefdef::table[-1]{'width'}=$TeXwidth;
1820: }
1821: #table's border
1822: my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval);
1823: my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
1824: unless (defined $border) { $border = 0; }
1825: if ($border) {
1826: $Apache::londefdef::table[-1]{'hinc'} = '\hline ';
1827: $Apache::londefdef::table[-1]{'vinc'} = '&';
1828: $Apache::londefdef::table[-1]{'vvinc'} = '|';
1829: } else {
1830: $Apache::londefdef::table[-1]{'hinc'} = '';
1831: $Apache::londefdef::table[-1]{'vinc'} = '&';
1832: $Apache::londefdef::table[-1]{'vvinc'} = '';
1833: }
1834: if ($#Apache::londefdef::table==0) {
1835: $Apache::londefdef::table[-1]{'output'}='\newline\setlength{\tabcolsep}{1 mm}';
1836: }
1837: $Apache::londefdef::table[-1]{'output'}.=' \noindent \begin{tabular} ';
1838: $Apache::londefdef::table[-1]{'TeXlen'}=[];
1839: $Apache::londefdef::table[-1]{'objectlen'}=[];
1840: $Apache::londefdef::table[-1]{'maxlen'}=[];
1841: $Apache::londefdef::table[-1]{'minlen'}=[];
1842: $Apache::londefdef::table[-1]{'content'}=[];
1843: $Apache::londefdef::table[-1]{'align'}=[];
1844: $currentstring='\keephidden{NEW TABLE ENTRY}';
1845: }
1846: return $currentstring;
1847: }
1848:
1849: sub end_table {
1850: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1851: my $currentstring = '';
1852: if ($target eq 'web') {
1853: $currentstring = $token->[2];
1854: } elsif ($target eq 'tex') {
1855: my $inmemory = '';
1856: my $output = '';
1857: my $WARNING='';
1858: #width of columns from TeXwidth attributes
1859: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1860: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
1861: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]<$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn]) {
1862: $Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]=$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn];
1863: }
1864: }
1865: }
1866: #free space and number of empty columns
1867: my ($available_space,$empty_columns)=($Apache::londefdef::table[-1]{'width'},0);
1868: ## &Apache::lonnet::logthis("Available space $Apache::londefdef::table[-1]{'width'}");
1869: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
1870: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]==0) {
1871: $empty_columns++;
1872: } else {
1873: $available_space=$available_space-$Apache::londefdef::table[-1]{'TeXlen'}[0][$jn];
1874: }
1875: }
1876: #boundaries for contents columns
1877: my @min_len=();#columns can not be narrower
1878: my @max_len=();#maximum length of column
1879: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
1880: my ($localmin,$localmax)=(0,0);
1881: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1882: if ($localmin<$Apache::londefdef::table[-1]{'minlen'}[$in][$jn]) {
1883: $localmin=$Apache::londefdef::table[-1]{'minlen'}[$in][$jn];
1884: }
1885: if ($localmax<$Apache::londefdef::table[-1]{'maxlen'}[$in][$jn]) {
1886: $localmax=$Apache::londefdef::table[-1]{'maxlen'}[$in][$jn];
1887: }
1888: }
1889: push @min_len, $localmin;
1890: push @max_len, $localmax;
1891: }
1892: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
1893: my $localmin=0,;
1894: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1895: if ($localmin<$Apache::londefdef::table[-1]{'objectlen'}[$in][$jn]) {
1896: $localmin=$Apache::londefdef::table[-1]{'objectlen'}[$in][$jn];
1897: }
1898: }
1899: if ($max_len[$jn]<$localmin) {$max_len[$jn]=$localmin;}#object size is bigger
1900: if ($min_len[$jn]<$localmin) {$min_len[$jn]=$localmin;}#object size is bigger
1901: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]!=0) {
1902: $min_len[$jn]=0;
1903: $max_len[$jn]=0;
1904: }
1905: }
1906: #final adjustment of column width
1907: my @fwidth=@{$Apache::londefdef::table[-1]{'TeXlen'}[0]};#final width array
1908: my @adjust=();
1909: #step 1. adjustment by maximum value
1910: my $space_neeeded=0;
1911: for (my $jn=0;$jn<=$#max_len;$jn++) {
1912: $space_neeeded=$space_neeeded+$max_len[$jn];
1913: }
1914: if ($space_neeeded<=$available_space) {
1915: for (my $jn=0;$jn<=$#max_len;$jn++) {
1916: if ($fwidth[$jn]==0) {
1917: $fwidth[$jn]=$max_len[$jn];
1918: }
1919: }
1920: } else {
1921: #step 2. adjustment by minimum value (estimation)
1922: $space_neeeded=0;
1923: for (my $jn=0;$jn<=$#min_len;$jn++) {
1924: $space_neeeded+=$min_len[$jn];
1925: }
1926: if ($space_neeeded>$available_space) {
1927: $WARNING=' \textbf{NOT ENOUGH SPACE FOR TABLE} ';
1928: for (my $jn=0;$jn<=$#max_len;$jn++) {
1929: if ($fwidth[$jn]==0) {
1930: $fwidth[$jn]=$min_len[$jn];
1931: }
1932: }
1933: } else {
1934: #step 3. adjustment over minimal + corrections
1935: my $enlarge_coef=$available_space/$space_neeeded;
1936: my $acsessive=0;
1937: for (my $jn=0;$jn<=$#min_len;$jn++) {
1938: $adjust[$jn]=$min_len[$jn]*$enlarge_coef;
1939: if ($adjust[$jn]>$max_len[$jn]) {
1940: $fwidth[$jn]=$max_len[$jn];
1941: $acsessive=$acsessive+$adjust[$jn]-$max_len[$jn];
1942: $adjust[$jn]=0;
1943: }
1944: }
1945: if ($acsessive>0) {
1946: #we have an excess of space and can redistribute it
1947: my $notempty_columns=0;
1948: for (my $jn=0;$jn<=$#min_len;$jn++) {
1949: if ($adjust[$jn]!=0) {
1950: $notempty_columns++;
1951: }
1952: }
1953: my $per_column=$acsessive/$notempty_columns;
1954: for (my $jn=0;$jn<=$#min_len;$jn++) {
1955: if ($adjust[$jn]!=0) {
1956: $adjust[$jn]+=$per_column;
1957: $fwidth[$jn]=$adjust[$jn];
1958: }
1959: }
1960: }
1961: }
1962: }
1963: #recalculation for the use of all available width if width is defined in %
1964: if ($Apache::londefdef::table[-1]{'percent'}==1) {
1965: my $current=0;
1966: for (my $i=0;$i<=$#fwidth;$i++) {
1967: $current+=$fwidth[$i];
1968: }
1969: my $coef=$Apache::londefdef::table[-1]{'width'}/$current;
1970: for (my $i=0;$i<=$#fwidth;$i++) {
1971: $fwidth[$i]*=$coef;
1972: }
1973: }
1974: #removing of empty columns if allowed
1975: my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
1976: if ($permission eq 'yes') {
1977: my @cleaned_table=();
1978: my @cleaned_header=();
1979: my $colind=0;
1980: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
1981: if ($fwidth[$jn]!=0) {
1982: #we need to copy column
1983: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1984: $cleaned_table[$in][$colind]=$Apache::londefdef::table[-1]{'content'}[$in][$jn];
1985: $cleaned_header[$colind]=$fwidth[$jn];
1986: }
1987: $colind++;
1988: }
1989: }
1990: $Apache::londefdef::table[-1]{'content'}=\@cleaned_table;
1991: @fwidth=@cleaned_header;
1992: }
1993: #construct header of the table
1994: my $header_of_table = '{'.$Apache::londefdef::table[-1]{'vvinc'};
1995: for (my $in=0;$in<=$#fwidth;$in++) {
1996: $header_of_table.='p{'.$fwidth[$in].' mm}'.$Apache::londefdef::table[-1]{'vvinc'};
1997: }
1998: $header_of_table .= '}';
1999: #fill the table
2000: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2001: for (my $jn=0;$jn<=$#fwidth;$jn++) {
2002: if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
2003: $output.='\begin{center}';
2004: } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
2005: $output.=' \hfill \llap{'
2006: }
2007: $output.=$Apache::londefdef::table[-1]{'content'}[$in][$jn];
2008: if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
2009: $output.='\end{center}';
2010: } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
2011: $output.='} ';
2012: }
2013: if ($jn!=$#fwidth) {$output.=' '.$Apache::londefdef::table[-1]{'vinc'};}
2014: }
2015: $output.=' \\\\ '.$Apache::londefdef::table[-1]{'hinc'}.' ';
2016: }
2017: $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\vskip 0 mm ';
2018: if ($#Apache::londefdef::table > 0) {
2019: my $inmemory = $Apache::londefdef::table[-1]{'output'};
2020: pop @Apache::londefdef::table;
2021: push @{$Apache::londefdef::table[-1]{'include'}}, $inmemory;
2022: } else {
2023: $currentstring .= $Apache::londefdef::table[-1]{'output'};
2024: pop @Apache::londefdef::table;
2025: undef @Apache::londefdef::table;
2026: }
2027: }
2028: return $currentstring;
2029: }
2030:
2031: #-- <tr> tag (end tag optional)
2032: sub start_tr {
2033: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2034: my $currentstring = '';
2035: if ($target eq 'web') {
2036: $currentstring = $token->[4];
2037: } elsif ($target eq 'tex') {
2038: $Apache::londefdef::table[-1]{'row_number'}++;
2039: my $alignchar=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
2040: if ($alignchar ne '') {
2041: push @ {$Apache::londefdef::table[-1]{'rows'} },substr($alignchar,0,1);
2042: } else {
2043: push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l';
2044: }
2045: push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'});
2046: $Apache::londefdef::table[-1]{'counter_columns'} = -1;
2047: push @ {$Apache::londefdef::table[-1]{'TeXlen'}}, [];
2048: push @ {$Apache::londefdef::table[-1]{'objectlen'}}, [];
2049: push @ {$Apache::londefdef::table[-1]{'minlen'}}, [];
2050: push @ {$Apache::londefdef::table[-1]{'maxlen'}}, [];
2051: push @ {$Apache::londefdef::table[-1]{'content'}}, [];
2052: }
2053: return $currentstring;
2054: }
2055:
2056: sub end_tr {
2057: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2058: my $currentstring = '';
2059: if ($target eq 'web') {
2060: $currentstring = $token->[2];
2061: } elsif ($target eq 'tex') {
2062: if ($Apache::londefdef::TD_redirection) {
2063: &end_td_tex($parstack,$parser,$safeeval);
2064: }
2065: }
2066: return $currentstring;
2067: }
2068:
2069: #-- <td> tag (end tag optional)
2070: sub start_td {
2071: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2072: my $currentstring = '';
2073: if ($target eq 'web') {
2074: $currentstring = $token->[4];
2075: } elsif ($target eq 'tex') {
2076: $Apache::londefdef::TD_redirection = 1;
2077: &tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval);
2078: }
2079: return $currentstring;
2080: }
2081:
2082: sub tag_check {
2083: my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
2084: my @ar=@$parstack;
2085: for (my $i=$#ar-1;$i>=0;$i--) {
2086: if (lc($$tagstack[$i]) eq $good_tag) {
2087: &start_td_tex($parstack,$parser,$safeeval);
2088: last;
2089: } elsif (lc($$tagstack[$i]) eq $bad_tag) {
2090: splice @ar, $i+1;
2091: &end_td_tex(\@ar,$parser,$safeeval);
2092: &start_td_tex($parstack,$parser,$safeeval);
2093: last;
2094: }
2095: }
2096: return '';
2097: }
2098:
2099: sub start_td_tex {
2100: my ($parstack,$parser,$safeeval) = @_;
2101: my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
2102: if ($alignchar eq '') {
2103: $alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
2104: }
2105: push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
2106: $Apache::londefdef::table[-1]{'counter_columns'}++;
2107: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2108: if (defined $TeXwidth) {
2109: my $current_length=&recalc($TeXwidth);
2110: $current_length=~/(\d+\.?\d*)/;
2111: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
2112: }
2113: &Apache::lonxml::startredirection();
2114: return '';
2115: }
2116:
2117: sub end_td_tex {
2118: my ($parstack,$parser,$safeeval) = @_;
2119: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
2120: my $data=&Apache::lonxml::endredirection();
2121: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2122: if (defined $TeXwidth) {
2123: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2124: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2125: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2126: } else {
2127: if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
2128: my $garbage_data=$data;
2129: my $fwidth=0;
2130: while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2131: my $current_length=&recalc($1);
2132: $current_length=~/(\d+\.?\d*)/;
2133: if ($fwidth<$1) {$fwidth=$1;}
2134: $garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2135: }
2136: while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
2137: my $current_length=$1;
2138: if ($fwidth<$current_length) {$fwidth=$current_length;}
2139: $garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
2140: }
2141: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2142: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2143: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2144: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2145: } else {
2146: $data=~s/^\s+(\S.*)/$1/;
2147: $data=~s/(.*\S)\s+$/$1/;
2148: $data=~s/(\s)+/$1/;
2149: my ($current_length,$min_length)=(0,0);
2150: if ($data=~/\\vskip/) {
2151: my $newdata=$data;
2152: $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
2153: my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
2154: foreach my $elementdata (@newdata) {
2155: my $lengthnewdata=2.5*&LATEX_length($elementdata);
2156: if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
2157: my @words=split(/ /,$elementdata);
2158: foreach my $word (@words) {
2159: my $lengthword=2.5*&LATEX_length($word);
2160: if ($min_length<$lengthword) {$min_length=$lengthword;}
2161: }
2162: }
2163: } else {
2164: $current_length=2.5*&LATEX_length($data);
2165: my @words=split(/ /,$data);
2166: foreach my $word (@words) {
2167: my $lengthword=2.5*&LATEX_length($word);
2168: if ($min_length<$lengthword) {$min_length=$lengthword;}
2169: }
2170: }
2171: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2172: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2173: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
2174: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
2175: }
2176: }
2177: for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {
2178: $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
2179: }
2180: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
2181: return'';
2182: }
2183:
2184: sub end_td {
2185: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2186: my $currentstring = '';
2187: if ($target eq 'web') {
2188: $currentstring = $token->[2];
2189: } elsif ($target eq 'tex') {
2190: $Apache::londefdef::TD_redirection =0;
2191: &end_td_tex($parstack,$parser,$safeeval);
2192: }
2193: return $currentstring;
2194: }
2195:
2196: #-- <th> tag (end tag optional)
2197: sub start_th {
2198: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2199: my $currentstring = '';
2200: if ($target eq 'web') {
2201: $currentstring = $token->[4];
2202: } elsif ($target eq 'tex') {
2203: my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
2204: if ($what_to_push eq '') {
2205: $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);;
2206: }
2207: push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push;
2208: $Apache::londefdef::table[-1]{'counter_columns'}++;
2209: &Apache::lonxml::startredirection();
2210: }
2211: return $currentstring;
2212: }
2213:
2214: sub end_th {
2215: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2216: my $currentstring = '';
2217: if ($target eq 'web') {
2218: $currentstring = $token->[2];
2219: } elsif ($target eq 'tex') {
2220: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
2221: my $data=&Apache::lonxml::endredirection();
2222: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2223: if (defined $TeXwidth) {
2224: my $current_length=&recalc($TeXwidth);
2225: $current_length=~/(\d+)/;
2226: $Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
2227: $Apache::londefdef::table[-1]{'length'} .= '0,';
2228: } else {
2229: if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2230: my $current_length=&recalc($1);
2231: $current_length=~/(\d+)/;
2232: $Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
2233: $Apache::londefdef::table[-1]{'length'} .= '0,';
2234: } else {
2235: $data=~/^\s*(\S.*)/;
2236: $data=$1;
2237: $data=~/(.*\S)\s*$/;
2238: $data=$1;
2239: my $current_length=2*length($data);
2240: $Apache::londefdef::table[-1]{'length'} .= $current_length.',';
2241: $Apache::londefdef::table[-1]{'TeXlength'} .= '0,';
2242: }
2243: }
2244: for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {
2245: $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
2246: }
2247: $data='\textbf{'.$data.'}';
2248: @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'};
2249: }
2250: return $currentstring;
2251: }
2252: #-- <img> tag (end tag forbidden)
2253: sub start_img {
2254: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2255: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,
2256: undef,1);
2257: if (not $src and ($target eq 'web' or $target eq 'tex')) {
2258: my $inside = &Apache::lonxml::get_all_text("/img",$parser);
2259: &Apache::lonnet::logthis("inside was $inside");
2260: return '';
2261: }
2262: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
2263: my $currentstring = '';
2264: my $scaling = .3;
2265: if ($target eq 'web') {
2266: if ($ENV{'browser.imagesuppress'} ne 'on') {
2267: $currentstring.= $token->[4];
2268: } else {
2269: my $alttag= &Apache::lonxml::get_param
2270: ('alt',$parstack,$safeeval,undef,1);
2271: unless ($alttag) {
2272: $alttag=&Apache::lonmeta::alttag
2273: ($Apache::lonxml::pwd[-1],$src);
2274: }
2275: $currentstring.='[IMAGE: '.$alttag.']';
2276: }
2277: } elsif ($target eq 'tex') {
2278: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
2279: #if uploaded restore the path
2280: if ($src=~/^\/uploaded\/([^\/]+)\/([^\/]+)\/simplepage\/([^\/]+)$/) {
2281: $src=&Apache::loncommon::propath($1,$2).'/userfiles/simplepage/'.$3;
2282: } elsif ($src=~/^\/uploaded\/([^\/]+)\/([^\/]+)\/aboutme\/([^\/]+)$/) {
2283: $src=&Apache::loncommon::propath($1,$2).'/userfiles/aboutme/'.$3;
2284: }
2285: #if original gif/jpg/png file exist do following:
2286: if (-e $src) {
2287: #what is the image size?
2288: my $width_param=&image_size($src,$scaling,$parstack,$safeeval);
2289: my ($file,$path)=&file_path($src);
2290: my $newsrc = $src;
2291: $newsrc =~ s/\.(gif|jpg|png)$/.eps/i;
2292: $file=~s/\.(gif|jpg|png)$/.eps/i;
2293: #where can we find the picture?
2294: if (-e $newsrc) {
2295: #eps counterpart for image exist
2296: if ($path) {
2297: $currentstring .= '\vskip 1 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
2298: }
2299: } else {
2300: #there is no eps counterpart for image - check for ps one
2301: $newsrc =~ s/\.eps$/\.ps/;
2302: if (-e $newsrc) {
2303: #ps counterpart for image exist
2304: $file =~ s/\.eps$/\.ps/;
2305: if ($path) {
2306: $currentstring .= '\vskip 1 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
2307: }
2308: } else {
2309: #care about eps dynamical generation
2310: $currentstring.='\vskip 1 mm '.&eps_generation($src,$file,$width_param);
2311: }
2312: }
2313: } else {
2314: #original image file doesn't exist so check the alt attribute
2315: my $alt =
2316: &Apache::lonxml::get_param('alt',$parstack,$safeeval,undef,1);
2317: unless ($alt) {
2318: $alt=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
2319: }
2320:
2321: if ($alt) {
2322: $currentstring .= ' '.$alt.' ';
2323: } else {
2324: #<allow> tag will care about replication
2325: }
2326: }
2327: } elsif ($target eq 'edit') {
2328: $currentstring .=&Apache::edit::tag_start($target,$token);
2329: $currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70).
2330: &Apache::edit::browse('src',undef,'alt').' '.
2331: &Apache::edit::search('src',undef,'alt').'<br />';
2332: $currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'<br />';
2333: $currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5);
2334: $currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'<br />';
2335: $currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5);
2336: $currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5);
2337: $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
2338: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval);
2339: my $alt=&Apache::lonxml::get_param('alt',$parstack,$safeeval);
2340: my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval);
2341: my $height=&Apache::lonxml::get_param('height',$parstack,$safeeval);
2342: $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
2343: if ($width) { $currentstring.=' width="'.$width.'" '; }
2344: if ($height) { $currentstring.=' height="'.$height.'" '; }
2345: $currentstring .= ' />';
2346: } elsif ($target eq 'modified') {
2347: my ($osrc,$owidth,$oheight)=
2348: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
2349: my $ctag=&Apache::edit::get_new_args($token,$parstack,
2350: $safeeval,'src','alt',
2351: 'TeXwidth','TeXheight',
2352: 'width','height');
2353: my ($nsrc,$nwidth,$nheight)=
2354: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
2355: my $loc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$nsrc);
2356: &image_replication($loc);
2357: my ($iwidth,$iheight);
2358: if (-e $loc) {
2359: my $image = Image::Magick->new;
2360: $image->Read($loc);
2361: ($iwidth, $iheight) = ($image->Get('width'),
2362: $image->Get('height'));
2363: }
2364: if ($osrc ne $nsrc || (!$nwidth && !$nheight)) {
2365: # changed image or no size specified,
2366: # if they didn't explicitly change the
2367: # width or height use the ones from the image
2368: if ($iwidth && $iheight) {
2369: if ($owidth == $nwidth || (!$nwidth && !$nheight)) {
2370: $token->[2]{'width'} = $iwidth;$ctag=1;
2371: }
2372: if ($oheight == $nheight || (!$nwidth && !$nheight)) {
2373: $token->[2]{'height'}=$iheight;$ctag=1;
2374: }
2375: }
2376: }
2377: my ($cwidth,$cheight)=($token->[2]{'width'},$token->[2]{'height'});
2378: # if we don't have a width or height
2379: if ($iwidth && $cwidth && !$cheight) {
2380: $token->[2]{'height'}=int(($cwidth/$iwidth)*$iheight);$ctag=1;
2381: }
2382: if ($iheight && $cheight && !$cwidth) {
2383: $token->[2]{'width'}=int(($cheight/$iheight)*$iwidth);$ctag=1;
2384: }
2385: if ($ctag) {$currentstring=&Apache::edit::rebuild_tag($token);}
2386: }
2387: return $currentstring;
2388: }
2389:
2390: sub end_img {
2391: my ($target,$token) = @_;
2392: my $currentstring = '';
2393: if ($target eq 'web') {
2394: $currentstring = $token->[2];
2395: } elsif ($target eq 'tex') {
2396: $currentstring = '';
2397: }
2398: return $currentstring;
2399: }
2400:
2401: #-- <applet> tag (end tag required)
2402: sub start_applet {
2403: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2404:
2405: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,undef,1);
2406: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$code;
2407:
2408: my $archive=&Apache::lonxml::get_param('archive',$parstack,$safeeval,
2409: undef,1);
2410: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$archive;
2411:
2412: my $currentstring = '';
2413: if ($target eq 'web') {
2414: if ($ENV{'browser.appletsuppress'} ne 'on') {
2415: $currentstring = $token->[4];
2416: } else {
2417: my $alttag= &Apache::lonxml::get_param('alt',$parstack,
2418: $safeeval,undef,1);
2419: unless ($alttag) {
2420: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
2421: $code);
2422: }
2423: $currentstring='[APPLET: '.$alttag.']';
2424: }
2425: } elsif ($target eq 'tex') {
2426: my $alttag= &Apache::lonxml::get_param('alt',$parstack,
2427: $safeeval,undef,1);
2428: unless ($alttag) {
2429: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,
2430: undef,1);
2431: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
2432: $code);
2433: }
2434: $currentstring.='\begin{center} \fbox{Java Applet: '.$alttag.
2435: '.}\end{center}';
2436: }
2437: return $currentstring;
2438: }
2439:
2440: sub end_applet {
2441: my ($target,$token) = @_;
2442: my $currentstring = '';
2443: if ($target eq 'web') {
2444: $currentstring = $token->[2];
2445: } elsif ($target eq 'tex') {
2446: }
2447: return $currentstring;
2448: }
2449:
2450: #-- <embed> tag (end tag optional/required)
2451: sub start_embed {
2452: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2453: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
2454: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
2455: my $currentstring = '';
2456: if ($target eq 'web') {
2457: if ($ENV{'browser.embedsuppress'} ne 'on') {
2458: $currentstring = $token->[4];
2459: } else {
2460: my $alttag=&Apache::lonxml::get_param
2461: ('alt',$parstack,$safeeval,undef,1);
2462: unless ($alttag) {
2463: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
2464: }
2465: $currentstring='[EMBED: '.$alttag.']';
2466: }
2467: } elsif ($target eq 'tex') {
2468: }
2469: return $currentstring;
2470: }
2471:
2472: sub end_embed {
2473: my ($target,$token) = @_;
2474: my $currentstring = '';
2475: if ($target eq 'web') {
2476: $currentstring = $token->[2];
2477: } elsif ($target eq 'tex') {
2478: }
2479: return $currentstring;
2480: }
2481:
2482: #-- <param> tag (end tag forbidden)
2483: sub start_param {
2484: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2485: if (&Apache::lonxml::get_param
2486: ('name',$parstack,$safeeval,undef,1)=~/^cabbase$/i) {
2487: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
2488: &Apache::lonxml::get_param('value',$parstack,$safeeval,undef,1);
2489: }
2490: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
2491: &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
2492: my $currentstring = '';
2493: if ($target eq 'web') {
2494: $currentstring = $token->[4];
2495: } elsif ($target eq 'tex') {
2496: }
2497: return $currentstring;
2498: }
2499:
2500: sub end_param {
2501: my ($target,$token) = @_;
2502: my $currentstring = '';
2503: if ($target eq 'web') {
2504: $currentstring = $token->[2];
2505: } elsif ($target eq 'tex') {
2506: }
2507: return $currentstring;
2508: }
2509:
2510: #-- <allow> tag
2511: sub start_allow {
2512: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2513: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
2514: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
2515: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
2516: &Apache::lonnet::clutter($src);
2517: &image_replication($src);
2518: my $result;
2519: if ($target eq 'edit') {
2520: $result .=&Apache::edit::tag_start($target,$token);
2521: $result .=&Apache::edit::text_arg('File Spec:','src',$token,70);
2522: $result .=&Apache::edit::end_row();#.&Apache::edit::start_spanning_row();
2523: } elsif ($target eq 'modified') {
2524: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
2525: $safeeval,'src');
2526: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
2527: }
2528: return $result;
2529: }
2530:
2531: sub end_allow {
2532: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2533: if ( $target eq 'edit') { return (&Apache::edit::end_table()); }
2534: return '';
2535: }
2536:
2537: #-- Frames (end tag required)
2538: #-- <frameset>
2539: sub start_frameset {
2540: my ($target,$token) = @_;
2541: my $currentstring = '';
2542: if ($target eq 'web') {
2543: if (!$Apache::lonxml::registered &&
2544: $ENV{'request.state'} eq 'published') {
2545: $currentstring.='<head>'.
2546: &Apache::lonmenu::registerurl(undef,$target).'</head>';
2547: }
2548: my $onLoad='';
2549: foreach my $key (keys(%{$token->[2]})) {
2550: if ($key =~ /^onload$/i) {
2551: $onLoad.=$token->[2]->{$key}.';';
2552: delete($token->[2]->{$key});
2553: }
2554: }
2555: $token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad;
2556: my $onUnload='';
2557: foreach my $key (keys(%{$token->[2]})) {
2558: if ($key =~ /^onunload$/i) {
2559: $onUnload.=$token->[2]->{$key}.';';
2560: delete($token->[2]->{$key});
2561: }
2562: }
2563: $token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents().
2564: ';'.$onUnload;
2565:
2566: $currentstring .= '<'.$token->[1];
2567: foreach (keys %{$token->[2]}) {
2568: $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
2569: }
2570: $currentstring.='>';
2571: }
2572: return $currentstring;
2573: }
2574:
2575: sub end_frameset {
2576: my ($target,$token) = @_;
2577: my $currentstring = '';
2578: if ($target eq 'web') {
2579: $currentstring = $token->[2];
2580: }
2581: return $currentstring;
2582: }
2583:
2584: #-- <xmp> (end tag required)
2585: sub start_xmp {
2586: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2587: my $currentstring = '';
2588: if ($target eq 'web') {
2589: $currentstring .= $token->[4];
2590: } elsif ($target eq 'tex') {
2591: $currentstring .= '\begin{verbatim}';
2592: }
2593: return $currentstring;
2594: }
2595:
2596: sub end_xmp {
2597: my ($target,$token) = @_;
2598: my $currentstring = '';
2599: if ($target eq 'web') {
2600: $currentstring .= $token->[2];
2601: } elsif ($target eq 'tex') {
2602: $currentstring .= '\end{verbatim}';
2603: }
2604: return $currentstring;
2605: }
2606:
2607: #-- <pre> (end tag required)
2608: sub start_pre {
2609: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2610: my $currentstring = '';
2611: if ($target eq 'web') {
2612: $currentstring .= $token->[4];
2613: } elsif ($target eq 'tex') {
2614: $currentstring .= '\begin{verbatim}';
2615: }
2616: return $currentstring;
2617: }
2618:
2619: sub end_pre {
2620: my ($target,$token) = @_;
2621: my $currentstring = '';
2622: if ($target eq 'web') {
2623: $currentstring .= $token->[2];
2624: } elsif ($target eq 'tex') {
2625: $currentstring .= '\end{verbatim}';
2626: }
2627: return $currentstring;
2628: }
2629:
2630: #-- <insert>
2631: sub start_insert {
2632: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2633: my $currentstring = '';
2634: if ($target eq 'web') {
2635: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
2636: $currentstring .= '<b>'.$display.'</b>';;
2637: }
2638: return $currentstring;
2639: }
2640:
2641: sub end_insert {
2642: my ($target,$token) = @_;
2643: my $currentstring = '';
2644: if ($target eq 'web') {
2645: $currentstring .= '';
2646: }
2647: return $currentstring;
2648: }
2649:
2650: #-- <externallink>
2651: sub start_externallink {
2652: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2653: my $currentstring = '';
2654: if ($target eq 'web') {
2655: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
2656: $currentstring .= '<b>'.$display.'</b>';;
2657: }
2658: return $currentstring;
2659: }
2660:
2661: sub end_externallink {
2662: my ($target,$token) = @_;
2663: my $currentstring = '';
2664: if ($target eq 'web') {
2665: $currentstring .= '';
2666: }
2667: return $currentstring;
2668: }
2669:
2670: #-- <blankspace heigth="">
2671: sub start_blankspace {
2672: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2673: my $currentstring = '';
2674: if ($target eq 'tex') {
2675: my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval,undef,1);
2676: $currentstring .= '\vskip '.$howmuch.' ';
2677: }
2678: return $currentstring;
2679: }
2680:
2681: sub end_blankspace {
2682: my ($target,$token) = @_;
2683: my $currentstring = '';
2684: if ($target eq 'tex') {
2685: $currentstring .= '';
2686: }
2687: return $currentstring;
2688: }
2689:
2690: #-- <abbr> tag (end tag required)
2691: sub start_abbr {
2692: my ($target,$token) = @_;
2693: my $currentstring = '';
2694: if ($target eq 'web') {
2695: $currentstring = $token->[4];
2696: }
2697: return $currentstring;
2698: }
2699:
2700: sub end_abbr {
2701: my ($target,$token) = @_;
2702: my $currentstring = '';
2703: if ($target eq 'web') {
2704: $currentstring = $token->[2];
2705: }
2706: return $currentstring;
2707: }
2708:
2709: #-- <acronym> tag (end tag required)
2710: sub start_acronym {
2711: my ($target,$token) = @_;
2712: my $currentstring = '';
2713: if ($target eq 'web') {
2714: $currentstring = $token->[4];
2715: }
2716: return $currentstring;
2717: }
2718:
2719: sub end_acronym {
2720: my ($target,$token) = @_;
2721: my $currentstring = '';
2722: if ($target eq 'web') {
2723: $currentstring = $token->[2];
2724: }
2725: return $currentstring;
2726: }
2727:
2728: #-- <area> tag (end tag forbidden)
2729: sub start_area {
2730: my ($target,$token) = @_;
2731: my $currentstring = '';
2732: if ($target eq 'web') {
2733: $currentstring = $token->[4];
2734: }
2735: return $currentstring;
2736: }
2737:
2738: sub end_area {
2739: my ($target,$token) = @_;
2740: my $currentstring = '';
2741: if ($target eq 'web') {
2742: $currentstring = $token->[2];
2743: }
2744: return $currentstring;
2745: }
2746:
2747: #-- <base> tag (end tag forbidden)
2748: sub start_base {
2749: my ($target,$token) = @_;
2750: my $currentstring = '';
2751: if ($target eq 'web') {
2752: $currentstring = $token->[4];
2753: }
2754: return $currentstring;
2755: }
2756:
2757: sub end_base {
2758: my ($target,$token) = @_;
2759: my $currentstring = '';
2760: if ($target eq 'web') {
2761: $currentstring = $token->[2];
2762: }
2763: return $currentstring;
2764: }
2765:
2766: #-- <bdo> tag (end tag required)
2767: sub start_bdo {
2768: my ($target,$token) = @_;
2769: my $currentstring = '';
2770: if ($target eq 'web') {
2771: $currentstring = $token->[4];
2772: }
2773: return $currentstring;
2774: }
2775:
2776: sub end_bdo {
2777: my ($target,$token) = @_;
2778: my $currentstring = '';
2779: if ($target eq 'web') {
2780: $currentstring = $token->[2];
2781: }
2782: return $currentstring;
2783: }
2784:
2785: #-- <bgsound> tag (end tag optional)
2786: sub start_bgsound {
2787: my ($target,$token) = @_;
2788: my $currentstring = '';
2789: if ($target eq 'web') {
2790: $currentstring = $token->[4];
2791: }
2792: return $currentstring;
2793: }
2794:
2795: sub end_bgsound {
2796: my ($target,$token) = @_;
2797: my $currentstring = '';
2798: if ($target eq 'web') {
2799: $currentstring = $token->[2];
2800: }
2801: return $currentstring;
2802: }
2803:
2804: #-- <blink> tag (end tag required)
2805: sub start_blink {
2806: my ($target,$token) = @_;
2807: my $currentstring = '';
2808: if ($target eq 'web') {
2809: $currentstring = $token->[4];
2810: }
2811: return $currentstring;
2812: }
2813:
2814: sub end_blink {
2815: my ($target,$token) = @_;
2816: my $currentstring = '';
2817: if ($target eq 'web') {
2818: $currentstring = $token->[2];
2819: }
2820: return $currentstring;
2821: }
2822:
2823: #-- <blockquote> tag (end tag required)
2824: sub start_blockquote {
2825: my ($target,$token) = @_;
2826: my $currentstring = '';
2827: if ($target eq 'web') {
2828: $currentstring = $token->[4];
2829: }
2830: return $currentstring;
2831: }
2832:
2833: sub end_blockquote {
2834: my ($target,$token) = @_;
2835: my $currentstring = '';
2836: if ($target eq 'web') {
2837: $currentstring = $token->[2];
2838: }
2839: return $currentstring;
2840: }
2841:
2842: #-- <button> tag (end tag required)
2843: sub start_button {
2844: my ($target,$token) = @_;
2845: my $currentstring = '';
2846: if ($target eq 'web') {
2847: $currentstring = $token->[4];
2848: }
2849: return $currentstring;
2850: }
2851:
2852: sub end_button {
2853: my ($target,$token) = @_;
2854: my $currentstring = '';
2855: if ($target eq 'web') {
2856: $currentstring = $token->[2];
2857: }
2858: return $currentstring;
2859: }
2860:
2861: #-- <caption> tag (end tag required)
2862: sub start_caption {
2863: my ($target,$token) = @_;
2864: my $currentstring = '';
2865: if ($target eq 'web') {
2866: $currentstring = $token->[4];
2867: }
2868: return $currentstring;
2869: }
2870:
2871: sub end_caption {
2872: my ($target,$token) = @_;
2873: my $currentstring = '';
2874: if ($target eq 'web') {
2875: $currentstring = $token->[2];
2876: }
2877: return $currentstring;
2878: }
2879:
2880: #-- <col> tag (end tag forbdden)
2881: sub start_col {
2882: my ($target,$token) = @_;
2883: my $currentstring = '';
2884: if ($target eq 'web') {
2885: $currentstring = $token->[4];
2886: }
2887: return $currentstring;
2888: }
2889:
2890: sub end_col {
2891: my ($target,$token) = @_;
2892: my $currentstring = '';
2893: if ($target eq 'web') {
2894: $currentstring = $token->[2];
2895: }
2896: return $currentstring;
2897: }
2898:
2899: #-- <colgroup> tag (end tag optional)
2900: sub start_colgroup {
2901: my ($target,$token) = @_;
2902: my $currentstring = '';
2903: if ($target eq 'web') {
2904: $currentstring = $token->[4];
2905: }
2906: return $currentstring;
2907: }
2908:
2909: sub end_colgroup {
2910: my ($target,$token) = @_;
2911: my $currentstring = '';
2912: if ($target eq 'web') {
2913: $currentstring = $token->[2];
2914: }
2915: return $currentstring;
2916: }
2917:
2918: #-- <del> tag (end tag required)
2919: sub start_del {
2920: my ($target,$token) = @_;
2921: my $currentstring = '';
2922: if ($target eq 'web') {
2923: $currentstring = $token->[4];
2924: }
2925: return $currentstring;
2926: }
2927:
2928: sub end_del {
2929: my ($target,$token) = @_;
2930: my $currentstring = '';
2931: if ($target eq 'web') {
2932: $currentstring = $token->[2];
2933: }
2934: return $currentstring;
2935: }
2936:
2937: #-- <fieldset> tag (end tag required)
2938: sub start_fieldset {
2939: my ($target,$token) = @_;
2940: my $currentstring = '';
2941: if ($target eq 'web') {
2942: $currentstring = $token->[4];
2943: }
2944: return $currentstring;
2945: }
2946:
2947: sub end_fieldset {
2948: my ($target,$token) = @_;
2949: my $currentstring = '';
2950: if ($target eq 'web') {
2951: $currentstring = $token->[2];
2952: }
2953: return $currentstring;
2954: }
2955:
2956: #-- <frame> tag (end tag forbidden)
2957: sub start_frame {
2958: my ($target,$token) = @_;
2959: my $currentstring = '';
2960: if ($target eq 'web') {
2961: $currentstring = $token->[4];
2962: }
2963: return $currentstring;
2964: }
2965:
2966: sub end_frame {
2967: my ($target,$token) = @_;
2968: my $currentstring = '';
2969: if ($target eq 'web') {
2970: $currentstring = $token->[2];
2971: }
2972: return $currentstring;
2973: }
2974:
2975: #-- <iframe> tag (end tag required)
2976: sub start_iframe {
2977: my ($target,$token) = @_;
2978: my $currentstring = '';
2979: if ($target eq 'web') {
2980: $currentstring = $token->[4];
2981: }
2982: return $currentstring;
2983: }
2984:
2985: sub end_iframe {
2986: my ($target,$token) = @_;
2987: my $currentstring = '';
2988: if ($target eq 'web') {
2989: $currentstring = $token->[2];
2990: }
2991: return $currentstring;
2992: }
2993:
2994: #-- <ins> tag (end tag required)
2995: sub start_ins {
2996: my ($target,$token) = @_;
2997: my $currentstring = '';
2998: if ($target eq 'web') {
2999: $currentstring = $token->[4];
3000: }
3001: return $currentstring;
3002: }
3003:
3004: sub end_ins {
3005: my ($target,$token) = @_;
3006: my $currentstring = '';
3007: if ($target eq 'web') {
3008: $currentstring = $token->[2];
3009: }
3010: return $currentstring;
3011: }
3012:
3013: #-- <isindex> tag (end tag forbidden)
3014: sub start_isindex {
3015: my ($target,$token) = @_;
3016: my $currentstring = '';
3017: if ($target eq 'web') {
3018: $currentstring = $token->[4];
3019: }
3020: return $currentstring;
3021: }
3022:
3023: sub end_isindex {
3024: my ($target,$token) = @_;
3025: my $currentstring = '';
3026: if ($target eq 'web') {
3027: $currentstring = $token->[2];
3028: }
3029: return $currentstring;
3030: }
3031:
3032: #-- <keygen> tag (end tag forbidden)
3033: sub start_keygen {
3034: my ($target,$token) = @_;
3035: my $currentstring = '';
3036: if ($target eq 'web') {
3037: $currentstring = $token->[4];
3038: }
3039: return $currentstring;
3040: }
3041:
3042: sub end_keygen {
3043: my ($target,$token) = @_;
3044: my $currentstring = '';
3045: if ($target eq 'web') {
3046: $currentstring = $token->[2];
3047: }
3048: return $currentstring;
3049: }
3050:
3051: #-- <label> tag
3052: sub start_label {
3053: my ($target,$token) = @_;
3054: my $currentstring = '';
3055: if ($target eq 'web') {
3056: $currentstring = $token->[4];
3057: }
3058: return $currentstring;
3059: }
3060:
3061: sub end_label {
3062: my ($target,$token) = @_;
3063: my $currentstring = '';
3064: if ($target eq 'web') {
3065: $currentstring = $token->[2];
3066: }
3067: return $currentstring;
3068: }
3069:
3070: #-- <layer> tag (end tag required)
3071: sub start_layer {
3072: my ($target,$token) = @_;
3073: my $currentstring = '';
3074: if ($target eq 'web') {
3075: $currentstring = $token->[4];
3076: }
3077: return $currentstring;
3078: }
3079:
3080: sub end_layer {
3081: my ($target,$token) = @_;
3082: my $currentstring = '';
3083: if ($target eq 'web') {
3084: $currentstring = $token->[2];
3085: }
3086: return $currentstring;
3087: }
3088:
3089: #-- <legend> tag (end tag required)
3090: sub start_legend {
3091: my ($target,$token) = @_;
3092: my $currentstring = '';
3093: if ($target eq 'web') {
3094: $currentstring = $token->[4];
3095: }
3096: return $currentstring;
3097: }
3098:
3099: sub end_legend {
3100: my ($target,$token) = @_;
3101: my $currentstring = '';
3102: if ($target eq 'web') {
3103: $currentstring = $token->[2];
3104: }
3105: return $currentstring;
3106: }
3107:
3108: #-- <link> tag (end tag forbidden)
3109: sub start_link {
3110: my ($target,$token) = @_;
3111: my $currentstring = '';
3112: if ($target eq 'web') {
3113: $currentstring = $token->[4];
3114: }
3115: return $currentstring;
3116: }
3117:
3118: sub end_link {
3119: my ($target,$token) = @_;
3120: my $currentstring = '';
3121: if ($target eq 'web') {
3122: $currentstring = $token->[2];
3123: }
3124: return $currentstring;
3125: }
3126:
3127: #-- <marquee> tag (end tag optional)
3128: sub start_marquee {
3129: my ($target,$token) = @_;
3130: my $currentstring = '';
3131: if ($target eq 'web') {
3132: $currentstring = $token->[4];
3133: }
3134: return $currentstring;
3135: }
3136:
3137: sub end_marquee {
3138: my ($target,$token) = @_;
3139: my $currentstring = '';
3140: if ($target eq 'web') {
3141: $currentstring = $token->[2];
3142: }
3143: return $currentstring;
3144: }
3145:
3146: #-- <multicol> tag (end tag required)
3147: sub start_multicol {
3148: my ($target,$token) = @_;
3149: my $currentstring = '';
3150: if ($target eq 'web') {
3151: $currentstring = $token->[4];
3152: }
3153: return $currentstring;
3154: }
3155:
3156: sub end_multicol {
3157: my ($target,$token) = @_;
3158: my $currentstring = '';
3159: if ($target eq 'web') {
3160: $currentstring = $token->[2];
3161: }
3162: return $currentstring;
3163: }
3164:
3165: #-- <nobr> tag (end tag required)
3166: sub start_nobr {
3167: my ($target,$token) = @_;
3168: my $currentstring = '';
3169: if ($target eq 'web') {
3170: $currentstring = $token->[4];
3171: } elsif ($target eq 'tex') {
3172: $currentstring='\mbox{';
3173: }
3174: return $currentstring;
3175: }
3176:
3177: sub end_nobr {
3178: my ($target,$token) = @_;
3179: my $currentstring = '';
3180: if ($target eq 'web') {
3181: $currentstring = $token->[2];
3182: } elsif ($target eq 'tex') {
3183: $currentstring='}';
3184: }
3185: return $currentstring;
3186: }
3187:
3188: #-- <noembed> tag (end tag required)
3189: sub start_noembed {
3190: my ($target,$token) = @_;
3191: my $currentstring = '';
3192: if ($target eq 'web') {
3193: $currentstring = $token->[4];
3194: }
3195: return $currentstring;
3196: }
3197:
3198: sub end_noembed {
3199: my ($target,$token) = @_;
3200: my $currentstring = '';
3201: if ($target eq 'web') {
3202: $currentstring = $token->[2];
3203: }
3204: return $currentstring;
3205: }
3206:
3207: #-- <noframes> tag (end tag required)
3208: sub start_noframes {
3209: my ($target,$token) = @_;
3210: my $currentstring = '';
3211: if ($target eq 'web') {
3212: $currentstring = $token->[4];
3213: }
3214: return $currentstring;
3215: }
3216:
3217: sub end_noframes {
3218: my ($target,$token) = @_;
3219: my $currentstring = '';
3220: if ($target eq 'web') {
3221: $currentstring = $token->[2];
3222: }
3223: return $currentstring;
3224: }
3225:
3226: #-- <nolayer> tag (end tag required)
3227: sub start_nolayer {
3228: my ($target,$token) = @_;
3229: my $currentstring = '';
3230: if ($target eq 'web') {
3231: $currentstring = $token->[4];
3232: }
3233: return $currentstring;
3234: }
3235:
3236: sub end_nolayer {
3237: my ($target,$token) = @_;
3238: my $currentstring = '';
3239: if ($target eq 'web') {
3240: $currentstring = $token->[2];
3241: }
3242: return $currentstring;
3243: }
3244:
3245: #-- <noscript> tag (end tag required)
3246: sub start_noscript {
3247: my ($target,$token) = @_;
3248: my $currentstring = '';
3249: if ($target eq 'web') {
3250: $currentstring = $token->[4];
3251: }
3252: return $currentstring;
3253: }
3254:
3255: sub end_noscript {
3256: my ($target,$token) = @_;
3257: my $currentstring = '';
3258: if ($target eq 'web') {
3259: $currentstring = $token->[2];
3260: }
3261: return $currentstring;
3262: }
3263:
3264: #-- <object> tag (end tag required)
3265: sub start_object {
3266: my ($target,$token) = @_;
3267: my $currentstring = '';
3268: if ($target eq 'web') {
3269: $currentstring = $token->[4];
3270: }
3271: return $currentstring;
3272: }
3273:
3274: sub end_object {
3275: my ($target,$token) = @_;
3276: my $currentstring = '';
3277: if ($target eq 'web') {
3278: $currentstring = $token->[2];
3279: }
3280: return $currentstring;
3281: }
3282:
3283: #-- <optgroup> tag (end tag required)
3284: sub start_optgroup {
3285: my ($target,$token) = @_;
3286: my $currentstring = '';
3287: if ($target eq 'web') {
3288: $currentstring = $token->[4];
3289: }
3290: return $currentstring;
3291: }
3292:
3293: sub end_optgroup {
3294: my ($target,$token) = @_;
3295: my $currentstring = '';
3296: if ($target eq 'web') {
3297: $currentstring = $token->[2];
3298: }
3299: return $currentstring;
3300: }
3301:
3302: #-- <samp> tag (end tag required)
3303: sub start_samp {
3304: my ($target,$token) = @_;
3305: my $currentstring = '';
3306: if ($target eq 'web') {
3307: $currentstring = $token->[4];
3308: } elsif ($target eq 'tex') {
3309: $currentstring='\texttt{';
3310: }
3311: return $currentstring;
3312: }
3313:
3314: sub end_samp {
3315: my ($target,$token) = @_;
3316: my $currentstring = '';
3317: if ($target eq 'web') {
3318: $currentstring = $token->[2];
3319: } elsif ($target eq 'tex') {
3320: $currentstring='}';
3321: }
3322: return $currentstring;
3323: }
3324:
3325: #-- <server> tag
3326: sub start_server {
3327: my ($target,$token) = @_;
3328: my $currentstring = '';
3329: if ($target eq 'web') {
3330: $currentstring = $token->[4];
3331: }
3332: return $currentstring;
3333: }
3334:
3335: sub end_server {
3336: my ($target,$token) = @_;
3337: my $currentstring = '';
3338: if ($target eq 'web') {
3339: $currentstring = $token->[2];
3340: }
3341: return $currentstring;
3342: }
3343:
3344: #-- <spacer> tag (end tag forbidden)
3345: sub start_spacer {
3346: my ($target,$token) = @_;
3347: my $currentstring = '';
3348: if ($target eq 'web') {
3349: $currentstring = $token->[4];
3350: }
3351: return $currentstring;
3352: }
3353:
3354: sub end_spacer {
3355: my ($target,$token) = @_;
3356: my $currentstring = '';
3357: if ($target eq 'web') {
3358: $currentstring = $token->[2];
3359: }
3360: return $currentstring;
3361: }
3362:
3363: #-- <span> tag (end tag required)
3364: sub start_span {
3365: my ($target,$token) = @_;
3366: my $currentstring = '';
3367: if ($target eq 'web') {
3368: $currentstring = $token->[4];
3369: }
3370: return $currentstring;
3371: }
3372:
3373: sub end_span {
3374: my ($target,$token) = @_;
3375: my $currentstring = '';
3376: if ($target eq 'web') {
3377: $currentstring = $token->[2];
3378: }
3379: return $currentstring;
3380: }
3381:
3382: #-- <tbody> tag (end tag optional)
3383: sub start_tbody {
3384: my ($target,$token) = @_;
3385: my $currentstring = '';
3386: if ($target eq 'web') {
3387: $currentstring = $token->[4];
3388: }
3389: return $currentstring;
3390: }
3391:
3392: sub end_tbody {
3393: my ($target,$token) = @_;
3394: my $currentstring = '';
3395: if ($target eq 'web') {
3396: $currentstring = $token->[2];
3397: }
3398: return $currentstring;
3399: }
3400:
3401: #-- <tfoot> tag (end tag optional)
3402: sub start_tfoot {
3403: my ($target,$token) = @_;
3404: my $currentstring = '';
3405: if ($target eq 'web') {
3406: $currentstring = $token->[4];
3407: }
3408: return $currentstring;
3409: }
3410:
3411: sub end_tfoot {
3412: my ($target,$token) = @_;
3413: my $currentstring = '';
3414: if ($target eq 'web') {
3415: $currentstring = $token->[2];
3416: }
3417: return $currentstring;
3418: }
3419:
3420: #-- <thead> tag (end tag optional)
3421: sub start_thead {
3422: my ($target,$token) = @_;
3423: my $currentstring = '';
3424: if ($target eq 'web') {
3425: $currentstring = $token->[4];
3426: }
3427: return $currentstring;
3428: }
3429:
3430: sub end_thead {
3431: my ($target,$token) = @_;
3432: my $currentstring = '';
3433: if ($target eq 'web') {
3434: $currentstring = $token->[2];
3435: }
3436: return $currentstring;
3437: }
3438:
3439: #-- <var> tag
3440: sub start_var {
3441: my ($target,$token) = @_;
3442: my $currentstring = '';
3443: if ($target eq 'web') {
3444: $currentstring = $token->[4];
3445: } elsif ($target eq 'tex') {
3446: $currentstring = '\textit{';
3447: }
3448: return $currentstring;
3449: }
3450:
3451: sub end_var {
3452: my ($target,$token) = @_;
3453: my $currentstring = '';
3454: if ($target eq 'web') {
3455: $currentstring = $token->[2];
3456: } elsif ($target eq 'tex') {
3457: $currentstring = '}';
3458: }
3459: return $currentstring;
3460: }
3461:
3462: #-- <wbr> tag (end tag forbidden)
3463: sub start_wbr {
3464: my ($target,$token) = @_;
3465: my $currentstring = '';
3466: if ($target eq 'web') {
3467: $currentstring = $token->[4];
3468: }
3469: return $currentstring;
3470: }
3471:
3472: sub end_wbr {
3473: my ($target,$token) = @_;
3474: my $currentstring = '';
3475: if ($target eq 'web') {
3476: $currentstring = $token->[2];
3477: }
3478: return $currentstring;
3479: }
3480:
3481: #-- <hideweboutput> tag
3482: sub start_hideweboutput {
3483: my ($target,$token) = @_;
3484: if ($target eq 'web') {
3485: &Apache::lonxml::startredirection();
3486: }
3487: return '';
3488: }
3489:
3490: sub end_hideweboutput {
3491: my ($target,$token) = @_;
3492: my $currentstring = '';
3493: if ($target eq 'web') {
3494: $currentstring = &Apache::lonxml::endredirection();
3495: }
3496: return '';
3497: }
3498:
3499:
3500: sub image_replication {
3501: my $src = shift;
3502: if (not -e $src) { &Apache::lonnet::repcopy($src); }
3503: #replicates eps or ps
3504: my $epssrc = my $pssrc = $src;
3505: $epssrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i;
3506: $pssrc =~ s/\.(gif|jpg|jpeg|png)$/.ps/i;
3507: if (not -e $epssrc && not -e $pssrc) {
3508: my $result=&Apache::lonnet::repcopy($epssrc);
3509: if ($result ne OK) { &Apache::lonnet::repcopy($pssrc); }
3510: }
3511: return '';
3512: }
3513:
3514: sub image_size {
3515: my ($src,$scaling,$parstack,$safeeval)=@_;
3516: #size of image from gif/jpg/jpeg/png
3517: my $image = Image::Magick->new;
3518: my $current_figure = $image->Read($src);
3519: my $width_param = $image->Get('width') * $scaling;;
3520: my $height_param = $image->Get('height') * $scaling;;
3521: undef $image;
3522: #do we have any specified LaTeX size of the picture?
3523: my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval);
3524: my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval);
3525: #do we have any specified web size of the picture?
3526: my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval,
3527: undef,1);
3528: if ($TeXwidth ne '') {
3529: if ($TeXwidth=~/(\d+)\s*\%/) {
3530: $width_param = $1*$ENV{'form.textwidth'}/100;
3531: } else {
3532: $width_param = $TeXwidth;
3533: }
3534: } elsif ($TeXheight ne '') {
3535: $width_param = $TeXheight/$height_param*$width_param;
3536: } elsif ($width ne '') {
3537: $width_param = $width*$scaling;
3538: }
3539: if ($width_param > $ENV{'form.textwidth'}) {$width_param =0.95*$ENV{'form.textwidth'}}
3540: return $width_param;
3541: }
3542:
3543: sub eps_generation {
3544: my ($src,$file,$width_param) = @_;
3545: my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat";
3546: my $temp_file = Apache::File->new('>>'.$filename);
3547: print $temp_file "$src\n";
3548: my $newsrc = $src;
3549: $newsrc =~ s/(\.gif|\.jpg|\.jpeg)$/\.eps/i;
3550: $newsrc=~s/\/home\/httpd\/html\/res//;
3551: $newsrc=~s/\/home\/([^\/]*)\/public_html\//\/$1\//;
3552: $newsrc=~s/\/\.\//\//;
3553: $newsrc=~s/\/([^\/]+)\.(ps|eps)/\//;
3554: if ($newsrc=~/\/home\/httpd\/lonUsers\//) {
3555: $newsrc=~s/\/home\/httpd\/lonUsers//;
3556: $newsrc=~s/\/([^\/]+)\/(\w)\/(\w)\/(\w)\//\/$1\//;
3557: }
3558: return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
3559: }
3560:
3561: sub file_path {
3562: my $src=shift;
3563: my ($file,$path);
3564: if ($src =~ m!(.*)/([^/]*)$!) {
3565: $file = $2;
3566: $path = $1.'/';
3567: }
3568: return $file,$path;
3569: }
3570:
3571: sub recalc {
3572: my $argument = shift;
3573: if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}
3574: $argument=~/\s*(\d+\.?\d*)\s*(mm|cm|in|pc|pt)/;
3575: my $value=$1;
3576: my $units=$2;
3577: if ($units eq 'cm') {
3578: $value*=10;
3579: } elsif ($units eq 'in') {
3580: $value*=25.4;
3581: } elsif ($units eq 'pc') {
3582: $value*=(25.4*12/72.27);
3583: } elsif ($units eq 'pt') {
3584: $value*=(25.4/72.27);
3585: }
3586: return $value.' mm';
3587: }
3588:
3589: sub LATEX_length {
3590: my $garbage=shift;
3591: $garbage=~s/^\s+$//;
3592: $garbage=~s/^\s+(\S.*)/$1/;#space before
3593: $garbage=~s/(.*\S)\s+$/$1/;#space after
3594: $garbage=~s/(\s)+/$1/;#only one space
3595: $garbage=~s/(\\begin{([^\}]+)}|\\end{([^\}]+)})//g;#remove LaTeX \begin{...} and \end{...}
3596: $garbage=~s/(\$\_\{|\$\_|\$\^{|\$\^|\}\$)//g;#remove $_{,$_,$^{,$^,}$
3597: $garbage=~s/([^\\])\$/$1/g;#$
3598: $garbage=~s/(\\ensuremath\{\_\{|\\ensuremath\{\_|\\ensuremath\{\^{|\\ensuremath\{\^|\})//g;#remove \ensuremath{...}
3599: $garbage=~s/(\\alpha|\\beta|\\gamma|\\delta|\\epsilon|\\verepsilon|\\zeta|\\eta|\\theta|\\vartheta|\\iota|\\kappa|\\lambda|\\mu|\\nu|\\xi|\\pi|\\varpi|\\rho|\\varrho|\\sigma|\\varsigma|\\tau|\\upsilon|\\phi|\\varphi|\\chi|\\psi|\\omega|\\Gamma|\\Delta|\\Theta|\\Lambda|\\Xi|\\Pi|\\Sigma|\\Upsilon|\\Phi|\\Psi|\\Omega)/1/g;
3600: $garbage=~s/(\\pm|\\mp|\\times|\\div|\\cdot|\\ast|\\star|\\dagger|\\ddagger|\\amalg|\\cap|\\cup|\\uplus|\\sqcap|\\sqcup|\\vee|\\wedge|\\oplus|\\ominus|\\otimes|\\circ|\\bullet|\\diamond|\\lhd|\\rhd|\\unlhd|\\unrhd|\\oslash|\\odot|\\bigcirc|\\Box|\\Diamond|\\bigtriangleup|\\bigtriangledown|\\triangleleft|\\triangleright|\\setminus|\\wr)/1/g;
3601: $garbage=~s/(\\le|\\ll|\\leq|\\ge|\\geq|\\gg|\\neq|\\doreq|\\sim|\\simeq|\\subset|\\subseteq|\\sqsubset|\\sqsubseteq|\\in|\\vdash|\\models|\\supset|\\supseteq|\\sqsupset|\\sqsupseteq|\\ni|\\dash|\\perp|\\approx|\\cong|\\equiv|\\propto|\\prec|\\preceq|\\parallel|\\asymp|\\smile|\\frown|\\bowtie|\\succ|\\succeq|\\mid)/1/g;
3602: $garbage=~s/(\\not<|\\\\not\\le|\\not\\prec|\\not\\preceq|\\not\\subset|\\not\\subseteq|\\not\\sqsubseteq|\\not\\in|\\not>|\\not\\ge|\\not\\succ|\\notsucceq|\\not\\supset|\\notsupseteq|\\not\\sqsupseteq|\\notin|\\not=|\\not\\equiv|\\not\\sim|\\not\\simeq|\\not\\approx|\\not\\cong|\\not\\asymp)/1/g;
3603: $garbage=~s/(\\leftarrow|\\gets|\\Leftarrow|\\rightarrow|\\to|\\Rightarrow|\\leftrightarrow|\\Leftrightarrow|\\mapsto|\\hookleftarrow|\\leftharpoonup|\\leftkarpoondown|\\rightleftharpoons|\\longleftarrow|\\Longleftarrow|\\longrightarrow|\\Longrightarrow|\\longleftrightarrow|\\Longleftrightarrow|\\longmapsto|\\hookrightarrow|\\rightharpoonup|\\rightharpoondown|\\uparrow|\\Uparrow|\\downarrow|\\Downarrow|\\updownarrow|\\Updownarrow|\\nearrow|\\searrow|\\swarrow|\\nwarrow)/11/g;
3604: $garbage=~s/(\\aleph|\\hbar|\\imath|\\jmath|\\ell|\\wp|\\Re|\\Im|\\mho|\\prime|\\emptyset|\\nabla|\\surd|\\partial|\\top|\\bot|\\vdash|\\dashv|\\forall|\\exists|\\neg|\\flat|\\natural|\\sharp|\\\||\\angle|\\backslash|\\Box|\\Diamond|\\triangle|\\clubsuit|\\diamondsuit|\\heartsuit|\\spadesuit|\\Join|\\infty)/11/g;
3605: $garbage=~s/(\\hat{([^}]+)}|\\check{([^}]+)}|\\dot{([^}]+)}|\\breve{([^}]+)}|\\acute{([^}]+)}|\\ddot{([^}]+)}|\\grave{([^}]+)}|\\tilde{([^}]+)}|\\mathring{([^}]+)}|\\bar{([^}]+)}|\\vec{([^}]+)})/$1/g;
3606: #remove some other LaTeX command
3607: $garbage=~s|\\(\w+)\\|\\|g;
3608: $garbage=~s|\\(\w+)(\s*)|$2|g;
3609: $garbage=~s|\+|11|g;
3610:
3611: &Apache::lonnet::logthis("garbage was just $garbage");
3612: my $value=length($garbage);
3613: return $value;
3614: }
3615:
3616:
3617:
3618:
3619: 1;
3620: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>