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