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