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