1: # The LearningOnline Network with CAPA
2: # Tags Default Definition Module
3: #
4: # $Id: londefdef.pm,v 1.247 2004/11/19 22:16:33 albertel Exp $
5: #
6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
28: ## Copyright for TtHfunc and TtMfunc by Ian Hutchinson.
29: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into
30: # binary executable programs or libraries distributed by the
31: # Michigan State University (the "Licensee"), but any binaries so
32: # distributed are hereby licensed only for use in the context
33: # of a program or computational system for which the Licensee is the
34: # primary author or distributor, and which performs substantial
35: # additional tasks beyond the translation of (La)TeX into HTML.
36: # The C source of the Code may not be distributed by the Licensee
37: # to any other parties under any circumstances.
38: #
39: #
40: # last modified 06/26/00 by Alexander Sakharuk
41: # 11/6,11/30,02/01/01,5/4 Gerd Kortemeyer
42: # 01/18 Alex Sakharuk
43:
44: package Apache::londefdef;
45:
46: use Apache::lonnet();
47: use strict;
48: use Apache::lonxml;
49: use Apache::File();
50: use Image::Magick;
51: use Apache::lonmenu();
52: use Apache::lonmeta();
53: use Apache::Constants qw(:common);
54:
55:
56: BEGIN {
57:
58: &Apache::lonxml::register('Apache::londefdef',('a','abbr','acronym','accessrule','address','allow','applet','area','b','base','basefont','bgo','bgsound','big','blink','blockquote','blankspace','body','br','button','caption','center','cite','code','col','colgroup','dd','del','dfn','dir','div','dl','dt','em','embed','externallink','fieldset','font','form','frame','frameset','h1','h2','h3','h4','h5','h6','head','hr','html','i','iframe','img','input','ins','insert','isindex','kbd','keygen','label','layer','legend','li','link','m','map','marquee','menu','meta','multicol','nobr','noembed','noframes','nolayer','noscript','object','ol','optgroup','option','output','p','param','pre','q','s','samp','select','server','small','spacer','span','strike','strong','sub','sup','table','tbody','td','textarea','tfoot','th','thead','title','tr','tt','tthoption','u','ul','var','wbr','hideweboutput'));
59:
60: }
61:
62: sub initialize_londefdef {
63: $Apache::londefdef::TD_redirection=0;
64: @Apache::londefdef::table = ();
65: $Apache::londefdef::select=0;
66: undef(@Apache::londefdef::description);
67: @Apache::londefdef::DD=(0);
68: @Apache::londefdef::DT=(0);
69: @Apache::londefdef::seenDT=(0);
70: $Apache::londefdef::list_index=0;
71: }
72:
73: #======================= TAG SUBROUTINES =====================
74: #-- <output>
75: sub start_output {
76: my ($target) = @_;
77: if ($target eq 'meta') { $Apache::lonxml::metamode--; }
78: return '';
79: }
80: sub end_output {
81: my ($target) = @_;
82: if ($target eq 'meta') { $Apache::lonxml::metamode++; }
83: return '';
84: }
85: #-- <m> tag
86: sub start_m {
87: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
88: my $currentstring = '';
89: my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser);
90: if ($target eq 'web' || $target eq 'analyze') {
91: $inside ='\\documentstyle{article}'.$inside;
92: &Apache::lonxml::debug("M is starting with:$inside:");
93: my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
94: if ($eval eq 'on') {
95: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
96: #&Apache::lonxml::debug("M is evaulated to:$inside:");
97: }
98: $currentstring = &Apache::lontexconvert::converted(\$inside);
99: if ($Apache::lontexconvert::errorstring) {
100: &Apache::lonxml::warning("tth error: ".
101: $Apache::lontexconvert::errorstring);
102: $Apache::lontexconvert::errorstring='';
103: }
104: #&Apache::lonxml::debug("M is ends with:$currentstring:");
105: $Apache::lonxml::post_evaluate=0;
106: } elsif ($target eq 'tex') {
107: $currentstring = $inside;
108: my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
109: if ($eval eq 'on') {
110: $currentstring=&Apache::run::evaluate($currentstring,$safeeval,$$parstack[-1]);
111: }
112: if ($currentstring=~/^(\s*\\\\\s*)*$/) {$currentstring = ' \vskip 0 mm ';}
113: $Apache::lonxml::post_evaluate=0;
114: }
115: return $currentstring;
116: }
117:
118: sub end_m {
119: my ($target,$token) = @_;
120: my $currentstring = '';
121: if ($target eq 'tex') {
122: $currentstring = "";
123: }
124: return $currentstring;
125: }
126:
127: sub start_tthoption {
128: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
129: my $result;
130: if ($target eq 'web') {
131: my $inside = &Apache::lonxml::get_all_text("/tthoption",$parser);
132: $inside=~s/^\s*//;
133: if ($ENV{'browser.mathml'}) {
134: &tth::ttmoptions($inside);
135: } else {
136: &tth::tthoptions($inside);
137: }
138: }
139: return $result;
140: }
141:
142: sub end_tthoption {
143: my ($target,$token) = @_;
144: my $result;
145: return $result;
146: }
147:
148: #-- <html> tag (end tag optional)
149: sub start_html {
150: my ($target,$token) = @_;
151: my $currentstring = '';
152: my $options=$ENV{'course.'.$ENV{'request.course.id'}.'.tthoptions'};
153: &Apache::lontexconvert::init_tth();
154: if ($target eq 'web' || $target eq 'edit') {
155: $currentstring = &Apache::lonxml::xmlbegin();
156: } elsif ($target eq 'tex') {
157: @Apache::londefdef::table = ();
158: $currentstring .= '\documentclass[letterpaper]{article}';
159: if ($ENV{'form.latex_type'}=~'batchmode') {$currentstring .='\batchmode';}
160: $currentstring .= '\newcommand{\keephidden}[1]{}'.
161: '\renewcommand{\deg}{$^{\circ}$}'.
162: '\usepackage{longtable}'.
163: '\usepackage{textcomp}'.
164: '\usepackage{makeidx}'.
165: '\usepackage[dvips]{graphicx}'.
166: '\usepackage{epsfig}'.
167: '\usepackage{calc}'.
168: '\usepackage{amsmath}'.
169: '\usepackage{amssymb}'.
170: '\usepackage{amsfonts}'.
171: '\usepackage{amsthm}'.
172: '\usepackage{amscd}'.
173: '\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}}'.
174: '\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}}';
175: }
176: return $currentstring;
177: }
178:
179: sub end_html {
180: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
181: my $currentstring = '';
182: if ($target eq 'web') {
183: $currentstring = &Apache::lonxml::xmlend($target,$parser);
184: }
185: return $currentstring;
186: }
187:
188: #-- <head> tag (end tag optional)
189: sub start_head {
190: my ($target,$token) = @_;
191: my $currentstring = '';
192: if ($target eq 'web') {
193: $currentstring = $token->[4].&Apache::lonxml::fontsettings();
194: }
195: return $currentstring;
196: }
197:
198: sub end_head {
199: my ($target,$token) = @_;
200: my $currentstring = '';
201: if ($target eq 'web' && $ENV{'request.state'} eq 'published') {
202: $currentstring = &Apache::lonmenu::registerurl(undef,$target).
203: $token->[2];
204: }
205: return $currentstring;
206: }
207:
208: #-- <map> tag (end tag required)
209: sub start_map {
210: my ($target,$token) = @_;
211: my $currentstring = '';
212: if ($target eq 'web') {
213: $currentstring = $token->[4];
214: }
215: return $currentstring;
216: }
217:
218: sub end_map {
219: my ($target,$token) = @_;
220: my $currentstring = '';
221: if ($target eq 'web') {
222: $currentstring = $token->[2];
223: }
224: return $currentstring;
225: }
226:
227: #-- <select> tag (end tag required)
228: sub start_select {
229: my ($target,$token) = @_;
230: my $currentstring = '';
231: if ($target eq 'web') {
232: $currentstring = $token->[4];
233: } elsif ($target eq 'tex') {
234: $Apache::londefdef::select=0;
235: }
236: return $currentstring;
237: }
238:
239: sub end_select {
240: my ($target,$token) = @_;
241: my $currentstring = '';
242: if ($target eq 'web') {
243: $currentstring = $token->[2];
244: }
245: return $currentstring;
246: }
247:
248: #-- <option> tag (end tag optional)
249: sub start_option {
250: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
251: my $currentstring = '';
252: if ($target eq 'web') {
253: $currentstring = $token->[4];
254: } elsif ($target eq 'tex') {
255: $Apache::londefdef::select++;
256: if ($Apache::londefdef::select == 1) {
257: $currentstring='\noindent\fbox{'.&Apache::lonxml::get_param('value',$parstack,$safeeval).'}\keephidden{';
258: } else {
259: $currentstring='\keephidden{';
260: }
261: }
262: return $currentstring;
263: }
264:
265: sub end_option {
266: my ($target,$token) = @_;
267: my $currentstring = '';
268: if ($target eq 'web') {
269: $currentstring = $token->[2];
270: } elsif ($target eq 'tex') {
271: $currentstring='}';
272: }
273: return $currentstring;
274: }
275:
276: #-- <input> tag (end tag forbidden)
277: sub start_input {
278: my ($target,$token) = @_;
279: my $currentstring = '';
280: if ($target eq 'web') {
281: $currentstring = $token->[4];
282: }
283: return $currentstring;
284: }
285:
286: sub end_input {
287: my ($target,$token) = @_;
288: my $currentstring = '';
289: if ($target eq 'web') {
290: $currentstring = $token->[2];
291: }
292: return $currentstring;
293: }
294:
295: #-- <textarea> tag (end tag required)
296: sub start_textarea {
297: my ($target,$token) = @_;
298: my $currentstring = '';
299: if ($target eq 'web') {
300: $currentstring = $token->[4];
301: }
302: return $currentstring;
303: }
304:
305: sub end_textarea {
306: my ($target,$token) = @_;
307: my $currentstring = '';
308: if ($target eq 'web') {
309: $currentstring = $token->[2];
310: }
311: return $currentstring;
312: }
313:
314: #-- <form> tag (end tag required)
315: sub start_form {
316: my ($target,$token) = @_;
317: my $currentstring = '';
318: if ($target eq 'web') {
319: $currentstring = $token->[4];
320: }
321: return $currentstring;
322: }
323:
324: sub end_form {
325: my ($target,$token) = @_;
326: my $currentstring = '';
327: if ($target eq 'web') {
328: $currentstring = $token->[2];
329: }
330: return $currentstring;
331: }
332:
333: #-- <title> tag (end tag required)
334: sub start_title {
335: my ($target,$token) = @_;
336: my $currentstring = '';
337: if ($target eq 'web') {
338: $currentstring = $token->[4];
339: } elsif ($target eq 'tex') {
340: $currentstring .= '\keephidden{Title of the document: '
341: }
342: if ($target eq 'meta') {
343: $currentstring='<title>';
344: &start_output($target);
345: }
346: return $currentstring;
347: }
348:
349: sub end_title {
350: my ($target,$token) = @_;
351: my $currentstring = '';
352: if ($target eq 'web') {
353: $currentstring = $token->[2];
354: } elsif ($target eq 'tex') {
355: $currentstring .= '}';
356: }
357: if ($target eq 'meta') {
358: &end_output($target);
359: $currentstring='</title>';
360: }
361: return $currentstring;
362: }
363:
364: #-- <meta> tag (end tag forbidden)
365: sub start_meta {
366: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
367: my $currentstring = '';
368: if ($target eq 'web') {
369: my $args='';
370: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
371: if ($args eq '') {
372: &Apache::lonxml::get_all_text("/meta",$parser);
373: } else {
374: $currentstring = $token->[4];
375: }
376: } elsif ($target eq 'meta') {
377: unless (&Apache::lonxml::get_param
378: ('http-equiv',$parstack,$safeeval,undef,1)) {
379: my $name=$token->[2]->{'name'};
380: $name=~tr/A-Z/a-z/;
381: $name=~s/\s/\_/gs;
382: $name=~s/\W//gs;
383: if ($name) {
384: $currentstring='<'.$name;
385: my $display=&Apache::lonxml::get_param
386: ('display',$parstack,$safeeval,undef,1);
387: if ($display) {
388: $display=~s/\"/\'/g;
389: $currentstring.=' display="'.$display.'"';
390: }
391: $currentstring.='>'.
392: &Apache::lonxml::get_param
393: ('content',$parstack,$safeeval,undef,1).
394: '</'.$name.'>';
395: }
396: my $display=&Apache::lonxml::get_param
397: ('display',$parstack,$safeeval,undef,1);
398: if ($display) {
399: $display=&HTML::Entities::encode($display,'<>&"');
400: $currentstring.='<'.$name.'.display>'.$display.
401: '</'.$name.'.display>';
402: }
403: }
404: } elsif ($target eq 'tex') {
405: my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval);
406: my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval);
407: if ((not defined $content) && (not defined $name)) {
408: &Apache::lonxml::startredirection();
409: }
410: }
411: return $currentstring;
412: }
413:
414: sub end_meta {
415: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
416: my $currentstring = '';
417: if ($target eq 'web') {
418: my $args='';
419: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
420: if ($args ne '') {
421: $currentstring = $token->[4];
422: }
423: } elsif ($target eq 'tex') {
424: my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval);
425: my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval);
426: if ((not defined $content) && (not defined $name)) {
427: &Apache::lonxml::endredirection();
428: }
429: }
430: return $currentstring;
431: }
432:
433: # accessrule
434: sub start_accessrule {
435: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
436: my $currentstring = '';
437: my $eff=&Apache::lonxml::get_param
438: ('effect',$parstack,$safeeval,undef,1);
439: my $realm=&Apache::lonxml::get_param
440: ('realm',$parstack,$safeeval,undef,1);
441: my $role=&Apache::lonxml::get_param
442: ('role',$parstack,$safeeval,undef,1);
443: $realm=~s/\s+//g;
444: $realm=~s/\//\_/g;
445: $realm=~s/^\_//;
446: $realm=~s/\W/\;/g;
447: $role=~s/\s+//g;
448: $role=~s/\//\_/g;
449: $role=~s/\W/\;/g;
450: if ($target eq 'web') {
451: my $args='';
452: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
453: if ($args eq '') {
454: &Apache::lonxml::get_all_text("/accessrule",$parser);
455: } else {
456: $currentstring = $token->[4];
457: }
458: }
459: if ($target eq 'meta') {
460: $currentstring='<rule>'.$eff.':'.$realm.':'.$role.'</rule>';
461: }
462: return $currentstring;
463: }
464:
465: sub end_accessrule {
466: my ($target,$token,$tagstack,$parstack,$parser) = @_;
467: my $currentstring = '';
468: if ($target eq 'web') {
469: my $args='';
470: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
471: if ($args ne '') {
472: $currentstring = $token->[4];
473: }
474: }
475: return $currentstring;
476: }
477:
478: #-- <body> tag (end tag required)
479: sub start_body {
480: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
481: my $currentstring = '';
482:
483: if ($target eq 'web') {
484: if ($Apache::lonhomework::parsing_a_problem) {
485: &Apache::lonxml::warning("<body> tag found inside of <problem> tag this can cause problems.");
486: return '';
487: }
488: if (!$Apache::lonxml::registered &&
489: $ENV{'request.state'} eq 'published') {
490: $currentstring.='<head>'.
491: &Apache::lonmenu::registerurl(undef,$target).'</head>';
492: }
493: # Accessibility
494: if ($ENV{'browser.imagesuppress'} eq 'on') {
495: delete($token->[2]->{'background'});
496: }
497: if ($ENV{'browser.fontenhance'} eq 'on') {
498: my $style='';
499: foreach my $key (keys(%{$token->[2]})) {
500: if ($key =~ /^style$/i) {
501: $style.=$token->[2]->{$key}.';';
502: delete($token->[2]->{$key});
503: }
504: }
505: $token->[2]->{'style'}=$style.'; font-size: x-large;';
506: }
507: if ($ENV{'browser.blackwhite'} eq 'on') {
508: delete($token->[2]->{'font'});
509: delete($token->[2]->{'link'});
510: delete($token->[2]->{'alink'});
511: delete($token->[2]->{'vlink'});
512: delete($token->[2]->{'bgcolor'});
513: delete($token->[2]->{'background'});
514: }
515: # Overload loads
516: my $onLoad='';
517: foreach my $key (keys(%{$token->[2]})) {
518: if ($key =~ /^onload$/i) {
519: $onLoad.=$token->[2]->{$key}.';';
520: delete($token->[2]->{$key});
521: }
522: }
523: $token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad;
524: my $onUnload='';
525: foreach my $key (keys(%{$token->[2]})) {
526: if ($key =~ /^onunload$/i) {
527: $onUnload.=$token->[2]->{$key}.';';
528: delete($token->[2]->{$key});
529: }
530: }
531: $token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents().
532: ';'.$onUnload;
533:
534: if ($ENV{'request.state'} ne 'construct') {
535: $currentstring .= '<'.$token->[1];
536: }
537: foreach (keys %{$token->[2]}) {
538: $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
539: }
540: if ($ENV{'request.state'} ne 'construct') {
541: $currentstring.='>';
542: }
543: if ($ENV{'request.state'} ne 'published') {
544: my $remote=($ENV{'environment.remote'} ne 'off');
545: $currentstring=&Apache::loncommon::bodytag(undef,undef,
546: $currentstring,$remote);
547: $currentstring.=(<<EDITBUTTON);
548: <form method="post">
549: <input type="submit" name="editmode" accesskey="e" value="Edit" />
550: </form>
551: EDITBUTTON
552: } else {
553: $currentstring.=&Apache::lonmenu::menubuttons(undef,$target,1);
554: }
555: $currentstring.=&Apache::lonxml::message_location();
556: } elsif ($target eq 'tex') {
557: $currentstring = '\begin{document}';
558: }
559: return $currentstring;
560: }
561:
562: sub end_body {
563: my ($target,$token) = @_;
564: my $currentstring = '';
565: if ($target eq 'web') {
566: $currentstring = $token->[2];
567: } elsif ($target eq 'tex') {
568: $currentstring = '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}';
569: }
570: return $currentstring;
571: }
572:
573: #-- <center> tag (end tag required)
574: sub start_center {
575: my ($target,$token) = @_;
576: my $currentstring = '';
577: if ($target eq 'web') {
578: $currentstring = $token->[4];
579: } elsif ($target eq 'tex') {
580: $currentstring = '\begin{center}';
581: }
582: return $currentstring;
583: }
584:
585: sub end_center {
586: my ($target,$token) = @_;
587: my $currentstring = '';
588: if ($target eq 'web') {
589: $currentstring = $token->[2];
590: } elsif ($target eq 'tex') {
591: $currentstring = '\end{center}';
592: }
593: return $currentstring;
594: }
595:
596: #-- <b> tag (end tag required)
597: sub start_b {
598: my ($target,$token) = @_;
599: my $currentstring = '';
600: if ($target eq 'web') {
601: $currentstring = $token->[4];
602: } elsif ($target eq 'tex') {
603: $currentstring = '\textbf{';
604: }
605: return $currentstring;
606: }
607:
608: sub end_b {
609: my ($target,$token) = @_;
610: my $currentstring = '';
611: if ($target eq 'web') {
612: $currentstring = $token->[2];
613: } elsif ($target eq 'tex') {
614: $currentstring = '}';
615: }
616: return $currentstring;
617: }
618:
619: #-- <strong> tag (end tag required)
620: sub start_strong {
621: my ($target,$token) = @_;
622: my $currentstring = '';
623: if ($target eq 'web') {
624: $currentstring = $token->[4];
625: } elsif ($target eq 'tex') {
626: $currentstring = '\textbf{';
627: }
628: return $currentstring;
629: }
630:
631: sub end_strong {
632: my ($target,$token) = @_;
633: my $currentstring = '';
634: if ($target eq 'web') {
635: $currentstring = $token->[2];
636: } elsif ($target eq 'tex') {
637: $currentstring = '}';
638: }
639: return $currentstring;
640: }
641:
642: #-- <h1> tag (end tag required)
643: sub start_h1 {
644: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
645: my $currentstring = '';
646: if ($target eq 'web') {
647: $currentstring .= $token->[4];
648: } elsif ($target eq 'tex') {
649: my $pre;
650: my $align=lc(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1));
651: if ($align eq 'center') {
652: $pre='\begin{center}';
653: } elsif ($align eq 'left') {
654: $pre='\rlap{';
655: } elsif ($align eq 'right') {
656: $pre=' \hfill \llap{';
657: }
658: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
659: if (not defined $TeXsize) {$TeXsize="large";}
660: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
661: } elsif ($target eq 'meta') {
662: $currentstring='<subject>';
663: &start_output($target);
664: }
665: return $currentstring;
666: }
667:
668: sub end_h1 {
669: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
670: my $currentstring = '';
671: if ($target eq 'web') {
672: $currentstring .= $token->[2];
673: } elsif ($target eq 'tex') {
674: my $post='\vskip 0 mm ';
675: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
676: if ($align eq 'center') {
677: $post='\end{center}';
678: } elsif ($align eq 'left') {
679: $post='} \hfill'.'\vskip 0 mm ';
680: } elsif ($align eq 'right') {
681: $post='}'.'\vskip 0 mm ';
682: }
683: $currentstring .= '}}'.$post;
684: } elsif ($target eq 'meta') {
685: &end_output($target);
686: $currentstring='</subject>';
687: }
688: return $currentstring;
689: }
690:
691: #-- <h2> tag
692: sub start_h2 {
693: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
694: my $currentstring = '';
695: if ($target eq 'web') {
696: $currentstring .= $token->[4];
697: } elsif ($target eq 'tex') {
698: my $pre;
699: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
700: if ($align eq 'center') {
701: $pre='\begin{center}';
702: } elsif ($align eq 'left') {
703: $pre='\rlap{';
704: } elsif ($align eq 'right') {
705: $pre=' \hfill \llap{';
706: }
707: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
708: if (not defined $TeXsize) {$TeXsize="large";}
709: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
710: }
711: return $currentstring;
712: }
713:
714: sub end_h2 {
715: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
716: my $currentstring = '';
717: if ($target eq 'web') {
718: $currentstring .= $token->[2];
719: } elsif ($target eq 'tex') {
720: my $post='\vskip 0 mm ';
721: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
722: if ($align eq 'center') {
723: $post='\end{center}';
724: } elsif ($align eq 'left') {
725: $post='} \hfill'.'\vskip 0 mm ';
726: } elsif ($align eq 'right') {
727: $post='}'.'\vskip 0 mm ';
728: }
729: $currentstring .= '}}'.$post;
730: }
731: return $currentstring;
732: }
733:
734: #-- <h3> tag
735: sub start_h3 {
736: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
737: my $currentstring = '';
738: if ($target eq 'web') {
739: $currentstring .= $token->[4];
740: } elsif ($target eq 'tex') {
741: my $pre;
742: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
743: if ($align eq 'center') {
744: $pre='\begin{center}';
745: } elsif ($align eq 'left') {
746: $pre='\rlap{';
747: } elsif ($align eq 'right') {
748: $pre=' \hfill \llap{';
749: }
750: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
751: if (not defined $TeXsize) {$TeXsize="large";}
752: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
753: }
754: return $currentstring;
755: }
756:
757: sub end_h3 {
758: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
759: my $currentstring = '';
760: if ($target eq 'web') {
761: $currentstring .= $token->[2];
762: } elsif ($target eq 'tex') {
763: my $post='\vskip 0 mm ';
764: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
765: if ($align eq 'center') {
766: $post='\end{center}';
767: } elsif ($align eq 'left') {
768: $post='} \hfill'.'\vskip 0 mm ';
769: } elsif ($align eq 'right') {
770: $post='}'.'\vskip 0 mm ';
771: }
772: $currentstring .= '}}'.$post;
773: }
774: return $currentstring;
775: }
776:
777: #-- <h4> tag
778: sub start_h4 {
779: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
780: my $currentstring = '';
781: if ($target eq 'web') {
782: $currentstring .= $token->[4];
783: } elsif ($target eq 'tex') {
784: my $pre;
785: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
786: if ($align eq 'center') {
787: $pre='\begin{center}';
788: } elsif ($align eq 'left') {
789: $pre='\rlap{';
790: } elsif ($align eq 'right') {
791: $pre=' \hfill \llap{';
792: }
793: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
794: if (not defined $TeXsize) {$TeXsize="large";}
795: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
796: }
797: return $currentstring;
798: }
799:
800: sub end_h4 {
801: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
802: my $currentstring = '';
803: if ($target eq 'web') {
804: $currentstring .= $token->[2];
805: } elsif ($target eq 'tex') {
806: my $post='\vskip 0 mm ';
807: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
808: if ($align eq 'center') {
809: $post='\end{center}';
810: } elsif ($align eq 'left') {
811: $post='} \hfill'.'\vskip 0 mm ';
812: } elsif ($align eq 'right') {
813: $post='}'.'\vskip 0 mm ';
814: }
815: $currentstring .= '}}'.$post;
816: }
817: return $currentstring;
818: }
819:
820: #-- <h5> tag
821: sub start_h5 {
822: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
823: my $currentstring = '';
824: if ($target eq 'web') {
825: $currentstring .= $token->[4];
826: } elsif ($target eq 'tex') {
827: my $pre;
828: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
829: if ($align eq 'center') {
830: $pre='\begin{center}';
831: } elsif ($align eq 'left') {
832: $pre='\rlap{';
833: } elsif ($align eq 'right') {
834: $pre=' \hfill \llap{';
835: }
836: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
837: if (not defined $TeXsize) {$TeXsize="large";}
838: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
839: }
840: return $currentstring;
841: }
842:
843: sub end_h5 {
844: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
845: my $currentstring = '';
846: if ($target eq 'web') {
847: $currentstring .= $token->[2];
848: } elsif ($target eq 'tex') {
849: my $post='\vskip 0 mm ';
850: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
851: if ($align eq 'center') {
852: $post='\end{center}';
853: } elsif ($align eq 'left') {
854: $post='} \hfill'.'\vskip 0 mm ';
855: } elsif ($align eq 'right') {
856: $post='}'.'\vskip 0 mm ';
857: }
858: $currentstring .= '}}'.$post;
859: }
860: return $currentstring;
861: }
862:
863: #-- <h6> tag
864: sub start_h6 {
865: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
866: my $currentstring = '';
867: if ($target eq 'web') {
868: $currentstring .= $token->[4];
869: } elsif ($target eq 'tex') {
870: my $pre;
871: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
872: if ($align eq 'center') {
873: $pre='\begin{center}';
874: } elsif ($align eq 'left') {
875: $pre='\rlap{';
876: } elsif ($align eq 'right') {
877: $pre=' \hfill \llap{';
878: }
879: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
880: if (not defined $TeXsize) {$TeXsize="large";}
881: $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
882: }
883: return $currentstring;
884: }
885:
886: sub end_h6 {
887: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
888: my $currentstring = '';
889: if ($target eq 'web') {
890: $currentstring .= $token->[2];
891: } elsif ($target eq 'tex') {
892: my $post='\vskip 0 mm ';
893: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
894: if ($align eq 'center') {
895: $post='\end{center}';
896: } elsif ($align eq 'left') {
897: $post='} \hfill'.'\vskip 0 mm ';
898: } elsif ($align eq 'right') {
899: $post='}'.'\vskip 0 mm ';
900: }
901: $currentstring .= '}}'.$post;
902: }
903: return $currentstring;
904: }
905:
906: #--- <cite> tag (end tag required)
907: sub start_cite {
908: my ($target,$token) = @_;
909: my $currentstring = '';
910: if ($target eq 'web') {
911: $currentstring .= $token->[4];
912: } elsif ($target eq 'tex') {
913: $currentstring .= '\textit{';
914: }
915: return $currentstring;
916: }
917:
918: sub end_cite {
919: my ($target,$token) = @_;
920: my $currentstring = '';
921: if ($target eq 'web') {
922: $currentstring .= $token->[2];
923: } elsif ($target eq 'tex') {
924: $currentstring .= '}';
925: }
926: return $currentstring;
927: }
928:
929: #-- <i> tag (end tag required)
930: sub start_i {
931: my ($target,$token) = @_;
932: my $currentstring = '';
933: if ($target eq 'web') {
934: $currentstring .= $token->[4];
935: } elsif ($target eq 'tex') {
936: $currentstring .= '\textit{';
937: }
938: return $currentstring;
939: }
940:
941: sub end_i {
942: my ($target,$token) = @_;
943: my $currentstring = '';
944: if ($target eq 'web') {
945: $currentstring .= $token->[2];
946: } elsif ($target eq 'tex') {
947: $currentstring .= '}';
948: }
949: return $currentstring;
950: }
951:
952: #-- <address> tag (end tag required)
953: sub start_address {
954: my ($target,$token) = @_;
955: my $currentstring = '';
956: if ($target eq 'web') {
957: $currentstring .= $token->[4];
958: } elsif ($target eq 'tex') {
959: $currentstring .= '\textit{';
960: }
961: return $currentstring;
962: }
963:
964: sub end_address {
965: my ($target,$token) = @_;
966: my $currentstring = '';
967: if ($target eq 'web') {
968: $currentstring .= $token->[2];
969: } elsif ($target eq 'tex') {
970: $currentstring .= '}';
971: }
972: return $currentstring;
973: }
974:
975: #-- <dfn> tag (end tag required)
976: sub start_dfn {
977: my ($target,$token) = @_;
978: my $currentstring = '';
979: if ($target eq 'web') {
980: $currentstring .= $token->[4];
981: } elsif ($target eq 'tex') {
982: $currentstring .= '\textit{';
983: }
984: return $currentstring;
985: }
986:
987: sub end_dfn {
988: my ($target,$token) = @_;
989: my $currentstring = '';
990: if ($target eq 'web') {
991: $currentstring .= $token->[2];
992: } elsif ($target eq 'tex') {
993: $currentstring .= '}';
994: }
995: return $currentstring;
996: }
997:
998: #-- <tt> tag (end tag required)
999: sub start_tt {
1000: my ($target,$token) = @_;
1001: my $currentstring = '';
1002: if ($target eq 'web') {
1003: $currentstring .= $token->[4];
1004: } elsif ($target eq 'tex') {
1005: $currentstring .= '\texttt{';
1006: }
1007: return $currentstring;
1008: }
1009:
1010: sub end_tt {
1011: my ($target,$token) = @_;
1012: my $currentstring = '';
1013: if ($target eq 'web') {
1014: $currentstring .= $token->[2];
1015: } elsif ($target eq 'tex') {
1016: $currentstring .= '}';
1017: }
1018: return $currentstring;
1019: }
1020:
1021: #-- <kbd> tag (end tag required)
1022: sub start_kbd {
1023: my ($target,$token) = @_;
1024: my $currentstring = '';
1025: if ($target eq 'web') {
1026: $currentstring .= $token->[4];
1027: } elsif ($target eq 'tex') {
1028: $currentstring .= '\texttt{';
1029: }
1030: return $currentstring;
1031: }
1032:
1033: sub end_kbd {
1034: my ($target,$token) = @_;
1035: my $currentstring = '';
1036: if ($target eq 'web') {
1037: $currentstring .= $token->[2];
1038: } elsif ($target eq 'tex') {
1039: $currentstring .= '}';
1040: }
1041: return $currentstring;
1042: }
1043:
1044: #-- <code> tag (end tag required)
1045: sub start_code {
1046: my ($target,$token) = @_;
1047: my $currentstring = '';
1048: if ($target eq 'web') {
1049: $currentstring .= $token->[4];
1050: } elsif ($target eq 'tex') {
1051: $currentstring .= '\texttt{';
1052: }
1053: return $currentstring;
1054: }
1055:
1056: sub end_code {
1057: my ($target,$token) = @_;
1058: my $currentstring = '';
1059: if ($target eq 'web') {
1060: $currentstring .= $token->[2];
1061: } elsif ($target eq 'tex') {
1062: $currentstring .= '}';
1063: }
1064: return $currentstring;
1065: }
1066:
1067: #-- <em> tag (end tag required)
1068: sub start_em {
1069: my ($target,$token) = @_;
1070: my $currentstring = '';
1071: if ($target eq 'web') {
1072: $currentstring .= $token->[4];
1073: } elsif ($target eq 'tex') {
1074: $currentstring .= '\emph{';
1075: }
1076: return $currentstring;
1077: }
1078:
1079: sub end_em {
1080: my ($target,$token) = @_;
1081: my $currentstring = '';
1082: if ($target eq 'web') {
1083: $currentstring .= $token->[2];
1084: } elsif ($target eq 'tex') {
1085: $currentstring .= '}';
1086: }
1087: return $currentstring;
1088: }
1089:
1090: #-- <q> tag (end tag required)
1091: sub start_q {
1092: my ($target,$token) = @_;
1093: my $currentstring = '';
1094: if ($target eq 'web') {
1095: $currentstring .= $token->[4];
1096: } elsif ($target eq 'tex') {
1097: $currentstring .= '\emph{';
1098: }
1099: return $currentstring;
1100: }
1101:
1102: sub end_q {
1103: my ($target,$token) = @_;
1104: my $currentstring = '';
1105: if ($target eq 'web') {
1106: $currentstring .= $token->[2];
1107: } elsif ($target eq 'tex') {
1108: $currentstring .= '}';
1109: }
1110: return $currentstring;
1111: }
1112:
1113: #-- <p> tag (end tag optional)
1114: #optional attribute - align="center|left|right"
1115: sub start_p {
1116: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1117: my $currentstring = '';
1118: if ($target eq 'web') {
1119: $currentstring .= $token->[4];
1120: } elsif ($target eq 'tex') {
1121: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1122: if ($align eq 'center') {
1123: $currentstring='\begin{center}\par';
1124: } elsif ($align eq 'right') {
1125: $currentstring='\makebox['.$ENV{'form.textwidth'}.']{\hfill\llap{';
1126: } elsif ($align eq 'left') {
1127: $currentstring='\noindent\makebox['.$ENV{'form.textwidth'}.']{\rlap{';
1128: } else {
1129: $currentstring='\par ';
1130: }
1131: my $signal=1;#<p> does not work inside <b>...</b>
1132: foreach my $tag (@$tagstack) {if (lc($tag) eq 'b') {$signal=0;}
1133: if (!$signal) {$currentstring = '';}
1134: }
1135: }
1136: return $currentstring;
1137: }
1138:
1139: sub end_p {
1140: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1141: my $currentstring = '';
1142: if ($target eq 'web') {
1143: $currentstring .= $token->[2];
1144: } elsif ($target eq 'tex') {
1145: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1146: if (not defined $align) {
1147: $currentstring.='\strut\\\\\strut ';
1148: } elsif ($align eq 'center') {
1149: $currentstring .= '\end{center}';
1150: } elsif ($align eq 'right') {
1151: $currentstring .= '}}';
1152: } elsif ($align eq 'left') {
1153: $currentstring .= '}\hfill}';
1154: }
1155: }
1156: return $currentstring;
1157: }
1158:
1159: #-- <br> tag (end tag forbidden)
1160: sub start_br {
1161: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1162: my $currentstring = '';
1163: if ($target eq 'web') {
1164: $currentstring .= $token->[4];
1165: } elsif ($target eq 'tex') {
1166: my @tempo=@$tagstack;
1167: my $signal=0;
1168: for (my $i=$#tempo;$i>=0;$i--) {
1169: if (($tempo[$i] eq 'b') || ($tempo[$i] eq 'strong') ||
1170: ($tempo[$i] eq 'ol') || ($tempo[$i] eq 'ul') ||
1171: ($tempo[$i] eq 'td') || ($tempo[$i] eq 'th')) {
1172: $signal=1;
1173: last;
1174: }
1175: }
1176: if ($signal) {
1177: $currentstring .= ' \vskip 0 mm ';
1178: } elsif ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') {
1179: $currentstring .= '\strut \\\\ \strut ';
1180: }
1181: }
1182: return $currentstring;
1183: }
1184:
1185: sub end_br {
1186: my ($target,$token) = @_;
1187: my $currentstring = '';
1188: if ($target eq 'web') {
1189: $currentstring .= $token->[2];
1190: }
1191: return $currentstring;
1192: }
1193:
1194: #-- <big> tag (end tag required)
1195: sub start_big {
1196: my ($target,$token) = @_;
1197: my $currentstring = '';
1198: if ($target eq 'web') {
1199: $currentstring .= $token->[4];
1200: } elsif ($target eq 'tex') {
1201: $currentstring .= '{\large ';
1202: }
1203: return $currentstring;
1204: }
1205:
1206: sub end_big {
1207: my ($target,$token) = @_;
1208: my $currentstring = '';
1209: if ($target eq 'web') {
1210: $currentstring .= $token->[2];
1211: } elsif ($target eq 'tex') {
1212: $currentstring .= '}';
1213: }
1214: return $currentstring;
1215: }
1216:
1217: #-- <small> tag (end tag required)
1218: sub start_small {
1219: my ($target,$token) = @_;
1220: my $currentstring = '';
1221: if ($target eq 'web') {
1222: $currentstring .= $token->[4];
1223: } elsif ($target eq 'tex') {
1224: $currentstring .= '{\footnotesize ';
1225: }
1226: return $currentstring;
1227: }
1228:
1229: sub end_small {
1230: my ($target,$token) = @_;
1231: my $currentstring = '';
1232: if ($target eq 'web') {
1233: $currentstring .= $token->[2];
1234: } elsif ($target eq 'tex') {
1235: $currentstring .= '}';
1236: }
1237: return $currentstring;
1238: }
1239:
1240: #-- <basefont> tag (end tag forbidden)
1241: sub start_basefont {
1242: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1243: my $currentstring = '';
1244: if ($target eq 'web') {
1245: $currentstring = $token->[4];
1246: } elsif ($target eq 'tex') {
1247: my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1248: if (defined $basesize) {
1249: $currentstring = '{\\'.$basesize.' ';
1250: }
1251: }
1252: return $currentstring;
1253: }
1254:
1255: sub end_basefont {
1256: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1257: my $currentstring = '';
1258: if ($target eq 'web') {
1259: $currentstring = $token->[4];
1260: } elsif ($target eq 'tex') {
1261: my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1262: if (defined $basesize) {
1263: $currentstring = '}';
1264: }
1265: }
1266: return $currentstring;
1267: }
1268:
1269: #-- <font> tag (end tag required)
1270: sub start_font {
1271: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1272: my $currentstring = '';
1273: if ($target eq 'web') {
1274: my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
1275: if ($face!~/symbol/i) {
1276: if (($ENV{'browser.fontenhance'} eq 'on') ||
1277: ($ENV{'browser.blackwhite'} eq 'on')) { return ''; }
1278: }
1279: $currentstring = $token->[4];
1280: } elsif ($target eq 'tex') {
1281: my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1282: if (defined $fontsize) {
1283: $currentstring = '{\\'.$fontsize.' ';
1284: }
1285: }
1286: return $currentstring;
1287: }
1288:
1289: sub end_font {
1290: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1291: my $currentstring = '';
1292: if ($target eq 'web') {
1293: $currentstring = $token->[2];
1294: } elsif ($target eq 'tex') {
1295: my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1296: if (defined $fontsize) {
1297: $currentstring = '}';
1298: }
1299: }
1300: return $currentstring;
1301: }
1302:
1303: #-- <strike> tag (end tag required)
1304: sub start_strike {
1305: my ($target,$token) = @_;
1306: my $currentstring = '';
1307: if ($target eq 'web') {
1308: $currentstring .= $token->[4];
1309: } elsif ($target eq 'tex') {
1310: &Apache::lonxml::startredirection();
1311: }
1312: return $currentstring;
1313: }
1314:
1315: sub end_strike {
1316: my ($target,$token) = @_;
1317: my $currentstring = '';
1318: if ($target eq 'web') {
1319: $currentstring .= $token->[2];
1320: } elsif ($target eq 'tex') {
1321: $currentstring=&Apache::lonxml::endredirection();
1322: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1323: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1324: $currentstring=~s/(\S)\s*$/$1\}/;
1325: }
1326: return $currentstring;
1327: }
1328:
1329: #-- <s> tag (end tag required)
1330: sub start_s {
1331: my ($target,$token) = @_;
1332: my $currentstring = '';
1333: if ($target eq 'web') {
1334: $currentstring .= $token->[4];
1335: } elsif ($target eq 'tex') {
1336: &Apache::lonxml::startredirection();
1337: }
1338: return $currentstring;
1339: }
1340:
1341: sub end_s {
1342: my ($target,$token) = @_;
1343: my $currentstring = '';
1344: if ($target eq 'web') {
1345: $currentstring .= $token->[2];
1346: } elsif ($target eq 'tex') {
1347: $currentstring=&Apache::lonxml::endredirection();
1348: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1349: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1350: $currentstring=~s/(\S)\s*$/$1\}/;
1351: }
1352: return $currentstring;
1353: }
1354:
1355: #-- <sub> tag (end tag required)
1356: sub start_sub {
1357: my ($target,$token) = @_;
1358: my $currentstring = '';
1359: if ($target eq 'web') {
1360: $currentstring .= $token->[4];
1361: } elsif ($target eq 'tex') {
1362: $currentstring .= '\ensuremath{_{';
1363: }
1364: return $currentstring;
1365: }
1366:
1367: sub end_sub {
1368: my ($target,$token) = @_;
1369: my $currentstring = '';
1370: if ($target eq 'web') {
1371: $currentstring .= $token->[2];
1372: } elsif ($target eq 'tex') {
1373: $currentstring .= '}}';
1374: }
1375: return $currentstring;
1376: }
1377:
1378: #-- <sup> tag (end tag required)
1379: sub start_sup {
1380: my ($target,$token) = @_;
1381: my $currentstring = '';
1382: if ($target eq 'web') {
1383: $currentstring .= $token->[4];
1384: } elsif ($target eq 'tex') {
1385: $currentstring .= '\ensuremath{^{';
1386: }
1387: return $currentstring;
1388: }
1389:
1390: sub end_sup {
1391: my ($target,$token) = @_;
1392: my $currentstring = '';
1393: if ($target eq 'web') {
1394: $currentstring .= $token->[2];
1395: } elsif ($target eq 'tex') {
1396: $currentstring .= '}}';
1397: }
1398: return $currentstring;
1399: }
1400:
1401: #-- <hr> tag (end tag forbidden)
1402: sub start_hr {
1403: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1404: my $currentstring = '';
1405: if ($target eq 'web') {
1406: $currentstring .= $token->[4];
1407: } elsif ($target eq 'tex') {
1408: my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
1409: if (defined $LaTeXwidth) {
1410: if ($LaTeXwidth=~/^%/) {
1411: substr($LaTeXwidth,0,1)='';
1412: $LaTeXwidth=($LaTeXwidth/100).'\textwidth';
1413: }
1414: } else {
1415: $LaTeXwidth ='0.9\textwidth';
1416: }
1417: my ($pre,$post);
1418: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1419: if (($align eq 'center') || (not defined $align)) {
1420: $pre=''; $post='';
1421: } elsif ($align eq 'left') {
1422: $pre='\rlap{'; $post='} \hfill';
1423: } elsif ($align eq 'right') {
1424: $pre=' \hfill \llap{'; $post='}';
1425: }
1426: $currentstring .= ' \vskip 0 mm \noindent\makebox['.$LaTeXwidth.']{'.$pre.'\makebox['.
1427: $LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm ';
1428: }
1429: return $currentstring;
1430: }
1431:
1432: sub end_hr {
1433: my ($target,$token) = @_;
1434: my $currentstring = '';
1435: if ($target eq 'web') {
1436: $currentstring .= $token->[2];
1437: }
1438: return $currentstring;
1439: }
1440:
1441: #-- <div> tag (end tag required)
1442: sub start_div {
1443: my ($target,$token) = @_;
1444: my $currentstring = '';
1445: if ($target eq 'web') {
1446: $currentstring .= $token->[4];
1447: }
1448: return $currentstring;
1449: }
1450:
1451: sub end_div {
1452: my ($target,$token) = @_;
1453: my $currentstring = '';
1454: if ($target eq 'web') {
1455: $currentstring .= $token->[2];
1456: }
1457: return $currentstring;
1458: }
1459:
1460: #-- <a> tag (end tag required)
1461: sub start_a {
1462: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1463: my $currentstring = '';
1464: if ($target eq 'web') {
1465: $currentstring .= $token->[4];
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: sub start_img {
2423: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2424: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,
2425: undef,1);
2426: if (not $src and ($target eq 'web' or $target eq 'tex')) {
2427: my $inside = &Apache::lonxml::get_all_text("/img",$parser);
2428: return '';
2429: }
2430: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
2431: my $currentstring = '';
2432: my $scaling = .3;
2433: if ($target eq 'web') {
2434: if ($ENV{'browser.imagesuppress'} ne 'on') {
2435: $currentstring.= $token->[4];
2436: } else {
2437: my $alttag= &Apache::lonxml::get_param
2438: ('alt',$parstack,$safeeval,undef,1);
2439: unless ($alttag) {
2440: $alttag=&Apache::lonmeta::alttag
2441: ($Apache::lonxml::pwd[-1],$src);
2442: }
2443: $currentstring.='[IMAGE: '.$alttag.']';
2444: }
2445: } elsif ($target eq 'tex') {
2446: my $oldSRC=$src;
2447: $oldSRC=~s/\.(gif|jpg|png)$/\.eps/;
2448: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
2449: #if original gif/jpg/png file exist do following:
2450: if (-e $src) {
2451: #what is the image size?
2452: my $width_param=&image_size($src,$scaling,$parstack,$safeeval);
2453: my ($file,$path)=&file_path($src);
2454: my $newsrc = $src;
2455: $newsrc =~ s/\.(gif|jpg|png)$/.eps/i;
2456: &Apache::lonnet::repcopy($oldSRC);
2457: $file=~s/\.(gif|jpg|png)$/.eps/i;
2458: #where can we find the picture?
2459: if (-e $newsrc) {
2460: #eps counterpart for image exist
2461: if ($path) {
2462: $currentstring .= '\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
2463: }
2464: } else {
2465: #there is no eps counterpart for image - check for ps one
2466: $newsrc =~ s/\.eps$/\.ps/;
2467: if (-e $newsrc) {
2468: #ps counterpart for image exist
2469: $file =~ s/\.eps$/\.ps/;
2470: if ($path) {
2471: $currentstring .= '\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
2472: }
2473: } else {
2474: #care about eps dynamical generation
2475: $currentstring.=&eps_generation($src,$file,$width_param);
2476: }
2477: }
2478: } else {
2479: #original image file doesn't exist so check the alt attribute
2480: my $alt =
2481: &Apache::lonxml::get_param('alt',$parstack,$safeeval,undef,1);
2482: unless ($alt) {
2483: $alt=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
2484: }
2485:
2486: if ($alt) {
2487: $currentstring .= ' '.$alt.' ';
2488: } else {
2489: #<allow> tag will care about replication
2490: }
2491: }
2492: } elsif ($target eq 'edit') {
2493: $currentstring .=&Apache::edit::tag_start($target,$token);
2494: $currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70).
2495: &Apache::edit::browse('src',undef,'alt').' '.
2496: &Apache::edit::search('src',undef,'alt').'<br />';
2497: $currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'<br />';
2498: $currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5);
2499: $currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'<br />';
2500: $currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5);
2501: $currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5);
2502: $currentstring .=&Apache::edit::select_arg('Alignment:','align',
2503: ['','bottom','middle','top','left','right'],$token,5);
2504: $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
2505: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval);
2506: my $alt=&Apache::lonxml::get_param('alt',$parstack,$safeeval);
2507: my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval);
2508: my $height=&Apache::lonxml::get_param('height',$parstack,$safeeval);
2509: $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
2510: if ($width) { $currentstring.=' width="'.$width.'" '; }
2511: if ($height) { $currentstring.=' height="'.$height.'" '; }
2512: $currentstring .= ' />';
2513: } elsif ($target eq 'modified') {
2514: my ($osrc,$owidth,$oheight)=
2515: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
2516: my $ctag=&Apache::edit::get_new_args($token,$parstack,
2517: $safeeval,'src','alt','align',
2518: 'TeXwidth','TeXheight',
2519: 'width','height');
2520: my ($nsrc,$nwidth,$nheight)=
2521: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
2522: my $loc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$nsrc);
2523: &image_replication($loc);
2524: my ($iwidth,$iheight);
2525: if (-e $loc) {
2526: my $image = Image::Magick->new;
2527: $image->Read($loc);
2528: ($iwidth, $iheight) = ($image->Get('width'),
2529: $image->Get('height'));
2530: }
2531: if ($osrc ne $nsrc || (!$nwidth && !$nheight)) {
2532: # changed image or no size specified,
2533: # if they didn't explicitly change the
2534: # width or height use the ones from the image
2535: if ($iwidth && $iheight) {
2536: if ($owidth == $nwidth || (!$nwidth && !$nheight)) {
2537: $token->[2]{'width'} = $iwidth;$ctag=1;
2538: }
2539: if ($oheight == $nheight || (!$nwidth && !$nheight)) {
2540: $token->[2]{'height'}=$iheight;$ctag=1;
2541: }
2542: }
2543: }
2544: my ($cwidth,$cheight)=($token->[2]{'width'},$token->[2]{'height'});
2545: # if we don't have a width or height
2546: if ($iwidth && $cwidth && !$cheight) {
2547: $token->[2]{'height'}=int(($cwidth/$iwidth)*$iheight);$ctag=1;
2548: }
2549: if ($iheight && $cheight && !$cwidth) {
2550: $token->[2]{'width'}=int(($cheight/$iheight)*$iwidth);$ctag=1;
2551: }
2552: if ($ctag) {$currentstring=&Apache::edit::rebuild_tag($token);}
2553: }
2554: return $currentstring;
2555: }
2556:
2557: sub end_img {
2558: my ($target,$token) = @_;
2559: my $currentstring = '';
2560: if ($target eq 'web') {
2561: $currentstring = $token->[2];
2562: } elsif ($target eq 'tex') {
2563: $currentstring = '';
2564: }
2565: return $currentstring;
2566: }
2567:
2568: #-- <applet> tag (end tag required)
2569: sub start_applet {
2570: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2571:
2572: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,undef,1);
2573: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$code;
2574:
2575: my $archive=&Apache::lonxml::get_param('archive',$parstack,$safeeval,
2576: undef,1);
2577: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$archive;
2578:
2579: my $currentstring = '';
2580: if ($target eq 'web') {
2581: if ($ENV{'browser.appletsuppress'} ne 'on') {
2582: $currentstring = $token->[4];
2583: } else {
2584: my $alttag= &Apache::lonxml::get_param('alt',$parstack,
2585: $safeeval,undef,1);
2586: unless ($alttag) {
2587: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
2588: $code);
2589: }
2590: $currentstring='[APPLET: '.$alttag.']';
2591: }
2592: } elsif ($target eq 'tex') {
2593: my $alttag= &Apache::lonxml::get_param('alt',$parstack,
2594: $safeeval,undef,1);
2595: unless ($alttag) {
2596: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,
2597: undef,1);
2598: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
2599: $code);
2600: }
2601: $currentstring.='\begin{center} \fbox{Java Applet: '.$alttag.
2602: '.}\end{center}';
2603: }
2604: return $currentstring;
2605: }
2606:
2607: sub end_applet {
2608: my ($target,$token) = @_;
2609: my $currentstring = '';
2610: if ($target eq 'web') {
2611: $currentstring = $token->[2];
2612: } elsif ($target eq 'tex') {
2613: }
2614: return $currentstring;
2615: }
2616:
2617: #-- <embed> tag (end tag optional/required)
2618: sub start_embed {
2619: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2620: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
2621: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
2622: my $currentstring = '';
2623: if ($target eq 'web') {
2624: if ($ENV{'browser.embedsuppress'} ne 'on') {
2625: $currentstring = $token->[4];
2626: } else {
2627: my $alttag=&Apache::lonxml::get_param
2628: ('alt',$parstack,$safeeval,undef,1);
2629: unless ($alttag) {
2630: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
2631: }
2632: $currentstring='[EMBED: '.$alttag.']';
2633: }
2634: } elsif ($target eq 'tex') {
2635: }
2636: return $currentstring;
2637: }
2638:
2639: sub end_embed {
2640: my ($target,$token) = @_;
2641: my $currentstring = '';
2642: if ($target eq 'web') {
2643: $currentstring = $token->[2];
2644: } elsif ($target eq 'tex') {
2645: }
2646: return $currentstring;
2647: }
2648:
2649: #-- <param> tag (end tag forbidden)
2650: sub start_param {
2651: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2652: if (&Apache::lonxml::get_param
2653: ('name',$parstack,$safeeval,undef,1)=~/^cabbase$/i) {
2654: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
2655: &Apache::lonxml::get_param('value',$parstack,$safeeval,undef,1);
2656: }
2657: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
2658: &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
2659: my $currentstring = '';
2660: if ($target eq 'web') {
2661: $currentstring = $token->[4];
2662: } elsif ($target eq 'tex') {
2663: }
2664: return $currentstring;
2665: }
2666:
2667: sub end_param {
2668: my ($target,$token) = @_;
2669: my $currentstring = '';
2670: if ($target eq 'web') {
2671: $currentstring = $token->[2];
2672: } elsif ($target eq 'tex') {
2673: }
2674: return $currentstring;
2675: }
2676:
2677: #-- <allow> tag
2678: sub start_allow {
2679: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2680: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
2681: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
2682: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
2683: &Apache::lonnet::clutter($src);
2684: if ($target eq 'tex') { &image_replication($src); }
2685: my $result;
2686: if ($target eq 'edit') {
2687: $result .=&Apache::edit::tag_start($target,$token);
2688: $result .=&Apache::edit::text_arg('File Spec:','src',$token,70);
2689: $result .=&Apache::edit::end_row();#.&Apache::edit::start_spanning_row();
2690: } elsif ($target eq 'modified') {
2691: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
2692: $safeeval,'src');
2693: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
2694: }
2695: return $result;
2696: }
2697:
2698: sub end_allow {
2699: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2700: if ( $target eq 'edit') { return (&Apache::edit::end_table()); }
2701: return '';
2702: }
2703:
2704: #-- Frames (end tag required)
2705: #-- <frameset>
2706: sub start_frameset {
2707: my ($target,$token) = @_;
2708: my $currentstring = '';
2709: if ($target eq 'web') {
2710: if (!$Apache::lonxml::registered &&
2711: $ENV{'request.state'} eq 'published') {
2712: $currentstring.='<head>'.
2713: &Apache::lonmenu::registerurl(undef,$target).'</head>';
2714: }
2715: my $onLoad='';
2716: foreach my $key (keys(%{$token->[2]})) {
2717: if ($key =~ /^onload$/i) {
2718: $onLoad.=$token->[2]->{$key}.';';
2719: delete($token->[2]->{$key});
2720: }
2721: }
2722: $token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad;
2723: my $onUnload='';
2724: foreach my $key (keys(%{$token->[2]})) {
2725: if ($key =~ /^onunload$/i) {
2726: $onUnload.=$token->[2]->{$key}.';';
2727: delete($token->[2]->{$key});
2728: }
2729: }
2730: $token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents().
2731: ';'.$onUnload;
2732:
2733: $currentstring .= '<'.$token->[1];
2734: foreach (keys %{$token->[2]}) {
2735: $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
2736: }
2737: $currentstring.='>';
2738: }
2739: return $currentstring;
2740: }
2741:
2742: sub end_frameset {
2743: my ($target,$token) = @_;
2744: my $currentstring = '';
2745: if ($target eq 'web') {
2746: $currentstring = $token->[2];
2747: }
2748: return $currentstring;
2749: }
2750:
2751: #-- <xmp> (end tag required)
2752: sub start_xmp {
2753: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2754: my $currentstring = '';
2755: if ($target eq 'web') {
2756: $currentstring .= $token->[4];
2757: } elsif ($target eq 'tex') {
2758: $currentstring .= '\begin{verbatim}';
2759: }
2760: return $currentstring;
2761: }
2762:
2763: sub end_xmp {
2764: my ($target,$token) = @_;
2765: my $currentstring = '';
2766: if ($target eq 'web') {
2767: $currentstring .= $token->[2];
2768: } elsif ($target eq 'tex') {
2769: $currentstring .= '\end{verbatim}';
2770: }
2771: return $currentstring;
2772: }
2773:
2774: #-- <pre> (end tag required)
2775: sub start_pre {
2776: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2777: my $currentstring = '';
2778: if ($target eq 'web') {
2779: $currentstring .= $token->[4];
2780: } elsif ($target eq 'tex') {
2781: $currentstring .= '\begin{verbatim}';
2782: }
2783: return $currentstring;
2784: }
2785:
2786: sub end_pre {
2787: my ($target,$token) = @_;
2788: my $currentstring = '';
2789: if ($target eq 'web') {
2790: $currentstring .= $token->[2];
2791: } elsif ($target eq 'tex') {
2792: $currentstring .= '\end{verbatim}';
2793: }
2794: return $currentstring;
2795: }
2796:
2797: #-- <insert>
2798: sub start_insert {
2799: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2800: my $currentstring = '';
2801: if ($target eq 'web') {
2802: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
2803: $currentstring .= '<b>'.$display.'</b>';;
2804: }
2805: return $currentstring;
2806: }
2807:
2808: sub end_insert {
2809: my ($target,$token) = @_;
2810: my $currentstring = '';
2811: if ($target eq 'web') {
2812: $currentstring .= '';
2813: }
2814: return $currentstring;
2815: }
2816:
2817: #-- <externallink>
2818: sub start_externallink {
2819: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2820: my $currentstring = '';
2821: if ($target eq 'web') {
2822: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
2823: $currentstring .= '<b>'.$display.'</b>';;
2824: }
2825: return $currentstring;
2826: }
2827:
2828: sub end_externallink {
2829: my ($target,$token) = @_;
2830: my $currentstring = '';
2831: if ($target eq 'web') {
2832: $currentstring .= '';
2833: }
2834: return $currentstring;
2835: }
2836:
2837: #-- <blankspace heigth="">
2838: sub start_blankspace {
2839: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2840: my $currentstring = '';
2841: if ($target eq 'tex') {
2842: my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval,undef,1);
2843: $currentstring .= '\vskip '.$howmuch.' ';
2844: }
2845: return $currentstring;
2846: }
2847:
2848: sub end_blankspace {
2849: my ($target,$token) = @_;
2850: my $currentstring = '';
2851: if ($target eq 'tex') {
2852: $currentstring .= '';
2853: }
2854: return $currentstring;
2855: }
2856:
2857: #-- <abbr> tag (end tag required)
2858: sub start_abbr {
2859: my ($target,$token) = @_;
2860: my $currentstring = '';
2861: if ($target eq 'web') {
2862: $currentstring = $token->[4];
2863: }
2864: return $currentstring;
2865: }
2866:
2867: sub end_abbr {
2868: my ($target,$token) = @_;
2869: my $currentstring = '';
2870: if ($target eq 'web') {
2871: $currentstring = $token->[2];
2872: }
2873: return $currentstring;
2874: }
2875:
2876: #-- <acronym> tag (end tag required)
2877: sub start_acronym {
2878: my ($target,$token) = @_;
2879: my $currentstring = '';
2880: if ($target eq 'web') {
2881: $currentstring = $token->[4];
2882: }
2883: return $currentstring;
2884: }
2885:
2886: sub end_acronym {
2887: my ($target,$token) = @_;
2888: my $currentstring = '';
2889: if ($target eq 'web') {
2890: $currentstring = $token->[2];
2891: }
2892: return $currentstring;
2893: }
2894:
2895: #-- <area> tag (end tag forbidden)
2896: sub start_area {
2897: my ($target,$token) = @_;
2898: my $currentstring = '';
2899: if ($target eq 'web') {
2900: $currentstring = $token->[4];
2901: }
2902: return $currentstring;
2903: }
2904:
2905: sub end_area {
2906: my ($target,$token) = @_;
2907: my $currentstring = '';
2908: if ($target eq 'web') {
2909: $currentstring = $token->[2];
2910: }
2911: return $currentstring;
2912: }
2913:
2914: #-- <base> tag (end tag forbidden)
2915: sub start_base {
2916: my ($target,$token) = @_;
2917: my $currentstring = '';
2918: if ($target eq 'web') {
2919: $currentstring = $token->[4];
2920: }
2921: return $currentstring;
2922: }
2923:
2924: sub end_base {
2925: my ($target,$token) = @_;
2926: my $currentstring = '';
2927: if ($target eq 'web') {
2928: $currentstring = $token->[2];
2929: }
2930: return $currentstring;
2931: }
2932:
2933: #-- <bdo> tag (end tag required)
2934: sub start_bdo {
2935: my ($target,$token) = @_;
2936: my $currentstring = '';
2937: if ($target eq 'web') {
2938: $currentstring = $token->[4];
2939: }
2940: return $currentstring;
2941: }
2942:
2943: sub end_bdo {
2944: my ($target,$token) = @_;
2945: my $currentstring = '';
2946: if ($target eq 'web') {
2947: $currentstring = $token->[2];
2948: }
2949: return $currentstring;
2950: }
2951:
2952: #-- <bgsound> tag (end tag optional)
2953: sub start_bgsound {
2954: my ($target,$token) = @_;
2955: my $currentstring = '';
2956: if ($target eq 'web') {
2957: $currentstring = $token->[4];
2958: }
2959: return $currentstring;
2960: }
2961:
2962: sub end_bgsound {
2963: my ($target,$token) = @_;
2964: my $currentstring = '';
2965: if ($target eq 'web') {
2966: $currentstring = $token->[2];
2967: }
2968: return $currentstring;
2969: }
2970:
2971: #-- <blink> tag (end tag required)
2972: sub start_blink {
2973: my ($target,$token) = @_;
2974: my $currentstring = '';
2975: if ($target eq 'web') {
2976: $currentstring = $token->[4];
2977: }
2978: return $currentstring;
2979: }
2980:
2981: sub end_blink {
2982: my ($target,$token) = @_;
2983: my $currentstring = '';
2984: if ($target eq 'web') {
2985: $currentstring = $token->[2];
2986: }
2987: return $currentstring;
2988: }
2989:
2990: #-- <blockquote> tag (end tag required)
2991: sub start_blockquote {
2992: my ($target,$token) = @_;
2993: my $currentstring = '';
2994: if ($target eq 'web') {
2995: $currentstring = $token->[4];
2996: }
2997: return $currentstring;
2998: }
2999:
3000: sub end_blockquote {
3001: my ($target,$token) = @_;
3002: my $currentstring = '';
3003: if ($target eq 'web') {
3004: $currentstring = $token->[2];
3005: }
3006: return $currentstring;
3007: }
3008:
3009: #-- <button> tag (end tag required)
3010: sub start_button {
3011: my ($target,$token) = @_;
3012: my $currentstring = '';
3013: if ($target eq 'web') {
3014: $currentstring = $token->[4];
3015: }
3016: return $currentstring;
3017: }
3018:
3019: sub end_button {
3020: my ($target,$token) = @_;
3021: my $currentstring = '';
3022: if ($target eq 'web') {
3023: $currentstring = $token->[2];
3024: }
3025: return $currentstring;
3026: }
3027:
3028: #-- <caption> tag (end tag required)
3029: sub start_caption {
3030: my ($target,$token) = @_;
3031: my $currentstring = '';
3032: if ($target eq 'web') {
3033: $currentstring = $token->[4];
3034: }
3035: return $currentstring;
3036: }
3037:
3038: sub end_caption {
3039: my ($target,$token) = @_;
3040: my $currentstring = '';
3041: if ($target eq 'web') {
3042: $currentstring = $token->[2];
3043: }
3044: return $currentstring;
3045: }
3046:
3047: #-- <col> tag (end tag forbdden)
3048: sub start_col {
3049: my ($target,$token) = @_;
3050: my $currentstring = '';
3051: if ($target eq 'web') {
3052: $currentstring = $token->[4];
3053: }
3054: return $currentstring;
3055: }
3056:
3057: sub end_col {
3058: my ($target,$token) = @_;
3059: my $currentstring = '';
3060: if ($target eq 'web') {
3061: $currentstring = $token->[2];
3062: }
3063: return $currentstring;
3064: }
3065:
3066: #-- <colgroup> tag (end tag optional)
3067: sub start_colgroup {
3068: my ($target,$token) = @_;
3069: my $currentstring = '';
3070: if ($target eq 'web') {
3071: $currentstring = $token->[4];
3072: }
3073: return $currentstring;
3074: }
3075:
3076: sub end_colgroup {
3077: my ($target,$token) = @_;
3078: my $currentstring = '';
3079: if ($target eq 'web') {
3080: $currentstring = $token->[2];
3081: }
3082: return $currentstring;
3083: }
3084:
3085: #-- <del> tag (end tag required)
3086: sub start_del {
3087: my ($target,$token) = @_;
3088: my $currentstring = '';
3089: if ($target eq 'web') {
3090: $currentstring = $token->[4];
3091: }
3092: return $currentstring;
3093: }
3094:
3095: sub end_del {
3096: my ($target,$token) = @_;
3097: my $currentstring = '';
3098: if ($target eq 'web') {
3099: $currentstring = $token->[2];
3100: }
3101: return $currentstring;
3102: }
3103:
3104: #-- <fieldset> tag (end tag required)
3105: sub start_fieldset {
3106: my ($target,$token) = @_;
3107: my $currentstring = '';
3108: if ($target eq 'web') {
3109: $currentstring = $token->[4];
3110: }
3111: return $currentstring;
3112: }
3113:
3114: sub end_fieldset {
3115: my ($target,$token) = @_;
3116: my $currentstring = '';
3117: if ($target eq 'web') {
3118: $currentstring = $token->[2];
3119: }
3120: return $currentstring;
3121: }
3122:
3123: #-- <frame> tag (end tag forbidden)
3124: sub start_frame {
3125: my ($target,$token) = @_;
3126: my $currentstring = '';
3127: if ($target eq 'web') {
3128: $currentstring = $token->[4];
3129: }
3130: return $currentstring;
3131: }
3132:
3133: sub end_frame {
3134: my ($target,$token) = @_;
3135: my $currentstring = '';
3136: if ($target eq 'web') {
3137: $currentstring = $token->[2];
3138: }
3139: return $currentstring;
3140: }
3141:
3142: #-- <iframe> tag (end tag required)
3143: sub start_iframe {
3144: my ($target,$token) = @_;
3145: my $currentstring = '';
3146: if ($target eq 'web') {
3147: $currentstring = $token->[4];
3148: }
3149: return $currentstring;
3150: }
3151:
3152: sub end_iframe {
3153: my ($target,$token) = @_;
3154: my $currentstring = '';
3155: if ($target eq 'web') {
3156: $currentstring = $token->[2];
3157: }
3158: return $currentstring;
3159: }
3160:
3161: #-- <ins> tag (end tag required)
3162: sub start_ins {
3163: my ($target,$token) = @_;
3164: my $currentstring = '';
3165: if ($target eq 'web') {
3166: $currentstring = $token->[4];
3167: }
3168: return $currentstring;
3169: }
3170:
3171: sub end_ins {
3172: my ($target,$token) = @_;
3173: my $currentstring = '';
3174: if ($target eq 'web') {
3175: $currentstring = $token->[2];
3176: }
3177: return $currentstring;
3178: }
3179:
3180: #-- <isindex> tag (end tag forbidden)
3181: sub start_isindex {
3182: my ($target,$token) = @_;
3183: my $currentstring = '';
3184: if ($target eq 'web') {
3185: $currentstring = $token->[4];
3186: }
3187: return $currentstring;
3188: }
3189:
3190: sub end_isindex {
3191: my ($target,$token) = @_;
3192: my $currentstring = '';
3193: if ($target eq 'web') {
3194: $currentstring = $token->[2];
3195: }
3196: return $currentstring;
3197: }
3198:
3199: #-- <keygen> tag (end tag forbidden)
3200: sub start_keygen {
3201: my ($target,$token) = @_;
3202: my $currentstring = '';
3203: if ($target eq 'web') {
3204: $currentstring = $token->[4];
3205: }
3206: return $currentstring;
3207: }
3208:
3209: sub end_keygen {
3210: my ($target,$token) = @_;
3211: my $currentstring = '';
3212: if ($target eq 'web') {
3213: $currentstring = $token->[2];
3214: }
3215: return $currentstring;
3216: }
3217:
3218: #-- <label> tag
3219: sub start_label {
3220: my ($target,$token) = @_;
3221: my $currentstring = '';
3222: if ($target eq 'web') {
3223: $currentstring = $token->[4];
3224: }
3225: return $currentstring;
3226: }
3227:
3228: sub end_label {
3229: my ($target,$token) = @_;
3230: my $currentstring = '';
3231: if ($target eq 'web') {
3232: $currentstring = $token->[2];
3233: }
3234: return $currentstring;
3235: }
3236:
3237: #-- <layer> tag (end tag required)
3238: sub start_layer {
3239: my ($target,$token) = @_;
3240: my $currentstring = '';
3241: if ($target eq 'web') {
3242: $currentstring = $token->[4];
3243: }
3244: return $currentstring;
3245: }
3246:
3247: sub end_layer {
3248: my ($target,$token) = @_;
3249: my $currentstring = '';
3250: if ($target eq 'web') {
3251: $currentstring = $token->[2];
3252: }
3253: return $currentstring;
3254: }
3255:
3256: #-- <legend> tag (end tag required)
3257: sub start_legend {
3258: my ($target,$token) = @_;
3259: my $currentstring = '';
3260: if ($target eq 'web') {
3261: $currentstring = $token->[4];
3262: }
3263: return $currentstring;
3264: }
3265:
3266: sub end_legend {
3267: my ($target,$token) = @_;
3268: my $currentstring = '';
3269: if ($target eq 'web') {
3270: $currentstring = $token->[2];
3271: }
3272: return $currentstring;
3273: }
3274:
3275: #-- <link> tag (end tag forbidden)
3276: sub start_link {
3277: my ($target,$token) = @_;
3278: my $currentstring = '';
3279: if ($target eq 'web') {
3280: $currentstring = $token->[4];
3281: }
3282: return $currentstring;
3283: }
3284:
3285: sub end_link {
3286: my ($target,$token) = @_;
3287: my $currentstring = '';
3288: if ($target eq 'web') {
3289: $currentstring = $token->[2];
3290: }
3291: return $currentstring;
3292: }
3293:
3294: #-- <marquee> tag (end tag optional)
3295: sub start_marquee {
3296: my ($target,$token) = @_;
3297: my $currentstring = '';
3298: if ($target eq 'web') {
3299: $currentstring = $token->[4];
3300: }
3301: return $currentstring;
3302: }
3303:
3304: sub end_marquee {
3305: my ($target,$token) = @_;
3306: my $currentstring = '';
3307: if ($target eq 'web') {
3308: $currentstring = $token->[2];
3309: }
3310: return $currentstring;
3311: }
3312:
3313: #-- <multicol> tag (end tag required)
3314: sub start_multicol {
3315: my ($target,$token) = @_;
3316: my $currentstring = '';
3317: if ($target eq 'web') {
3318: $currentstring = $token->[4];
3319: }
3320: return $currentstring;
3321: }
3322:
3323: sub end_multicol {
3324: my ($target,$token) = @_;
3325: my $currentstring = '';
3326: if ($target eq 'web') {
3327: $currentstring = $token->[2];
3328: }
3329: return $currentstring;
3330: }
3331:
3332: #-- <nobr> tag (end tag required)
3333: sub start_nobr {
3334: my ($target,$token) = @_;
3335: my $currentstring = '';
3336: if ($target eq 'web') {
3337: $currentstring = $token->[4];
3338: } elsif ($target eq 'tex') {
3339: $currentstring='\mbox{';
3340: }
3341: return $currentstring;
3342: }
3343:
3344: sub end_nobr {
3345: my ($target,$token) = @_;
3346: my $currentstring = '';
3347: if ($target eq 'web') {
3348: $currentstring = $token->[2];
3349: } elsif ($target eq 'tex') {
3350: $currentstring='}';
3351: }
3352: return $currentstring;
3353: }
3354:
3355: #-- <noembed> tag (end tag required)
3356: sub start_noembed {
3357: my ($target,$token) = @_;
3358: my $currentstring = '';
3359: if ($target eq 'web') {
3360: $currentstring = $token->[4];
3361: }
3362: return $currentstring;
3363: }
3364:
3365: sub end_noembed {
3366: my ($target,$token) = @_;
3367: my $currentstring = '';
3368: if ($target eq 'web') {
3369: $currentstring = $token->[2];
3370: }
3371: return $currentstring;
3372: }
3373:
3374: #-- <noframes> tag (end tag required)
3375: sub start_noframes {
3376: my ($target,$token) = @_;
3377: my $currentstring = '';
3378: if ($target eq 'web') {
3379: $currentstring = $token->[4];
3380: }
3381: return $currentstring;
3382: }
3383:
3384: sub end_noframes {
3385: my ($target,$token) = @_;
3386: my $currentstring = '';
3387: if ($target eq 'web') {
3388: $currentstring = $token->[2];
3389: }
3390: return $currentstring;
3391: }
3392:
3393: #-- <nolayer> tag (end tag required)
3394: sub start_nolayer {
3395: my ($target,$token) = @_;
3396: my $currentstring = '';
3397: if ($target eq 'web') {
3398: $currentstring = $token->[4];
3399: }
3400: return $currentstring;
3401: }
3402:
3403: sub end_nolayer {
3404: my ($target,$token) = @_;
3405: my $currentstring = '';
3406: if ($target eq 'web') {
3407: $currentstring = $token->[2];
3408: }
3409: return $currentstring;
3410: }
3411:
3412: #-- <noscript> tag (end tag required)
3413: sub start_noscript {
3414: my ($target,$token) = @_;
3415: my $currentstring = '';
3416: if ($target eq 'web') {
3417: $currentstring = $token->[4];
3418: }
3419: return $currentstring;
3420: }
3421:
3422: sub end_noscript {
3423: my ($target,$token) = @_;
3424: my $currentstring = '';
3425: if ($target eq 'web') {
3426: $currentstring = $token->[2];
3427: }
3428: return $currentstring;
3429: }
3430:
3431: #-- <object> tag (end tag required)
3432: sub start_object {
3433: my ($target,$token) = @_;
3434: my $currentstring = '';
3435: if ($target eq 'web') {
3436: $currentstring = $token->[4];
3437: }
3438: return $currentstring;
3439: }
3440:
3441: sub end_object {
3442: my ($target,$token) = @_;
3443: my $currentstring = '';
3444: if ($target eq 'web') {
3445: $currentstring = $token->[2];
3446: }
3447: return $currentstring;
3448: }
3449:
3450: #-- <optgroup> tag (end tag required)
3451: sub start_optgroup {
3452: my ($target,$token) = @_;
3453: my $currentstring = '';
3454: if ($target eq 'web') {
3455: $currentstring = $token->[4];
3456: }
3457: return $currentstring;
3458: }
3459:
3460: sub end_optgroup {
3461: my ($target,$token) = @_;
3462: my $currentstring = '';
3463: if ($target eq 'web') {
3464: $currentstring = $token->[2];
3465: }
3466: return $currentstring;
3467: }
3468:
3469: #-- <samp> tag (end tag required)
3470: sub start_samp {
3471: my ($target,$token) = @_;
3472: my $currentstring = '';
3473: if ($target eq 'web') {
3474: $currentstring = $token->[4];
3475: } elsif ($target eq 'tex') {
3476: $currentstring='\texttt{';
3477: }
3478: return $currentstring;
3479: }
3480:
3481: sub end_samp {
3482: my ($target,$token) = @_;
3483: my $currentstring = '';
3484: if ($target eq 'web') {
3485: $currentstring = $token->[2];
3486: } elsif ($target eq 'tex') {
3487: $currentstring='}';
3488: }
3489: return $currentstring;
3490: }
3491:
3492: #-- <server> tag
3493: sub start_server {
3494: my ($target,$token) = @_;
3495: my $currentstring = '';
3496: if ($target eq 'web') {
3497: $currentstring = $token->[4];
3498: }
3499: return $currentstring;
3500: }
3501:
3502: sub end_server {
3503: my ($target,$token) = @_;
3504: my $currentstring = '';
3505: if ($target eq 'web') {
3506: $currentstring = $token->[2];
3507: }
3508: return $currentstring;
3509: }
3510:
3511: #-- <spacer> tag (end tag forbidden)
3512: sub start_spacer {
3513: my ($target,$token) = @_;
3514: my $currentstring = '';
3515: if ($target eq 'web') {
3516: $currentstring = $token->[4];
3517: }
3518: return $currentstring;
3519: }
3520:
3521: sub end_spacer {
3522: my ($target,$token) = @_;
3523: my $currentstring = '';
3524: if ($target eq 'web') {
3525: $currentstring = $token->[2];
3526: }
3527: return $currentstring;
3528: }
3529:
3530: #-- <span> tag (end tag required)
3531: sub start_span {
3532: my ($target,$token) = @_;
3533: my $currentstring = '';
3534: if ($target eq 'web') {
3535: $currentstring = $token->[4];
3536: }
3537: return $currentstring;
3538: }
3539:
3540: sub end_span {
3541: my ($target,$token) = @_;
3542: my $currentstring = '';
3543: if ($target eq 'web') {
3544: $currentstring = $token->[2];
3545: }
3546: return $currentstring;
3547: }
3548:
3549: #-- <tbody> tag (end tag optional)
3550: sub start_tbody {
3551: my ($target,$token) = @_;
3552: my $currentstring = '';
3553: if ($target eq 'web') {
3554: $currentstring = $token->[4];
3555: }
3556: return $currentstring;
3557: }
3558:
3559: sub end_tbody {
3560: my ($target,$token) = @_;
3561: my $currentstring = '';
3562: if ($target eq 'web') {
3563: $currentstring = $token->[2];
3564: }
3565: return $currentstring;
3566: }
3567:
3568: #-- <tfoot> tag (end tag optional)
3569: sub start_tfoot {
3570: my ($target,$token) = @_;
3571: my $currentstring = '';
3572: if ($target eq 'web') {
3573: $currentstring = $token->[4];
3574: }
3575: return $currentstring;
3576: }
3577:
3578: sub end_tfoot {
3579: my ($target,$token) = @_;
3580: my $currentstring = '';
3581: if ($target eq 'web') {
3582: $currentstring = $token->[2];
3583: }
3584: return $currentstring;
3585: }
3586:
3587: #-- <thead> tag (end tag optional)
3588: sub start_thead {
3589: my ($target,$token) = @_;
3590: my $currentstring = '';
3591: if ($target eq 'web') {
3592: $currentstring = $token->[4];
3593: }
3594: return $currentstring;
3595: }
3596:
3597: sub end_thead {
3598: my ($target,$token) = @_;
3599: my $currentstring = '';
3600: if ($target eq 'web') {
3601: $currentstring = $token->[2];
3602: }
3603: return $currentstring;
3604: }
3605:
3606: #-- <var> tag
3607: sub start_var {
3608: my ($target,$token) = @_;
3609: my $currentstring = '';
3610: if ($target eq 'web') {
3611: $currentstring = $token->[4];
3612: } elsif ($target eq 'tex') {
3613: $currentstring = '\textit{';
3614: }
3615: return $currentstring;
3616: }
3617:
3618: sub end_var {
3619: my ($target,$token) = @_;
3620: my $currentstring = '';
3621: if ($target eq 'web') {
3622: $currentstring = $token->[2];
3623: } elsif ($target eq 'tex') {
3624: $currentstring = '}';
3625: }
3626: return $currentstring;
3627: }
3628:
3629: #-- <wbr> tag (end tag forbidden)
3630: sub start_wbr {
3631: my ($target,$token) = @_;
3632: my $currentstring = '';
3633: if ($target eq 'web') {
3634: $currentstring = $token->[4];
3635: }
3636: return $currentstring;
3637: }
3638:
3639: sub end_wbr {
3640: my ($target,$token) = @_;
3641: my $currentstring = '';
3642: if ($target eq 'web') {
3643: $currentstring = $token->[2];
3644: }
3645: return $currentstring;
3646: }
3647:
3648: #-- <hideweboutput> tag
3649: sub start_hideweboutput {
3650: my ($target,$token) = @_;
3651: if ($target eq 'web') {
3652: &Apache::lonxml::startredirection();
3653: }
3654: return '';
3655: }
3656:
3657: sub end_hideweboutput {
3658: my ($target,$token) = @_;
3659: my $currentstring = '';
3660: if ($target eq 'web') {
3661: $currentstring = &Apache::lonxml::endredirection();
3662: }
3663: return '';
3664: }
3665:
3666:
3667: sub image_replication {
3668: my $src = shift;
3669: if (not -e $src) { &Apache::lonnet::repcopy($src); }
3670: #replicates eps or ps
3671: my $epssrc = my $pssrc = $src;
3672: $epssrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i;
3673: $pssrc =~ s/\.(gif|jpg|jpeg|png)$/.ps/i;
3674: if (not -e $epssrc && not -e $pssrc) {
3675: my $result=&Apache::lonnet::repcopy($epssrc);
3676: if ($result ne OK) { &Apache::lonnet::repcopy($pssrc); }
3677: }
3678: return '';
3679: }
3680:
3681: sub image_size {
3682: my ($src,$scaling,$parstack,$safeeval)=@_;
3683: #size of image from gif/jpg/jpeg/png
3684: my $image = Image::Magick->new;
3685: my $current_figure = $image->Read($src);
3686: my $width_param = $image->Get('width') * $scaling;;
3687: my $height_param = $image->Get('height') * $scaling;;
3688: undef $image;
3689: #do we have any specified LaTeX size of the picture?
3690: my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval);
3691: my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval);
3692: #do we have any specified web size of the picture?
3693: my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval,
3694: undef,1);
3695: if ($TeXwidth ne '') {
3696: if ($TeXwidth=~/(\d+)\s*\%/) {
3697: $width_param = $1*$ENV{'form.textwidth'}/100;
3698: } else {
3699: $width_param = $TeXwidth;
3700: }
3701: } elsif ($TeXheight ne '') {
3702: $width_param = $TeXheight/$height_param*$width_param;
3703: } elsif ($width ne '') {
3704: $width_param = $width*$scaling;
3705: }
3706: if ($width_param > $ENV{'form.textwidth'}) {$width_param =0.95*$ENV{'form.textwidth'}}
3707: return $width_param;
3708: }
3709:
3710: sub eps_generation {
3711: my ($src,$file,$width_param) = @_;
3712: my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat";
3713: my $temp_file = Apache::File->new('>>'.$filename);
3714: print $temp_file "$src\n";
3715: my $newsrc = $src;
3716: $newsrc =~ s/(\.gif|\.jpg|\.jpeg)$/\.eps/i;
3717: $newsrc=~s/\/home\/httpd\/html\/res//;
3718: $newsrc=~s/\/home\/([^\/]*)\/public_html\//\/$1\//;
3719: $newsrc=~s/\/\.\//\//;
3720: $newsrc=~s/\/([^\/]+)\.(ps|eps)/\//;
3721: if ($newsrc=~/\/home\/httpd\/lonUsers\//) {
3722: $newsrc=~s/\/home\/httpd\/lonUsers//;
3723: $newsrc=~s/\/([^\/]+)\/(\w)\/(\w)\/(\w)\//\/$1\//;
3724: }
3725: if ($newsrc=~/\/userfiles\//) {
3726: return ' \graphicspath{{'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
3727: } else {
3728: return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
3729: }
3730: }
3731:
3732: sub file_path {
3733: my $src=shift;
3734: my ($file,$path);
3735: if ($src =~ m!(.*)/([^/]*)$!) {
3736: $file = $2;
3737: $path = $1.'/';
3738: }
3739: return $file,$path;
3740: }
3741:
3742: sub recalc {
3743: my $argument = shift;
3744: if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}
3745: $argument=~/\s*(\d+\.?\d*)\s*(mm|cm|in|pc|pt)/;
3746: my $value=$1;
3747: my $units=$2;
3748: if ($units eq 'cm') {
3749: $value*=10;
3750: } elsif ($units eq 'in') {
3751: $value*=25.4;
3752: } elsif ($units eq 'pc') {
3753: $value*=(25.4*12/72.27);
3754: } elsif ($units eq 'pt') {
3755: $value*=(25.4/72.27);
3756: }
3757: return $value.' mm';
3758: }
3759:
3760: sub LATEX_length {
3761: my $garbage=shift;
3762: $garbage=~s/^\s+$//;
3763: $garbage=~s/^\s+(\S.*)/$1/;#space before
3764: $garbage=~s/(.*\S)\s+$/$1/;#space after
3765: $garbage=~s/(\s)+/$1/;#only one space
3766: $garbage=~s/(\\begin{([^\}]+)}|\\end{([^\}]+)})//g;#remove LaTeX \begin{...} and \end{...}
3767: $garbage=~s/(\$\_\{|\$\_|\$\^{|\$\^|\}\$)//g;#remove $_{,$_,$^{,$^,}$
3768: $garbage=~s/([^\\])\$/$1/g;#$
3769: $garbage=~s/(\\ensuremath\{\_\{|\\ensuremath\{\_|\\ensuremath\{\^{|\\ensuremath\{\^|\})//g;#remove \ensuremath{...}
3770: $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;
3771: $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;
3772: $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;
3773: $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;
3774: $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;
3775: $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;
3776: $garbage=~s/(\\hat{([^}]+)}|\\check{([^}]+)}|\\dot{([^}]+)}|\\breve{([^}]+)}|\\acute{([^}]+)}|\\ddot{([^}]+)}|\\grave{([^}]+)}|\\tilde{([^}]+)}|\\mathring{([^}]+)}|\\bar{([^}]+)}|\\vec{([^}]+)})/$1/g;
3777: #remove some other LaTeX command
3778: $garbage=~s|\\(\w+)\\|\\|g;
3779: $garbage=~s|\\(\w+)(\s*)|$2|g;
3780: $garbage=~s|\+|11|g;
3781: my $value=length($garbage);
3782: return $value;
3783: }
3784:
3785:
3786:
3787:
3788: 1;
3789: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>