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