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