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