Annotation of loncom/xml/londefdef.pm, revision 1.216
1.1 sakharuk 1: # The LearningOnline Network with CAPA
2: # Tags Default Definition Module
3: #
1.216 ! matthew 4: # $Id: londefdef.pm,v 1.215 2004/05/12 18:59:38 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.212 sakharuk 636: if ($align eq 'center') {
1.125 sakharuk 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.212 sakharuk 659: my $post='\vskip 0 mm ';
1.125 sakharuk 660: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1.212 sakharuk 661: if ($align eq 'center') {
1.125 sakharuk 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);
1.212 sakharuk 685: if ($align eq 'center') {
1.125 sakharuk 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.212 sakharuk 705: my $post='\vskip 0 mm ';
1.125 sakharuk 706: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1.212 sakharuk 707: if ($align eq 'center') {
1.125 sakharuk 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);
1.212 sakharuk 728: if ($align eq 'center') {
1.125 sakharuk 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.212 sakharuk 748: my $post='\vskip 0 mm ';
1.125 sakharuk 749: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1.212 sakharuk 750: if ($align eq 'center') {
1.125 sakharuk 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);
1.212 sakharuk 771: if ($align eq 'center') {
1.125 sakharuk 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.212 sakharuk 791: my $post='\vskip 0 mm ';
1.125 sakharuk 792: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1.212 sakharuk 793: if ($align eq 'center') {
1.125 sakharuk 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);
1.212 sakharuk 814: if ($align eq 'center') {
1.125 sakharuk 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.212 sakharuk 834: my $post='\vskip 0 mm ';
1.125 sakharuk 835: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1.212 sakharuk 836: if ($align eq 'center') {
1.125 sakharuk 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);
1.212 sakharuk 857: if ($align eq 'center') {
1.125 sakharuk 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.212 sakharuk 877: my $post='\vskip 0 mm ';
1.125 sakharuk 878: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1.212 sakharuk 879: if ($align eq 'center') {
1.125 sakharuk 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{';
1.216 ! matthew 1113: } else {
! 1114: $currentstring='\par ';
! 1115: }
1.198 sakharuk 1116: my $signal=1;#<p> does not work inside <b>...</b>
1117: foreach my $tag (@$tagstack) {if (lc($tag) eq 'b') {$signal=0;}
1118: if (!$signal) {$currentstring = '';}
1119: }
1.144 sakharuk 1120: }
1.122 albertel 1121: return $currentstring;
1122: }
1123:
1124: sub end_p {
1.198 sakharuk 1125: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1126: my $currentstring = '';
1127: if ($target eq 'web') {
1128: $currentstring .= $token->[2];
1.198 sakharuk 1129: } elsif ($target eq 'tex') {
1130: if ($$tagstack[-1] eq 'p') {
1131: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1132: if ($align eq 'center') {
1133: $currentstring .= '\end{center}';
1134: } elsif ($align eq 'right') {
1135: $currentstring .= '}}';
1136: } elsif ($align eq 'left') {
1137: $currentstring .= '}\hfill}';
1138: }
1139: }
1.122 albertel 1140: }
1141: return $currentstring;
1142: }
1143:
1.181 sakharuk 1144: #-- <br> tag (end tag forbidden)
1.122 albertel 1145: sub start_br {
1146: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1147: my $currentstring = '';
1148: if ($target eq 'web') {
1149: $currentstring .= $token->[4];
1150: } elsif ($target eq 'tex') {
1151: if ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') {
1.148 sakharuk 1152: $currentstring .= '\vskip 0.2 mm ';
1.1 sakharuk 1153: }
1.144 sakharuk 1154: }
1.122 albertel 1155: return $currentstring;
1156: }
1157:
1158: sub end_br {
1159: my ($target,$token) = @_;
1160: my $currentstring = '';
1161: if ($target eq 'web') {
1162: $currentstring .= $token->[2];
1163: }
1164: return $currentstring;
1165: }
1166:
1.181 sakharuk 1167: #-- <big> tag (end tag required)
1.122 albertel 1168: sub start_big {
1169: my ($target,$token) = @_;
1170: my $currentstring = '';
1171: if ($target eq 'web') {
1172: $currentstring .= $token->[4];
1173: } elsif ($target eq 'tex') {
1.137 sakharuk 1174: $currentstring .= '{\large ';
1.144 sakharuk 1175: }
1.122 albertel 1176: return $currentstring;
1177: }
1178:
1179: sub end_big {
1180: my ($target,$token) = @_;
1181: my $currentstring = '';
1182: if ($target eq 'web') {
1183: $currentstring .= $token->[2];
1184: } elsif ($target eq 'tex') {
1185: $currentstring .= '}';
1186: }
1187: return $currentstring;
1188: }
1189:
1.181 sakharuk 1190: #-- <small> tag (end tag required)
1.122 albertel 1191: sub start_small {
1192: my ($target,$token) = @_;
1193: my $currentstring = '';
1194: if ($target eq 'web') {
1195: $currentstring .= $token->[4];
1196: } elsif ($target eq 'tex') {
1197: $currentstring .= '{\footnotesize ';
1.144 sakharuk 1198: }
1.122 albertel 1199: return $currentstring;
1200: }
1201:
1202: sub end_small {
1203: my ($target,$token) = @_;
1204: my $currentstring = '';
1205: if ($target eq 'web') {
1206: $currentstring .= $token->[2];
1207: } elsif ($target eq 'tex') {
1208: $currentstring .= '}';
1209: }
1210: return $currentstring;
1211: }
1212:
1.181 sakharuk 1213: #-- <basefont> tag (end tag forbidden)
1.122 albertel 1214: sub start_basefont {
1.126 sakharuk 1215: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.122 albertel 1216: my $currentstring = '';
1217: if ($target eq 'web') {
1218: $currentstring = $token->[4];
1.126 sakharuk 1219: } elsif ($target eq 'tex') {
1220: my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1221: if (defined $basesize) {
1222: $currentstring = '{\\'.$basesize.' ';
1223: }
1224: }
1.122 albertel 1225: return $currentstring;
1226: }
1227:
1228: sub end_basefont {
1.126 sakharuk 1229: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1230: my $currentstring = '';
1231: if ($target eq 'web') {
1232: $currentstring = $token->[4];
1.126 sakharuk 1233: } elsif ($target eq 'tex') {
1234: my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1235: if (defined $basesize) {
1236: $currentstring = '}';
1237: }
1238: }
1.122 albertel 1239: return $currentstring;
1240: }
1241:
1.181 sakharuk 1242: #-- <font> tag (end tag required)
1.122 albertel 1243: sub start_font {
1244: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1245: my $currentstring = '';
1246: if ($target eq 'web') {
1247: my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
1.204 albertel 1248: if ($face!~/symbol/i) {
1.155 www 1249: if (($ENV{'browser.fontenhance'} eq 'on') ||
1250: ($ENV{'browser.blackwhite'} eq 'on')) { return ''; }
1251: }
1.122 albertel 1252: $currentstring = $token->[4];
1.126 sakharuk 1253: } elsif ($target eq 'tex') {
1254: my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1255: if (defined $fontsize) {
1256: $currentstring = '{\\'.$fontsize.' ';
1257: }
1258: }
1.122 albertel 1259: return $currentstring;
1260: }
1261:
1262: sub end_font {
1263: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1264: my $currentstring = '';
1265: if ($target eq 'web') {
1266: $currentstring = $token->[2];
1.126 sakharuk 1267: } elsif ($target eq 'tex') {
1268: my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1269: if (defined $fontsize) {
1270: $currentstring = '}';
1271: }
1272: }
1.122 albertel 1273: return $currentstring;
1274: }
1275:
1.181 sakharuk 1276: #-- <strike> tag (end tag required)
1.122 albertel 1277: sub start_strike {
1278: my ($target,$token) = @_;
1279: my $currentstring = '';
1280: if ($target eq 'web') {
1281: $currentstring .= $token->[4];
1282: } elsif ($target eq 'tex') {
1283: &Apache::lonxml::startredirection();
1284: }
1285: return $currentstring;
1286: }
1287:
1288: sub end_strike {
1289: my ($target,$token) = @_;
1290: my $currentstring = '';
1291: if ($target eq 'web') {
1292: $currentstring .= $token->[2];
1293: } elsif ($target eq 'tex') {
1294: $currentstring=&Apache::lonxml::endredirection();
1295: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1296: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1297: $currentstring=~s/(\S)\s*$/$1\}/;
1298: }
1299: return $currentstring;
1300: }
1301:
1.181 sakharuk 1302: #-- <s> tag (end tag required)
1.122 albertel 1303: sub start_s {
1304: my ($target,$token) = @_;
1305: my $currentstring = '';
1306: if ($target eq 'web') {
1307: $currentstring .= $token->[4];
1308: } elsif ($target eq 'tex') {
1309: &Apache::lonxml::startredirection();
1310: }
1311: return $currentstring;
1312: }
1313:
1314: sub end_s {
1315: my ($target,$token) = @_;
1316: my $currentstring = '';
1317: if ($target eq 'web') {
1318: $currentstring .= $token->[2];
1319: } elsif ($target eq 'tex') {
1320: $currentstring=&Apache::lonxml::endredirection();
1321: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1322: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1323: $currentstring=~s/(\S)\s*$/$1\}/;
1324: }
1325: return $currentstring;
1326: }
1327:
1.181 sakharuk 1328: #-- <sub> tag (end tag required)
1.122 albertel 1329: sub start_sub {
1330: my ($target,$token) = @_;
1331: my $currentstring = '';
1332: if ($target eq 'web') {
1333: $currentstring .= $token->[4];
1334: } elsif ($target eq 'tex') {
1.202 sakharuk 1335: $currentstring .= '\ensuremath{_{';
1.122 albertel 1336: }
1337: return $currentstring;
1338: }
1339:
1340: sub end_sub {
1341: my ($target,$token) = @_;
1342: my $currentstring = '';
1343: if ($target eq 'web') {
1344: $currentstring .= $token->[2];
1345: } elsif ($target eq 'tex') {
1.202 sakharuk 1346: $currentstring .= '}}';
1.122 albertel 1347: }
1348: return $currentstring;
1349: }
1350:
1.181 sakharuk 1351: #-- <sup> tag (end tag required)
1.122 albertel 1352: sub start_sup {
1353: my ($target,$token) = @_;
1354: my $currentstring = '';
1355: if ($target eq 'web') {
1356: $currentstring .= $token->[4];
1357: } elsif ($target eq 'tex') {
1.202 sakharuk 1358: $currentstring .= '\ensuremath{^{';
1.122 albertel 1359: }
1360: return $currentstring;
1361: }
1362:
1363: sub end_sup {
1364: my ($target,$token) = @_;
1365: my $currentstring = '';
1366: if ($target eq 'web') {
1367: $currentstring .= $token->[2];
1368: } elsif ($target eq 'tex') {
1.202 sakharuk 1369: $currentstring .= '}}';
1.122 albertel 1370: }
1371: return $currentstring;
1372: }
1373:
1.181 sakharuk 1374: #-- <hr> tag (end tag forbidden)
1.122 albertel 1375: sub start_hr {
1.124 sakharuk 1376: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1377: my $currentstring = '';
1378: if ($target eq 'web') {
1379: $currentstring .= $token->[4];
1380: } elsif ($target eq 'tex') {
1.149 sakharuk 1381: my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
1.124 sakharuk 1382: if (defined $LaTeXwidth) {
1383: if ($LaTeXwidth=~/^%/) {
1384: substr($LaTeXwidth,0,1)='';
1385: $LaTeXwidth=($LaTeXwidth/100).'\textwidth';
1386: }
1387: } else {
1.148 sakharuk 1388: $LaTeXwidth ='0.9\textwidth';
1.124 sakharuk 1389: }
1390: my ($pre,$post);
1391: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1392: if (($align eq 'center') || (not defined $align)) {
1393: $pre=''; $post='';
1394: } elsif ($align eq 'left') {
1395: $pre='\rlap{'; $post='} \hfill';
1396: } elsif ($align eq 'right') {
1397: $pre=' \hfill \llap{'; $post='}';
1398: }
1.148 sakharuk 1399: $currentstring .= ' \vskip 0 mm \noindent\makebox['.$LaTeXwidth.']{'.$pre.'\makebox['.
1.124 sakharuk 1400: $LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm ';
1.122 albertel 1401: }
1402: return $currentstring;
1403: }
1404:
1405: sub end_hr {
1406: my ($target,$token) = @_;
1407: my $currentstring = '';
1408: if ($target eq 'web') {
1409: $currentstring .= $token->[2];
1.148 sakharuk 1410: }
1.122 albertel 1411: return $currentstring;
1412: }
1413:
1.181 sakharuk 1414: #-- <div> tag (end tag required)
1.122 albertel 1415: sub start_div {
1416: my ($target,$token) = @_;
1417: my $currentstring = '';
1418: if ($target eq 'web') {
1419: $currentstring .= $token->[4];
1420: }
1421: return $currentstring;
1422: }
1423:
1424: sub end_div {
1425: my ($target,$token) = @_;
1426: my $currentstring = '';
1427: if ($target eq 'web') {
1428: $currentstring .= $token->[2];
1429: }
1430: return $currentstring;
1431: }
1432:
1.181 sakharuk 1433: #-- <a> tag (end tag required)
1.122 albertel 1434: sub start_a {
1.149 sakharuk 1435: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1436: my $currentstring = '';
1437: if ($target eq 'web') {
1438: $currentstring .= $token->[4];
1439: } elsif ($target eq 'tex') {
1.149 sakharuk 1440: my $a=&Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1);
1.161 sakharuk 1441: my $b=&Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1);
1442: if ($a=~/\S/) {
1443: $a=~s/([^\\])%/$1\\\%/g;
1444: $currentstring .= '\ref{URI: '.$a.'}';
1445: } elsif ($b=~/\S/) {
1446: $currentstring .= '\ref{Anchor: '.$b.'}';
1447: } else {
1448: $currentstring.='';
1449: }
1.122 albertel 1450: }
1451: return $currentstring;
1452: }
1453:
1454: sub end_a {
1.168 albertel 1455: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1456: my $currentstring = '';
1457: if ($target eq 'web') {
1458: $currentstring .= $token->[2];
1459: }
1460: return $currentstring;
1461: }
1462:
1.181 sakharuk 1463: #-- <li> tag (end tag optional)
1.122 albertel 1464: sub start_li {
1.168 albertel 1465: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1466: my $currentstring = '';
1467: if ($target eq 'web') {
1468: $currentstring = $token->[4];
1469: } elsif ($target eq 'tex') {
1.146 sakharuk 1470: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,1);
1471: if ($type=~/circle/) {
1472: $currentstring .= ' \item[o] ';
1473: } elsif ($type=~/square/) {
1474: $currentstring .= ' \item[$\Box$] ';
1475: } elsif ($type ne '') {
1476: $currentstring .= ' \item['.$type.'] ';
1.122 albertel 1477: } else {
1.146 sakharuk 1478: $currentstring .= ' \item ';
1.122 albertel 1479: }
1480: }
1481: return $currentstring;
1482: }
1483:
1484: sub end_li {
1485: my ($target,$token) = @_;
1486: my $currentstring = '';
1487: if ($target eq 'web') {
1488: $currentstring = $token->[2];
1489: }
1490: return $currentstring;
1491: }
1492:
1.181 sakharuk 1493: #-- <u> tag (end tag required)
1.122 albertel 1494: sub start_u {
1495: my ($target,$token) = @_;
1496: my $currentstring = '';
1497: if ($target eq 'web') {
1498: $currentstring .= $token->[4];
1499: } elsif ($target eq 'tex') {
1500: &Apache::lonxml::startredirection();
1501: }
1502: return $currentstring;
1503: }
1504:
1505: sub end_u {
1506: my ($target,$token) = @_;
1507: my $currentstring = '';
1508: if ($target eq 'web') {
1509: $currentstring .= $token->[2];
1510: } elsif ($target eq 'tex') {
1511: $currentstring=&Apache::lonxml::endredirection();
1512: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1513: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1514: $currentstring=~s/(\S)\s*$/$1\}/;
1515: }
1516: return $currentstring;
1517: }
1518:
1.181 sakharuk 1519: #-- <ul> tag (end tag required)
1.122 albertel 1520: sub start_ul {
1.125 sakharuk 1521: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1522: my $currentstring = '';
1523: if ($target eq 'web') {
1524: $currentstring = $token->[4];
1525: } elsif ($target eq 'tex') {
1.125 sakharuk 1526: my $TeXtype=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1527: if ($TeXtype eq 'disc') {
1528: $currentstring .= ' \renewcommand{\labelitemi}{$\bullet$}
1529: \renewcommand{\labelitemii}{$\bullet$}
1530: \renewcommand{\labelitemiii}{$\bullet$}
1531: \renewcommand{\labelitemiv}{$\bullet$}';
1532: } elsif ($TeXtype eq 'circle') {
1533: $currentstring .= ' \renewcommand{\labelitemi}{$\circ$}
1534: \renewcommand{\labelitemii}{$\circ$}
1535: \renewcommand{\labelitemiii}{$\circ$}
1536: \renewcommand{\labelitemiv}{$\circ$}';
1537: } elsif ($TeXtype eq 'square') {
1538: $currentstring .= ' \renewcommand{\labelitemi}{$\diamond$}
1539: \renewcommand{\labelitemii}{$\diamond$}
1540: \renewcommand{\labelitemiii}{$\diamond$}
1541: \renewcommand{\labelitemiv}{$\diamond$}';
1542: }
1543: $currentstring .= '\begin{itemize}';
1.122 albertel 1544: }
1545: return $currentstring;
1546: }
1547:
1548: sub end_ul {
1549: my ($target,$token) = @_;
1550: my $currentstring = '';
1551: if ($target eq 'web') {
1552: $currentstring = $token->[2];
1553: } elsif ($target eq 'tex') {
1.125 sakharuk 1554: $currentstring = '\end{itemize} \renewcommand{\labelitemi}{$\bullet$}
1555: \renewcommand{\labelitemii}{$\bullet$}
1556: \renewcommand{\labelitemiii}{$\bullet$}
1557: \renewcommand{\labelitemiv}{$\bullet$}';
1.122 albertel 1558: }
1559: return $currentstring;
1560: }
1561:
1.181 sakharuk 1562: #-- <menu> tag (end tag required)
1.122 albertel 1563: sub start_menu {
1564: my ($target,$token) = @_;
1565: my $currentstring = '';
1566: if ($target eq 'web') {
1567: $currentstring = $token->[4];
1568: } elsif ($target eq 'tex') {
1569: $currentstring = " \\begin{itemize} ";
1570: }
1571: return $currentstring;
1572: }
1573:
1574: sub end_menu {
1575: my ($target,$token) = @_;
1576: my $currentstring = '';
1577: if ($target eq 'web') {
1578: $currentstring = $token->[2];
1579: } elsif ($target eq 'tex') {
1580: $currentstring = " \\end{itemize}";
1581: }
1582: return $currentstring;
1583: }
1584:
1.181 sakharuk 1585: #-- <dir> tag (end tag required)
1.122 albertel 1586: sub start_dir {
1587: my ($target,$token) = @_;
1588: my $currentstring = '';
1589: if ($target eq 'web') {
1590: $currentstring = $token->[4];
1591: } elsif ($target eq 'tex') {
1592: $currentstring = " \\begin{itemize} ";
1593: }
1594: return $currentstring;
1595: }
1596:
1597: sub end_dir {
1598: my ($target,$token) = @_;
1599: my $currentstring = '';
1600: if ($target eq 'web') {
1601: $currentstring = $token->[2];
1602: } elsif ($target eq 'tex') {
1603: $currentstring = " \\end{itemize}";
1604: }
1605: return $currentstring;
1606: }
1607:
1.181 sakharuk 1608: #-- <ol> tag (end tag required)
1.122 albertel 1609: sub start_ol {
1.125 sakharuk 1610: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1611: my $currentstring = '';
1612: if ($target eq 'web') {
1613: $currentstring = $token->[4];
1614: } elsif ($target eq 'tex') {
1.125 sakharuk 1615: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1616: if ($type eq '1') {
1617: $currentstring .= ' \renewcommand{\labelenumi}{\arabic{enumi}.}
1618: \renewcommand{\labelenumii}{\arabic{enumii}.}
1619: \renewcommand{\labelenumiii}{\arabic{enumiii}.}
1620: \renewcommand{\labelenumiv}{\arabic{enumiv}.}';
1621: } elsif ($type eq 'A') {
1622: $currentstring .= ' \renewcommand{\labelenumi}{\Alph{enumi}.}
1623: \renewcommand{\labelenumii}{\Alph{enumii}.}
1624: \renewcommand{\labelenumiii}{\Alph{enumiii}.}
1625: \renewcommand{\labelenumiv}{\Alph{enumiv}.}';
1626: } elsif ($type eq 'a') {
1627: $currentstring .= ' \renewcommand{\labelenumi}{\alph{enumi}.}
1628: \renewcommand{\labelenumii}{\alph{enumii}.}
1629: \renewcommand{\labelenumiii}{\alph{enumiii}.}
1630: \renewcommand{\labelenumiv}{\alph{enumiv}.} ';
1631: } elsif ($type eq 'i') {
1632: $currentstring .= ' \renewcommand{\labelenumi}{\roman{enumi}.}
1633: \renewcommand{\labelenumii}{\roman{enumii}.}
1634: \renewcommand{\labelenumiii}{\roman{enumiii}.}
1635: \renewcommand{\labelenumiv}{\roman{enumiv}.} ';
1636: } elsif ($type eq 'I') {
1637: $currentstring .= ' \renewcommand{\labelenumi}{\Roman{enumi}.}
1638: \renewcommand{\labelenumii}{\Roman{enumii}.}
1639: \renewcommand{\labelenumiii}{\Roman{enumiii}.}
1640: \renewcommand{\labelenumiv}{\Roman{enumiv}.} ';
1641: }
1642: $currentstring .= '\begin{enumerate}';
1.122 albertel 1643: }
1644: return $currentstring;
1645: }
1646:
1647: sub end_ol {
1648: my ($target,$token) = @_;
1649: my $currentstring = '';
1650: if ($target eq 'web') {
1651: $currentstring = $token->[2];
1652: } elsif ($target eq 'tex') {
1.125 sakharuk 1653: $currentstring = '\end{enumerate} \renewcommand{\labelenumi}{\arabic{enumi}.}
1654: \renewcommand{\labelenumii}{\arabic{enumii}.}
1655: \renewcommand{\labelenumiii}{\arabic{enumiii}.}
1656: \renewcommand{\labelenumiv}{\arabic{enumiv}.}';
1.122 albertel 1657: }
1658: return $currentstring;
1659: }
1660:
1.181 sakharuk 1661: #-- <dl> tag (end tag required)
1.122 albertel 1662: sub start_dl {
1663: my ($target,$token) = @_;
1664: my $currentstring = '';
1665: if ($target eq 'web') {
1666: $currentstring = $token->[4];
1667: } elsif ($target eq 'tex') {
1.174 sakharuk 1668: $currentstring = '\begin{description}';
1669: @Apache::londefdef::description=();
1670: $Apache::londefdef::DD_redirection=0;
1671: $Apache::londefdef::DT_redirection=0;
1.122 albertel 1672: }
1673: return $currentstring;
1674: }
1675:
1676: sub end_dl {
1.174 sakharuk 1677: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1678: my $currentstring = '';
1679: if ($target eq 'web') {
1680: $currentstring = $token->[2];
1681: } elsif ($target eq 'tex') {
1.174 sakharuk 1682: if ($Apache::londefdef::DT_redirection) {
1683: my $data=&item_cleanup;
1684: push @Apache::londefdef::description,'\item['.$data.']';
1685: $Apache::londefdef::DT_redirection=0;
1686: } elsif ($Apache::londefdef::DD_redirection) {
1687: $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection();
1688: }
1689: foreach my $element (@Apache::londefdef::description) {
1690: $currentstring.=' '.$element.' ';
1691: }
1692: @Apache::londefdef::description=();
1693: $currentstring.='\end{description}';
1.122 albertel 1694: }
1695: return $currentstring;
1696: }
1697:
1.172 sakharuk 1698: #-- <dt> tag (end tag optional)
1.122 albertel 1699: sub start_dt {
1.172 sakharuk 1700: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1701: my $currentstring='';
1.122 albertel 1702: if ($target eq 'web') {
1703: $currentstring = $token->[4];
1704: } elsif ($target eq 'tex') {
1.174 sakharuk 1705: if ($Apache::londefdef::DT_redirection) {
1706: my $data=&item_cleanup;
1707: push @Apache::londefdef::description,'\item['.$data.']';
1708: $Apache::londefdef::DT_redirection=0;
1709: } elsif ($Apache::londefdef::DD_redirection) {
1710: $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection();
1711: $Apache::londefdef::DD_redirection=0;
1712: }
1713: &Apache::lonxml::startredirection();
1714: $Apache::londefdef::DT_redirection=1;
1.122 albertel 1715: }
1716: return $currentstring;
1717: }
1718:
1719: sub end_dt {
1.172 sakharuk 1720: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1721: my $currentstring = '';
1722: if ($target eq 'web') {
1723: $currentstring = $token->[2];
1724: } elsif ($target eq 'tex') {
1.173 sakharuk 1725: my $data=&item_cleanup;
1.174 sakharuk 1726: push @Apache::londefdef::description,'\item['.$data.']';
1727: $Apache::londefdef::DT_redirection=0;
1.122 albertel 1728: }
1729: return $currentstring;
1730: }
1731:
1.173 sakharuk 1732: sub item_cleanup {
1.174 sakharuk 1733: my $item=&Apache::lonxml::endredirection();
1.173 sakharuk 1734: $item=~s/\\begin{center}//g;
1735: $item=~s/\\end{center}//g;
1736: return $item;
1737: }
1738:
1.181 sakharuk 1739: #-- <dd> tag (end tag optional)
1.122 albertel 1740: sub start_dd {
1.147 sakharuk 1741: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1742: my $currentstring = '';
1743: if ($target eq 'web') {
1744: $currentstring = $token->[4];
1.147 sakharuk 1745: } elsif ($target eq 'tex') {
1.174 sakharuk 1746: if ($Apache::londefdef::DT_redirection) {
1.173 sakharuk 1747: my $data=&item_cleanup;
1.174 sakharuk 1748: push @Apache::londefdef::description,'\item['.$data.']';
1749: $Apache::londefdef::DT_redirection=0;
1.147 sakharuk 1750: }
1.174 sakharuk 1751: $Apache::londefdef::DD_redirection=1;
1752: &Apache::lonxml::startredirection();
1.122 albertel 1753: }
1754: return $currentstring;
1755: }
1756:
1757: sub end_dd {
1.174 sakharuk 1758: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1759: my $currentstring = '';
1760: if ($target eq 'web') {
1761: $currentstring = $token->[2];
1.174 sakharuk 1762: } elsif ($target eq 'tex') {
1763: $Apache::londefdef::description[-1].=&Apache::lonxml::endredirection();
1764: $Apache::londefdef::DD_redirection=0;
1765: }
1.122 albertel 1766: return $currentstring;
1767: }
1768:
1.181 sakharuk 1769: #-- <table> tag (end tag required)
1.206 sakharuk 1770: #list of supported attributes: border,width,TeXwidth
1.91 sakharuk 1771: sub start_table {
1772: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.206 sakharuk 1773: my ($textwidth,$currentstring)=('','');
1.91 sakharuk 1774: if ($target eq 'web') {
1775: $currentstring = $token->[4];
1776: } elsif ($target eq 'tex') {
1777: my $aa = {};
1778: push @Apache::londefdef::table, $aa;
1779: $Apache::londefdef::table[-1]{'row_number'} = -1;
1.206 sakharuk 1780: #table's width
1781: #default coincides with text line length
1782: if ($#Apache::londefdef::table==0) {
1783: $textwidth=&recalc($ENV{'form.textwidth'}); #result is always in mm
1784: $textwidth=~/(\d+\.?\d*)/;
1785: $textwidth=0.95*$1; #accounts "internal" LaTeX space for table frame
1786: } else {
1787: if ($Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]=~/\d/) {
1788: #the maximum width of nested table is determined by LATeX width of parent cell
1789: $textwidth=$Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}];
1790: } else {
1791: #try to use all space not used before (minus 5% for LaTeX table internal) - rather silly
1792: my $textwidth=$Apache::londefdef::table[-2]{'width'};
1793: for (my $i=0;$i<$Apache::londefdef::table[-2]{'counter_columns'};$i++) {
1794: $textwidth=$textwidth-$Apache::londefdef::table[-2]{'TeXlen'}[0][$i];
1795: }
1796: }
1797: }
1.126 sakharuk 1798: my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
1799: if (not defined $TeXwidth) {
1800: my $htmlwidth = &Apache::lonxml::get_param('width',$parstack,$safeeval,undef,1);
1801: if ($htmlwidth=~/%/) {
1.203 sakharuk 1802: $Apache::londefdef::table[-1]{'percent'}=1;
1.126 sakharuk 1803: $htmlwidth=~/(\d+)/;
1.203 sakharuk 1804: $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;;
1.126 sakharuk 1805: } else {
1806: $Apache::londefdef::table[-1]{'width'}=$textwidth;
1807: }
1808: } elsif ($TeXwidth=~/%/) {
1.203 sakharuk 1809: $Apache::londefdef::table[-1]{'percent'}=1;
1.126 sakharuk 1810: $TeXwidth=~/(\d+)/;
1.206 sakharuk 1811: $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;
1.126 sakharuk 1812: } else {
1.206 sakharuk 1813: $Apache::londefdef::table[-1]{'width'}=$TeXwidth;
1.126 sakharuk 1814: }
1815: #table's border
1.206 sakharuk 1816: my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval);
1.208 sakharuk 1817: my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
1.91 sakharuk 1818: unless (defined $border) { $border = 0; }
1819: if ($border) {
1820: $Apache::londefdef::table[-1]{'hinc'} = '\hline ';
1821: $Apache::londefdef::table[-1]{'vinc'} = '&';
1822: $Apache::londefdef::table[-1]{'vvinc'} = '|';
1823: } else {
1824: $Apache::londefdef::table[-1]{'hinc'} = '';
1825: $Apache::londefdef::table[-1]{'vinc'} = '&';
1826: $Apache::londefdef::table[-1]{'vvinc'} = '';
1827: }
1.206 sakharuk 1828: if ($#Apache::londefdef::table==0) {
1.207 sakharuk 1829: $Apache::londefdef::table[-1]{'output'}='\newline\setlength{\tabcolsep}{1 mm}';
1.206 sakharuk 1830: }
1831: $Apache::londefdef::table[-1]{'output'}.=' \noindent \begin{tabular} ';
1832: $Apache::londefdef::table[-1]{'TeXlen'}=[];
1833: $Apache::londefdef::table[-1]{'objectlen'}=[];
1834: $Apache::londefdef::table[-1]{'maxlen'}=[];
1835: $Apache::londefdef::table[-1]{'minlen'}=[];
1836: $Apache::londefdef::table[-1]{'content'}=[];
1837: $Apache::londefdef::table[-1]{'align'}=[];
1838: $currentstring='\keephidden{NEW TABLE ENTRY}';
1839: }
1.91 sakharuk 1840: return $currentstring;
1841: }
1.122 albertel 1842:
1843: sub end_table {
1844: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1845: my $currentstring = '';
1846: if ($target eq 'web') {
1847: $currentstring = $token->[2];
1848: } elsif ($target eq 'tex') {
1849: my $inmemory = '';
1850: my $output = '';
1.206 sakharuk 1851: my $WARNING='';
1852: #width of columns from TeXwidth attributes
1853: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1854: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
1855: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]<$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn]) {
1856: $Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]=$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn];
1857: }
1858: }
1859: }
1860: #free space and number of empty columns
1861: my ($available_space,$empty_columns)=($Apache::londefdef::table[-1]{'width'},0);
1862: ## &Apache::lonnet::logthis("Available space $Apache::londefdef::table[-1]{'width'}");
1863: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
1864: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]==0) {
1865: $empty_columns++;
1866: } else {
1867: $available_space=$available_space-$Apache::londefdef::table[-1]{'TeXlen'}[0][$jn];
1868: }
1869: }
1870: #boundaries for contents columns
1871: my @min_len=();#columns can not be narrower
1872: my @max_len=();#maximum length of column
1873: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
1874: my ($localmin,$localmax)=(0,0);
1875: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1876: if ($localmin<$Apache::londefdef::table[-1]{'minlen'}[$in][$jn]) {
1877: $localmin=$Apache::londefdef::table[-1]{'minlen'}[$in][$jn];
1878: }
1879: if ($localmax<$Apache::londefdef::table[-1]{'maxlen'}[$in][$jn]) {
1880: $localmax=$Apache::londefdef::table[-1]{'maxlen'}[$in][$jn];
1881: }
1882: }
1883: push @min_len, $localmin;
1884: push @max_len, $localmax;
1.122 albertel 1885: }
1.206 sakharuk 1886: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
1887: my $localmin=0,;
1888: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1889: if ($localmin<$Apache::londefdef::table[-1]{'objectlen'}[$in][$jn]) {
1890: $localmin=$Apache::londefdef::table[-1]{'objectlen'}[$in][$jn];
1891: }
1892: }
1893: if ($max_len[$jn]<$localmin) {$max_len[$jn]=$localmin;}#object size is bigger
1894: if ($min_len[$jn]<$localmin) {$min_len[$jn]=$localmin;}#object size is bigger
1895: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]!=0) {
1896: $min_len[$jn]=0;
1897: $max_len[$jn]=0;
1898: }
1899: }
1900: #final adjustment of column width
1901: my @fwidth=@{$Apache::londefdef::table[-1]{'TeXlen'}[0]};#final width array
1902: my @adjust=();
1903: #step 1. adjustment by maximum value
1904: my $space_neeeded=0;
1905: for (my $jn=0;$jn<=$#max_len;$jn++) {
1906: $space_neeeded=$space_neeeded+$max_len[$jn];
1907: }
1908: if ($space_neeeded<=$available_space) {
1909: for (my $jn=0;$jn<=$#max_len;$jn++) {
1910: if ($fwidth[$jn]==0) {
1911: $fwidth[$jn]=$max_len[$jn];
1.53 sakharuk 1912: }
1.51 sakharuk 1913: }
1.206 sakharuk 1914: } else {
1915: #step 2. adjustment by minimum value (estimation)
1916: $space_neeeded=0;
1917: for (my $jn=0;$jn<=$#min_len;$jn++) {
1918: $space_neeeded+=$min_len[$jn];
1919: }
1920: if ($space_neeeded>$available_space) {
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: my $enlarge_coef=$available_space/$space_neeeded;
1930: my $acsessive=0;
1931: for (my $jn=0;$jn<=$#min_len;$jn++) {
1932: $adjust[$jn]=$min_len[$jn]*$enlarge_coef;
1933: if ($adjust[$jn]>$max_len[$jn]) {
1934: $fwidth[$jn]=$max_len[$jn];
1935: $acsessive=$acsessive+$adjust[$jn]-$max_len[$jn];
1936: $adjust[$jn]=0;
1937: }
1938: }
1939: if ($acsessive>0) {
1940: #we have an excess of space and can redistribute it
1941: my $notempty_columns=0;
1942: for (my $jn=0;$jn<=$#min_len;$jn++) {
1943: if ($adjust[$jn]!=0) {
1944: $notempty_columns++;
1945: }
1946: }
1947: my $per_column=$acsessive/$notempty_columns;
1948: for (my $jn=0;$jn<=$#min_len;$jn++) {
1949: if ($adjust[$jn]!=0) {
1950: $adjust[$jn]+=$per_column;
1951: $fwidth[$jn]=$adjust[$jn];
1952: }
1953: }
1954: }
1.203 sakharuk 1955: }
1956: }
1957: #recalculation for the use of all available width if width is defined in %
1958: if ($Apache::londefdef::table[-1]{'percent'}==1) {
1959: my $current=0;
1.206 sakharuk 1960: for (my $i=0;$i<=$#fwidth;$i++) {
1961: $current+=$fwidth[$i];
1.203 sakharuk 1962: }
1963: my $coef=$Apache::londefdef::table[-1]{'width'}/$current;
1.206 sakharuk 1964: for (my $i=0;$i<=$#fwidth;$i++) {
1965: $fwidth[$i]*=$coef;
1966: }
1967: }
1968: #removing of empty columns if allowed
1.208 sakharuk 1969: my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
1.206 sakharuk 1970: if ($permission eq 'yes') {
1971: my @cleaned_table=();
1972: my @cleaned_header=();
1973: my $colind=0;
1974: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
1975: if ($fwidth[$jn]!=0) {
1976: #we need to copy column
1977: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1978: $cleaned_table[$in][$colind]=$Apache::londefdef::table[-1]{'content'}[$in][$jn];
1979: $cleaned_header[$colind]=$fwidth[$jn];
1980: }
1981: $colind++;
1982: }
1.122 albertel 1983: }
1.206 sakharuk 1984: $Apache::londefdef::table[-1]{'content'}=\@cleaned_table;
1985: @fwidth=@cleaned_header;
1.122 albertel 1986: }
1.206 sakharuk 1987: #construct header of the table
1988: my $header_of_table = '{'.$Apache::londefdef::table[-1]{'vvinc'};
1989: for (my $in=0;$in<=$#fwidth;$in++) {
1990: $header_of_table.='p{'.$fwidth[$in].' mm}'.$Apache::londefdef::table[-1]{'vvinc'};
1991: }
1992: $header_of_table .= '}';
1.126 sakharuk 1993: #fill the table
1994: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1.206 sakharuk 1995: for (my $jn=0;$jn<=$#fwidth;$jn++) {
1996: if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
1997: $output.='\begin{center}';
1998: } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
1999: $output.=' \hfill \llap{'
2000: }
2001: $output.=$Apache::londefdef::table[-1]{'content'}[$in][$jn];
2002: if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
2003: $output.='\end{center}';
2004: } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
2005: $output.='} ';
2006: }
2007: if ($jn!=$#fwidth) {$output.=' '.$Apache::londefdef::table[-1]{'vinc'};}
2008: }
2009: $output.=' \\\\ '.$Apache::londefdef::table[-1]{'hinc'}.' ';
1.122 albertel 2010: }
1.206 sakharuk 2011: $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\vskip 0 mm ';
1.127 sakharuk 2012: if ($#Apache::londefdef::table > 0) {
2013: my $inmemory = $Apache::londefdef::table[-1]{'output'};
2014: pop @Apache::londefdef::table;
1.129 sakharuk 2015: push @{$Apache::londefdef::table[-1]{'include'}}, $inmemory;
1.127 sakharuk 2016: } else {
2017: $currentstring .= $Apache::londefdef::table[-1]{'output'};
2018: pop @Apache::londefdef::table;
1.143 sakharuk 2019: undef @Apache::londefdef::table;
1.127 sakharuk 2020: }
1.122 albertel 2021: }
2022: return $currentstring;
2023: }
2024:
1.166 sakharuk 2025: #-- <tr> tag (end tag optional)
1.122 albertel 2026: sub start_tr {
2027: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2028: my $currentstring = '';
2029: if ($target eq 'web') {
2030: $currentstring = $token->[4];
2031: } elsif ($target eq 'tex') {
2032: $Apache::londefdef::table[-1]{'row_number'}++;
1.206 sakharuk 2033: my $alignchar=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1.122 albertel 2034: if ($alignchar ne '') {
1.206 sakharuk 2035: push @ {$Apache::londefdef::table[-1]{'rows'} },substr($alignchar,0,1);
1.122 albertel 2036: } else {
2037: push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l';
2038: }
2039: push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'});
2040: $Apache::londefdef::table[-1]{'counter_columns'} = -1;
1.206 sakharuk 2041: push @ {$Apache::londefdef::table[-1]{'TeXlen'}}, [];
2042: push @ {$Apache::londefdef::table[-1]{'objectlen'}}, [];
2043: push @ {$Apache::londefdef::table[-1]{'minlen'}}, [];
2044: push @ {$Apache::londefdef::table[-1]{'maxlen'}}, [];
2045: push @ {$Apache::londefdef::table[-1]{'content'}}, [];
1.122 albertel 2046: }
2047: return $currentstring;
2048: }
2049:
2050: sub end_tr {
1.160 sakharuk 2051: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 2052: my $currentstring = '';
2053: if ($target eq 'web') {
2054: $currentstring = $token->[2];
2055: } elsif ($target eq 'tex') {
1.160 sakharuk 2056: if ($Apache::londefdef::TD_redirection) {
2057: &end_td_tex($parstack,$parser,$safeeval);
2058: }
1.122 albertel 2059: }
2060: return $currentstring;
2061: }
2062:
1.166 sakharuk 2063: #-- <td> tag (end tag optional)
1.122 albertel 2064: sub start_td {
2065: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2066: my $currentstring = '';
2067: if ($target eq 'web') {
2068: $currentstring = $token->[4];
2069: } elsif ($target eq 'tex') {
1.160 sakharuk 2070: $Apache::londefdef::TD_redirection = 1;
1.159 sakharuk 2071: &tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval);
1.122 albertel 2072: }
2073: return $currentstring;
2074: }
1.159 sakharuk 2075:
2076: sub tag_check {
2077: my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
1.160 sakharuk 2078: my @ar=@$parstack;
2079: for (my $i=$#ar-1;$i>=0;$i--) {
2080: if (lc($$tagstack[$i]) eq $good_tag) {
2081: &start_td_tex($parstack,$parser,$safeeval);
2082: last;
2083: } elsif (lc($$tagstack[$i]) eq $bad_tag) {
2084: splice @ar, $i+1;
2085: &end_td_tex(\@ar,$parser,$safeeval);
2086: &start_td_tex($parstack,$parser,$safeeval);
2087: last;
1.159 sakharuk 2088: }
1.160 sakharuk 2089: }
1.159 sakharuk 2090: return '';
2091: }
2092:
2093: sub start_td_tex {
2094: my ($parstack,$parser,$safeeval) = @_;
1.206 sakharuk 2095: my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
2096: if ($alignchar eq '') {
2097: $alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
1.159 sakharuk 2098: }
1.206 sakharuk 2099: push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
1.159 sakharuk 2100: $Apache::londefdef::table[-1]{'counter_columns'}++;
1.206 sakharuk 2101: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2102: if (defined $TeXwidth) {
2103: my $current_length=&recalc($TeXwidth);
2104: $current_length=~/(\d+\.?\d*)/;
2105: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
2106: }
1.159 sakharuk 2107: &Apache::lonxml::startredirection();
2108: return '';
2109: }
2110:
2111: sub end_td_tex {
2112: my ($parstack,$parser,$safeeval) = @_;
2113: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
2114: my $data=&Apache::lonxml::endredirection();
2115: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2116: if (defined $TeXwidth) {
1.206 sakharuk 2117: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2118: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2119: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
1.159 sakharuk 2120: } else {
1.206 sakharuk 2121: if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
2122: my $garbage_data=$data;
2123: my $fwidth=0;
2124: while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2125: my $current_length=&recalc($1);
2126: $current_length=~/(\d+\.?\d*)/;
2127: if ($fwidth<$1) {$fwidth=$1;}
2128: $garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2129: }
2130: while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
2131: my $current_length=$1;
2132: if ($fwidth<$current_length) {$fwidth=$current_length;}
2133: $garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
2134: }
2135: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2136: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2137: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2138: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
1.159 sakharuk 2139: } else {
1.166 sakharuk 2140: $data=~s/^\s+(\S.*)/$1/;
1.159 sakharuk 2141: $data=~s/(.*\S)\s+$/$1/;
1.166 sakharuk 2142: $data=~s/(\s)+/$1/;
1.206 sakharuk 2143: my ($current_length,$min_length)=(0,0);
1.166 sakharuk 2144: if ($data=~/\\vskip/) {
2145: my $newdata=$data;
2146: $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
2147: my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
2148: foreach my $elementdata (@newdata) {
1.206 sakharuk 2149: my $lengthnewdata=2.5*&LATEX_length($elementdata);
1.166 sakharuk 2150: if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
1.206 sakharuk 2151: my @words=split(/ /,$elementdata);
2152: foreach my $word (@words) {
2153: my $lengthword=2.5*&LATEX_length($word);
2154: if ($min_length<$lengthword) {$min_length=$lengthword;}
2155: }
1.166 sakharuk 2156: }
2157: } else {
1.206 sakharuk 2158: $current_length=2.5*&LATEX_length($data);
2159: my @words=split(/ /,$data);
2160: foreach my $word (@words) {
2161: my $lengthword=2.5*&LATEX_length($word);
2162: if ($min_length<$lengthword) {$min_length=$lengthword;}
2163: }
1.166 sakharuk 2164: }
1.206 sakharuk 2165: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2166: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2167: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
2168: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
1.159 sakharuk 2169: }
2170: }
2171: for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {
2172: $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
2173: }
1.206 sakharuk 2174: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
1.159 sakharuk 2175: return'';
2176: }
2177:
1.122 albertel 2178: sub end_td {
1.126 sakharuk 2179: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 2180: my $currentstring = '';
2181: if ($target eq 'web') {
2182: $currentstring = $token->[2];
2183: } elsif ($target eq 'tex') {
1.160 sakharuk 2184: $Apache::londefdef::TD_redirection =0;
1.159 sakharuk 2185: &end_td_tex($parstack,$parser,$safeeval);
1.122 albertel 2186: }
2187: return $currentstring;
2188: }
2189:
1.166 sakharuk 2190: #-- <th> tag (end tag optional)
1.122 albertel 2191: sub start_th {
2192: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2193: my $currentstring = '';
2194: if ($target eq 'web') {
2195: $currentstring = $token->[4];
2196: } elsif ($target eq 'tex') {
2197: my $what_to_push = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
2198: if ($what_to_push eq '') {
2199: $what_to_push = substr($Apache::londefdef::table[-1]{'rows'}[0],0,1);;
2200: }
2201: push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push;
2202: $Apache::londefdef::table[-1]{'counter_columns'}++;
2203: &Apache::lonxml::startredirection();
2204: }
2205: return $currentstring;
1.130 sakharuk 2206: }
2207:
1.122 albertel 2208: sub end_th {
1.130 sakharuk 2209: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 2210: my $currentstring = '';
2211: if ($target eq 'web') {
2212: $currentstring = $token->[2];
2213: } elsif ($target eq 'tex') {
2214: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
2215: my $data=&Apache::lonxml::endredirection();
1.130 sakharuk 2216: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2217: if (defined $TeXwidth) {
2218: my $current_length=&recalc($TeXwidth);
2219: $current_length=~/(\d+)/;
2220: $Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
2221: $Apache::londefdef::table[-1]{'length'} .= '0,';
1.122 albertel 2222: } else {
1.130 sakharuk 2223: if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2224: my $current_length=&recalc($1);
2225: $current_length=~/(\d+)/;
2226: $Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
2227: $Apache::londefdef::table[-1]{'length'} .= '0,';
2228: } else {
2229: $data=~/^\s*(\S.*)/;
2230: $data=$1;
2231: $data=~/(.*\S)\s*$/;
2232: $data=$1;
2233: my $current_length=2*length($data);
2234: $Apache::londefdef::table[-1]{'length'} .= $current_length.',';
2235: $Apache::londefdef::table[-1]{'TeXlength'} .= '0,';
2236: }
2237: }
2238: for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {
2239: $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
2240: }
2241: $data='\textbf{'.$data.'}';
2242: @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'};
1.122 albertel 2243: }
2244: return $currentstring;
2245: }
1.181 sakharuk 2246: #-- <img> tag (end tag forbidden)
1.122 albertel 2247: sub start_img {
2248: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2249: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,
2250: undef,1);
1.189 albertel 2251: if (not $src and ($target eq 'web' or $target eq 'tex')) {
2252: my $inside = &Apache::lonxml::get_all_text("/img",$parser);
2253: &Apache::lonnet::logthis("inside was $inside");
2254: return '';
2255: }
1.122 albertel 2256: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
2257: my $currentstring = '';
2258: my $scaling = .3;
2259: if ($target eq 'web') {
2260: if ($ENV{'browser.imagesuppress'} ne 'on') {
1.158 sakharuk 2261: $currentstring.= $token->[4];
1.122 albertel 2262: } else {
2263: my $alttag= &Apache::lonxml::get_param
2264: ('alt',$parstack,$safeeval,undef,1);
2265: unless ($alttag) {
2266: $alttag=&Apache::lonmeta::alttag
2267: ($Apache::lonxml::pwd[-1],$src);
1.51 sakharuk 2268: }
1.158 sakharuk 2269: $currentstring.='[IMAGE: '.$alttag.']';
1.1 sakharuk 2270: }
1.122 albertel 2271: } elsif ($target eq 'tex') {
2272: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
1.213 sakharuk 2273: #if uploaded restore the path
1.214 sakharuk 2274: if ($src=~/^\/uploaded\/([^\/]+)\/([^\/]+)\/simplepage\/([^\/]+)$/) {
2275: $src=&Apache::loncommon::propath($1,$2).'/userfiles/simplepage/'.$3;
1.215 sakharuk 2276: } elsif ($src=~/^\/uploaded\/([^\/]+)\/([^\/]+)\/aboutme\/([^\/]+)$/) {
2277: $src=&Apache::loncommon::propath($1,$2).'/userfiles/aboutme/'.$3;
1.213 sakharuk 2278: }
1.122 albertel 2279: #if original gif/jpg/png file exist do following:
1.192 sakharuk 2280: if (-e $src) {
1.197 sakharuk 2281: #what is the image size?
2282: my $width_param=&image_size($src,$scaling,$parstack,$safeeval);
2283: my ($file,$path)=&file_path($src);
1.122 albertel 2284: my $newsrc = $src;
2285: $newsrc =~ s/\.(gif|jpg|png)$/.eps/i;
2286: $file=~s/\.(gif|jpg|png)$/.eps/i;
2287: #where can we find the picture?
2288: if (-e $newsrc) {
2289: #eps counterpart for image exist
2290: if ($path) {
2291: $currentstring .= '\vskip 1 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
1.51 sakharuk 2292: }
1.122 albertel 2293: } else {
2294: #there is no eps counterpart for image - check for ps one
2295: $newsrc =~ s/\.eps$/\.ps/;
2296: if (-e $newsrc) {
2297: #ps counterpart for image exist
2298: $file =~ s/\.eps$/\.ps/;
2299: if ($path) {
2300: $currentstring .= '\vskip 1 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
2301: }
1.78 sakharuk 2302: } else {
1.195 sakharuk 2303: #care about eps dynamical generation
2304: $currentstring.='\vskip 1 mm '.&eps_generation($src,$file,$width_param);
1.122 albertel 2305: }
2306: }
2307: } else {
2308: #original image file doesn't exist so check the alt attribute
2309: my $alt =
2310: &Apache::lonxml::get_param('alt',$parstack,$safeeval,undef,1);
2311: unless ($alt) {
2312: $alt=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
2313: }
2314:
2315: if ($alt) {
2316: $currentstring .= ' '.$alt.' ';
2317: } else {
2318: #<allow> tag will care about replication
1.59 sakharuk 2319: }
2320: }
1.186 albertel 2321: } elsif ($target eq 'edit') {
2322: $currentstring .=&Apache::edit::tag_start($target,$token);
2323: $currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70).
2324: &Apache::edit::browse('src',undef,'alt').' '.
2325: &Apache::edit::search('src',undef,'alt').'<br />';
2326: $currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'<br />';
2327: $currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5);
2328: $currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'<br />';
2329: $currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5);
2330: $currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5);
2331: $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
2332: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval);
2333: my $alt=&Apache::lonxml::get_param('alt',$parstack,$safeeval);
2334: my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval);
2335: my $height=&Apache::lonxml::get_param('height',$parstack,$safeeval);
2336: $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
2337: if ($width) { $currentstring.=' width="'.$width.'" '; }
2338: if ($height) { $currentstring.=' height="'.$height.'" '; }
2339: $currentstring .= ' />';
2340: } elsif ($target eq 'modified') {
1.210 albertel 2341: my ($osrc,$owidth,$oheight)=
2342: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
2343: my $ctag=&Apache::edit::get_new_args($token,$parstack,
2344: $safeeval,'src','alt',
2345: 'TeXwidth','TeXheight',
2346: 'width','height');
2347: my ($nsrc,$nwidth,$nheight)=
2348: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
2349: my $loc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$nsrc);
2350: &image_replication($loc);
2351: my ($iwidth,$iheight);
2352: if (-e $loc) {
2353: my $image = Image::Magick->new;
2354: $image->Read($loc);
2355: ($iwidth, $iheight) = ($image->Get('width'),
2356: $image->Get('height'));
2357: }
2358: if ($osrc ne $nsrc || (!$nwidth && !$nheight)) {
2359: # changed image or no size specified,
2360: # if they didn't explicitly change the
2361: # width or height use the ones from the image
2362: if ($iwidth && $iheight) {
2363: if ($owidth == $nwidth || (!$nwidth && !$nheight)) {
2364: $token->[2]{'width'} = $iwidth;$ctag=1;
2365: }
2366: if ($oheight == $nheight || (!$nwidth && !$nheight)) {
2367: $token->[2]{'height'}=$iheight;$ctag=1;
1.186 albertel 2368: }
2369: }
2370: }
1.210 albertel 2371: my ($cwidth,$cheight)=($token->[2]{'width'},$token->[2]{'height'});
2372: # if we don't have a width or height
2373: if ($iwidth && $cwidth && !$cheight) {
2374: $token->[2]{'height'}=int(($cwidth/$iwidth)*$iheight);$ctag=1;
2375: }
2376: if ($iheight && $cheight && !$cwidth) {
2377: $token->[2]{'width'}=int(($cheight/$iheight)*$iwidth);$ctag=1;
2378: }
2379: if ($ctag) {$currentstring=&Apache::edit::rebuild_tag($token);}
1.122 albertel 2380: }
2381: return $currentstring;
2382: }
2383:
2384: sub end_img {
2385: my ($target,$token) = @_;
2386: my $currentstring = '';
2387: if ($target eq 'web') {
2388: $currentstring = $token->[2];
2389: } elsif ($target eq 'tex') {
2390: $currentstring = '';
2391: }
2392: return $currentstring;
2393: }
2394:
1.181 sakharuk 2395: #-- <applet> tag (end tag required)
1.122 albertel 2396: sub start_applet {
2397: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2398:
2399: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,undef,1);
2400: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$code;
2401:
2402: my $archive=&Apache::lonxml::get_param('archive',$parstack,$safeeval,
2403: undef,1);
2404: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$archive;
2405:
2406: my $currentstring = '';
2407: if ($target eq 'web') {
2408: if ($ENV{'browser.appletsuppress'} ne 'on') {
2409: $currentstring = $token->[4];
2410: } else {
2411: my $alttag= &Apache::lonxml::get_param('alt',$parstack,
2412: $safeeval,undef,1);
2413: unless ($alttag) {
2414: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
2415: $code);
1.44 sakharuk 2416: }
1.122 albertel 2417: $currentstring='[APPLET: '.$alttag.']';
1.1 sakharuk 2418: }
1.122 albertel 2419: } elsif ($target eq 'tex') {
1.177 albertel 2420: my $alttag= &Apache::lonxml::get_param('alt',$parstack,
2421: $safeeval,undef,1);
2422: unless ($alttag) {
2423: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,
2424: undef,1);
2425: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
2426: $code);
1.175 sakharuk 2427: }
1.177 albertel 2428: $currentstring.='\begin{center} \fbox{Java Applet: '.$alttag.
2429: '.}\end{center}';
1.122 albertel 2430: }
2431: return $currentstring;
2432: }
2433:
2434: sub end_applet {
2435: my ($target,$token) = @_;
2436: my $currentstring = '';
2437: if ($target eq 'web') {
2438: $currentstring = $token->[2];
2439: } elsif ($target eq 'tex') {
2440: }
2441: return $currentstring;
2442: }
2443:
1.181 sakharuk 2444: #-- <embed> tag (end tag optional/required)
1.122 albertel 2445: sub start_embed {
2446: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2447: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
2448: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
2449: my $currentstring = '';
2450: if ($target eq 'web') {
2451: if ($ENV{'browser.embedsuppress'} ne 'on') {
2452: $currentstring = $token->[4];
2453: } else {
2454: my $alttag=&Apache::lonxml::get_param
2455: ('alt',$parstack,$safeeval,undef,1);
2456: unless ($alttag) {
2457: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
1.42 albertel 2458: }
1.122 albertel 2459: $currentstring='[EMBED: '.$alttag.']';
1.10 www 2460: }
1.122 albertel 2461: } elsif ($target eq 'tex') {
2462: }
2463: return $currentstring;
2464: }
2465:
2466: sub end_embed {
2467: my ($target,$token) = @_;
2468: my $currentstring = '';
2469: if ($target eq 'web') {
2470: $currentstring = $token->[2];
1.175 sakharuk 2471: } elsif ($target eq 'tex') {
1.122 albertel 2472: }
2473: return $currentstring;
2474: }
2475:
1.181 sakharuk 2476: #-- <param> tag (end tag forbidden)
1.122 albertel 2477: sub start_param {
2478: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2479: if (&Apache::lonxml::get_param
2480: ('name',$parstack,$safeeval,undef,1)=~/^cabbase$/i) {
2481: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
2482: &Apache::lonxml::get_param('value',$parstack,$safeeval,undef,1);
2483: }
2484: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
2485: &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
2486: my $currentstring = '';
2487: if ($target eq 'web') {
2488: $currentstring = $token->[4];
2489: } elsif ($target eq 'tex') {
2490: }
2491: return $currentstring;
2492: }
2493:
2494: sub end_param {
2495: my ($target,$token) = @_;
2496: my $currentstring = '';
2497: if ($target eq 'web') {
2498: $currentstring = $token->[2];
2499: } elsif ($target eq 'tex') {
2500: }
2501: return $currentstring;
2502: }
2503:
2504: #-- <allow> tag
2505: sub start_allow {
2506: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2507: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
2508: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
1.138 www 2509: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
2510: &Apache::lonnet::clutter($src);
1.122 albertel 2511: &image_replication($src);
2512: my $result;
2513: if ($target eq 'edit') {
2514: $result .=&Apache::edit::tag_start($target,$token);
2515: $result .=&Apache::edit::text_arg('File Spec:','src',$token,70);
2516: $result .=&Apache::edit::end_row();#.&Apache::edit::start_spanning_row();
2517: } elsif ($target eq 'modified') {
2518: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
2519: $safeeval,'src');
2520: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
2521: }
2522: return $result;
2523: }
2524:
2525: sub end_allow {
2526: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2527: if ( $target eq 'edit') { return (&Apache::edit::end_table()); }
2528: return '';
2529: }
1.119 www 2530:
1.181 sakharuk 2531: #-- Frames (end tag required)
2532: #-- <frameset>
1.122 albertel 2533: sub start_frameset {
2534: my ($target,$token) = @_;
2535: my $currentstring = '';
2536: if ($target eq 'web') {
1.180 albertel 2537: if (!$Apache::lonxml::registered &&
2538: $ENV{'request.state'} eq 'published') {
1.122 albertel 2539: $currentstring.='<head>'.
2540: &Apache::lonmenu::registerurl(undef,$target).'</head>';
1.10 www 2541: }
1.133 www 2542: my $onLoad='';
2543: foreach my $key (keys(%{$token->[2]})) {
2544: if ($key =~ /^onload$/i) {
2545: $onLoad.=$token->[2]->{$key}.';';
2546: delete($token->[2]->{$key});
2547: }
2548: }
2549: $token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad;
2550: my $onUnload='';
2551: foreach my $key (keys(%{$token->[2]})) {
2552: if ($key =~ /^onunload$/i) {
2553: $onUnload.=$token->[2]->{$key}.';';
2554: delete($token->[2]->{$key});
2555: }
2556: }
2557: $token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents().
2558: ';'.$onUnload;
2559:
2560: $currentstring .= '<'.$token->[1];
2561: foreach (keys %{$token->[2]}) {
2562: $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
2563: }
2564: $currentstring.='>';
1.122 albertel 2565: }
2566: return $currentstring;
2567: }
2568:
2569: sub end_frameset {
2570: my ($target,$token) = @_;
2571: my $currentstring = '';
2572: if ($target eq 'web') {
2573: $currentstring = $token->[2];
2574: }
2575: return $currentstring;
2576: }
1.162 sakharuk 2577:
1.181 sakharuk 2578: #-- <xmp> (end tag required)
1.162 sakharuk 2579: sub start_xmp {
2580: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2581: my $currentstring = '';
2582: if ($target eq 'web') {
2583: $currentstring .= $token->[4];
2584: } elsif ($target eq 'tex') {
2585: $currentstring .= '\begin{verbatim}';
2586: }
2587: return $currentstring;
2588: }
2589:
2590: sub end_xmp {
2591: my ($target,$token) = @_;
2592: my $currentstring = '';
2593: if ($target eq 'web') {
2594: $currentstring .= $token->[2];
2595: } elsif ($target eq 'tex') {
2596: $currentstring .= '\end{verbatim}';
2597: }
2598: return $currentstring;
2599: }
2600:
1.181 sakharuk 2601: #-- <pre> (end tag required)
1.122 albertel 2602: sub start_pre {
1.126 sakharuk 2603: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 2604: my $currentstring = '';
2605: if ($target eq 'web') {
2606: $currentstring .= $token->[4];
2607: } elsif ($target eq 'tex') {
1.136 sakharuk 2608: $currentstring .= '\begin{verbatim}';
1.122 albertel 2609: }
2610: return $currentstring;
2611: }
2612:
2613: sub end_pre {
2614: my ($target,$token) = @_;
2615: my $currentstring = '';
2616: if ($target eq 'web') {
2617: $currentstring .= $token->[2];
2618: } elsif ($target eq 'tex') {
1.136 sakharuk 2619: $currentstring .= '\end{verbatim}';
1.122 albertel 2620: }
2621: return $currentstring;
2622: }
2623:
2624: #-- <insert>
2625: sub start_insert {
2626: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2627: my $currentstring = '';
2628: if ($target eq 'web') {
2629: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
2630: $currentstring .= '<b>'.$display.'</b>';;
2631: }
2632: return $currentstring;
2633: }
2634:
2635: sub end_insert {
2636: my ($target,$token) = @_;
2637: my $currentstring = '';
2638: if ($target eq 'web') {
2639: $currentstring .= '';
2640: }
2641: return $currentstring;
2642: }
2643:
2644: #-- <externallink>
2645: sub start_externallink {
2646: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2647: my $currentstring = '';
2648: if ($target eq 'web') {
2649: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
2650: $currentstring .= '<b>'.$display.'</b>';;
2651: }
2652: return $currentstring;
2653: }
2654:
2655: sub end_externallink {
2656: my ($target,$token) = @_;
2657: my $currentstring = '';
2658: if ($target eq 'web') {
2659: $currentstring .= '';
2660: }
2661: return $currentstring;
2662: }
2663:
2664: #-- <blankspace heigth="">
2665: sub start_blankspace {
2666: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2667: my $currentstring = '';
2668: if ($target eq 'tex') {
2669: my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval,undef,1);
2670: $currentstring .= '\vskip '.$howmuch.' ';
2671: }
2672: return $currentstring;
2673: }
2674:
2675: sub end_blankspace {
2676: my ($target,$token) = @_;
2677: my $currentstring = '';
2678: if ($target eq 'tex') {
2679: $currentstring .= '';
2680: }
2681: return $currentstring;
2682: }
2683:
1.181 sakharuk 2684: #-- <abbr> tag (end tag required)
1.122 albertel 2685: sub start_abbr {
2686: my ($target,$token) = @_;
2687: my $currentstring = '';
2688: if ($target eq 'web') {
2689: $currentstring = $token->[4];
2690: }
2691: return $currentstring;
2692: }
2693:
2694: sub end_abbr {
2695: my ($target,$token) = @_;
2696: my $currentstring = '';
2697: if ($target eq 'web') {
2698: $currentstring = $token->[2];
2699: }
2700: return $currentstring;
2701: }
2702:
1.181 sakharuk 2703: #-- <acronym> tag (end tag required)
1.122 albertel 2704: sub start_acronym {
2705: my ($target,$token) = @_;
2706: my $currentstring = '';
2707: if ($target eq 'web') {
2708: $currentstring = $token->[4];
2709: }
2710: return $currentstring;
2711: }
2712:
2713: sub end_acronym {
2714: my ($target,$token) = @_;
2715: my $currentstring = '';
2716: if ($target eq 'web') {
2717: $currentstring = $token->[2];
2718: }
2719: return $currentstring;
2720: }
2721:
1.181 sakharuk 2722: #-- <area> tag (end tag forbidden)
1.122 albertel 2723: sub start_area {
2724: my ($target,$token) = @_;
2725: my $currentstring = '';
2726: if ($target eq 'web') {
2727: $currentstring = $token->[4];
2728: }
2729: return $currentstring;
2730: }
2731:
2732: sub end_area {
2733: my ($target,$token) = @_;
2734: my $currentstring = '';
2735: if ($target eq 'web') {
2736: $currentstring = $token->[2];
2737: }
2738: return $currentstring;
2739: }
2740:
1.181 sakharuk 2741: #-- <base> tag (end tag forbidden)
1.122 albertel 2742: sub start_base {
2743: my ($target,$token) = @_;
2744: my $currentstring = '';
2745: if ($target eq 'web') {
2746: $currentstring = $token->[4];
1.161 sakharuk 2747: }
1.122 albertel 2748: return $currentstring;
2749: }
2750:
2751: sub end_base {
2752: my ($target,$token) = @_;
2753: my $currentstring = '';
2754: if ($target eq 'web') {
2755: $currentstring = $token->[2];
2756: }
2757: return $currentstring;
2758: }
2759:
1.181 sakharuk 2760: #-- <bdo> tag (end tag required)
1.122 albertel 2761: sub start_bdo {
2762: my ($target,$token) = @_;
2763: my $currentstring = '';
2764: if ($target eq 'web') {
2765: $currentstring = $token->[4];
2766: }
2767: return $currentstring;
2768: }
2769:
2770: sub end_bdo {
2771: my ($target,$token) = @_;
2772: my $currentstring = '';
2773: if ($target eq 'web') {
2774: $currentstring = $token->[2];
2775: }
2776: return $currentstring;
2777: }
2778:
1.181 sakharuk 2779: #-- <bgsound> tag (end tag optional)
1.122 albertel 2780: sub start_bgsound {
2781: my ($target,$token) = @_;
2782: my $currentstring = '';
2783: if ($target eq 'web') {
2784: $currentstring = $token->[4];
2785: }
2786: return $currentstring;
2787: }
2788:
2789: sub end_bgsound {
2790: my ($target,$token) = @_;
2791: my $currentstring = '';
2792: if ($target eq 'web') {
2793: $currentstring = $token->[2];
2794: }
2795: return $currentstring;
2796: }
2797:
1.181 sakharuk 2798: #-- <blink> tag (end tag required)
1.122 albertel 2799: sub start_blink {
2800: my ($target,$token) = @_;
2801: my $currentstring = '';
2802: if ($target eq 'web') {
2803: $currentstring = $token->[4];
2804: }
2805: return $currentstring;
2806: }
2807:
2808: sub end_blink {
2809: my ($target,$token) = @_;
2810: my $currentstring = '';
2811: if ($target eq 'web') {
2812: $currentstring = $token->[2];
2813: }
2814: return $currentstring;
2815: }
2816:
1.181 sakharuk 2817: #-- <blockquote> tag (end tag required)
1.122 albertel 2818: sub start_blockquote {
2819: my ($target,$token) = @_;
2820: my $currentstring = '';
2821: if ($target eq 'web') {
2822: $currentstring = $token->[4];
2823: }
2824: return $currentstring;
2825: }
2826:
2827: sub end_blockquote {
2828: my ($target,$token) = @_;
2829: my $currentstring = '';
2830: if ($target eq 'web') {
2831: $currentstring = $token->[2];
2832: }
2833: return $currentstring;
2834: }
2835:
1.181 sakharuk 2836: #-- <button> tag (end tag required)
1.122 albertel 2837: sub start_button {
2838: my ($target,$token) = @_;
2839: my $currentstring = '';
2840: if ($target eq 'web') {
2841: $currentstring = $token->[4];
2842: }
2843: return $currentstring;
2844: }
2845:
2846: sub end_button {
2847: my ($target,$token) = @_;
2848: my $currentstring = '';
2849: if ($target eq 'web') {
2850: $currentstring = $token->[2];
2851: }
2852: return $currentstring;
2853: }
2854:
1.181 sakharuk 2855: #-- <caption> tag (end tag required)
1.122 albertel 2856: sub start_caption {
2857: my ($target,$token) = @_;
2858: my $currentstring = '';
2859: if ($target eq 'web') {
2860: $currentstring = $token->[4];
2861: }
2862: return $currentstring;
2863: }
2864:
2865: sub end_caption {
2866: my ($target,$token) = @_;
2867: my $currentstring = '';
2868: if ($target eq 'web') {
2869: $currentstring = $token->[2];
2870: }
2871: return $currentstring;
2872: }
2873:
1.181 sakharuk 2874: #-- <col> tag (end tag forbdden)
1.122 albertel 2875: sub start_col {
2876: my ($target,$token) = @_;
2877: my $currentstring = '';
2878: if ($target eq 'web') {
2879: $currentstring = $token->[4];
2880: }
2881: return $currentstring;
2882: }
2883:
2884: sub end_col {
2885: my ($target,$token) = @_;
2886: my $currentstring = '';
2887: if ($target eq 'web') {
2888: $currentstring = $token->[2];
2889: }
2890: return $currentstring;
2891: }
2892:
1.181 sakharuk 2893: #-- <colgroup> tag (end tag optional)
1.122 albertel 2894: sub start_colgroup {
2895: my ($target,$token) = @_;
2896: my $currentstring = '';
2897: if ($target eq 'web') {
2898: $currentstring = $token->[4];
2899: }
2900: return $currentstring;
2901: }
2902:
2903: sub end_colgroup {
2904: my ($target,$token) = @_;
2905: my $currentstring = '';
2906: if ($target eq 'web') {
2907: $currentstring = $token->[2];
2908: }
2909: return $currentstring;
2910: }
2911:
1.181 sakharuk 2912: #-- <del> tag (end tag required)
1.122 albertel 2913: sub start_del {
2914: my ($target,$token) = @_;
2915: my $currentstring = '';
2916: if ($target eq 'web') {
2917: $currentstring = $token->[4];
2918: }
2919: return $currentstring;
2920: }
2921:
2922: sub end_del {
2923: my ($target,$token) = @_;
2924: my $currentstring = '';
2925: if ($target eq 'web') {
2926: $currentstring = $token->[2];
2927: }
2928: return $currentstring;
2929: }
2930:
1.181 sakharuk 2931: #-- <fieldset> tag (end tag required)
1.122 albertel 2932: sub start_fieldset {
2933: my ($target,$token) = @_;
2934: my $currentstring = '';
2935: if ($target eq 'web') {
2936: $currentstring = $token->[4];
2937: }
2938: return $currentstring;
2939: }
2940:
2941: sub end_fieldset {
2942: my ($target,$token) = @_;
2943: my $currentstring = '';
2944: if ($target eq 'web') {
2945: $currentstring = $token->[2];
2946: }
2947: return $currentstring;
2948: }
2949:
1.181 sakharuk 2950: #-- <frame> tag (end tag forbidden)
1.122 albertel 2951: sub start_frame {
2952: my ($target,$token) = @_;
2953: my $currentstring = '';
2954: if ($target eq 'web') {
2955: $currentstring = $token->[4];
2956: }
2957: return $currentstring;
2958: }
2959:
2960: sub end_frame {
2961: my ($target,$token) = @_;
2962: my $currentstring = '';
2963: if ($target eq 'web') {
2964: $currentstring = $token->[2];
2965: }
2966: return $currentstring;
2967: }
2968:
1.181 sakharuk 2969: #-- <iframe> tag (end tag required)
1.122 albertel 2970: sub start_iframe {
2971: my ($target,$token) = @_;
2972: my $currentstring = '';
2973: if ($target eq 'web') {
2974: $currentstring = $token->[4];
2975: }
2976: return $currentstring;
2977: }
2978:
2979: sub end_iframe {
2980: my ($target,$token) = @_;
2981: my $currentstring = '';
2982: if ($target eq 'web') {
2983: $currentstring = $token->[2];
2984: }
2985: return $currentstring;
2986: }
2987:
1.181 sakharuk 2988: #-- <ins> tag (end tag required)
1.122 albertel 2989: sub start_ins {
2990: my ($target,$token) = @_;
2991: my $currentstring = '';
2992: if ($target eq 'web') {
2993: $currentstring = $token->[4];
2994: }
2995: return $currentstring;
2996: }
2997:
2998: sub end_ins {
2999: my ($target,$token) = @_;
3000: my $currentstring = '';
3001: if ($target eq 'web') {
3002: $currentstring = $token->[2];
3003: }
3004: return $currentstring;
3005: }
3006:
1.181 sakharuk 3007: #-- <isindex> tag (end tag forbidden)
1.122 albertel 3008: sub start_isindex {
3009: my ($target,$token) = @_;
3010: my $currentstring = '';
3011: if ($target eq 'web') {
3012: $currentstring = $token->[4];
3013: }
3014: return $currentstring;
3015: }
3016:
3017: sub end_isindex {
3018: my ($target,$token) = @_;
3019: my $currentstring = '';
3020: if ($target eq 'web') {
3021: $currentstring = $token->[2];
3022: }
3023: return $currentstring;
3024: }
3025:
1.181 sakharuk 3026: #-- <keygen> tag (end tag forbidden)
1.122 albertel 3027: sub start_keygen {
3028: my ($target,$token) = @_;
3029: my $currentstring = '';
3030: if ($target eq 'web') {
3031: $currentstring = $token->[4];
3032: }
3033: return $currentstring;
3034: }
3035:
3036: sub end_keygen {
3037: my ($target,$token) = @_;
3038: my $currentstring = '';
3039: if ($target eq 'web') {
3040: $currentstring = $token->[2];
3041: }
3042: return $currentstring;
3043: }
3044:
3045: #-- <label> tag
3046: sub start_label {
3047: my ($target,$token) = @_;
3048: my $currentstring = '';
3049: if ($target eq 'web') {
3050: $currentstring = $token->[4];
3051: }
3052: return $currentstring;
3053: }
3054:
3055: sub end_label {
3056: my ($target,$token) = @_;
3057: my $currentstring = '';
3058: if ($target eq 'web') {
3059: $currentstring = $token->[2];
3060: }
3061: return $currentstring;
3062: }
3063:
1.181 sakharuk 3064: #-- <layer> tag (end tag required)
1.122 albertel 3065: sub start_layer {
3066: my ($target,$token) = @_;
3067: my $currentstring = '';
3068: if ($target eq 'web') {
3069: $currentstring = $token->[4];
3070: }
3071: return $currentstring;
3072: }
3073:
3074: sub end_layer {
3075: my ($target,$token) = @_;
3076: my $currentstring = '';
3077: if ($target eq 'web') {
3078: $currentstring = $token->[2];
3079: }
3080: return $currentstring;
3081: }
3082:
1.181 sakharuk 3083: #-- <legend> tag (end tag required)
1.122 albertel 3084: sub start_legend {
3085: my ($target,$token) = @_;
3086: my $currentstring = '';
3087: if ($target eq 'web') {
3088: $currentstring = $token->[4];
3089: }
3090: return $currentstring;
3091: }
3092:
3093: sub end_legend {
3094: my ($target,$token) = @_;
3095: my $currentstring = '';
3096: if ($target eq 'web') {
3097: $currentstring = $token->[2];
3098: }
3099: return $currentstring;
3100: }
3101:
1.181 sakharuk 3102: #-- <link> tag (end tag forbidden)
1.122 albertel 3103: sub start_link {
3104: my ($target,$token) = @_;
3105: my $currentstring = '';
3106: if ($target eq 'web') {
3107: $currentstring = $token->[4];
3108: }
3109: return $currentstring;
3110: }
3111:
3112: sub end_link {
3113: my ($target,$token) = @_;
3114: my $currentstring = '';
3115: if ($target eq 'web') {
3116: $currentstring = $token->[2];
3117: }
3118: return $currentstring;
3119: }
3120:
1.181 sakharuk 3121: #-- <marquee> tag (end tag optional)
1.122 albertel 3122: sub start_marquee {
3123: my ($target,$token) = @_;
3124: my $currentstring = '';
3125: if ($target eq 'web') {
3126: $currentstring = $token->[4];
3127: }
3128: return $currentstring;
3129: }
3130:
3131: sub end_marquee {
3132: my ($target,$token) = @_;
3133: my $currentstring = '';
3134: if ($target eq 'web') {
3135: $currentstring = $token->[2];
3136: }
3137: return $currentstring;
3138: }
3139:
1.179 sakharuk 3140: #-- <multicol> tag (end tag required)
3141: sub start_multicol {
1.122 albertel 3142: my ($target,$token) = @_;
3143: my $currentstring = '';
3144: if ($target eq 'web') {
3145: $currentstring = $token->[4];
3146: }
3147: return $currentstring;
3148: }
3149:
1.179 sakharuk 3150: sub end_multicol {
1.122 albertel 3151: my ($target,$token) = @_;
3152: my $currentstring = '';
3153: if ($target eq 'web') {
3154: $currentstring = $token->[2];
3155: }
3156: return $currentstring;
3157: }
3158:
1.179 sakharuk 3159: #-- <nobr> tag (end tag required)
1.122 albertel 3160: sub start_nobr {
3161: my ($target,$token) = @_;
3162: my $currentstring = '';
3163: if ($target eq 'web') {
3164: $currentstring = $token->[4];
1.179 sakharuk 3165: } elsif ($target eq 'tex') {
3166: $currentstring='\mbox{';
3167: }
1.122 albertel 3168: return $currentstring;
3169: }
3170:
3171: sub end_nobr {
3172: my ($target,$token) = @_;
3173: my $currentstring = '';
3174: if ($target eq 'web') {
3175: $currentstring = $token->[2];
1.179 sakharuk 3176: } elsif ($target eq 'tex') {
3177: $currentstring='}';
3178: }
1.122 albertel 3179: return $currentstring;
3180: }
3181:
1.179 sakharuk 3182: #-- <noembed> tag (end tag required)
1.122 albertel 3183: sub start_noembed {
3184: my ($target,$token) = @_;
3185: my $currentstring = '';
3186: if ($target eq 'web') {
3187: $currentstring = $token->[4];
3188: }
3189: return $currentstring;
3190: }
3191:
3192: sub end_noembed {
3193: my ($target,$token) = @_;
3194: my $currentstring = '';
3195: if ($target eq 'web') {
3196: $currentstring = $token->[2];
3197: }
3198: return $currentstring;
3199: }
3200:
1.179 sakharuk 3201: #-- <noframes> tag (end tag required)
1.122 albertel 3202: sub start_noframes {
3203: my ($target,$token) = @_;
3204: my $currentstring = '';
3205: if ($target eq 'web') {
3206: $currentstring = $token->[4];
3207: }
3208: return $currentstring;
3209: }
3210:
3211: sub end_noframes {
3212: my ($target,$token) = @_;
3213: my $currentstring = '';
3214: if ($target eq 'web') {
3215: $currentstring = $token->[2];
3216: }
3217: return $currentstring;
3218: }
3219:
1.179 sakharuk 3220: #-- <nolayer> tag (end tag required)
1.122 albertel 3221: sub start_nolayer {
3222: my ($target,$token) = @_;
3223: my $currentstring = '';
3224: if ($target eq 'web') {
3225: $currentstring = $token->[4];
3226: }
3227: return $currentstring;
3228: }
3229:
3230: sub end_nolayer {
3231: my ($target,$token) = @_;
3232: my $currentstring = '';
3233: if ($target eq 'web') {
3234: $currentstring = $token->[2];
3235: }
3236: return $currentstring;
3237: }
3238:
1.179 sakharuk 3239: #-- <noscript> tag (end tag required)
1.122 albertel 3240: sub start_noscript {
3241: my ($target,$token) = @_;
3242: my $currentstring = '';
3243: if ($target eq 'web') {
3244: $currentstring = $token->[4];
3245: }
3246: return $currentstring;
3247: }
3248:
3249: sub end_noscript {
3250: my ($target,$token) = @_;
3251: my $currentstring = '';
3252: if ($target eq 'web') {
3253: $currentstring = $token->[2];
3254: }
3255: return $currentstring;
3256: }
3257:
1.179 sakharuk 3258: #-- <object> tag (end tag required)
1.122 albertel 3259: sub start_object {
3260: my ($target,$token) = @_;
3261: my $currentstring = '';
3262: if ($target eq 'web') {
3263: $currentstring = $token->[4];
3264: }
3265: return $currentstring;
3266: }
3267:
3268: sub end_object {
3269: my ($target,$token) = @_;
3270: my $currentstring = '';
3271: if ($target eq 'web') {
3272: $currentstring = $token->[2];
3273: }
3274: return $currentstring;
3275: }
3276:
1.179 sakharuk 3277: #-- <optgroup> tag (end tag required)
1.122 albertel 3278: sub start_optgroup {
3279: my ($target,$token) = @_;
3280: my $currentstring = '';
3281: if ($target eq 'web') {
3282: $currentstring = $token->[4];
3283: }
3284: return $currentstring;
3285: }
3286:
3287: sub end_optgroup {
3288: my ($target,$token) = @_;
3289: my $currentstring = '';
3290: if ($target eq 'web') {
3291: $currentstring = $token->[2];
3292: }
3293: return $currentstring;
3294: }
3295:
1.179 sakharuk 3296: #-- <samp> tag (end tag required)
1.122 albertel 3297: sub start_samp {
3298: my ($target,$token) = @_;
3299: my $currentstring = '';
3300: if ($target eq 'web') {
3301: $currentstring = $token->[4];
1.179 sakharuk 3302: } elsif ($target eq 'tex') {
3303: $currentstring='\texttt{';
3304: }
1.122 albertel 3305: return $currentstring;
3306: }
3307:
3308: sub end_samp {
3309: my ($target,$token) = @_;
3310: my $currentstring = '';
3311: if ($target eq 'web') {
3312: $currentstring = $token->[2];
1.179 sakharuk 3313: } elsif ($target eq 'tex') {
3314: $currentstring='}';
3315: }
1.122 albertel 3316: return $currentstring;
3317: }
3318:
3319: #-- <server> tag
3320: sub start_server {
3321: my ($target,$token) = @_;
3322: my $currentstring = '';
3323: if ($target eq 'web') {
3324: $currentstring = $token->[4];
3325: }
3326: return $currentstring;
3327: }
3328:
3329: sub end_server {
3330: my ($target,$token) = @_;
3331: my $currentstring = '';
3332: if ($target eq 'web') {
3333: $currentstring = $token->[2];
3334: }
3335: return $currentstring;
3336: }
3337:
1.179 sakharuk 3338: #-- <spacer> tag (end tag forbidden)
1.122 albertel 3339: sub start_spacer {
3340: my ($target,$token) = @_;
3341: my $currentstring = '';
3342: if ($target eq 'web') {
3343: $currentstring = $token->[4];
3344: }
3345: return $currentstring;
3346: }
3347:
3348: sub end_spacer {
3349: my ($target,$token) = @_;
3350: my $currentstring = '';
3351: if ($target eq 'web') {
3352: $currentstring = $token->[2];
3353: }
3354: return $currentstring;
3355: }
3356:
1.179 sakharuk 3357: #-- <span> tag (end tag required)
1.122 albertel 3358: sub start_span {
3359: my ($target,$token) = @_;
3360: my $currentstring = '';
3361: if ($target eq 'web') {
3362: $currentstring = $token->[4];
3363: }
3364: return $currentstring;
3365: }
3366:
3367: sub end_span {
3368: my ($target,$token) = @_;
3369: my $currentstring = '';
3370: if ($target eq 'web') {
3371: $currentstring = $token->[2];
3372: }
3373: return $currentstring;
3374: }
3375:
1.179 sakharuk 3376: #-- <tbody> tag (end tag optional)
1.122 albertel 3377: sub start_tbody {
3378: my ($target,$token) = @_;
3379: my $currentstring = '';
3380: if ($target eq 'web') {
3381: $currentstring = $token->[4];
3382: }
3383: return $currentstring;
3384: }
3385:
3386: sub end_tbody {
3387: my ($target,$token) = @_;
3388: my $currentstring = '';
3389: if ($target eq 'web') {
3390: $currentstring = $token->[2];
3391: }
3392: return $currentstring;
3393: }
3394:
1.166 sakharuk 3395: #-- <tfoot> tag (end tag optional)
1.122 albertel 3396: sub start_tfoot {
3397: my ($target,$token) = @_;
3398: my $currentstring = '';
3399: if ($target eq 'web') {
3400: $currentstring = $token->[4];
3401: }
3402: return $currentstring;
3403: }
3404:
3405: sub end_tfoot {
3406: my ($target,$token) = @_;
3407: my $currentstring = '';
3408: if ($target eq 'web') {
3409: $currentstring = $token->[2];
3410: }
3411: return $currentstring;
3412: }
3413:
1.166 sakharuk 3414: #-- <thead> tag (end tag optional)
1.122 albertel 3415: sub start_thead {
3416: my ($target,$token) = @_;
3417: my $currentstring = '';
3418: if ($target eq 'web') {
3419: $currentstring = $token->[4];
3420: }
3421: return $currentstring;
3422: }
1.10 www 3423:
1.122 albertel 3424: sub end_thead {
3425: my ($target,$token) = @_;
3426: my $currentstring = '';
3427: if ($target eq 'web') {
3428: $currentstring = $token->[2];
3429: }
3430: return $currentstring;
3431: }
1.119 www 3432:
1.122 albertel 3433: #-- <var> tag
3434: sub start_var {
1.44 sakharuk 3435: my ($target,$token) = @_;
3436: my $currentstring = '';
3437: if ($target eq 'web') {
1.122 albertel 3438: $currentstring = $token->[4];
1.163 sakharuk 3439: } elsif ($target eq 'tex') {
3440: $currentstring = '\textit{';
3441: }
1.44 sakharuk 3442: return $currentstring;
3443: }
1.10 www 3444:
1.122 albertel 3445: sub end_var {
3446: my ($target,$token) = @_;
1.44 sakharuk 3447: my $currentstring = '';
3448: if ($target eq 'web') {
1.163 sakharuk 3449: $currentstring = $token->[2];
3450: } elsif ($target eq 'tex') {
3451: $currentstring = '}';
1.44 sakharuk 3452: }
3453: return $currentstring;
3454: }
1.119 www 3455:
1.163 sakharuk 3456: #-- <wbr> tag (end tag forbidden)
1.122 albertel 3457: sub start_wbr {
3458: my ($target,$token) = @_;
3459: my $currentstring = '';
3460: if ($target eq 'web') {
3461: $currentstring = $token->[4];
3462: }
3463: return $currentstring;
1.98 albertel 3464: }
3465:
1.122 albertel 3466: sub end_wbr {
3467: my ($target,$token) = @_;
3468: my $currentstring = '';
3469: if ($target eq 'web') {
3470: $currentstring = $token->[2];
3471: }
3472: return $currentstring;
1.98 albertel 3473: }
1.134 sakharuk 3474:
3475: #-- <hideweboutput> tag
3476: sub start_hideweboutput {
3477: my ($target,$token) = @_;
3478: if ($target eq 'web') {
3479: &Apache::lonxml::startredirection();
3480: }
3481: return '';
3482: }
3483:
3484: sub end_hideweboutput {
3485: my ($target,$token) = @_;
3486: my $currentstring = '';
3487: if ($target eq 'web') {
3488: $currentstring = &Apache::lonxml::endredirection();
3489: }
3490: return '';
3491: }
3492:
1.94 sakharuk 3493:
3494: sub image_replication {
3495: my $src = shift;
1.187 albertel 3496: if (not -e $src) { &Apache::lonnet::repcopy($src); }
3497: #replicates eps or ps
3498: my $epssrc = my $pssrc = $src;
3499: $epssrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i;
3500: $pssrc =~ s/\.(gif|jpg|jpeg|png)$/.ps/i;
3501: if (not -e $epssrc && not -e $pssrc) {
3502: my $result=&Apache::lonnet::repcopy($epssrc);
3503: if ($result ne OK) { &Apache::lonnet::repcopy($pssrc); }
1.94 sakharuk 3504: }
3505: return '';
1.195 sakharuk 3506: }
3507:
1.197 sakharuk 3508: sub image_size {
3509: my ($src,$scaling,$parstack,$safeeval)=@_;
3510: #size of image from gif/jpg/jpeg/png
3511: my $image = Image::Magick->new;
3512: my $current_figure = $image->Read($src);
3513: my $width_param = $image->Get('width') * $scaling;;
3514: my $height_param = $image->Get('height') * $scaling;;
3515: undef $image;
3516: #do we have any specified LaTeX size of the picture?
3517: my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval);
3518: my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval);
3519: #do we have any specified web size of the picture?
3520: my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval,
3521: undef,1);
3522: if ($TeXwidth ne '') {
3523: if ($TeXwidth=~/(\d+)\s*\%/) {
3524: $width_param = $1*$ENV{'form.textwidth'}/100;
3525: } else {
3526: $width_param = $TeXwidth;
3527: }
3528: } elsif ($TeXheight ne '') {
3529: $width_param = $TeXheight/$height_param*$width_param;
3530: } elsif ($width ne '') {
3531: $width_param = $width*$scaling;
3532: }
3533: if ($width_param > $ENV{'form.textwidth'}) {$width_param =0.95*$ENV{'form.textwidth'}}
3534: return $width_param;
3535: }
3536:
1.195 sakharuk 3537: sub eps_generation {
3538: my ($src,$file,$width_param) = @_;
3539: my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat";
3540: my $temp_file = Apache::File->new('>>'.$filename);
3541: print $temp_file "$src\n";
3542: my $newsrc = $src;
3543: $newsrc =~ s/(\.gif|\.jpg|\.jpeg)$/\.eps/i;
3544: $newsrc=~s/\/home\/httpd\/html\/res//;
3545: $newsrc=~s/\/home\/([^\/]*)\/public_html\//\/$1\//;
3546: $newsrc=~s/\/\.\//\//;
3547: $newsrc=~s/\/([^\/]+)\.(ps|eps)/\//;
1.213 sakharuk 3548: if ($newsrc=~/\/home\/httpd\/lonUsers\//) {
3549: $newsrc=~s/\/home\/httpd\/lonUsers//;
3550: $newsrc=~s/\/([^\/]+)\/(\w)\/(\w)\/(\w)\//\/$1\//;
3551: }
1.195 sakharuk 3552: return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
1.197 sakharuk 3553: }
3554:
3555: sub file_path {
3556: my $src=shift;
3557: my ($file,$path);
3558: if ($src =~ m!(.*)/([^/]*)$!) {
3559: $file = $2;
3560: $path = $1.'/';
3561: }
3562: return $file,$path;
1.126 sakharuk 3563: }
3564:
3565: sub recalc {
3566: my $argument = shift;
3567: if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}
1.132 sakharuk 3568: $argument=~/\s*(\d+\.?\d*)\s*(mm|cm|in|pc|pt)/;
1.126 sakharuk 3569: my $value=$1;
3570: my $units=$2;
3571: if ($units eq 'cm') {
3572: $value*=10;
3573: } elsif ($units eq 'in') {
3574: $value*=25.4;
3575: } elsif ($units eq 'pc') {
3576: $value*=(25.4*12/72.27);
3577: } elsif ($units eq 'pt') {
3578: $value*=(25.4/72.27);
3579: }
3580: return $value.' mm';
1.94 sakharuk 3581: }
1.184 sakharuk 3582:
3583: sub LATEX_length {
3584: my $garbage=shift;
1.206 sakharuk 3585: $garbage=~s/^\s+$//;
3586: $garbage=~s/^\s+(\S.*)/$1/;#space before
3587: $garbage=~s/(.*\S)\s+$/$1/;#space after
3588: $garbage=~s/(\s)+/$1/;#only one space
3589: $garbage=~s/(\\begin{([^\}]+)}|\\end{([^\}]+)})//g;#remove LaTeX \begin{...} and \end{...}
3590: $garbage=~s/(\$\_\{|\$\_|\$\^{|\$\^|\}\$)//g;#remove $_{,$_,$^{,$^,}$
3591: $garbage=~s/([^\\])\$/$1/g;#$
3592: $garbage=~s/(\\ensuremath\{\_\{|\\ensuremath\{\_|\\ensuremath\{\^{|\\ensuremath\{\^|\})//g;#remove \ensuremath{...}
3593: $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 3594: $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;
3595: $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;
3596: $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 3597: $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;
3598: $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;
3599: $garbage=~s/(\\hat{([^}]+)}|\\check{([^}]+)}|\\dot{([^}]+)}|\\breve{([^}]+)}|\\acute{([^}]+)}|\\ddot{([^}]+)}|\\grave{([^}]+)}|\\tilde{([^}]+)}|\\mathring{([^}]+)}|\\bar{([^}]+)}|\\vec{([^}]+)})/$1/g;
3600: #remove some other LaTeX command
3601: $garbage=~s|\\(\w+)\\|\\|g;
3602: $garbage=~s|\\(\w+)(\s*)|$2|g;
3603: $garbage=~s|\+|11|g;
3604:
3605: &Apache::lonnet::logthis("garbage was just $garbage");
1.184 sakharuk 3606: my $value=length($garbage);
3607: return $value;
3608: }
3609:
3610:
3611:
1.94 sakharuk 3612:
1.1 sakharuk 3613: 1;
3614: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>