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