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