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