Annotation of loncom/xml/londefdef.pm, revision 1.313
1.1 sakharuk 1: # The LearningOnline Network with CAPA
2: # Tags Default Definition Module
3: #
1.313 ! foxr 4: # $Id: londefdef.pm,v 1.312 2006/01/11 11:58:06 foxr Exp $
1.41 sakharuk 5: #
1.34 www 6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
1.156 sakharuk 28: ## Copyright for TtHfunc and TtMfunc by Ian Hutchinson.
1.34 www 29: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into
30: # binary executable programs or libraries distributed by the
31: # Michigan State University (the "Licensee"), but any binaries so
32: # distributed are hereby licensed only for use in the context
33: # of a program or computational system for which the Licensee is the
34: # primary author or distributor, and which performs substantial
35: # additional tasks beyond the translation of (La)TeX into HTML.
36: # The C source of the Code may not be distributed by the Licensee
37: # to any other parties under any circumstances.
38: #
1.1 sakharuk 39:
1.2 albertel 40: package Apache::londefdef;
1.1 sakharuk 41:
1.267 albertel 42: use Apache::lonnet;
1.1 sakharuk 43: use strict;
1.124 sakharuk 44: use Apache::lonxml;
1.57 sakharuk 45: use Apache::File();
1.70 sakharuk 46: use Image::Magick;
1.118 www 47: use Apache::lonmenu();
48: use Apache::lonmeta();
1.187 albertel 49: use Apache::Constants qw(:common);
1.282 foxr 50: use File::Basename;
1.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) {
1.313 ! foxr 1190:
1.279 foxr 1191: $currentstring .= &end_p(); # close off prior para if in progress.
1.198 sakharuk 1192: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1193: if ($align eq 'center') {
1.277 foxr 1194: $currentstring .='\begin{center}\par';
1195: $closing_string = '\end{center}';
1.309 albertel 1196: if (&is_inside_of($tagstack, "table")) {
1197: $currentstring = ¢er_correction().$currentstring;
1198: $closing_string .= ¢er_correction();
1199: }
1.198 sakharuk 1200: } elsif ($align eq 'right') {
1.277 foxr 1201: $currentstring.='\makebox['.$env{'form.textwidth'}.']{\hfill\llap{';
1202: $closing_string= '}}';
1.198 sakharuk 1203: } elsif ($align eq 'left') {
1.277 foxr 1204: $currentstring.='\noindent\makebox['.$env{'form.textwidth'}.']{\rlap{';
1205: $closing_string = '}\hfill}';
1.216 matthew 1206: } else {
1.277 foxr 1207: $currentstring.='\par ';
1.313 ! foxr 1208: if (&is_inside_of($tagstack, 'table')) {
! 1209: $closing_string = '\vskip 12pt'; # Safer in tables.
! 1210: } else {
! 1211: $closing_string = '\strut\\\\\strut ';
! 1212: }
1.216 matthew 1213: }
1.277 foxr 1214:
1.144 sakharuk 1215: }
1.122 albertel 1216: return $currentstring;
1217: }
1.277 foxr 1218: #
1219: # End paragraph processing just requires that we output the
1220: # closing string that was saved and blank it.
1221: sub end_p {
1.279 foxr 1222: # Note only 'tex' mode uses disable_para and enable_para
1223: # so we don't need to know the target in the check below:
1224:
1225: if (!$para_disabled) {
1226: my $current_string = $closing_string;
1227: $closing_string = ''; # Not in a para anymore.
1228: return $current_string;
1229: } else {
1230: return '';
1231: }
1.122 albertel 1232:
1233: }
1.277 foxr 1234: }
1.181 sakharuk 1235: #-- <br> tag (end tag forbidden)
1.122 albertel 1236: sub start_br {
1237: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1238: my $currentstring = '';
1239: if ($target eq 'web') {
1240: $currentstring .= $token->[4];
1241: } elsif ($target eq 'tex') {
1.227 sakharuk 1242: my @tempo=@$tagstack;
1.229 sakharuk 1243: my $signal=0;
1.287 foxr 1244: # Not going to factor this to is_inside_of since that would require
1245: # multiple stack traversals.
1246: #
1.227 sakharuk 1247: for (my $i=$#tempo;$i>=0;$i--) {
1248: if (($tempo[$i] eq 'b') || ($tempo[$i] eq 'strong') ||
1.230 sakharuk 1249: ($tempo[$i] eq 'ol') || ($tempo[$i] eq 'ul') ||
1250: ($tempo[$i] eq 'td') || ($tempo[$i] eq 'th')) {
1.229 sakharuk 1251: $signal=1;
1.227 sakharuk 1252: last;
1253: }
1254: }
1.229 sakharuk 1255: if ($signal) {
1.219 sakharuk 1256: $currentstring .= ' \vskip 0 mm ';
1257: } elsif ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') {
1258: $currentstring .= '\strut \\\\ \strut ';
1.1 sakharuk 1259: }
1.144 sakharuk 1260: }
1.122 albertel 1261: return $currentstring;
1262: }
1263:
1264: sub end_br {
1265: my ($target,$token) = @_;
1266: my $currentstring = '';
1267: if ($target eq 'web') {
1268: $currentstring .= $token->[2];
1269: }
1270: return $currentstring;
1271: }
1272:
1.181 sakharuk 1273: #-- <big> tag (end tag required)
1.122 albertel 1274: sub start_big {
1275: my ($target,$token) = @_;
1276: my $currentstring = '';
1277: if ($target eq 'web') {
1278: $currentstring .= $token->[4];
1279: } elsif ($target eq 'tex') {
1.137 sakharuk 1280: $currentstring .= '{\large ';
1.144 sakharuk 1281: }
1.122 albertel 1282: return $currentstring;
1283: }
1284:
1285: sub end_big {
1286: my ($target,$token) = @_;
1287: my $currentstring = '';
1288: if ($target eq 'web') {
1289: $currentstring .= $token->[2];
1290: } elsif ($target eq 'tex') {
1291: $currentstring .= '}';
1292: }
1293: return $currentstring;
1294: }
1295:
1.181 sakharuk 1296: #-- <small> tag (end tag required)
1.122 albertel 1297: sub start_small {
1298: my ($target,$token) = @_;
1299: my $currentstring = '';
1300: if ($target eq 'web') {
1301: $currentstring .= $token->[4];
1302: } elsif ($target eq 'tex') {
1303: $currentstring .= '{\footnotesize ';
1.144 sakharuk 1304: }
1.122 albertel 1305: return $currentstring;
1306: }
1307:
1308: sub end_small {
1309: my ($target,$token) = @_;
1310: my $currentstring = '';
1311: if ($target eq 'web') {
1312: $currentstring .= $token->[2];
1313: } elsif ($target eq 'tex') {
1314: $currentstring .= '}';
1315: }
1316: return $currentstring;
1317: }
1318:
1.181 sakharuk 1319: #-- <basefont> tag (end tag forbidden)
1.122 albertel 1320: sub start_basefont {
1.126 sakharuk 1321: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.122 albertel 1322: my $currentstring = '';
1323: if ($target eq 'web') {
1324: $currentstring = $token->[4];
1.126 sakharuk 1325: } elsif ($target eq 'tex') {
1326: my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1327: if (defined $basesize) {
1328: $currentstring = '{\\'.$basesize.' ';
1329: }
1330: }
1.122 albertel 1331: return $currentstring;
1332: }
1333:
1334: sub end_basefont {
1.126 sakharuk 1335: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1336: my $currentstring = '';
1337: if ($target eq 'web') {
1338: $currentstring = $token->[4];
1.126 sakharuk 1339: } elsif ($target eq 'tex') {
1340: my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1341: if (defined $basesize) {
1342: $currentstring = '}';
1343: }
1344: }
1.122 albertel 1345: return $currentstring;
1346: }
1347:
1.181 sakharuk 1348: #-- <font> tag (end tag required)
1.122 albertel 1349: sub start_font {
1350: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1351: my $currentstring = '';
1352: if ($target eq 'web') {
1353: my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
1.204 albertel 1354: if ($face!~/symbol/i) {
1.267 albertel 1355: if (($env{'browser.fontenhance'} eq 'on') ||
1356: ($env{'browser.blackwhite'} eq 'on')) { return ''; }
1.155 www 1357: }
1.122 albertel 1358: $currentstring = $token->[4];
1.126 sakharuk 1359: } elsif ($target eq 'tex') {
1360: my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1361: if (defined $fontsize) {
1362: $currentstring = '{\\'.$fontsize.' ';
1363: }
1364: }
1.122 albertel 1365: return $currentstring;
1366: }
1367:
1368: sub end_font {
1369: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1370: my $currentstring = '';
1371: if ($target eq 'web') {
1372: $currentstring = $token->[2];
1.126 sakharuk 1373: } elsif ($target eq 'tex') {
1374: my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1375: if (defined $fontsize) {
1376: $currentstring = '}';
1377: }
1378: }
1.122 albertel 1379: return $currentstring;
1380: }
1381:
1.181 sakharuk 1382: #-- <strike> tag (end tag required)
1.122 albertel 1383: sub start_strike {
1384: my ($target,$token) = @_;
1385: my $currentstring = '';
1386: if ($target eq 'web') {
1387: $currentstring .= $token->[4];
1388: } elsif ($target eq 'tex') {
1389: &Apache::lonxml::startredirection();
1390: }
1391: return $currentstring;
1392: }
1393:
1394: sub end_strike {
1395: my ($target,$token) = @_;
1396: my $currentstring = '';
1397: if ($target eq 'web') {
1398: $currentstring .= $token->[2];
1399: } elsif ($target eq 'tex') {
1400: $currentstring=&Apache::lonxml::endredirection();
1401: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1402: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1403: $currentstring=~s/(\S)\s*$/$1\}/;
1404: }
1405: return $currentstring;
1406: }
1407:
1.181 sakharuk 1408: #-- <s> tag (end tag required)
1.122 albertel 1409: sub start_s {
1410: my ($target,$token) = @_;
1411: my $currentstring = '';
1412: if ($target eq 'web') {
1413: $currentstring .= $token->[4];
1414: } elsif ($target eq 'tex') {
1415: &Apache::lonxml::startredirection();
1416: }
1417: return $currentstring;
1418: }
1419:
1420: sub end_s {
1421: my ($target,$token) = @_;
1422: my $currentstring = '';
1423: if ($target eq 'web') {
1424: $currentstring .= $token->[2];
1425: } elsif ($target eq 'tex') {
1426: $currentstring=&Apache::lonxml::endredirection();
1427: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1428: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1429: $currentstring=~s/(\S)\s*$/$1\}/;
1430: }
1431: return $currentstring;
1432: }
1433:
1.181 sakharuk 1434: #-- <sub> tag (end tag required)
1.122 albertel 1435: sub start_sub {
1436: my ($target,$token) = @_;
1437: my $currentstring = '';
1438: if ($target eq 'web') {
1439: $currentstring .= $token->[4];
1440: } elsif ($target eq 'tex') {
1.202 sakharuk 1441: $currentstring .= '\ensuremath{_{';
1.122 albertel 1442: }
1443: return $currentstring;
1444: }
1445:
1446: sub end_sub {
1447: my ($target,$token) = @_;
1448: my $currentstring = '';
1449: if ($target eq 'web') {
1450: $currentstring .= $token->[2];
1451: } elsif ($target eq 'tex') {
1.202 sakharuk 1452: $currentstring .= '}}';
1.122 albertel 1453: }
1454: return $currentstring;
1455: }
1456:
1.181 sakharuk 1457: #-- <sup> tag (end tag required)
1.122 albertel 1458: sub start_sup {
1459: my ($target,$token) = @_;
1460: my $currentstring = '';
1461: if ($target eq 'web') {
1462: $currentstring .= $token->[4];
1463: } elsif ($target eq 'tex') {
1.202 sakharuk 1464: $currentstring .= '\ensuremath{^{';
1.122 albertel 1465: }
1466: return $currentstring;
1467: }
1468:
1469: sub end_sup {
1470: my ($target,$token) = @_;
1471: my $currentstring = '';
1472: if ($target eq 'web') {
1473: $currentstring .= $token->[2];
1474: } elsif ($target eq 'tex') {
1.202 sakharuk 1475: $currentstring .= '}}';
1.122 albertel 1476: }
1477: return $currentstring;
1478: }
1479:
1.181 sakharuk 1480: #-- <hr> tag (end tag forbidden)
1.122 albertel 1481: sub start_hr {
1.124 sakharuk 1482: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.279 foxr 1483: my $currentstring = &end_p(); # End enclosing para.
1.122 albertel 1484: if ($target eq 'web') {
1485: $currentstring .= $token->[4];
1486: } elsif ($target eq 'tex') {
1.149 sakharuk 1487: my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
1.124 sakharuk 1488: if (defined $LaTeXwidth) {
1489: if ($LaTeXwidth=~/^%/) {
1490: substr($LaTeXwidth,0,1)='';
1491: $LaTeXwidth=($LaTeXwidth/100).'\textwidth';
1492: }
1493: } else {
1.148 sakharuk 1494: $LaTeXwidth ='0.9\textwidth';
1.124 sakharuk 1495: }
1496: my ($pre,$post);
1497: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1498: if (($align eq 'center') || (not defined $align)) {
1499: $pre=''; $post='';
1500: } elsif ($align eq 'left') {
1501: $pre='\rlap{'; $post='} \hfill';
1502: } elsif ($align eq 'right') {
1503: $pre=' \hfill \llap{'; $post='}';
1504: }
1.148 sakharuk 1505: $currentstring .= ' \vskip 0 mm \noindent\makebox['.$LaTeXwidth.']{'.$pre.'\makebox['.
1.124 sakharuk 1506: $LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm ';
1.122 albertel 1507: }
1508: return $currentstring;
1509: }
1510:
1511: sub end_hr {
1512: my ($target,$token) = @_;
1513: my $currentstring = '';
1514: if ($target eq 'web') {
1515: $currentstring .= $token->[2];
1.148 sakharuk 1516: }
1.122 albertel 1517: return $currentstring;
1518: }
1519:
1.181 sakharuk 1520: #-- <div> tag (end tag required)
1.280 foxr 1521: {
1522:
1523: # Since div can be nested, the stack below is used
1524: # in 'tex' mode to store the ending strings
1525: # for the div stack.
1526:
1527: my @div_end_stack;
1528:
1.122 albertel 1529: sub start_div {
1.280 foxr 1530: my ($target,$token, $tagstack, $parstack, $parser, $safeeval) = @_;
1.279 foxr 1531: my $currentstring = &end_p(); # Close enclosing para.
1.122 albertel 1532: if ($target eq 'web') {
1533: $currentstring .= $token->[4];
1534: }
1.280 foxr 1535: if ($target eq 'tex') {
1536: # 4 possible alignments: left, right, center, and -missing-.
1537:
1538: my $endstring = '';
1539:
1540: my $align = lc(&Apache::lonxml::get_param('align', $parstack,
1541: $safeeval, undef, 1));
1542: if ($align eq 'center') {
1543: $currentstring .= '\begin{center}';
1544: $endstring = '\end{center}';
1.309 albertel 1545: if (&is_inside_of($tagstack, "table")) {
1546: $currentstring = ¢er_correction().$currentstring;
1547: $endstring .= ¢er_correction();
1548: }
1.280 foxr 1549: }
1550: elsif ($align eq 'right') {
1551: $currentstring .= '\begin{flushright}';
1552: $endstring .= '\end{flushright}';
1553: } elsif ($align eq 'left') {
1554: $currentstring .= '\begin{flushleft}';
1555: $endstring = '\end{flushleft}';
1556: } else {
1557:
1558: }
1559: $currentstring .= "\n"; # For human readability.
1560: $endstring = "\n$endstring\n"; # For human readability
1561: push(@div_end_stack, $endstring);
1562: }
1.122 albertel 1563: return $currentstring;
1564: }
1565:
1566: sub end_div {
1567: my ($target,$token) = @_;
1568: my $currentstring = '';
1569: if ($target eq 'web') {
1570: $currentstring .= $token->[2];
1.280 foxr 1571: }
1572: if ($target eq 'tex') {
1573: my $endstring = pop @div_end_stack;
1574: $currentstring .= $endstring;
1575: }
1.122 albertel 1576: return $currentstring;
1577: }
1.280 foxr 1578: }
1.122 albertel 1579:
1.181 sakharuk 1580: #-- <a> tag (end tag required)
1.122 albertel 1581: sub start_a {
1.149 sakharuk 1582: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1583: my $currentstring = '';
1584: if ($target eq 'web') {
1.250 albertel 1585: my $href=&Apache::lonxml::get_param('href',$parstack,$safeeval,
1586: undef,1);
1587: $currentstring=&Apache::lonenc::encrypt_ref($token,{'href'=>$href});
1.122 albertel 1588: } elsif ($target eq 'tex') {
1.149 sakharuk 1589: my $a=&Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1);
1.161 sakharuk 1590: my $b=&Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1);
1591: if ($a=~/\S/) {
1592: $a=~s/([^\\])%/$1\\\%/g;
1593: $currentstring .= '\ref{URI: '.$a.'}';
1594: } elsif ($b=~/\S/) {
1595: $currentstring .= '\ref{Anchor: '.$b.'}';
1596: } else {
1597: $currentstring.='';
1598: }
1.122 albertel 1599: }
1600: return $currentstring;
1601: }
1602:
1603: sub end_a {
1.168 albertel 1604: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1605: my $currentstring = '';
1606: if ($target eq 'web') {
1607: $currentstring .= $token->[2];
1608: }
1609: return $currentstring;
1610: }
1611:
1.181 sakharuk 1612: #-- <li> tag (end tag optional)
1.122 albertel 1613: sub start_li {
1.168 albertel 1614: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1615: my $currentstring = '';
1616: if ($target eq 'web') {
1617: $currentstring = $token->[4];
1618: } elsif ($target eq 'tex') {
1.237 sakharuk 1619: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1620: my $value=&Apache::lonxml::get_param('value',$parstack,$safeeval,undef,0);
1.238 albertel 1621: #FIXME need to support types i and I
1622: if ($type=~/disc/) {
1623: $currentstring .= ' \item[$\bullet$] ';
1624: } elsif ($type=~/circle/) {
1625: $currentstring .= ' \item[$\circ$] ';
1.146 sakharuk 1626: } elsif ($type=~/square/) {
1.238 albertel 1627: $currentstring .= ' \item[$\diamond$] ';
1628: } elsif ($type eq '1') {
1629: $currentstring .= ' \item['.($Apache::londefdef::list_index+1).'.]';
1.237 sakharuk 1630: } elsif ($type eq 'A') {
1.238 albertel 1631: $currentstring .= ' \item['.('A'..'Z')[$Apache::londefdef::list_index].'.]';
1.237 sakharuk 1632: } elsif ($type eq 'a') {
1.238 albertel 1633: $currentstring .= ' \item['.('a'..'z')[$Apache::londefdef::list_index].'.]';
1.237 sakharuk 1634: } elsif ($value ne '') {
1635: $currentstring .= ' \item['.$value.'] ';
1.122 albertel 1636: } else {
1.146 sakharuk 1637: $currentstring .= ' \item ';
1.122 albertel 1638: }
1.238 albertel 1639: $Apache::londefdef::list_index++;
1640: }
1.122 albertel 1641: return $currentstring;
1642: }
1643:
1644: sub end_li {
1645: my ($target,$token) = @_;
1.279 foxr 1646: my $currentstring = &end_p(); # In case there's a <p> in the <li>
1.122 albertel 1647: if ($target eq 'web') {
1.277 foxr 1648: $currentstring .= $token->[2];
1.122 albertel 1649: }
1650: return $currentstring;
1651: }
1652:
1.181 sakharuk 1653: #-- <u> tag (end tag required)
1.122 albertel 1654: sub start_u {
1655: my ($target,$token) = @_;
1656: my $currentstring = '';
1657: if ($target eq 'web') {
1658: $currentstring .= $token->[4];
1659: } elsif ($target eq 'tex') {
1660: &Apache::lonxml::startredirection();
1661: }
1662: return $currentstring;
1663: }
1664:
1665: sub end_u {
1666: my ($target,$token) = @_;
1667: my $currentstring = '';
1668: if ($target eq 'web') {
1669: $currentstring .= $token->[2];
1670: } elsif ($target eq 'tex') {
1671: $currentstring=&Apache::lonxml::endredirection();
1672: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1673: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1674: $currentstring=~s/(\S)\s*$/$1\}/;
1675: }
1676: return $currentstring;
1677: }
1678:
1.181 sakharuk 1679: #-- <ul> tag (end tag required)
1.122 albertel 1680: sub start_ul {
1.125 sakharuk 1681: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.279 foxr 1682: my $currentstring = &end_p(); # Close off enclosing list.
1.122 albertel 1683: if ($target eq 'web') {
1.277 foxr 1684: $currentstring .= $token->[4];
1.122 albertel 1685: } elsif ($target eq 'tex') {
1.125 sakharuk 1686: my $TeXtype=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1.238 albertel 1687: $Apache::londefdef::list_index=0;
1.125 sakharuk 1688: if ($TeXtype eq 'disc') {
1.222 sakharuk 1689: $currentstring .= '\renewcommand{\labelitemi}{$\bullet$}'.
1690: '\renewcommand{\labelitemii}{$\bullet$}'.
1691: '\renewcommand{\labelitemiii}{$\bullet$}'.
1692: '\renewcommand{\labelitemiv}{$\bullet$}';
1.125 sakharuk 1693: } elsif ($TeXtype eq 'circle') {
1.222 sakharuk 1694: $currentstring .= '\renewcommand{\labelitemi}{$\circ$}'.
1695: '\renewcommand{\labelitemii}{$\circ$}'.
1696: '\renewcommand{\labelitemiii}{$\circ$}'.
1697: '\renewcommand{\labelitemiv}{$\circ$}';
1.125 sakharuk 1698: } elsif ($TeXtype eq 'square') {
1.222 sakharuk 1699: $currentstring .= '\renewcommand{\labelitemi}{$\diamond$}'.
1700: '\renewcommand{\labelitemii}{$\diamond$}'.
1701: '\renewcommand{\labelitemiii}{$\diamond$}'.
1702: '\renewcommand{\labelitemiv}{$\diamond$}';
1.125 sakharuk 1703: }
1.222 sakharuk 1704: $currentstring .= '\strut \begin{itemize}';
1.122 albertel 1705: }
1706: return $currentstring;
1707: }
1708:
1709: sub end_ul {
1710: my ($target,$token) = @_;
1711: my $currentstring = '';
1712: if ($target eq 'web') {
1713: $currentstring = $token->[2];
1714: } elsif ($target eq 'tex') {
1.222 sakharuk 1715: $currentstring = '\end{itemize} \renewcommand{\labelitemi}{$\bullet$}'.
1716: '\renewcommand{\labelitemii}{$\bullet$}'.
1717: '\renewcommand{\labelitemiii}{$\bullet$}'.
1718: '\renewcommand{\labelitemiv}{$\bullet$}\strut ';
1.122 albertel 1719: }
1720: return $currentstring;
1721: }
1722:
1.181 sakharuk 1723: #-- <menu> tag (end tag required)
1.122 albertel 1724: sub start_menu {
1725: my ($target,$token) = @_;
1726: my $currentstring = '';
1727: if ($target eq 'web') {
1728: $currentstring = $token->[4];
1729: } elsif ($target eq 'tex') {
1730: $currentstring = " \\begin{itemize} ";
1731: }
1732: return $currentstring;
1733: }
1734:
1735: sub end_menu {
1736: my ($target,$token) = @_;
1737: my $currentstring = '';
1738: if ($target eq 'web') {
1739: $currentstring = $token->[2];
1740: } elsif ($target eq 'tex') {
1741: $currentstring = " \\end{itemize}";
1742: }
1743: return $currentstring;
1744: }
1745:
1.181 sakharuk 1746: #-- <dir> tag (end tag required)
1.122 albertel 1747: sub start_dir {
1748: my ($target,$token) = @_;
1.279 foxr 1749: my $currentstring = &end_p(); # In case there's a <p> prior to the list.
1.122 albertel 1750: if ($target eq 'web') {
1.277 foxr 1751: $currentstring .= $token->[4];
1.122 albertel 1752: } elsif ($target eq 'tex') {
1.277 foxr 1753: $currentstring .= " \\begin{itemize} ";
1.122 albertel 1754: }
1755: return $currentstring;
1756: }
1757:
1758: sub end_dir {
1759: my ($target,$token) = @_;
1760: my $currentstring = '';
1761: if ($target eq 'web') {
1762: $currentstring = $token->[2];
1763: } elsif ($target eq 'tex') {
1764: $currentstring = " \\end{itemize}";
1765: }
1766: return $currentstring;
1767: }
1768:
1.181 sakharuk 1769: #-- <ol> tag (end tag required)
1.122 albertel 1770: sub start_ol {
1.125 sakharuk 1771: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.279 foxr 1772: my $currentstring = &end_p(); # In case there's a <p> prior to the list.
1.122 albertel 1773: if ($target eq 'web') {
1.277 foxr 1774: $currentstring .= $token->[4];
1.122 albertel 1775: } elsif ($target eq 'tex') {
1.238 albertel 1776: $Apache::londefdef::list_index=0;
1.125 sakharuk 1777: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1778: if ($type eq '1') {
1.222 sakharuk 1779: $currentstring .= '\renewcommand{\labelenumi}{\arabic{enumi}.}'.
1780: '\renewcommand{\labelenumii}{\arabic{enumii}.}'.
1781: '\renewcommand{\labelenumiii}{\arabic{enumiii}.}'.
1782: '\renewcommand{\labelenumiv}{\arabic{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 'a') {
1.222 sakharuk 1789: $currentstring .= '\renewcommand{\labelenumi}{\alph{enumi}.}'.
1790: '\renewcommand{\labelenumii}{\alph{enumii}.}'.
1791: '\renewcommand{\labelenumiii}{\alph{enumiii}.}'.
1792: '\renewcommand{\labelenumiv}{\alph{enumiv}.}';
1.125 sakharuk 1793: } elsif ($type eq '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: } elsif ($type eq 'I') {
1.222 sakharuk 1799: $currentstring .= '\renewcommand{\labelenumi}{\Roman{enumi}.}'.
1800: '\renewcommand{\labelenumii}{\Roman{enumii}.}'.
1801: '\renewcommand{\labelenumiii}{\Roman{enumiii}.}'.
1802: '\renewcommand{\labelenumiv}{\Roman{enumiv}.}';
1.125 sakharuk 1803: }
1.222 sakharuk 1804: $currentstring .= '\strut \begin{enumerate}';
1.122 albertel 1805: }
1806: return $currentstring;
1807: }
1808:
1809: sub end_ol {
1810: my ($target,$token) = @_;
1811: my $currentstring = '';
1812: if ($target eq 'web') {
1813: $currentstring = $token->[2];
1814: } elsif ($target eq 'tex') {
1.222 sakharuk 1815: $currentstring = '\end{enumerate}\renewcommand{\labelenumi}{\arabic{enumi}.}'.
1816: '\renewcommand{\labelenumii}{\arabic{enumii}.}'.
1817: '\renewcommand{\labelenumiii}{\arabic{enumiii}.}'.
1818: '\renewcommand{\labelenumiv}{\arabic{enumiv}.}\strut ';
1.122 albertel 1819: }
1820: return $currentstring;
1821: }
1822:
1.181 sakharuk 1823: #-- <dl> tag (end tag required)
1.122 albertel 1824: sub start_dl {
1825: my ($target,$token) = @_;
1.279 foxr 1826: my $currentstring = &end_p(); # In case there's a <p> unclosed prior to the list.
1.122 albertel 1827: if ($target eq 'web') {
1.277 foxr 1828: $currentstring .= $token->[4];
1.122 albertel 1829: } elsif ($target eq 'tex') {
1.277 foxr 1830: $currentstring .= '\begin{description}';
1.243 albertel 1831: $Apache::londefdef::DL++;
1832: push(@Apache::londefdef::description,[]);
1833: $Apache::londefdef::DD[$Apache::londefdef::DL]=0;
1834: $Apache::londefdef::DT[$Apache::londefdef::DL]=0;
1.244 albertel 1835: $Apache::londefdef::seenDT[$Apache::londefdef::DL]=0;
1.122 albertel 1836: }
1837: return $currentstring;
1838: }
1839:
1840: sub end_dl {
1.174 sakharuk 1841: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1842: my $currentstring = '';
1843: if ($target eq 'web') {
1844: $currentstring = $token->[2];
1845: } elsif ($target eq 'tex') {
1.243 albertel 1846: if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
1847: if ($Apache::londefdef::DD[-1]) { &end_dd(@_); }
1848: foreach my $element (@{$Apache::londefdef::description[-1]}) {
1.174 sakharuk 1849: $currentstring.=' '.$element.' ';
1850: }
1.243 albertel 1851: pop(@Apache::londefdef::description);
1.174 sakharuk 1852: $currentstring.='\end{description}';
1.243 albertel 1853: delete($Apache::londefdef::DD[$Apache::londefdef::DL]);
1854: delete($Apache::londefdef::DT[$Apache::londefdef::DL]);
1.244 albertel 1855: delete($Apache::londefdef::seenDT[$Apache::londefdef::DL]);
1.243 albertel 1856: $Apache::londefdef::DL--;
1.122 albertel 1857: }
1858: return $currentstring;
1859: }
1860:
1.172 sakharuk 1861: #-- <dt> tag (end tag optional)
1.122 albertel 1862: sub start_dt {
1.172 sakharuk 1863: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1864: my $currentstring='';
1.122 albertel 1865: if ($target eq 'web') {
1866: $currentstring = $token->[4];
1867: } elsif ($target eq 'tex') {
1.243 albertel 1868: if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
1869: if ($Apache::londefdef::DD[-1]) { &end_dd(@_); }
1.174 sakharuk 1870: &Apache::lonxml::startredirection();
1.243 albertel 1871: $Apache::londefdef::DT[-1]++;
1.244 albertel 1872: $Apache::londefdef::seenDT[-1]=1;
1.122 albertel 1873: }
1874: return $currentstring;
1875: }
1876:
1877: sub end_dt {
1.172 sakharuk 1878: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1879: my $currentstring = '';
1880: if ($target eq 'web') {
1881: $currentstring = $token->[2];
1882: } elsif ($target eq 'tex') {
1.243 albertel 1883: if ($Apache::londefdef::DT[-1]) {
1884: my $data=&item_cleanup();
1.244 albertel 1885: push(@{$Apache::londefdef::description[-1]},'\item['.$data.'] \strut \vskip 0mm');
1.243 albertel 1886: $Apache::londefdef::DT[-1]--;
1887: }
1.122 albertel 1888: }
1889: return $currentstring;
1890: }
1891:
1.173 sakharuk 1892: sub item_cleanup {
1.174 sakharuk 1893: my $item=&Apache::lonxml::endredirection();
1.173 sakharuk 1894: $item=~s/\\begin{center}//g;
1895: $item=~s/\\end{center}//g;
1896: return $item;
1897: }
1898:
1.181 sakharuk 1899: #-- <dd> tag (end tag optional)
1.122 albertel 1900: sub start_dd {
1.147 sakharuk 1901: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1902: my $currentstring = '';
1903: if ($target eq 'web') {
1904: $currentstring = $token->[4];
1.147 sakharuk 1905: } elsif ($target eq 'tex') {
1.243 albertel 1906: if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
1907: if ($Apache::londefdef::DD[-1]) { &end_dd(@_);}
1.244 albertel 1908: if (!$Apache::londefdef::seenDT[-1]) {
1909: push(@{$Apache::londefdef::description[-1]},'\item[\strut] \strut \vskip 0mm ');
1910: }
1.243 albertel 1911: push(@{$Apache::londefdef::description[-1]},'');
1912: $Apache::londefdef::description[-1]->[-1].=' \strut ';
1913: $Apache::londefdef::DD[-1]++;
1.174 sakharuk 1914: &Apache::lonxml::startredirection();
1.122 albertel 1915: }
1916: return $currentstring;
1917: }
1918:
1919: sub end_dd {
1.174 sakharuk 1920: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1921: my $currentstring = '';
1922: if ($target eq 'web') {
1923: $currentstring = $token->[2];
1.174 sakharuk 1924: } elsif ($target eq 'tex') {
1.243 albertel 1925: $Apache::londefdef::description[-1]->[-1].=
1926: &Apache::lonxml::endredirection().' \vskip 0mm ';
1927: $Apache::londefdef::DD[-1]--;
1.174 sakharuk 1928: }
1.122 albertel 1929: return $currentstring;
1930: }
1931:
1.181 sakharuk 1932: #-- <table> tag (end tag required)
1.277 foxr 1933: # <table> also ends any prior <p> that is not closed.
1934: # but, unless I allow <p>'s to nest, that's the
1935: # only way I could think of to allow <p> in
1936: # <tr> <th> bodies
1937: #
1.206 sakharuk 1938: #list of supported attributes: border,width,TeXwidth
1.91 sakharuk 1939: sub start_table {
1940: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.277 foxr 1941: my $textwidth = '';
1.279 foxr 1942: my $currentstring = &end_p();
1.91 sakharuk 1943: if ($target eq 'web') {
1.277 foxr 1944: $currentstring .= $token->[4];
1.91 sakharuk 1945: } elsif ($target eq 'tex') {
1946: my $aa = {};
1947: push @Apache::londefdef::table, $aa;
1948: $Apache::londefdef::table[-1]{'row_number'} = -1;
1.222 sakharuk 1949: #maximum table's width (default coincides with text line length)
1.206 sakharuk 1950: if ($#Apache::londefdef::table==0) {
1.267 albertel 1951: $textwidth=&recalc($env{'form.textwidth'}); #result is always in mm
1.206 sakharuk 1952: $textwidth=~/(\d+\.?\d*)/;
1953: $textwidth=0.95*$1; #accounts "internal" LaTeX space for table frame
1954: } else {
1955: if ($Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]=~/\d/) {
1956: #the maximum width of nested table is determined by LATeX width of parent cell
1957: $textwidth=$Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}];
1958: } else {
1959: #try to use all space not used before (minus 5% for LaTeX table internal) - rather silly
1.228 sakharuk 1960: $textwidth=$Apache::londefdef::table[-2]{'width'};
1.206 sakharuk 1961: for (my $i=0;$i<$Apache::londefdef::table[-2]{'counter_columns'};$i++) {
1962: $textwidth=$textwidth-$Apache::londefdef::table[-2]{'TeXlen'}[0][$i];
1963: }
1964: }
1965: }
1.294 foxr 1966:
1967: # width either comes forced from the TeXwidth or the width parameters.
1968: # in either case it can be a percentage or absolute width.
1.311 albertel 1969: # in the width case we ignore absolute width
1.126 sakharuk 1970: my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
1.308 albertel 1971: if (!defined($TeXwidth)) {
1.311 albertel 1972: my $htmlwidth = &Apache::lonxml::get_param('width',$parstack,
1973: $safeeval,undef,1);
1974: if ($htmlwidth =~ /%/) {
1975: $TeXwidth = $htmlwidth;
1976: } else {
1977: $TeXwidth = $textwidth;
1978: }
1.294 foxr 1979: } else {
1980: $Apache::londefdef::table[-1]{'forcedtablewidth'} = 1;
1981: }
1982: if ($TeXwidth=~/%/) {
1.203 sakharuk 1983: $Apache::londefdef::table[-1]{'percent'}=1;
1.126 sakharuk 1984: $TeXwidth=~/(\d+)/;
1.206 sakharuk 1985: $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;
1.126 sakharuk 1986: } else {
1.206 sakharuk 1987: $Apache::londefdef::table[-1]{'width'}=$TeXwidth;
1.126 sakharuk 1988: }
1.294 foxr 1989:
1.126 sakharuk 1990: #table's border
1.206 sakharuk 1991: my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval);
1.208 sakharuk 1992: my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
1.91 sakharuk 1993: unless (defined $border) { $border = 0; }
1994: if ($border) {
1995: $Apache::londefdef::table[-1]{'hinc'} = '\hline ';
1996: $Apache::londefdef::table[-1]{'vinc'} = '&';
1997: $Apache::londefdef::table[-1]{'vvinc'} = '|';
1998: } else {
1999: $Apache::londefdef::table[-1]{'hinc'} = '';
2000: $Apache::londefdef::table[-1]{'vinc'} = '&';
2001: $Apache::londefdef::table[-1]{'vvinc'} = '';
2002: }
1.206 sakharuk 2003: if ($#Apache::londefdef::table==0) {
1.281 foxr 2004: # Note that \newline seems to destroy the alignment envs.
2005: # $Apache::londefdef::table[-1]{'output'}='\strut\newline\strut\setlength{\tabcolsep}{1 mm}';
2006: $Apache::londefdef::table[-1]{'output'}='\strut'.'\\\\'."\n".'\strut\setlength{\tabcolsep}{1 mm}';
1.206 sakharuk 2007: }
2008: $Apache::londefdef::table[-1]{'output'}.=' \noindent \begin{tabular} ';
2009: $Apache::londefdef::table[-1]{'TeXlen'}=[];
2010: $Apache::londefdef::table[-1]{'objectlen'}=[];
1.229 sakharuk 2011: $Apache::londefdef::table[-1]{'objectsignal'}=[];
1.206 sakharuk 2012: $Apache::londefdef::table[-1]{'maxlen'}=[];
2013: $Apache::londefdef::table[-1]{'minlen'}=[];
2014: $Apache::londefdef::table[-1]{'content'}=[];
2015: $Apache::londefdef::table[-1]{'align'}=[];
1.277 foxr 2016: $currentstring.='\keephidden{NEW TABLE ENTRY}';
1.295 foxr 2017:
1.294 foxr 2018:
2019: }
1.91 sakharuk 2020: return $currentstring;
2021: }
1.122 albertel 2022:
2023: sub end_table {
2024: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2025: my $currentstring = '';
2026: if ($target eq 'web') {
2027: $currentstring = $token->[2];
2028: } elsif ($target eq 'tex') {
2029: my $inmemory = '';
2030: my $output = '';
1.206 sakharuk 2031: my $WARNING='';
1.305 foxr 2032: # &debug_dump_table($Apache::londefdef::table[-1]);
1.206 sakharuk 2033: #width of columns from TeXwidth attributes
1.294 foxr 2034:
1.206 sakharuk 2035: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2036: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
2037: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]<$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn]) {
2038: $Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]=$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn];
2039: }
2040: }
2041: }
2042: #free space and number of empty columns
2043: my ($available_space,$empty_columns)=($Apache::londefdef::table[-1]{'width'},0);
1.228 sakharuk 2044: if ($#Apache::londefdef::table ne 0) {$available_space=0.9*$available_space;}
1.206 sakharuk 2045: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
2046: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]==0) {
2047: $empty_columns++;
2048: } else {
2049: $available_space=$available_space-$Apache::londefdef::table[-1]{'TeXlen'}[0][$jn];
2050: }
2051: }
2052: #boundaries for contents columns
2053: my @min_len=();#columns can not be narrower
2054: my @max_len=();#maximum length of column
2055: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
2056: my ($localmin,$localmax)=(0,0);
2057: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2058: if ($localmin<$Apache::londefdef::table[-1]{'minlen'}[$in][$jn]) {
2059: $localmin=$Apache::londefdef::table[-1]{'minlen'}[$in][$jn];
2060: }
2061: if ($localmax<$Apache::londefdef::table[-1]{'maxlen'}[$in][$jn]) {
2062: $localmax=$Apache::londefdef::table[-1]{'maxlen'}[$in][$jn];
2063: }
2064: }
2065: push @min_len, $localmin;
2066: push @max_len, $localmax;
1.122 albertel 2067: }
1.206 sakharuk 2068: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
2069: my $localmin=0,;
2070: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2071: if ($localmin<$Apache::londefdef::table[-1]{'objectlen'}[$in][$jn]) {
2072: $localmin=$Apache::londefdef::table[-1]{'objectlen'}[$in][$jn];
2073: }
2074: }
1.229 sakharuk 2075: if ($max_len[$jn]<$localmin) {
2076: $max_len[$jn]=$localmin;
2077: $Apache::londefdef::table[-1]{'objectsignal'}[$jn]=1;
2078: }#object size is bigger
2079: if ($min_len[$jn]<$localmin) {
2080: $min_len[$jn]=$localmin;
2081: $Apache::londefdef::table[-1]{'objectsignal'}[$jn]=1;
2082: }#object size is bigger
1.206 sakharuk 2083: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]!=0) {
2084: $min_len[$jn]=0;
2085: $max_len[$jn]=0;
2086: }
2087: }
2088: #final adjustment of column width
2089: my @fwidth=@{$Apache::londefdef::table[-1]{'TeXlen'}[0]};#final width array
2090: my @adjust=();
2091: #step 1. adjustment by maximum value
2092: my $space_neeeded=0;
2093: for (my $jn=0;$jn<=$#max_len;$jn++) {
2094: $space_neeeded=$space_neeeded+$max_len[$jn];
2095: }
2096: if ($space_neeeded<=$available_space) {
2097: for (my $jn=0;$jn<=$#max_len;$jn++) {
2098: if ($fwidth[$jn]==0) {
2099: $fwidth[$jn]=$max_len[$jn];
1.53 sakharuk 2100: }
1.51 sakharuk 2101: }
1.206 sakharuk 2102: } else {
2103: #step 2. adjustment by minimum value (estimation)
2104: $space_neeeded=0;
2105: for (my $jn=0;$jn<=$#min_len;$jn++) {
2106: $space_neeeded+=$min_len[$jn];
2107: }
2108: if ($space_neeeded>$available_space) {
2109: $WARNING=' \textbf{NOT ENOUGH SPACE FOR TABLE} ';
2110: for (my $jn=0;$jn<=$#max_len;$jn++) {
2111: if ($fwidth[$jn]==0) {
2112: $fwidth[$jn]=$min_len[$jn];
2113: }
2114: }
1.229 sakharuk 2115: #check if we have objects which can be scaled
2116: my $how_many_to_scale=0;
2117: my @to_scale=();
2118: for (my $jn=0;$jn<=$#max_len;$jn++) {
2119: if ($Apache::londefdef::table[-1]{'objectsignal'}[$jn] eq '1') {
2120: $how_many_to_scale++;
2121: push @to_scale, $jn;
2122: }
2123: }
2124: if ($how_many_to_scale>0) {
2125: my $space_to_adjust=($space_neeeded-$available_space)/$how_many_to_scale;
2126: foreach my $jn (@to_scale) {
2127: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2128: $Apache::londefdef::table[-1]{'content'}[$in][$jn]=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/;
2129: if ($1 ne '') {
2130: my $current_length=&recalc($1);
2131: $current_length=~/(\d+\.?\d*)/;
2132: $current_length=$current_length-$space_to_adjust;
2133: $Apache::londefdef::table[-1]{'content'}[$in][$jn]=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/width=$current_length mm/;
2134: }
2135: $Apache::londefdef::table[-1]{'content'}[$in][$jn]=~m/\[(\d+\.?\d*)\s*mm\]/;
2136: if ($1 ne '') {
2137: my $current_length=$1;
2138: $current_length=$current_length-$space_to_adjust;
2139: $Apache::londefdef::table[-1]{'content'}[$in][$jn]=~s/\[(\d+\.?\d*)\s*mm\]/\[$current_length mm\]/;
2140: }
2141: }
2142: $fwidth[$jn]=$fwidth[$jn]-$space_to_adjust;
2143: }
2144: }
1.206 sakharuk 2145: } else {
2146: #step 3. adjustment over minimal + corrections
2147: my $enlarge_coef=$available_space/$space_neeeded;
2148: my $acsessive=0;
2149: for (my $jn=0;$jn<=$#min_len;$jn++) {
2150: $adjust[$jn]=$min_len[$jn]*$enlarge_coef;
2151: if ($adjust[$jn]>$max_len[$jn]) {
2152: $fwidth[$jn]=$max_len[$jn];
2153: $acsessive=$acsessive+$adjust[$jn]-$max_len[$jn];
2154: $adjust[$jn]=0;
2155: }
2156: }
2157: if ($acsessive>0) {
2158: #we have an excess of space and can redistribute it
2159: my $notempty_columns=0;
2160: for (my $jn=0;$jn<=$#min_len;$jn++) {
2161: if ($adjust[$jn]!=0) {
2162: $notempty_columns++;
2163: }
2164: }
2165: my $per_column=$acsessive/$notempty_columns;
2166: for (my $jn=0;$jn<=$#min_len;$jn++) {
2167: if ($adjust[$jn]!=0) {
2168: $adjust[$jn]+=$per_column;
2169: $fwidth[$jn]=$adjust[$jn];
2170: }
1.223 sakharuk 2171: }
2172: } else {
2173: for (my $jn=0;$jn<=$#min_len;$jn++) {
2174: $fwidth[$jn]=$adjust[$jn];
1.206 sakharuk 2175: }
2176: }
1.203 sakharuk 2177: }
2178: }
1.222 sakharuk 2179: #use all available width if it is defined in % or as TeXwidth
2180: if (($Apache::londefdef::table[-1]{'percent'}==1) || ($Apache::londefdef::table[-1]{'forcetablewidth'}==1)) {
1.203 sakharuk 2181: my $current=0;
1.206 sakharuk 2182: for (my $i=0;$i<=$#fwidth;$i++) {
2183: $current+=$fwidth[$i];
1.203 sakharuk 2184: }
2185: my $coef=$Apache::londefdef::table[-1]{'width'}/$current;
1.206 sakharuk 2186: for (my $i=0;$i<=$#fwidth;$i++) {
2187: $fwidth[$i]*=$coef;
2188: }
2189: }
2190: #removing of empty columns if allowed
1.208 sakharuk 2191: my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
1.206 sakharuk 2192: if ($permission eq 'yes') {
2193: my @cleaned_table=();
2194: my @cleaned_header=();
2195: my $colind=0;
2196: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
2197: if ($fwidth[$jn]!=0) {
2198: #we need to copy column
2199: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2200: $cleaned_table[$in][$colind]=$Apache::londefdef::table[-1]{'content'}[$in][$jn];
2201: $cleaned_header[$colind]=$fwidth[$jn];
2202: }
2203: $colind++;
2204: }
1.122 albertel 2205: }
1.206 sakharuk 2206: $Apache::londefdef::table[-1]{'content'}=\@cleaned_table;
2207: @fwidth=@cleaned_header;
1.122 albertel 2208: }
1.206 sakharuk 2209: #construct header of the table
2210: my $header_of_table = '{'.$Apache::londefdef::table[-1]{'vvinc'};
2211: for (my $in=0;$in<=$#fwidth;$in++) {
2212: $header_of_table.='p{'.$fwidth[$in].' mm}'.$Apache::londefdef::table[-1]{'vvinc'};
2213: }
2214: $header_of_table .= '}';
1.126 sakharuk 2215: #fill the table
2216: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1.306 foxr 2217: my $have_rowspan = 0;
1.206 sakharuk 2218: for (my $jn=0;$jn<=$#fwidth;$jn++) {
1.304 foxr 2219: #
2220: # Do the appropriate magic if this has a colspan
2221: #
2222: my $colspan = $Apache::londefdef::table[-1]{'colspan'}[$in][$jn];
2223: if ($colspan > 1) {
2224: $output .= '\multicolumn{'.
2225: $colspan
2226: .'}{|l|}{';
2227: }
1.306 foxr 2228: my $rowspan = $Apache::londefdef::table[-1]{'rowspan'}[$in][$jn];
2229:
2230: # Start a rowspan if necessary:
2231:
2232: if ($rowspan > 1) {
2233: $have_rowspan++;
2234: $output .= '\multirow{'.$rowspan.'}[0]{'.$fwidth[$jn].'mm}{';
2235: }
2236: if (($rowspan eq '^') || ($rowspan eq '_')) {
2237: $have_rowspan++;
2238: }
2239:
1.206 sakharuk 2240: if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
1.309 albertel 2241: $output.=¢er_correction().'\begin{center}';
1.206 sakharuk 2242: } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
2243: $output.=' \hfill \llap{'
2244: }
2245: $output.=$Apache::londefdef::table[-1]{'content'}[$in][$jn];
2246: if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
1.309 albertel 2247: $output.='\end{center}'.¢er_correction();
1.206 sakharuk 2248: } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
2249: $output.='} ';
2250: }
1.306 foxr 2251: # Close off any open multirow:
2252:
2253: if ($rowspan > 1) {
2254: $output .= '}';
2255: }
1.304 foxr 2256: # Close off the colspan...
2257: #
2258: if ($colspan > 1) {
2259: $output .= '}';
2260: $jn += $colspan-1; # Adjust for number of rows really left.
2261: }
1.206 sakharuk 2262: if ($jn!=$#fwidth) {$output.=' '.$Apache::londefdef::table[-1]{'vinc'};}
2263: }
1.306 foxr 2264: # If have_rowspan > 0, and borders are on, then
2265: # we need to do more than put an \hline at the bottom of row.
2266: # we need to do the appropriate \cline to ensure that
2267: # the spanned rows don't have \hlines through them.
2268:
2269: if (($Apache::londefdef::table[-1]{'hinc'} =~ /\\hline/) && $have_rowspan) {
2270: $output .= ' \\\\ ';
2271: for (my $jn=0; $jn<=$#fwidth;$jn++) {
2272: my $rowspan = $Apache::londefdef::table[-1]{'rowspan'}[$in][$jn];
2273: if (($rowspan <= 1) || ($rowspan eq '_')) {
2274: my $column = $jn+1;
2275: $output .= '\cline{'.$column.'-'.$column.'} ';
2276: }
2277: }
2278:
2279: } else {
2280: $output.=' \\\\ '.$Apache::londefdef::table[-1]{'hinc'}.' ';
2281: }
1.122 albertel 2282: }
1.281 foxr 2283: # Note that \newline destroys alignment env's produced by e.g. <div>
2284: # $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut\newline\strut ';
2285: $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut'.'\\\\'."\n".'\strut ';
1.127 sakharuk 2286: if ($#Apache::londefdef::table > 0) {
2287: my $inmemory = $Apache::londefdef::table[-1]{'output'};
1.294 foxr 2288: # Figure out max/and min width by summing us and then
2289: # apply that to the current column of the table we nest in
2290: # if it's larger than the current width or the current width
2291: # is undefined.
2292: #
2293: my $min_nested_width = 0;
2294: my $max_nested_width = 0;
2295: for (my $col = 0; $col <= $Apache::londefdef::table[-1]{'counter_columns'}; $col++) {
2296: $min_nested_width += $min_len[$col];
2297: $max_nested_width += $max_len[$col];
1.300 foxr 2298:
1.294 foxr 2299: }
2300: # Fudge in an extra 5 mm for borders etc:
2301:
2302: $min_nested_width += 5;
2303: $max_nested_width += 5;
2304:
2305: my $outer_column = $Apache::londefdef::table[-2]{'counter_columns'};
2306: my $outer_row = $Apache::londefdef::table[-2]{'row_number'};
2307: if ($min_nested_width > $Apache::londefdef::table[-2]{'minlen'}[$outer_row][$outer_column]) {
2308: $Apache::londefdef::table[-2]{'minlen'}[$outer_row][$outer_column] = $min_nested_width;
2309: }
2310: if ($max_nested_width > $Apache::londefdef::table[-2]{'maxlen'}[$outer_row][$outer_column]) {
2311: $Apache::londefdef::table[-2]{'maxlen'}[$outer_row][$outer_column] = $max_nested_width;
2312: }
2313:
1.127 sakharuk 2314: pop @Apache::londefdef::table;
1.129 sakharuk 2315: push @{$Apache::londefdef::table[-1]{'include'}}, $inmemory;
1.127 sakharuk 2316: } else {
2317: $currentstring .= $Apache::londefdef::table[-1]{'output'};
2318: pop @Apache::londefdef::table;
1.143 sakharuk 2319: undef @Apache::londefdef::table;
1.127 sakharuk 2320: }
1.122 albertel 2321: }
2322: return $currentstring;
2323: }
2324:
1.166 sakharuk 2325: #-- <tr> tag (end tag optional)
1.122 albertel 2326: sub start_tr {
2327: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2328: my $currentstring = '';
2329: if ($target eq 'web') {
2330: $currentstring = $token->[4];
2331: } elsif ($target eq 'tex') {
2332: $Apache::londefdef::table[-1]{'row_number'}++;
1.206 sakharuk 2333: my $alignchar=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1.122 albertel 2334: if ($alignchar ne '') {
1.206 sakharuk 2335: push @ {$Apache::londefdef::table[-1]{'rows'} },substr($alignchar,0,1);
1.122 albertel 2336: } else {
2337: push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l';
2338: }
2339: push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'});
1.300 foxr 2340: #
2341: # Need to save the number of table columns to preserve the max # columns.
2342: #
2343: $Apache::londefdef::table[-1]{'prior_columns'} = $Apache::londefdef::table[-1]{'counter_columns'};
1.122 albertel 2344: $Apache::londefdef::table[-1]{'counter_columns'} = -1;
1.206 sakharuk 2345: push @ {$Apache::londefdef::table[-1]{'TeXlen'}}, [];
2346: push @ {$Apache::londefdef::table[-1]{'objectlen'}}, [];
2347: push @ {$Apache::londefdef::table[-1]{'minlen'}}, [];
2348: push @ {$Apache::londefdef::table[-1]{'maxlen'}}, [];
2349: push @ {$Apache::londefdef::table[-1]{'content'}}, [];
1.122 albertel 2350: }
2351: return $currentstring;
2352: }
2353:
2354: sub end_tr {
1.160 sakharuk 2355: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.279 foxr 2356: my $currentstring = &end_p(); # Close any pending <p> in the row.
1.122 albertel 2357: if ($target eq 'web') {
1.277 foxr 2358: $currentstring .= $token->[2];
1.122 albertel 2359: } elsif ($target eq 'tex') {
1.160 sakharuk 2360: if ($Apache::londefdef::TD_redirection) {
2361: &end_td_tex($parstack,$parser,$safeeval);
2362: }
1.300 foxr 2363: # Counter columns must be the maximum number of columns seen
2364: # in the table so far so:
2365: if ($Apache::londefdef::table[-1]{'prior_columns'} > $Apache::londefdef::table[-1]{'counter_columns'}) {
2366: $Apache::londefdef::table[-1]{'counter_columns'} = $Apache::londefdef::table[-1]{'prior_columns'};
2367: }
1.295 foxr 2368:
2369:
1.294 foxr 2370:
1.122 albertel 2371: }
2372: return $currentstring;
2373: }
2374:
1.166 sakharuk 2375: #-- <td> tag (end tag optional)
1.122 albertel 2376: sub start_td {
2377: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2378: my $currentstring = '';
2379: if ($target eq 'web') {
2380: $currentstring = $token->[4];
2381: } elsif ($target eq 'tex') {
1.160 sakharuk 2382: $Apache::londefdef::TD_redirection = 1;
1.159 sakharuk 2383: &tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval);
1.122 albertel 2384: }
2385: return $currentstring;
2386: }
1.159 sakharuk 2387:
2388: sub tag_check {
2389: my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
1.160 sakharuk 2390: my @ar=@$parstack;
2391: for (my $i=$#ar-1;$i>=0;$i--) {
2392: if (lc($$tagstack[$i]) eq $good_tag) {
2393: &start_td_tex($parstack,$parser,$safeeval);
2394: last;
2395: } elsif (lc($$tagstack[$i]) eq $bad_tag) {
2396: splice @ar, $i+1;
2397: &end_td_tex(\@ar,$parser,$safeeval);
2398: &start_td_tex($parstack,$parser,$safeeval);
2399: last;
1.159 sakharuk 2400: }
1.160 sakharuk 2401: }
1.159 sakharuk 2402: return '';
2403: }
2404:
2405: sub start_td_tex {
2406: my ($parstack,$parser,$safeeval) = @_;
1.206 sakharuk 2407: my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
2408: if ($alignchar eq '') {
2409: $alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
1.159 sakharuk 2410: }
1.206 sakharuk 2411: push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
1.159 sakharuk 2412: $Apache::londefdef::table[-1]{'counter_columns'}++;
1.206 sakharuk 2413: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2414: if (defined $TeXwidth) {
2415: my $current_length=&recalc($TeXwidth);
2416: $current_length=~/(\d+\.?\d*)/;
2417: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
2418: }
1.159 sakharuk 2419: &Apache::lonxml::startredirection();
2420: return '';
2421: }
2422:
2423: sub end_td_tex {
2424: my ($parstack,$parser,$safeeval) = @_;
1.304 foxr 2425: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
2426: my $current_column = $Apache::londefdef::table[-1]{'counter_columns'};
1.303 foxr 2427: my $data = &Apache::lonxml::endredirection();
2428:
1.305 foxr 2429: # The rowspan array of the table indicates which cells are part of a span.
2430: # n indicates the start of a span set of n rows.
2431: # ^ indicates a cell that continues a span set.
1.306 foxr 2432: # _ indicates the cell is at the bottom of a span set.
1.305 foxr 2433: # If this and subsequent cells are part of a rowspan, we must
2434: # push along the row until we find one that is not.
2435:
2436: while ((defined $Apache::londefdef::table[-1]{'rowspan'}[$current_row] [$current_column])
1.306 foxr 2437: && ($Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column] =~ /[\^\_]/)) {
1.305 foxr 2438: # Part of a span.
2439: push @ {$Apache::londefdef::table[-1]{'content'}[-1]}, '';
2440: $current_column++;
2441: }
2442: $Apache::londefdef::table[-1]{'counter_columns'} = $current_column;
2443:
2444:
2445:
2446: my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval, undef, 0);
2447: if (!$rowspan) {
2448: $rowspan = 1;
2449: }
2450:
1.303 foxr 2451:
1.305 foxr 2452:
2453: $Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column] = $rowspan;
2454: for (my $i = 1; $i < $rowspan; $i++) {
2455: $Apache::londefdef::table[-1]{'rowspan'}[$current_row+$i][$current_column] = '^';
1.306 foxr 2456: if ($i == ($rowspan-1)) {
2457: $Apache::londefdef::table[-1]{'rowspan'}[$current_row+$i][$current_column] = '_';
2458: }
1.305 foxr 2459: }
1.304 foxr 2460:
1.159 sakharuk 2461: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2462: if (defined $TeXwidth) {
1.206 sakharuk 2463: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2464: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2465: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
1.159 sakharuk 2466: } else {
1.206 sakharuk 2467: if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
2468: my $garbage_data=$data;
2469: my $fwidth=0;
2470: while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2471: my $current_length=&recalc($1);
2472: $current_length=~/(\d+\.?\d*)/;
2473: if ($fwidth<$1) {$fwidth=$1;}
2474: $garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2475: }
2476: while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
2477: my $current_length=$1;
2478: if ($fwidth<$current_length) {$fwidth=$current_length;}
2479: $garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
2480: }
2481: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2482: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2483: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2484: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
1.231 sakharuk 2485: } 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)*/) {
2486: my $garbage_data=$data;
2487: my $fwidth=0;
2488: while ($garbage_data=~/\\parbox\{\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)\s*\}/) {
2489: my $current_length=&recalc($1);
2490: $current_length=~/(\d+\.?\d*)/;
2491: if ($fwidth<$1) {$fwidth=$1;}
2492: $garbage_data=~s/\\parbox\{\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2493: }
2494: while ($garbage_data=~/\\epsfxsize\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2495: my $current_length=&recalc($1);
2496: $current_length=~/(\d+\.?\d*)/;
2497: if ($fwidth<$1) {$fwidth=$1;}
2498: $garbage_data=~s/\\epsfxsize\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2499: }
2500: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2501: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2502: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2503: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2504: $data=~s/\\\\\s*$//;
1.159 sakharuk 2505: } else {
1.166 sakharuk 2506: $data=~s/^\s+(\S.*)/$1/;
1.159 sakharuk 2507: $data=~s/(.*\S)\s+$/$1/;
1.166 sakharuk 2508: $data=~s/(\s)+/$1/;
1.206 sakharuk 2509: my ($current_length,$min_length)=(0,0);
1.166 sakharuk 2510: if ($data=~/\\vskip/) {
2511: my $newdata=$data;
2512: $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
2513: my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
2514: foreach my $elementdata (@newdata) {
1.206 sakharuk 2515: my $lengthnewdata=2.5*&LATEX_length($elementdata);
1.166 sakharuk 2516: if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
1.206 sakharuk 2517: my @words=split(/ /,$elementdata);
2518: foreach my $word (@words) {
2519: my $lengthword=2.5*&LATEX_length($word);
2520: if ($min_length<$lengthword) {$min_length=$lengthword;}
2521: }
1.166 sakharuk 2522: }
2523: } else {
1.206 sakharuk 2524: $current_length=2.5*&LATEX_length($data);
2525: my @words=split(/ /,$data);
2526: foreach my $word (@words) {
1.228 sakharuk 2527: my $lengthword=2*&LATEX_length($word);
1.206 sakharuk 2528: if ($min_length<$lengthword) {$min_length=$lengthword;}
2529: }
1.166 sakharuk 2530: }
1.206 sakharuk 2531: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2532: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2533: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
2534: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
1.159 sakharuk 2535: }
2536: }
1.302 foxr 2537: # Substitute all of the tables nested in this cell in their appropriate places.
2538:
2539:
2540: my $nested_count = $#{$Apache::londefdef::table[-1]{'include'}}; # This one is constant...
2541: for (my $in=0; $in<=$nested_count; $in++) {
1.301 foxr 2542: my $nested = shift @{$Apache::londefdef::table[-1]{'include'}};
2543: $nested =~ s/\\end\{tabular\}\\strut\\\\/\\end\{tabular\}/;
2544: # $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
2545: $data =~ s/\\keephidden\{NEW TABLE ENTRY\}/$nested/;
2546:
2547: }
2548: # Should be be killing off the 'include' elements as they're used up?
1.305 foxr 2549:
1.206 sakharuk 2550: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
1.305 foxr 2551:
1.304 foxr 2552: # Get the column and row spans.
2553: # Colspan can be done via \multicolumn if I can figure out the data structs.
2554:
2555: my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval, undef, 0);
2556: if (!$colspan) {
2557: $colspan = 1;
2558: }
2559:
2560:
2561: # the colspan array will indicate how many columns will be spanned by this
2562: # cell..this requires that counter_columns also be adjusted accordingly
2563: # so that the next bunch of text goes in the right cell. Note that since
2564: # counter_columns is incremented in the start_td_tex, we adjust by colspan-1.
2565: #
2566:
2567: $Apache::londefdef::table[-1]{'colspan'}[$current_row][$current_column] = $colspan;
2568: $Apache::londefdef::table[-1]{'counter_columns'} += $colspan -1;
2569:
2570: # Put empty text in spanned cols.
2571:
2572: for (my $i = 0; $i < ($colspan -1); $i++) {
2573: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },'';
2574: }
2575:
2576:
1.301 foxr 2577: return '';
1.159 sakharuk 2578: }
2579:
1.122 albertel 2580: sub end_td {
1.126 sakharuk 2581: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 2582: my $currentstring = '';
2583: if ($target eq 'web') {
2584: $currentstring = $token->[2];
2585: } elsif ($target eq 'tex') {
1.160 sakharuk 2586: $Apache::londefdef::TD_redirection =0;
1.159 sakharuk 2587: &end_td_tex($parstack,$parser,$safeeval);
1.122 albertel 2588: }
2589: return $currentstring;
2590: }
2591:
1.166 sakharuk 2592: #-- <th> tag (end tag optional)
1.122 albertel 2593: sub start_th {
2594: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2595: my $currentstring = '';
2596: if ($target eq 'web') {
2597: $currentstring = $token->[4];
2598: } elsif ($target eq 'tex') {
1.230 sakharuk 2599: $Apache::londefdef::TD_redirection = 1;
2600: &tagg_check('tr','th',$tagstack,$parstack,$parser,$safeeval);
1.122 albertel 2601: }
2602: return $currentstring;
1.130 sakharuk 2603: }
1.230 sakharuk 2604:
2605: sub tagg_check {
2606: my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
2607: my @ar=@$parstack;
2608: for (my $i=$#ar-1;$i>=0;$i--) {
2609: if (lc($$tagstack[$i]) eq $good_tag) {
2610: &start_th_tex($parstack,$parser,$safeeval);
2611: last;
2612: } elsif (lc($$tagstack[$i]) eq $bad_tag) {
2613: splice @ar, $i+1;
2614: &end_th_tex(\@ar,$parser,$safeeval);
2615: &start_th_tex($parstack,$parser,$safeeval);
2616: last;
2617: }
2618: }
2619: return '';
2620: }
2621:
2622: sub start_th_tex {
2623: my ($parstack,$parser,$safeeval) = @_;
2624: my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
2625: if ($alignchar eq '') {
2626: $alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
2627: }
2628: push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
2629: $Apache::londefdef::table[-1]{'counter_columns'}++;
2630: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2631: if (defined $TeXwidth) {
2632: my $current_length=&recalc($TeXwidth);
2633: $current_length=~/(\d+\.?\d*)/;
2634: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
2635: }
2636: &Apache::lonxml::startredirection();
2637: return '';
2638: }
2639:
2640: sub end_th_tex {
2641: my ($parstack,$parser,$safeeval) = @_;
2642: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
2643: my $data=&Apache::lonxml::endredirection();
2644: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2645: if (defined $TeXwidth) {
2646: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2647: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2648: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2649: } else {
2650: if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
2651: my $garbage_data=$data;
2652: my $fwidth=0;
2653: while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2654: my $current_length=&recalc($1);
2655: $current_length=~/(\d+\.?\d*)/;
2656: if ($fwidth<$1) {$fwidth=$1;}
2657: $garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2658: }
2659: while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
2660: my $current_length=$1;
2661: if ($fwidth<$current_length) {$fwidth=$current_length;}
2662: $garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
2663: }
2664: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2665: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2666: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2667: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2668: } else {
2669: $data=~s/^\s+(\S.*)/$1/;
2670: $data=~s/(.*\S)\s+$/$1/;
2671: $data=~s/(\s)+/$1/;
2672: my ($current_length,$min_length)=(0,0);
2673: if ($data=~/\\vskip/) {
2674: my $newdata=$data;
2675: $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
2676: my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
2677: foreach my $elementdata (@newdata) {
2678: my $lengthnewdata=2.5*&LATEX_length($elementdata);
2679: if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
2680: my @words=split(/ /,$elementdata);
2681: foreach my $word (@words) {
2682: my $lengthword=2.5*&LATEX_length($word);
2683: if ($min_length<$lengthword) {$min_length=$lengthword;}
2684: }
2685: }
2686: } else {
2687: $current_length=2.5*&LATEX_length($data);
2688: my @words=split(/ /,$data);
2689: foreach my $word (@words) {
2690: my $lengthword=2*&LATEX_length($word);
2691: if ($min_length<$lengthword) {$min_length=$lengthword;}
2692: }
2693: }
2694: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2695: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2696: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
2697: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
2698: }
2699: }
2700: for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {
2701: $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
2702: }
2703: #make data bold
2704: $data='\textbf{'.$data.'}';
2705: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
2706: return'';
2707: }
2708:
1.122 albertel 2709: sub end_th {
1.130 sakharuk 2710: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.279 foxr 2711: my $currentstring = &end_p(); # Close any open <p> in the row.
1.122 albertel 2712: if ($target eq 'web') {
1.277 foxr 2713: $currentstring .= $token->[2];
1.122 albertel 2714: } elsif ($target eq 'tex') {
1.230 sakharuk 2715: $Apache::londefdef::TD_redirection =0;
2716: &end_th_tex($parstack,$parser,$safeeval);
1.122 albertel 2717: }
2718: return $currentstring;
2719: }
1.230 sakharuk 2720:
1.181 sakharuk 2721: #-- <img> tag (end tag forbidden)
1.249 foxr 2722: #
2723: # Render the <IMG> tag.
2724: # <IMG> has the following attributes (in addition to the
2725: # standard HTML ones:
2726: # TeXwrap - Governs how the tex target will try to wrap text around
2727: # horizontally aligned images.
2728: # TeXwidth - The width of the image when rendered for print (mm).
2729: # TeXheight - The height of the image when rendered for print (mm)
2730: # (Note there seems to also be support for this as a % of page size)
2731: #
1.122 albertel 2732: sub start_img {
1.299 albertel 2733: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
1.122 albertel 2734: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,
2735: undef,1);
1.189 albertel 2736: if (not $src and ($target eq 'web' or $target eq 'tex')) {
1.299 albertel 2737: my $inside = &Apache::lonxml::get_all_text("/img",$parser,$style);
1.189 albertel 2738: return '';
2739: }
1.290 albertel 2740: &Apache::lonxml::extlink($src);
1.122 albertel 2741: my $currentstring = '';
2742: my $scaling = .3;
1.249 foxr 2743:
2744: # Render unto browsers that which are the browser's...
2745:
1.122 albertel 2746: if ($target eq 'web') {
1.267 albertel 2747: if ($env{'browser.imagesuppress'} ne 'on') {
1.250 albertel 2748: $currentstring.=&Apache::lonenc::encrypt_ref($token,{'src'=>$src});
1.122 albertel 2749: } else {
2750: my $alttag= &Apache::lonxml::get_param
2751: ('alt',$parstack,$safeeval,undef,1);
2752: unless ($alttag) {
2753: $alttag=&Apache::lonmeta::alttag
2754: ($Apache::lonxml::pwd[-1],$src);
1.51 sakharuk 2755: }
1.158 sakharuk 2756: $currentstring.='[IMAGE: '.$alttag.']';
1.1 sakharuk 2757: }
1.249 foxr 2758:
2759: # and render unto TeX that which is LaTeX
2760:
1.122 albertel 2761: } elsif ($target eq 'tex') {
1.248 foxr 2762: #
2763: # The alignment will require some superstructure to be put around
2764: # the \includegraphics stuff. At present we can only partially
2765: # simulate the alignments offered by html.
2766: #
2767: #
2768: my $align = lc(&Apache::lonxml::get_param('align',
2769: $parstack,
2770: $safeeval,
2771: undef,1));
2772: if(!$align) {
1.287 foxr 2773: $align = "bottom"; # This is html's default so it's ours too.
1.248 foxr 2774: }
2775: #
2776: &Apache::lonxml::debug("Alignemnt = $align");
2777: # LaTeX's image/text wrapping is really bad since it wants to
2778: # make figures float.
2779: # The user has the optional parameter (applicable only to l/r
2780: # alignment to use the picins/parpic directive to get wrapped text
2781: # this is also imperfect.. that's why we give them a choice...
2782: # so they can't yell at us for our choice.
2783: #
2784: my $latex_rendering = &Apache::lonxml::get_param('TeXwrap',
2785: $parstack,
2786: $safeeval,
2787: undef,0);
1.312 foxr 2788: # &Apache::lonxml::debug("LaTeX rendering = $latex_rendering");
1.248 foxr 2789: if(!$latex_rendering) {
1.312 foxr 2790: $latex_rendering = "texwrap";
2791: }
2792: # using texwrap inside a table does not work. So, if after all of this,
2793: # texwrap is on, we turn it off if we detect we're in a table:
2794: #
2795: if (($latex_rendering eq 'texwrap') && &is_inside_of($tagstack, "table")) {
2796: $latex_rendering = 'parpic';
1.248 foxr 2797: }
1.312 foxr 2798: # &Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src");
1.248 foxr 2799:
1.256 albertel 2800: #if original gif/jpg/png file exist do following:
1.266 albertel 2801: my $origsrc=$src;
1.256 albertel 2802: my ($path,$file) = &get_eps_image($src);
1.122 albertel 2803: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
1.261 foxr 2804: &Apache::lonxml::debug("path = $path file = $file src = $src");
1.192 sakharuk 2805: if (-e $src) {
1.261 foxr 2806: &Apache::lonxml::debug("$src exists");
1.256 albertel 2807: my ($height_param,$width_param)=
1.266 albertel 2808: &image_size($origsrc,0.3,$parstack,$safeeval);
1.262 foxr 2809: my $destpath = $path;
1.263 foxr 2810: $destpath =~ s/ /\_/g; # Spaces in path cause LaTex to vomit.
2811: my $destfile = $file;
2812: $destfile =~ s/ /\_/g;
1.266 albertel 2813: my $size;
2814: if ($width_param) { $size.='width='.$width_param.' mm,'; }
2815: if ($height_param) { $size.='height='.$height_param.' mm]'; }
2816: $size='['.$size;
2817: $size=~s/,$/]/;
1.262 foxr 2818: $currentstring .= '\graphicspath{{'.$destpath.'}}'
1.266 albertel 2819: .'\includegraphics'.$size.'{'.$destfile.'} ';
1.256 albertel 2820:
1.248 foxr 2821: # If there's an alignment specification we need to honor it here.
2822: # For the horizontal alignments, we will also honor the
2823: # value of the latex specfication. The default is parbox,
2824: # and that's used for illegal values too.
2825: #
2826: # Even though we set a default alignment value, the user
2827: # could have given us an illegal value. In that case we
2828: # just use the default alignment of bottom..
2829: if ($align eq "top") {
2830: $currentstring = '\raisebox{-'.$height_param.'mm}{'.$currentstring.'}';
2831: } elsif (($align eq "center") || ($align eq "middle")) { # Being kind
2832: my $offset = $height_param/2;
2833: $currentstring = '\raisebox{-'.$offset.'mm}{'.$currentstring.'}';
2834: } elsif ($align eq "left") {
2835: if ($latex_rendering eq "parpic") {
2836: $currentstring = '\parpic[l]{'.$currentstring.'}';
1.286 foxr 2837: } else { # wrapfig render
2838: $currentstring = '\begin{wrapfigure}{l}{'.$width_param.'mm}'
2839: .'\scalebox{1.0}{'.$currentstring.'}\end{wrapfigure}';
1.248 foxr 2840: }
2841: } elsif ($align eq "right") {
2842: if ($latex_rendering eq "parpic") {
2843: $currentstring = '\parpic[r]{'.$currentstring.'}';
1.286 foxr 2844: } else { # wrapfig rendering
2845: $currentstring = '\begin{wrapfigure}{r}{'.$width_param.'mm}'
2846: .'\scalebox{1.0}{'.$currentstring.'}\end{wrapfigure}';
2847:
1.248 foxr 2848: }
2849: } else { # Bottom is also default.
2850: # $currentstring = '\raisebox{'.$height_param.'mm}{'.$currentstring.'}';
2851: }
1.122 albertel 2852: } else {
1.261 foxr 2853: &Apache::lonxml::debug("$src does not exist");
1.122 albertel 2854: #original image file doesn't exist so check the alt attribute
2855: my $alt =
2856: &Apache::lonxml::get_param('alt',$parstack,$safeeval,undef,1);
2857: unless ($alt) {
2858: $alt=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
2859: }
2860:
1.256 albertel 2861: if ($alt) { $currentstring .= ' '.$alt.' '; }
1.59 sakharuk 2862: }
1.249 foxr 2863:
2864: # And here's where the semi-quote breaks down: allow the user
2865: # to edit the beast as well by rendering the problem for edit:
1.186 albertel 2866: } elsif ($target eq 'edit') {
2867: $currentstring .=&Apache::edit::tag_start($target,$token);
2868: $currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70).
2869: &Apache::edit::browse('src',undef,'alt').' '.
2870: &Apache::edit::search('src',undef,'alt').'<br />';
2871: $currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'<br />';
2872: $currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5);
2873: $currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'<br />';
2874: $currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5);
2875: $currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5);
1.234 albertel 2876: $currentstring .=&Apache::edit::select_arg('Alignment:','align',
2877: ['','bottom','middle','top','left','right'],$token,5);
1.249 foxr 2878: $currentstring .=&Apache::edit::select_arg('TeXwrap:', 'TeXwrap',
2879: ['', 'parbox', 'parpic'], $token, 2);
1.186 albertel 2880: $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.249 foxr 2881: my $src= &Apache::lonxml::get_param('src',$parstack,$safeeval);
2882: my $alt= &Apache::lonxml::get_param('alt',$parstack,$safeeval);
2883: my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
2884: my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
2885:
2886:
1.186 albertel 2887: $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
2888: if ($width) { $currentstring.=' width="'.$width.'" '; }
2889: if ($height) { $currentstring.=' height="'.$height.'" '; }
2890: $currentstring .= ' />';
2891: } elsif ($target eq 'modified') {
1.210 albertel 2892: my ($osrc,$owidth,$oheight)=
2893: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
2894: my $ctag=&Apache::edit::get_new_args($token,$parstack,
1.234 albertel 2895: $safeeval,'src','alt','align',
1.249 foxr 2896: 'TeXwidth','TeXheight', 'TeXwrap',
1.210 albertel 2897: 'width','height');
2898: my ($nsrc,$nwidth,$nheight)=
2899: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
2900: my $loc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$nsrc);
2901: &image_replication($loc);
2902: my ($iwidth,$iheight);
2903: if (-e $loc) {
2904: my $image = Image::Magick->new;
2905: $image->Read($loc);
2906: ($iwidth, $iheight) = ($image->Get('width'),
2907: $image->Get('height'));
2908: }
2909: if ($osrc ne $nsrc || (!$nwidth && !$nheight)) {
2910: # changed image or no size specified,
2911: # if they didn't explicitly change the
2912: # width or height use the ones from the image
2913: if ($iwidth && $iheight) {
2914: if ($owidth == $nwidth || (!$nwidth && !$nheight)) {
2915: $token->[2]{'width'} = $iwidth;$ctag=1;
2916: }
2917: if ($oheight == $nheight || (!$nwidth && !$nheight)) {
2918: $token->[2]{'height'}=$iheight;$ctag=1;
1.186 albertel 2919: }
2920: }
2921: }
1.210 albertel 2922: my ($cwidth,$cheight)=($token->[2]{'width'},$token->[2]{'height'});
2923: # if we don't have a width or height
2924: if ($iwidth && $cwidth && !$cheight) {
2925: $token->[2]{'height'}=int(($cwidth/$iwidth)*$iheight);$ctag=1;
2926: }
2927: if ($iheight && $cheight && !$cwidth) {
2928: $token->[2]{'width'}=int(($cheight/$iheight)*$iwidth);$ctag=1;
2929: }
2930: if ($ctag) {$currentstring=&Apache::edit::rebuild_tag($token);}
1.122 albertel 2931: }
1.261 foxr 2932:
1.122 albertel 2933: return $currentstring;
2934: }
2935:
2936: sub end_img {
2937: my ($target,$token) = @_;
2938: my $currentstring = '';
2939: if ($target eq 'web') {
2940: $currentstring = $token->[2];
2941: } elsif ($target eq 'tex') {
2942: $currentstring = '';
2943: }
2944: return $currentstring;
2945: }
2946:
1.181 sakharuk 2947: #-- <applet> tag (end tag required)
1.122 albertel 2948: sub start_applet {
2949: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2950:
2951: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,undef,1);
1.290 albertel 2952: &Apache::lonxml::extlink($code);
1.122 albertel 2953: my $archive=&Apache::lonxml::get_param('archive',$parstack,$safeeval,
2954: undef,1);
1.290 albertel 2955: &Apache::lonxml::extlink($archive);
1.122 albertel 2956: my $currentstring = '';
2957: if ($target eq 'web') {
1.267 albertel 2958: if ($env{'browser.appletsuppress'} ne 'on') {
1.250 albertel 2959: $currentstring = &Apache::lonenc::encrypt_ref($token,
2960: {'code'=>$code,
2961: 'archive'=>$archive}
2962: );
1.122 albertel 2963: } else {
2964: my $alttag= &Apache::lonxml::get_param('alt',$parstack,
2965: $safeeval,undef,1);
2966: unless ($alttag) {
2967: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
2968: $code);
1.44 sakharuk 2969: }
1.122 albertel 2970: $currentstring='[APPLET: '.$alttag.']';
1.1 sakharuk 2971: }
1.122 albertel 2972: } elsif ($target eq 'tex') {
1.177 albertel 2973: my $alttag= &Apache::lonxml::get_param('alt',$parstack,
2974: $safeeval,undef,1);
2975: unless ($alttag) {
2976: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,
2977: undef,1);
2978: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
2979: $code);
1.175 sakharuk 2980: }
1.177 albertel 2981: $currentstring.='\begin{center} \fbox{Java Applet: '.$alttag.
2982: '.}\end{center}';
1.122 albertel 2983: }
2984: return $currentstring;
2985: }
2986:
2987: sub end_applet {
2988: my ($target,$token) = @_;
2989: my $currentstring = '';
2990: if ($target eq 'web') {
2991: $currentstring = $token->[2];
2992: } elsif ($target eq 'tex') {
2993: }
2994: return $currentstring;
2995: }
2996:
1.181 sakharuk 2997: #-- <embed> tag (end tag optional/required)
1.122 albertel 2998: sub start_embed {
2999: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3000: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
1.290 albertel 3001: &Apache::lonxml::extlink($src);
1.122 albertel 3002: my $currentstring = '';
3003: if ($target eq 'web') {
1.267 albertel 3004: if ($env{'browser.embedsuppress'} ne 'on') {
1.250 albertel 3005: $currentstring=&Apache::lonenc::encrypt_ref($token,{'src'=>$src});
1.122 albertel 3006: } else {
3007: my $alttag=&Apache::lonxml::get_param
3008: ('alt',$parstack,$safeeval,undef,1);
3009: unless ($alttag) {
3010: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
1.42 albertel 3011: }
1.122 albertel 3012: $currentstring='[EMBED: '.$alttag.']';
1.10 www 3013: }
1.122 albertel 3014: } elsif ($target eq 'tex') {
3015: }
3016: return $currentstring;
3017: }
3018:
3019: sub end_embed {
3020: my ($target,$token) = @_;
3021: my $currentstring = '';
3022: if ($target eq 'web') {
3023: $currentstring = $token->[2];
1.175 sakharuk 3024: } elsif ($target eq 'tex') {
1.122 albertel 3025: }
3026: return $currentstring;
3027: }
3028:
1.181 sakharuk 3029: #-- <param> tag (end tag forbidden)
1.122 albertel 3030: sub start_param {
3031: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.290 albertel 3032: if (&Apache::lonxml::get_param('name',$parstack,
3033: $safeeval,undef,1)=~/^cabbase$/i) {
3034: my $value=&Apache::lonxml::get_param('value',$parstack,
3035: $safeeval,undef,1);
3036: &Apache::lonxml::extlink($value);
3037: }
3038:
3039: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
3040: &Apache::lonxml::extlink($src);
1.122 albertel 3041: my $currentstring = '';
3042: if ($target eq 'web') {
1.250 albertel 3043: my %toconvert;
3044: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
3045: if ($src) { $toconvert{'src'}= $src; }
3046: my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval,
3047: undef,1);
1.251 albertel 3048: if ($name=~/^cabbase$/i) {
3049: $toconvert{'value'}=&Apache::lonxml::get_param('value',$parstack,
3050: $safeeval,undef,1);
3051: }
1.250 albertel 3052: $currentstring = &Apache::lonenc::encrypt_ref($token,\%toconvert);
1.122 albertel 3053: } elsif ($target eq 'tex') {
3054: }
3055: return $currentstring;
3056: }
3057:
3058: sub end_param {
3059: my ($target,$token) = @_;
3060: my $currentstring = '';
3061: if ($target eq 'web') {
3062: $currentstring = $token->[2];
3063: } elsif ($target eq 'tex') {
3064: }
3065: return $currentstring;
3066: }
3067:
3068: #-- <allow> tag
3069: sub start_allow {
3070: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3071: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
1.290 albertel 3072: &Apache::lonxml::extlink($src);
3073:
1.241 albertel 3074: if ($target eq 'tex') { &image_replication($src); }
1.122 albertel 3075: my $result;
3076: if ($target eq 'edit') {
3077: $result .=&Apache::edit::tag_start($target,$token);
3078: $result .=&Apache::edit::text_arg('File Spec:','src',$token,70);
3079: $result .=&Apache::edit::end_row();#.&Apache::edit::start_spanning_row();
3080: } elsif ($target eq 'modified') {
3081: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
3082: $safeeval,'src');
3083: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
3084: }
3085: return $result;
3086: }
3087:
3088: sub end_allow {
3089: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3090: if ( $target eq 'edit') { return (&Apache::edit::end_table()); }
3091: return '';
3092: }
1.119 www 3093:
1.181 sakharuk 3094: #-- Frames (end tag required)
3095: #-- <frameset>
1.122 albertel 3096: sub start_frameset {
3097: my ($target,$token) = @_;
1.277 foxr 3098: my $currentstring = ''; # Close any pending para.
1.122 albertel 3099: if ($target eq 'web') {
1.180 albertel 3100: if (!$Apache::lonxml::registered &&
1.267 albertel 3101: $env{'request.state'} eq 'published') {
1.122 albertel 3102: $currentstring.='<head>'.
3103: &Apache::lonmenu::registerurl(undef,$target).'</head>';
1.10 www 3104: }
1.133 www 3105: my $onLoad='';
3106: foreach my $key (keys(%{$token->[2]})) {
3107: if ($key =~ /^onload$/i) {
3108: $onLoad.=$token->[2]->{$key}.';';
3109: delete($token->[2]->{$key});
3110: }
3111: }
3112: $token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad;
3113: my $onUnload='';
3114: foreach my $key (keys(%{$token->[2]})) {
3115: if ($key =~ /^onunload$/i) {
3116: $onUnload.=$token->[2]->{$key}.';';
3117: delete($token->[2]->{$key});
3118: }
3119: }
3120: $token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents().
3121: ';'.$onUnload;
3122:
3123: $currentstring .= '<'.$token->[1];
3124: foreach (keys %{$token->[2]}) {
3125: $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
3126: }
3127: $currentstring.='>';
1.122 albertel 3128: }
3129: return $currentstring;
3130: }
3131:
3132: sub end_frameset {
3133: my ($target,$token) = @_;
3134: my $currentstring = '';
3135: if ($target eq 'web') {
3136: $currentstring = $token->[2];
3137: }
3138: return $currentstring;
3139: }
1.162 sakharuk 3140:
1.181 sakharuk 3141: #-- <xmp> (end tag required)
1.162 sakharuk 3142: sub start_xmp {
3143: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3144: my $currentstring = '';
3145: if ($target eq 'web') {
3146: $currentstring .= $token->[4];
3147: } elsif ($target eq 'tex') {
3148: $currentstring .= '\begin{verbatim}';
3149: }
3150: return $currentstring;
3151: }
3152:
3153: sub end_xmp {
3154: my ($target,$token) = @_;
3155: my $currentstring = '';
3156: if ($target eq 'web') {
3157: $currentstring .= $token->[2];
3158: } elsif ($target eq 'tex') {
3159: $currentstring .= '\end{verbatim}';
3160: }
3161: return $currentstring;
3162: }
3163:
1.181 sakharuk 3164: #-- <pre> (end tag required)
1.122 albertel 3165: sub start_pre {
1.126 sakharuk 3166: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.279 foxr 3167: my $currentstring = &end_p(); # close off pending <p>
1.122 albertel 3168: if ($target eq 'web') {
3169: $currentstring .= $token->[4];
3170: } elsif ($target eq 'tex') {
1.136 sakharuk 3171: $currentstring .= '\begin{verbatim}';
1.122 albertel 3172: }
3173: return $currentstring;
3174: }
3175:
3176: sub end_pre {
3177: my ($target,$token) = @_;
3178: my $currentstring = '';
3179: if ($target eq 'web') {
3180: $currentstring .= $token->[2];
3181: } elsif ($target eq 'tex') {
1.136 sakharuk 3182: $currentstring .= '\end{verbatim}';
1.122 albertel 3183: }
3184: return $currentstring;
3185: }
3186:
3187: #-- <insert>
3188: sub start_insert {
3189: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3190: my $currentstring = '';
3191: if ($target eq 'web') {
3192: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
3193: $currentstring .= '<b>'.$display.'</b>';;
3194: }
3195: return $currentstring;
3196: }
3197:
3198: sub end_insert {
3199: my ($target,$token) = @_;
3200: my $currentstring = '';
3201: if ($target eq 'web') {
3202: $currentstring .= '';
3203: }
3204: return $currentstring;
3205: }
3206:
3207: #-- <externallink>
3208: sub start_externallink {
3209: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3210: my $currentstring = '';
3211: if ($target eq 'web') {
3212: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
3213: $currentstring .= '<b>'.$display.'</b>';;
3214: }
3215: return $currentstring;
3216: }
3217:
3218: sub end_externallink {
3219: my ($target,$token) = @_;
3220: my $currentstring = '';
3221: if ($target eq 'web') {
3222: $currentstring .= '';
3223: }
3224: return $currentstring;
3225: }
3226:
3227: #-- <blankspace heigth="">
3228: sub start_blankspace {
3229: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.279 foxr 3230: my $currentstring = &end_p(); # closes off any unclosed <p>
1.122 albertel 3231: if ($target eq 'tex') {
3232: my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval,undef,1);
3233: $currentstring .= '\vskip '.$howmuch.' ';
3234: }
3235: return $currentstring;
3236: }
3237:
3238: sub end_blankspace {
3239: my ($target,$token) = @_;
3240: my $currentstring = '';
3241: if ($target eq 'tex') {
3242: $currentstring .= '';
3243: }
3244: return $currentstring;
3245: }
3246:
1.181 sakharuk 3247: #-- <abbr> tag (end tag required)
1.122 albertel 3248: sub start_abbr {
3249: my ($target,$token) = @_;
3250: my $currentstring = '';
3251: if ($target eq 'web') {
3252: $currentstring = $token->[4];
3253: }
3254: return $currentstring;
3255: }
3256:
3257: sub end_abbr {
3258: my ($target,$token) = @_;
3259: my $currentstring = '';
3260: if ($target eq 'web') {
3261: $currentstring = $token->[2];
3262: }
3263: return $currentstring;
3264: }
3265:
1.181 sakharuk 3266: #-- <acronym> tag (end tag required)
1.122 albertel 3267: sub start_acronym {
3268: my ($target,$token) = @_;
3269: my $currentstring = '';
3270: if ($target eq 'web') {
3271: $currentstring = $token->[4];
3272: }
3273: return $currentstring;
3274: }
3275:
3276: sub end_acronym {
3277: my ($target,$token) = @_;
3278: my $currentstring = '';
3279: if ($target eq 'web') {
3280: $currentstring = $token->[2];
3281: }
3282: return $currentstring;
3283: }
3284:
1.181 sakharuk 3285: #-- <area> tag (end tag forbidden)
1.122 albertel 3286: sub start_area {
3287: my ($target,$token) = @_;
3288: my $currentstring = '';
3289: if ($target eq 'web') {
3290: $currentstring = $token->[4];
3291: }
3292: return $currentstring;
3293: }
3294:
3295: sub end_area {
3296: my ($target,$token) = @_;
3297: my $currentstring = '';
3298: if ($target eq 'web') {
3299: $currentstring = $token->[2];
3300: }
3301: return $currentstring;
3302: }
3303:
1.181 sakharuk 3304: #-- <base> tag (end tag forbidden)
1.122 albertel 3305: sub start_base {
3306: my ($target,$token) = @_;
3307: my $currentstring = '';
3308: if ($target eq 'web') {
3309: $currentstring = $token->[4];
1.161 sakharuk 3310: }
1.122 albertel 3311: return $currentstring;
3312: }
3313:
3314: sub end_base {
3315: my ($target,$token) = @_;
3316: my $currentstring = '';
3317: if ($target eq 'web') {
3318: $currentstring = $token->[2];
3319: }
3320: return $currentstring;
3321: }
3322:
1.181 sakharuk 3323: #-- <bdo> tag (end tag required)
1.122 albertel 3324: sub start_bdo {
3325: my ($target,$token) = @_;
3326: my $currentstring = '';
3327: if ($target eq 'web') {
3328: $currentstring = $token->[4];
3329: }
3330: return $currentstring;
3331: }
3332:
3333: sub end_bdo {
3334: my ($target,$token) = @_;
3335: my $currentstring = '';
3336: if ($target eq 'web') {
3337: $currentstring = $token->[2];
3338: }
3339: return $currentstring;
3340: }
3341:
1.181 sakharuk 3342: #-- <bgsound> tag (end tag optional)
1.122 albertel 3343: sub start_bgsound {
3344: my ($target,$token) = @_;
3345: my $currentstring = '';
3346: if ($target eq 'web') {
3347: $currentstring = $token->[4];
3348: }
3349: return $currentstring;
3350: }
3351:
3352: sub end_bgsound {
3353: my ($target,$token) = @_;
3354: my $currentstring = '';
3355: if ($target eq 'web') {
3356: $currentstring = $token->[2];
3357: }
3358: return $currentstring;
3359: }
3360:
1.181 sakharuk 3361: #-- <blink> tag (end tag required)
1.122 albertel 3362: sub start_blink {
3363: my ($target,$token) = @_;
3364: my $currentstring = '';
3365: if ($target eq 'web') {
3366: $currentstring = $token->[4];
3367: }
3368: return $currentstring;
3369: }
3370:
3371: sub end_blink {
3372: my ($target,$token) = @_;
3373: my $currentstring = '';
3374: if ($target eq 'web') {
3375: $currentstring = $token->[2];
3376: }
3377: return $currentstring;
3378: }
3379:
1.181 sakharuk 3380: #-- <blockquote> tag (end tag required)
1.122 albertel 3381: sub start_blockquote {
3382: my ($target,$token) = @_;
1.279 foxr 3383: my $currentstring = &end_p(); # Close any unclosed <p>
1.122 albertel 3384: if ($target eq 'web') {
1.277 foxr 3385: $currentstring .= $token->[4];
1.122 albertel 3386: }
3387: return $currentstring;
3388: }
3389:
3390: sub end_blockquote {
3391: my ($target,$token) = @_;
3392: my $currentstring = '';
3393: if ($target eq 'web') {
3394: $currentstring = $token->[2];
3395: }
3396: return $currentstring;
3397: }
3398:
1.181 sakharuk 3399: #-- <button> tag (end tag required)
1.122 albertel 3400: sub start_button {
3401: my ($target,$token) = @_;
3402: my $currentstring = '';
3403: if ($target eq 'web') {
3404: $currentstring = $token->[4];
3405: }
3406: return $currentstring;
3407: }
3408:
3409: sub end_button {
3410: my ($target,$token) = @_;
3411: my $currentstring = '';
3412: if ($target eq 'web') {
3413: $currentstring = $token->[2];
3414: }
3415: return $currentstring;
3416: }
3417:
1.181 sakharuk 3418: #-- <caption> tag (end tag required)
1.122 albertel 3419: sub start_caption {
3420: my ($target,$token) = @_;
3421: my $currentstring = '';
3422: if ($target eq 'web') {
3423: $currentstring = $token->[4];
3424: }
3425: return $currentstring;
3426: }
3427:
3428: sub end_caption {
3429: my ($target,$token) = @_;
3430: my $currentstring = '';
3431: if ($target eq 'web') {
3432: $currentstring = $token->[2];
3433: }
3434: return $currentstring;
3435: }
3436:
1.181 sakharuk 3437: #-- <col> tag (end tag forbdden)
1.122 albertel 3438: sub start_col {
3439: my ($target,$token) = @_;
3440: my $currentstring = '';
3441: if ($target eq 'web') {
3442: $currentstring = $token->[4];
3443: }
3444: return $currentstring;
3445: }
3446:
3447: sub end_col {
3448: my ($target,$token) = @_;
3449: my $currentstring = '';
3450: if ($target eq 'web') {
3451: $currentstring = $token->[2];
3452: }
3453: return $currentstring;
3454: }
3455:
1.181 sakharuk 3456: #-- <colgroup> tag (end tag optional)
1.122 albertel 3457: sub start_colgroup {
3458: my ($target,$token) = @_;
3459: my $currentstring = '';
3460: if ($target eq 'web') {
3461: $currentstring = $token->[4];
3462: }
3463: return $currentstring;
3464: }
3465:
3466: sub end_colgroup {
3467: my ($target,$token) = @_;
3468: my $currentstring = '';
3469: if ($target eq 'web') {
3470: $currentstring = $token->[2];
3471: }
3472: return $currentstring;
3473: }
3474:
1.181 sakharuk 3475: #-- <del> tag (end tag required)
1.122 albertel 3476: sub start_del {
3477: my ($target,$token) = @_;
3478: my $currentstring = '';
3479: if ($target eq 'web') {
3480: $currentstring = $token->[4];
3481: }
3482: return $currentstring;
3483: }
3484:
3485: sub end_del {
3486: my ($target,$token) = @_;
3487: my $currentstring = '';
3488: if ($target eq 'web') {
3489: $currentstring = $token->[2];
3490: }
3491: return $currentstring;
3492: }
3493:
1.181 sakharuk 3494: #-- <fieldset> tag (end tag required)
1.122 albertel 3495: sub start_fieldset {
3496: my ($target,$token) = @_;
3497: my $currentstring = '';
3498: if ($target eq 'web') {
3499: $currentstring = $token->[4];
3500: }
3501: return $currentstring;
3502: }
3503:
3504: sub end_fieldset {
3505: my ($target,$token) = @_;
3506: my $currentstring = '';
3507: if ($target eq 'web') {
3508: $currentstring = $token->[2];
3509: }
3510: return $currentstring;
3511: }
3512:
1.181 sakharuk 3513: #-- <frame> tag (end tag forbidden)
1.122 albertel 3514: sub start_frame {
3515: my ($target,$token) = @_;
3516: my $currentstring = '';
3517: if ($target eq 'web') {
3518: $currentstring = $token->[4];
3519: }
3520: return $currentstring;
3521: }
3522:
3523: sub end_frame {
3524: my ($target,$token) = @_;
3525: my $currentstring = '';
3526: if ($target eq 'web') {
3527: $currentstring = $token->[2];
3528: }
3529: return $currentstring;
3530: }
3531:
1.181 sakharuk 3532: #-- <iframe> tag (end tag required)
1.122 albertel 3533: sub start_iframe {
3534: my ($target,$token) = @_;
3535: my $currentstring = '';
3536: if ($target eq 'web') {
3537: $currentstring = $token->[4];
3538: }
3539: return $currentstring;
3540: }
3541:
3542: sub end_iframe {
3543: my ($target,$token) = @_;
3544: my $currentstring = '';
3545: if ($target eq 'web') {
3546: $currentstring = $token->[2];
3547: }
3548: return $currentstring;
3549: }
3550:
1.181 sakharuk 3551: #-- <ins> tag (end tag required)
1.122 albertel 3552: sub start_ins {
3553: my ($target,$token) = @_;
3554: my $currentstring = '';
3555: if ($target eq 'web') {
3556: $currentstring = $token->[4];
3557: }
3558: return $currentstring;
3559: }
3560:
3561: sub end_ins {
3562: my ($target,$token) = @_;
3563: my $currentstring = '';
3564: if ($target eq 'web') {
3565: $currentstring = $token->[2];
3566: }
3567: return $currentstring;
3568: }
3569:
1.181 sakharuk 3570: #-- <isindex> tag (end tag forbidden)
1.122 albertel 3571: sub start_isindex {
3572: my ($target,$token) = @_;
3573: my $currentstring = '';
3574: if ($target eq 'web') {
3575: $currentstring = $token->[4];
3576: }
3577: return $currentstring;
3578: }
3579:
3580: sub end_isindex {
3581: my ($target,$token) = @_;
3582: my $currentstring = '';
3583: if ($target eq 'web') {
3584: $currentstring = $token->[2];
3585: }
3586: return $currentstring;
3587: }
3588:
1.181 sakharuk 3589: #-- <keygen> tag (end tag forbidden)
1.122 albertel 3590: sub start_keygen {
3591: my ($target,$token) = @_;
3592: my $currentstring = '';
3593: if ($target eq 'web') {
3594: $currentstring = $token->[4];
3595: }
3596: return $currentstring;
3597: }
3598:
3599: sub end_keygen {
3600: my ($target,$token) = @_;
3601: my $currentstring = '';
3602: if ($target eq 'web') {
3603: $currentstring = $token->[2];
3604: }
3605: return $currentstring;
3606: }
3607:
3608: #-- <label> tag
3609: sub start_label {
3610: my ($target,$token) = @_;
3611: my $currentstring = '';
3612: if ($target eq 'web') {
3613: $currentstring = $token->[4];
3614: }
3615: return $currentstring;
3616: }
3617:
3618: sub end_label {
3619: my ($target,$token) = @_;
3620: my $currentstring = '';
3621: if ($target eq 'web') {
3622: $currentstring = $token->[2];
3623: }
3624: return $currentstring;
3625: }
3626:
1.181 sakharuk 3627: #-- <layer> tag (end tag required)
1.122 albertel 3628: sub start_layer {
3629: my ($target,$token) = @_;
3630: my $currentstring = '';
3631: if ($target eq 'web') {
3632: $currentstring = $token->[4];
3633: }
3634: return $currentstring;
3635: }
3636:
3637: sub end_layer {
3638: my ($target,$token) = @_;
3639: my $currentstring = '';
3640: if ($target eq 'web') {
3641: $currentstring = $token->[2];
3642: }
3643: return $currentstring;
3644: }
3645:
1.181 sakharuk 3646: #-- <legend> tag (end tag required)
1.122 albertel 3647: sub start_legend {
3648: my ($target,$token) = @_;
3649: my $currentstring = '';
3650: if ($target eq 'web') {
3651: $currentstring = $token->[4];
3652: }
3653: return $currentstring;
3654: }
3655:
3656: sub end_legend {
3657: my ($target,$token) = @_;
3658: my $currentstring = '';
3659: if ($target eq 'web') {
3660: $currentstring = $token->[2];
3661: }
3662: return $currentstring;
3663: }
3664:
1.181 sakharuk 3665: #-- <link> tag (end tag forbidden)
1.122 albertel 3666: sub start_link {
1.292 albertel 3667: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 3668: my $currentstring = '';
3669: if ($target eq 'web') {
1.291 albertel 3670: my $href=&Apache::lonxml::get_param('href',$parstack,$safeeval,
3671: undef,1);
3672: &Apache::lonxml::extlink($href);
1.122 albertel 3673: $currentstring = $token->[4];
3674: }
3675: return $currentstring;
3676: }
3677:
3678: sub end_link {
3679: my ($target,$token) = @_;
3680: my $currentstring = '';
3681: if ($target eq 'web') {
3682: $currentstring = $token->[2];
3683: }
3684: return $currentstring;
3685: }
3686:
1.181 sakharuk 3687: #-- <marquee> tag (end tag optional)
1.122 albertel 3688: sub start_marquee {
3689: my ($target,$token) = @_;
3690: my $currentstring = '';
3691: if ($target eq 'web') {
3692: $currentstring = $token->[4];
3693: }
3694: return $currentstring;
3695: }
3696:
3697: sub end_marquee {
3698: my ($target,$token) = @_;
3699: my $currentstring = '';
3700: if ($target eq 'web') {
3701: $currentstring = $token->[2];
3702: }
3703: return $currentstring;
3704: }
3705:
1.179 sakharuk 3706: #-- <multicol> tag (end tag required)
3707: sub start_multicol {
1.122 albertel 3708: my ($target,$token) = @_;
1.279 foxr 3709: my $currentstring = &end_p(); # Close any pending <p>
1.122 albertel 3710: if ($target eq 'web') {
1.277 foxr 3711: $currentstring .= $token->[4];
1.122 albertel 3712: }
3713: return $currentstring;
3714: }
3715:
1.179 sakharuk 3716: sub end_multicol {
1.122 albertel 3717: my ($target,$token) = @_;
3718: my $currentstring = '';
3719: if ($target eq 'web') {
3720: $currentstring = $token->[2];
3721: }
3722: return $currentstring;
3723: }
3724:
1.179 sakharuk 3725: #-- <nobr> tag (end tag required)
1.122 albertel 3726: sub start_nobr {
3727: my ($target,$token) = @_;
3728: my $currentstring = '';
3729: if ($target eq 'web') {
3730: $currentstring = $token->[4];
1.179 sakharuk 3731: } elsif ($target eq 'tex') {
3732: $currentstring='\mbox{';
3733: }
1.122 albertel 3734: return $currentstring;
3735: }
3736:
3737: sub end_nobr {
3738: my ($target,$token) = @_;
3739: my $currentstring = '';
3740: if ($target eq 'web') {
3741: $currentstring = $token->[2];
1.179 sakharuk 3742: } elsif ($target eq 'tex') {
3743: $currentstring='}';
3744: }
1.122 albertel 3745: return $currentstring;
3746: }
3747:
1.179 sakharuk 3748: #-- <noembed> tag (end tag required)
1.122 albertel 3749: sub start_noembed {
3750: my ($target,$token) = @_;
3751: my $currentstring = '';
3752: if ($target eq 'web') {
3753: $currentstring = $token->[4];
3754: }
3755: return $currentstring;
3756: }
3757:
3758: sub end_noembed {
3759: my ($target,$token) = @_;
3760: my $currentstring = '';
3761: if ($target eq 'web') {
3762: $currentstring = $token->[2];
3763: }
3764: return $currentstring;
3765: }
3766:
1.179 sakharuk 3767: #-- <noframes> tag (end tag required)
1.122 albertel 3768: sub start_noframes {
3769: my ($target,$token) = @_;
3770: my $currentstring = '';
3771: if ($target eq 'web') {
3772: $currentstring = $token->[4];
3773: }
3774: return $currentstring;
3775: }
3776:
3777: sub end_noframes {
3778: my ($target,$token) = @_;
3779: my $currentstring = '';
3780: if ($target eq 'web') {
3781: $currentstring = $token->[2];
3782: }
3783: return $currentstring;
3784: }
3785:
1.179 sakharuk 3786: #-- <nolayer> tag (end tag required)
1.122 albertel 3787: sub start_nolayer {
3788: my ($target,$token) = @_;
3789: my $currentstring = '';
3790: if ($target eq 'web') {
3791: $currentstring = $token->[4];
3792: }
3793: return $currentstring;
3794: }
3795:
3796: sub end_nolayer {
3797: my ($target,$token) = @_;
3798: my $currentstring = '';
3799: if ($target eq 'web') {
3800: $currentstring = $token->[2];
3801: }
3802: return $currentstring;
3803: }
3804:
1.179 sakharuk 3805: #-- <noscript> tag (end tag required)
1.122 albertel 3806: sub start_noscript {
3807: my ($target,$token) = @_;
3808: my $currentstring = '';
3809: if ($target eq 'web') {
3810: $currentstring = $token->[4];
3811: }
3812: return $currentstring;
3813: }
3814:
3815: sub end_noscript {
3816: my ($target,$token) = @_;
3817: my $currentstring = '';
3818: if ($target eq 'web') {
3819: $currentstring = $token->[2];
3820: }
3821: return $currentstring;
3822: }
3823:
1.179 sakharuk 3824: #-- <object> tag (end tag required)
1.122 albertel 3825: sub start_object {
3826: my ($target,$token) = @_;
3827: my $currentstring = '';
3828: if ($target eq 'web') {
3829: $currentstring = $token->[4];
3830: }
3831: return $currentstring;
3832: }
3833:
3834: sub end_object {
3835: my ($target,$token) = @_;
3836: my $currentstring = '';
3837: if ($target eq 'web') {
3838: $currentstring = $token->[2];
3839: }
3840: return $currentstring;
3841: }
3842:
1.179 sakharuk 3843: #-- <optgroup> tag (end tag required)
1.122 albertel 3844: sub start_optgroup {
3845: my ($target,$token) = @_;
3846: my $currentstring = '';
3847: if ($target eq 'web') {
3848: $currentstring = $token->[4];
3849: }
3850: return $currentstring;
3851: }
3852:
3853: sub end_optgroup {
3854: my ($target,$token) = @_;
3855: my $currentstring = '';
3856: if ($target eq 'web') {
3857: $currentstring = $token->[2];
3858: }
3859: return $currentstring;
3860: }
3861:
1.179 sakharuk 3862: #-- <samp> tag (end tag required)
1.122 albertel 3863: sub start_samp {
3864: my ($target,$token) = @_;
3865: my $currentstring = '';
3866: if ($target eq 'web') {
3867: $currentstring = $token->[4];
1.179 sakharuk 3868: } elsif ($target eq 'tex') {
3869: $currentstring='\texttt{';
3870: }
1.122 albertel 3871: return $currentstring;
3872: }
3873:
3874: sub end_samp {
3875: my ($target,$token) = @_;
3876: my $currentstring = '';
3877: if ($target eq 'web') {
3878: $currentstring = $token->[2];
1.179 sakharuk 3879: } elsif ($target eq 'tex') {
3880: $currentstring='}';
3881: }
1.122 albertel 3882: return $currentstring;
3883: }
3884:
3885: #-- <server> tag
3886: sub start_server {
3887: my ($target,$token) = @_;
3888: my $currentstring = '';
3889: if ($target eq 'web') {
3890: $currentstring = $token->[4];
3891: }
3892: return $currentstring;
3893: }
3894:
3895: sub end_server {
3896: my ($target,$token) = @_;
3897: my $currentstring = '';
3898: if ($target eq 'web') {
3899: $currentstring = $token->[2];
3900: }
3901: return $currentstring;
3902: }
3903:
1.179 sakharuk 3904: #-- <spacer> tag (end tag forbidden)
1.122 albertel 3905: sub start_spacer {
3906: my ($target,$token) = @_;
1.279 foxr 3907: my $currentstring = &end_p(); # Close off any open <p> tag.
1.122 albertel 3908: if ($target eq 'web') {
1.277 foxr 3909: $currentstring .= $token->[4];
1.122 albertel 3910: }
3911: return $currentstring;
3912: }
3913:
3914: sub end_spacer {
3915: my ($target,$token) = @_;
3916: my $currentstring = '';
3917: if ($target eq 'web') {
3918: $currentstring = $token->[2];
3919: }
3920: return $currentstring;
3921: }
3922:
1.179 sakharuk 3923: #-- <span> tag (end tag required)
1.122 albertel 3924: sub start_span {
3925: my ($target,$token) = @_;
3926: my $currentstring = '';
3927: if ($target eq 'web') {
3928: $currentstring = $token->[4];
3929: }
3930: return $currentstring;
3931: }
3932:
3933: sub end_span {
3934: my ($target,$token) = @_;
3935: my $currentstring = '';
3936: if ($target eq 'web') {
3937: $currentstring = $token->[2];
3938: }
3939: return $currentstring;
3940: }
3941:
1.179 sakharuk 3942: #-- <tbody> tag (end tag optional)
1.122 albertel 3943: sub start_tbody {
3944: my ($target,$token) = @_;
3945: my $currentstring = '';
3946: if ($target eq 'web') {
3947: $currentstring = $token->[4];
3948: }
3949: return $currentstring;
3950: }
3951:
3952: sub end_tbody {
3953: my ($target,$token) = @_;
3954: my $currentstring = '';
3955: if ($target eq 'web') {
3956: $currentstring = $token->[2];
3957: }
3958: return $currentstring;
3959: }
3960:
1.166 sakharuk 3961: #-- <tfoot> tag (end tag optional)
1.122 albertel 3962: sub start_tfoot {
3963: my ($target,$token) = @_;
3964: my $currentstring = '';
3965: if ($target eq 'web') {
3966: $currentstring = $token->[4];
3967: }
3968: return $currentstring;
3969: }
3970:
3971: sub end_tfoot {
3972: my ($target,$token) = @_;
3973: my $currentstring = '';
3974: if ($target eq 'web') {
3975: $currentstring = $token->[2];
3976: }
3977: return $currentstring;
3978: }
3979:
1.166 sakharuk 3980: #-- <thead> tag (end tag optional)
1.122 albertel 3981: sub start_thead {
3982: my ($target,$token) = @_;
3983: my $currentstring = '';
3984: if ($target eq 'web') {
3985: $currentstring = $token->[4];
3986: }
3987: return $currentstring;
3988: }
1.10 www 3989:
1.122 albertel 3990: sub end_thead {
3991: my ($target,$token) = @_;
3992: my $currentstring = '';
3993: if ($target eq 'web') {
3994: $currentstring = $token->[2];
3995: }
3996: return $currentstring;
3997: }
1.119 www 3998:
1.122 albertel 3999: #-- <var> tag
4000: sub start_var {
1.44 sakharuk 4001: my ($target,$token) = @_;
4002: my $currentstring = '';
4003: if ($target eq 'web') {
1.122 albertel 4004: $currentstring = $token->[4];
1.163 sakharuk 4005: } elsif ($target eq 'tex') {
4006: $currentstring = '\textit{';
4007: }
1.44 sakharuk 4008: return $currentstring;
4009: }
1.10 www 4010:
1.122 albertel 4011: sub end_var {
4012: my ($target,$token) = @_;
1.44 sakharuk 4013: my $currentstring = '';
4014: if ($target eq 'web') {
1.163 sakharuk 4015: $currentstring = $token->[2];
4016: } elsif ($target eq 'tex') {
4017: $currentstring = '}';
1.44 sakharuk 4018: }
4019: return $currentstring;
4020: }
1.119 www 4021:
1.163 sakharuk 4022: #-- <wbr> tag (end tag forbidden)
1.122 albertel 4023: sub start_wbr {
4024: my ($target,$token) = @_;
4025: my $currentstring = '';
4026: if ($target eq 'web') {
4027: $currentstring = $token->[4];
4028: }
4029: return $currentstring;
1.98 albertel 4030: }
4031:
1.122 albertel 4032: sub end_wbr {
4033: my ($target,$token) = @_;
4034: my $currentstring = '';
4035: if ($target eq 'web') {
4036: $currentstring = $token->[2];
4037: }
4038: return $currentstring;
1.98 albertel 4039: }
1.134 sakharuk 4040:
4041: #-- <hideweboutput> tag
4042: sub start_hideweboutput {
4043: my ($target,$token) = @_;
4044: if ($target eq 'web') {
4045: &Apache::lonxml::startredirection();
4046: }
4047: return '';
4048: }
4049:
4050: sub end_hideweboutput {
4051: my ($target,$token) = @_;
4052: my $currentstring = '';
4053: if ($target eq 'web') {
4054: $currentstring = &Apache::lonxml::endredirection();
4055: }
4056: return '';
4057: }
4058:
1.94 sakharuk 4059:
4060: sub image_replication {
4061: my $src = shift;
1.187 albertel 4062: if (not -e $src) { &Apache::lonnet::repcopy($src); }
4063: #replicates eps or ps
4064: my $epssrc = my $pssrc = $src;
4065: $epssrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i;
4066: $pssrc =~ s/\.(gif|jpg|jpeg|png)$/.ps/i;
4067: if (not -e $epssrc && not -e $pssrc) {
4068: my $result=&Apache::lonnet::repcopy($epssrc);
1.264 raeburn 4069: if ($result ne 'ok') { &Apache::lonnet::repcopy($pssrc); }
1.94 sakharuk 4070: }
4071: return '';
1.195 sakharuk 4072: }
1.275 foxr 4073: #
4074: # Get correct sizing parameter for an image given
4075: # it's initial ht. and wid. This allows sizing of
4076: # images that are generated on-the-fly (e.g. gnuplot)
4077: # as well as serving as a utility for image_size.
4078: #
4079: # Parameter:
4080: # height_param
4081: # width_param - Initial picture dimensions.
4082: # scaling - A scale factor.
4083: # parstack, - the current stack of tag attributes
4084: # from the xml parser
4085: # safeeval, - pointer to the safespace
4086: # depth, - from what level in the stack to look for attributes
4087: # (assumes -1 if unspecified)
4088: # cis - look for attrubutes case insensitively
4089: # (assumes false)
4090: #
4091: # Returns:
4092: # height, width - new dimensions.
4093: #
4094: sub resize_image {
4095: my ($height_param, $width_param, $scaling,
4096: $parstack, $safeeval, $depth, $cis) = @_;
4097:
4098: # First apply the scaling...
1.271 foxr 4099:
1.275 foxr 4100: $height_param = $height_param * $scaling;
4101: $width_param = $width_param * $scaling;
1.261 foxr 4102:
1.197 sakharuk 4103: #do we have any specified LaTeX size of the picture?
1.261 foxr 4104: my $toget='TeXwidth';
4105: if ($cis) {
4106: $toget=lc($toget);
4107: }
1.256 albertel 4108: my $TeXwidth = &Apache::lonxml::get_param($toget,$parstack,
4109: $safeeval,$depth,$cis);
4110: $toget='TeXheight'; if ($cis) { $toget=lc($toget); }
4111: my $TeXheight = &Apache::lonxml::get_param($toget,$parstack,
4112: $safeeval,$depth,$cis);
1.197 sakharuk 4113: #do we have any specified web size of the picture?
4114: my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval,
1.256 albertel 4115: $depth,1);
4116: if ($TeXwidth) {
1.252 matthew 4117: my $old_width_param=$width_param;
1.197 sakharuk 4118: if ($TeXwidth=~/(\d+)\s*\%/) {
1.267 albertel 4119: $width_param = $1*$env{'form.textwidth'}/100;
1.197 sakharuk 4120: } else {
4121: $width_param = $TeXwidth;
4122: }
1.266 albertel 4123: if ($TeXheight) {
4124: $height_param = $TeXheight;
4125: } elsif ($old_width_param) {
4126: $height_param=$TeXwidth/$old_width_param*$height_param;
4127: }
1.256 albertel 4128: } elsif ($TeXheight) {
1.248 foxr 4129: $height_param = $TeXheight;
1.266 albertel 4130: if ($height_param) {
4131: $width_param = $TeXheight/$height_param*$width_param;
4132: }
1.256 albertel 4133: } elsif ($width) {
1.252 matthew 4134: my $old_width_param=$width_param;
1.256 albertel 4135: $width_param = $width*$scaling;
1.266 albertel 4136: if ($old_width_param) {
4137: $height_param=$width_param/$old_width_param*$height_param;
4138: }
1.252 matthew 4139: }
1.267 albertel 4140: if ($width_param > $env{'form.textwidth'}) {
1.252 matthew 4141: my $old_width_param=$width_param;
1.267 albertel 4142: $width_param =0.95*$env{'form.textwidth'};
1.266 albertel 4143: if ($old_width_param) {
4144: $height_param=$width_param/$old_width_param*$height_param;
4145: }
1.197 sakharuk 4146: }
1.275 foxr 4147:
4148: return ($height_param, $width_param);
4149: }
4150:
4151: sub image_size {
4152: my ($src,$scaling,$parstack,$safeeval,$depth,$cis)=@_;
4153:
4154: #size of image from gif/jpg/jpeg/png
4155: my $ressrc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
4156: if (-e $ressrc) {
4157: $src = $ressrc;
4158: }
4159: my $image = Image::Magick->new;
4160: my $current_figure = $image->Read($src);
4161: my $width_param = $image->Get('width');
4162: my $height_param = $image->Get('height');
4163: &Apache::lonxml::debug("Image magick says: $src : Height = $height_param width = $width_param");
4164: undef($image);
4165:
4166: ($height_param, $width_param) = &resize_image($height_param, $width_param,
4167: $scaling, $parstack, $safeeval,
4168: $depth, $cis);
4169:
1.248 foxr 4170: return ($height_param, $width_param);
4171: }
4172:
4173: sub image_width {
4174: my ($height, $width) = &image_size(@_);
4175: return $width;
4176: }
4177: # Not yet 100% sure this is correct in all circumstances..
4178: # due to my uncertainty about mods to image_size.
4179: #
4180: sub image_height {
4181: my ($height, $width) = &image_size(@_);
4182: return $height;
1.197 sakharuk 4183: }
4184:
1.256 albertel 4185: sub get_eps_image {
4186: my ($src)=@_;
1.261 foxr 4187: my $orig_src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1], $src);
1.285 foxr 4188:
4189: # In order to prevent the substitution of the alt text, we need to
4190: # be sure the orig_src file is on system now so:
4191:
4192: if (! -e $orig_src) {
4193: &Apache::lonnet::repcopy($orig_src); # Failure is not completely fatal.
4194: }
1.275 foxr 4195: &Apache::lonxml::debug("get_eps_image: Original image: $orig_src");
1.282 foxr 4196: my ($spath, $sname, $sext) = fileparse($src, qr/\.(gif|png|jpg|jpeg)/i);
1.256 albertel 4197: $src=~s/\.(gif|png|jpg|jpeg)$/\.eps/i;
4198: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
1.275 foxr 4199: &Apache::lonxml::debug("Filelocation gives: $src");
1.256 albertel 4200: if (! -e $src) {
1.261 foxr 4201: &Apache::lonxml::debug("$src does not exist");
1.264 raeburn 4202: if (&Apache::lonnet::repcopy($src) ne 'ok' ) {
1.261 foxr 4203: &Apache::lonxml::debug("Repcopy of $src failed (1)");
1.256 albertel 4204: #if replication failed try to find ps file
4205: $src=~s/\.eps$/\.ps/;
1.261 foxr 4206: &Apache::lonxml::debug("Now looking for $src");
1.270 foxr 4207: #if no ps file try to replicate it.
4208: my $didrepcopy = &Apache::lonnet::repcopy($src);
4209: &Apache::lonxml::debug("repcopy of $src ... $didrepcopy");
4210: if ( (not -e $src) ||
4211: ($didrepcopy ne 'ok')) {
1.261 foxr 4212: &Apache::lonxml::debug("Failed to find or replicate $src");
4213:
1.256 albertel 4214: #if replication failed try to produce eps file dynamically
4215: $src=~s/\.ps$/\.eps/;
4216: my $temp_file;
1.267 albertel 4217: open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat");
1.256 albertel 4218: my $newsrc=$orig_src;
4219: $newsrc =~ s|(.*)/res/|/home/httpd/html/res/|;
1.275 foxr 4220: &Apache::lonxml::debug("queueing $newsrc for dynamic eps production.");
1.256 albertel 4221: print FILE "$newsrc\n";
1.261 foxr 4222: close FILE;
1.256 albertel 4223: $src=~s|/home/httpd/html/res|/home/httpd/prtspool|;
4224: $src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|;
1.283 albertel 4225: if ($sext ne "") { # Put the ext. back in to uniquify.
4226: $src =~ s/\.eps$/$sext.eps/;
4227: }
1.256 albertel 4228: }
4229: }
4230: }
4231: my ($path,$file)=($src=~m|(.*)/([^/]*)$|);
1.261 foxr 4232: &Apache::lonxml::debug("get_eps_image returning: $path / $file<BR />");
1.256 albertel 4233: return ($path.'/',$file);
4234: }
4235:
1.195 sakharuk 4236: sub eps_generation {
4237: my ($src,$file,$width_param) = @_;
1.267 albertel 4238: my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat";
1.195 sakharuk 4239: my $temp_file = Apache::File->new('>>'.$filename);
4240: print $temp_file "$src\n";
4241: my $newsrc = $src;
4242: $newsrc =~ s/(\.gif|\.jpg|\.jpeg)$/\.eps/i;
4243: $newsrc=~s/\/home\/httpd\/html\/res//;
4244: $newsrc=~s/\/home\/([^\/]*)\/public_html\//\/$1\//;
4245: $newsrc=~s/\/\.\//\//;
4246: $newsrc=~s/\/([^\/]+)\.(ps|eps)/\//;
1.213 sakharuk 4247: if ($newsrc=~/\/home\/httpd\/lonUsers\//) {
4248: $newsrc=~s/\/home\/httpd\/lonUsers//;
4249: $newsrc=~s/\/([^\/]+)\/(\w)\/(\w)\/(\w)\//\/$1\//;
4250: }
1.239 sakharuk 4251: if ($newsrc=~/\/userfiles\//) {
4252: return ' \graphicspath{{'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
4253: } else {
4254: return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
4255: }
1.197 sakharuk 4256: }
4257:
4258: sub file_path {
4259: my $src=shift;
4260: my ($file,$path);
4261: if ($src =~ m!(.*)/([^/]*)$!) {
4262: $file = $2;
4263: $path = $1.'/';
4264: }
4265: return $file,$path;
1.126 sakharuk 4266: }
1.294 foxr 4267: # Converts a measurement in to mm from any of
4268: # the other valid LaTeX units of measure.
4269: # If the units of measure are missing from the
4270: # parameter, it is assumed to be in and returned
4271: # with mm units of measure
1.126 sakharuk 4272: sub recalc {
4273: my $argument = shift;
4274: if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}
1.132 sakharuk 4275: $argument=~/\s*(\d+\.?\d*)\s*(mm|cm|in|pc|pt)/;
1.126 sakharuk 4276: my $value=$1;
4277: my $units=$2;
4278: if ($units eq 'cm') {
4279: $value*=10;
4280: } elsif ($units eq 'in') {
4281: $value*=25.4;
4282: } elsif ($units eq 'pc') {
4283: $value*=(25.4*12/72.27);
4284: } elsif ($units eq 'pt') {
4285: $value*=(25.4/72.27);
4286: }
4287: return $value.' mm';
1.94 sakharuk 4288: }
1.184 sakharuk 4289:
4290: sub LATEX_length {
4291: my $garbage=shift;
1.206 sakharuk 4292: $garbage=~s/^\s+$//;
4293: $garbage=~s/^\s+(\S.*)/$1/;#space before
4294: $garbage=~s/(.*\S)\s+$/$1/;#space after
4295: $garbage=~s/(\s)+/$1/;#only one space
4296: $garbage=~s/(\\begin{([^\}]+)}|\\end{([^\}]+)})//g;#remove LaTeX \begin{...} and \end{...}
4297: $garbage=~s/(\$\_\{|\$\_|\$\^{|\$\^|\}\$)//g;#remove $_{,$_,$^{,$^,}$
4298: $garbage=~s/([^\\])\$/$1/g;#$
4299: $garbage=~s/(\\ensuremath\{\_\{|\\ensuremath\{\_|\\ensuremath\{\^{|\\ensuremath\{\^|\})//g;#remove \ensuremath{...}
4300: $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 4301: $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;
4302: $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;
4303: $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 4304: $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;
4305: $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;
4306: $garbage=~s/(\\hat{([^}]+)}|\\check{([^}]+)}|\\dot{([^}]+)}|\\breve{([^}]+)}|\\acute{([^}]+)}|\\ddot{([^}]+)}|\\grave{([^}]+)}|\\tilde{([^}]+)}|\\mathring{([^}]+)}|\\bar{([^}]+)}|\\vec{([^}]+)})/$1/g;
4307: #remove some other LaTeX command
4308: $garbage=~s|\\(\w+)\\|\\|g;
4309: $garbage=~s|\\(\w+)(\s*)|$2|g;
4310: $garbage=~s|\+|11|g;
1.184 sakharuk 4311: my $value=length($garbage);
4312: return $value;
4313: }
4314:
4315:
1.287 foxr 4316: # is_inside_of $tagstack $tag
4317: # This sub returns true if the current state of Xml processing
4318: # is inside of the tag.
4319: # Parameters:
4320: # tagstack - The tagstack from the parser.
4321: # tag - The tag (without the <>'s.).
4322: # Sample usage:
4323: # if (is_inside_of($tagstack "table")) {
4324: # # I'm in a table....
4325: # }
4326: sub is_inside_of {
4327: my ($tagstack, $tag) = @_;
4328: my @stack = @$tagstack;
4329: for (my $i = ($#stack - 1); $i >= 0; $i--) {
4330: if ($stack[$i] eq $tag) {
4331: return 1;
4332: }
4333: }
4334: return 0;
4335: }
1.184 sakharuk 4336:
1.94 sakharuk 4337:
1.1 sakharuk 4338: 1;
4339: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>