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