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