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