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