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