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