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