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