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