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