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