Annotation of loncom/xml/londefdef.pm, revision 1.248
1.1 sakharuk 1: # The LearningOnline Network with CAPA
2: # Tags Default Definition Module
3: #
1.248 ! foxr 4: # $Id: londefdef.pm,v 1.247 2004/11/19 22:16:33 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') {
1466: $currentstring .= $token->[4];
1467: } elsif ($target eq 'tex') {
1.149 sakharuk 1468: my $a=&Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1);
1.161 sakharuk 1469: my $b=&Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1);
1470: if ($a=~/\S/) {
1471: $a=~s/([^\\])%/$1\\\%/g;
1472: $currentstring .= '\ref{URI: '.$a.'}';
1473: } elsif ($b=~/\S/) {
1474: $currentstring .= '\ref{Anchor: '.$b.'}';
1475: } else {
1476: $currentstring.='';
1477: }
1.122 albertel 1478: }
1479: return $currentstring;
1480: }
1481:
1482: sub end_a {
1.168 albertel 1483: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1484: my $currentstring = '';
1485: if ($target eq 'web') {
1486: $currentstring .= $token->[2];
1487: }
1488: return $currentstring;
1489: }
1490:
1.181 sakharuk 1491: #-- <li> tag (end tag optional)
1.122 albertel 1492: sub start_li {
1.168 albertel 1493: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1494: my $currentstring = '';
1495: if ($target eq 'web') {
1496: $currentstring = $token->[4];
1497: } elsif ($target eq 'tex') {
1.237 sakharuk 1498: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1499: my $value=&Apache::lonxml::get_param('value',$parstack,$safeeval,undef,0);
1.238 albertel 1500: #FIXME need to support types i and I
1501: if ($type=~/disc/) {
1502: $currentstring .= ' \item[$\bullet$] ';
1503: } elsif ($type=~/circle/) {
1504: $currentstring .= ' \item[$\circ$] ';
1.146 sakharuk 1505: } elsif ($type=~/square/) {
1.238 albertel 1506: $currentstring .= ' \item[$\diamond$] ';
1507: } elsif ($type eq '1') {
1508: $currentstring .= ' \item['.($Apache::londefdef::list_index+1).'.]';
1.237 sakharuk 1509: } elsif ($type eq 'A') {
1.238 albertel 1510: $currentstring .= ' \item['.('A'..'Z')[$Apache::londefdef::list_index].'.]';
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 ($value ne '') {
1514: $currentstring .= ' \item['.$value.'] ';
1.122 albertel 1515: } else {
1.146 sakharuk 1516: $currentstring .= ' \item ';
1.122 albertel 1517: }
1.238 albertel 1518: $Apache::londefdef::list_index++;
1519: }
1.122 albertel 1520: return $currentstring;
1521: }
1522:
1523: sub end_li {
1524: my ($target,$token) = @_;
1525: my $currentstring = '';
1526: if ($target eq 'web') {
1527: $currentstring = $token->[2];
1528: }
1529: return $currentstring;
1530: }
1531:
1.181 sakharuk 1532: #-- <u> tag (end tag required)
1.122 albertel 1533: sub start_u {
1534: my ($target,$token) = @_;
1535: my $currentstring = '';
1536: if ($target eq 'web') {
1537: $currentstring .= $token->[4];
1538: } elsif ($target eq 'tex') {
1539: &Apache::lonxml::startredirection();
1540: }
1541: return $currentstring;
1542: }
1543:
1544: sub end_u {
1545: my ($target,$token) = @_;
1546: my $currentstring = '';
1547: if ($target eq 'web') {
1548: $currentstring .= $token->[2];
1549: } elsif ($target eq 'tex') {
1550: $currentstring=&Apache::lonxml::endredirection();
1551: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1552: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1553: $currentstring=~s/(\S)\s*$/$1\}/;
1554: }
1555: return $currentstring;
1556: }
1557:
1.181 sakharuk 1558: #-- <ul> tag (end tag required)
1.122 albertel 1559: sub start_ul {
1.125 sakharuk 1560: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1561: my $currentstring = '';
1562: if ($target eq 'web') {
1563: $currentstring = $token->[4];
1564: } elsif ($target eq 'tex') {
1.125 sakharuk 1565: my $TeXtype=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1.238 albertel 1566: $Apache::londefdef::list_index=0;
1.125 sakharuk 1567: if ($TeXtype eq 'disc') {
1.222 sakharuk 1568: $currentstring .= '\renewcommand{\labelitemi}{$\bullet$}'.
1569: '\renewcommand{\labelitemii}{$\bullet$}'.
1570: '\renewcommand{\labelitemiii}{$\bullet$}'.
1571: '\renewcommand{\labelitemiv}{$\bullet$}';
1.125 sakharuk 1572: } elsif ($TeXtype eq 'circle') {
1.222 sakharuk 1573: $currentstring .= '\renewcommand{\labelitemi}{$\circ$}'.
1574: '\renewcommand{\labelitemii}{$\circ$}'.
1575: '\renewcommand{\labelitemiii}{$\circ$}'.
1576: '\renewcommand{\labelitemiv}{$\circ$}';
1.125 sakharuk 1577: } elsif ($TeXtype eq 'square') {
1.222 sakharuk 1578: $currentstring .= '\renewcommand{\labelitemi}{$\diamond$}'.
1579: '\renewcommand{\labelitemii}{$\diamond$}'.
1580: '\renewcommand{\labelitemiii}{$\diamond$}'.
1581: '\renewcommand{\labelitemiv}{$\diamond$}';
1.125 sakharuk 1582: }
1.222 sakharuk 1583: $currentstring .= '\strut \begin{itemize}';
1.122 albertel 1584: }
1585: return $currentstring;
1586: }
1587:
1588: sub end_ul {
1589: my ($target,$token) = @_;
1590: my $currentstring = '';
1591: if ($target eq 'web') {
1592: $currentstring = $token->[2];
1593: } elsif ($target eq 'tex') {
1.222 sakharuk 1594: $currentstring = '\end{itemize} \renewcommand{\labelitemi}{$\bullet$}'.
1595: '\renewcommand{\labelitemii}{$\bullet$}'.
1596: '\renewcommand{\labelitemiii}{$\bullet$}'.
1597: '\renewcommand{\labelitemiv}{$\bullet$}\strut ';
1.122 albertel 1598: }
1599: return $currentstring;
1600: }
1601:
1.181 sakharuk 1602: #-- <menu> tag (end tag required)
1.122 albertel 1603: sub start_menu {
1604: my ($target,$token) = @_;
1605: my $currentstring = '';
1606: if ($target eq 'web') {
1607: $currentstring = $token->[4];
1608: } elsif ($target eq 'tex') {
1609: $currentstring = " \\begin{itemize} ";
1610: }
1611: return $currentstring;
1612: }
1613:
1614: sub end_menu {
1615: my ($target,$token) = @_;
1616: my $currentstring = '';
1617: if ($target eq 'web') {
1618: $currentstring = $token->[2];
1619: } elsif ($target eq 'tex') {
1620: $currentstring = " \\end{itemize}";
1621: }
1622: return $currentstring;
1623: }
1624:
1.181 sakharuk 1625: #-- <dir> tag (end tag required)
1.122 albertel 1626: sub start_dir {
1627: my ($target,$token) = @_;
1628: my $currentstring = '';
1629: if ($target eq 'web') {
1630: $currentstring = $token->[4];
1631: } elsif ($target eq 'tex') {
1632: $currentstring = " \\begin{itemize} ";
1633: }
1634: return $currentstring;
1635: }
1636:
1637: sub end_dir {
1638: my ($target,$token) = @_;
1639: my $currentstring = '';
1640: if ($target eq 'web') {
1641: $currentstring = $token->[2];
1642: } elsif ($target eq 'tex') {
1643: $currentstring = " \\end{itemize}";
1644: }
1645: return $currentstring;
1646: }
1647:
1.181 sakharuk 1648: #-- <ol> tag (end tag required)
1.122 albertel 1649: sub start_ol {
1.125 sakharuk 1650: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1651: my $currentstring = '';
1652: if ($target eq 'web') {
1653: $currentstring = $token->[4];
1654: } elsif ($target eq 'tex') {
1.238 albertel 1655: $Apache::londefdef::list_index=0;
1.125 sakharuk 1656: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1657: if ($type eq '1') {
1.222 sakharuk 1658: $currentstring .= '\renewcommand{\labelenumi}{\arabic{enumi}.}'.
1659: '\renewcommand{\labelenumii}{\arabic{enumii}.}'.
1660: '\renewcommand{\labelenumiii}{\arabic{enumiii}.}'.
1661: '\renewcommand{\labelenumiv}{\arabic{enumiv}.}';
1.125 sakharuk 1662: } elsif ($type eq 'A') {
1.222 sakharuk 1663: $currentstring .= '\renewcommand{\labelenumi}{\Alph{enumi}.}'.
1664: '\renewcommand{\labelenumii}{\Alph{enumii}.}'.
1665: '\renewcommand{\labelenumiii}{\Alph{enumiii}.}'.
1666: '\renewcommand{\labelenumiv}{\Alph{enumiv}.}';
1.125 sakharuk 1667: } elsif ($type eq 'a') {
1.222 sakharuk 1668: $currentstring .= '\renewcommand{\labelenumi}{\alph{enumi}.}'.
1669: '\renewcommand{\labelenumii}{\alph{enumii}.}'.
1670: '\renewcommand{\labelenumiii}{\alph{enumiii}.}'.
1671: '\renewcommand{\labelenumiv}{\alph{enumiv}.}';
1.125 sakharuk 1672: } elsif ($type eq 'i') {
1.222 sakharuk 1673: $currentstring .= '\renewcommand{\labelenumi}{\roman{enumi}.}'.
1674: '\renewcommand{\labelenumii}{\roman{enumii}.}'.
1675: '\renewcommand{\labelenumiii}{\roman{enumiii}.}'.
1676: '\renewcommand{\labelenumiv}{\roman{enumiv}.}';
1.125 sakharuk 1677: } elsif ($type eq 'I') {
1.222 sakharuk 1678: $currentstring .= '\renewcommand{\labelenumi}{\Roman{enumi}.}'.
1679: '\renewcommand{\labelenumii}{\Roman{enumii}.}'.
1680: '\renewcommand{\labelenumiii}{\Roman{enumiii}.}'.
1681: '\renewcommand{\labelenumiv}{\Roman{enumiv}.}';
1.125 sakharuk 1682: }
1.222 sakharuk 1683: $currentstring .= '\strut \begin{enumerate}';
1.122 albertel 1684: }
1685: return $currentstring;
1686: }
1687:
1688: sub end_ol {
1689: my ($target,$token) = @_;
1690: my $currentstring = '';
1691: if ($target eq 'web') {
1692: $currentstring = $token->[2];
1693: } elsif ($target eq 'tex') {
1.222 sakharuk 1694: $currentstring = '\end{enumerate}\renewcommand{\labelenumi}{\arabic{enumi}.}'.
1695: '\renewcommand{\labelenumii}{\arabic{enumii}.}'.
1696: '\renewcommand{\labelenumiii}{\arabic{enumiii}.}'.
1697: '\renewcommand{\labelenumiv}{\arabic{enumiv}.}\strut ';
1.122 albertel 1698: }
1699: return $currentstring;
1700: }
1701:
1.181 sakharuk 1702: #-- <dl> tag (end tag required)
1.122 albertel 1703: sub start_dl {
1704: my ($target,$token) = @_;
1705: my $currentstring = '';
1706: if ($target eq 'web') {
1707: $currentstring = $token->[4];
1708: } elsif ($target eq 'tex') {
1.174 sakharuk 1709: $currentstring = '\begin{description}';
1.243 albertel 1710: $Apache::londefdef::DL++;
1711: push(@Apache::londefdef::description,[]);
1712: $Apache::londefdef::DD[$Apache::londefdef::DL]=0;
1713: $Apache::londefdef::DT[$Apache::londefdef::DL]=0;
1.244 albertel 1714: $Apache::londefdef::seenDT[$Apache::londefdef::DL]=0;
1.122 albertel 1715: }
1716: return $currentstring;
1717: }
1718:
1719: sub end_dl {
1.174 sakharuk 1720: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1721: my $currentstring = '';
1722: if ($target eq 'web') {
1723: $currentstring = $token->[2];
1724: } elsif ($target eq 'tex') {
1.243 albertel 1725: if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
1726: if ($Apache::londefdef::DD[-1]) { &end_dd(@_); }
1727: foreach my $element (@{$Apache::londefdef::description[-1]}) {
1.174 sakharuk 1728: $currentstring.=' '.$element.' ';
1729: }
1.243 albertel 1730: pop(@Apache::londefdef::description);
1.174 sakharuk 1731: $currentstring.='\end{description}';
1.243 albertel 1732: delete($Apache::londefdef::DD[$Apache::londefdef::DL]);
1733: delete($Apache::londefdef::DT[$Apache::londefdef::DL]);
1.244 albertel 1734: delete($Apache::londefdef::seenDT[$Apache::londefdef::DL]);
1.243 albertel 1735: $Apache::londefdef::DL--;
1.122 albertel 1736: }
1737: return $currentstring;
1738: }
1739:
1.172 sakharuk 1740: #-- <dt> tag (end tag optional)
1.122 albertel 1741: sub start_dt {
1.172 sakharuk 1742: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1743: my $currentstring='';
1.122 albertel 1744: if ($target eq 'web') {
1745: $currentstring = $token->[4];
1746: } elsif ($target eq 'tex') {
1.243 albertel 1747: if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
1748: if ($Apache::londefdef::DD[-1]) { &end_dd(@_); }
1.174 sakharuk 1749: &Apache::lonxml::startredirection();
1.243 albertel 1750: $Apache::londefdef::DT[-1]++;
1.244 albertel 1751: $Apache::londefdef::seenDT[-1]=1;
1.122 albertel 1752: }
1753: return $currentstring;
1754: }
1755:
1756: sub end_dt {
1.172 sakharuk 1757: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1758: my $currentstring = '';
1759: if ($target eq 'web') {
1760: $currentstring = $token->[2];
1761: } elsif ($target eq 'tex') {
1.243 albertel 1762: if ($Apache::londefdef::DT[-1]) {
1763: my $data=&item_cleanup();
1.244 albertel 1764: push(@{$Apache::londefdef::description[-1]},'\item['.$data.'] \strut \vskip 0mm');
1.243 albertel 1765: $Apache::londefdef::DT[-1]--;
1766: }
1.122 albertel 1767: }
1768: return $currentstring;
1769: }
1770:
1.173 sakharuk 1771: sub item_cleanup {
1.174 sakharuk 1772: my $item=&Apache::lonxml::endredirection();
1.173 sakharuk 1773: $item=~s/\\begin{center}//g;
1774: $item=~s/\\end{center}//g;
1775: return $item;
1776: }
1777:
1.181 sakharuk 1778: #-- <dd> tag (end tag optional)
1.122 albertel 1779: sub start_dd {
1.147 sakharuk 1780: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1781: my $currentstring = '';
1782: if ($target eq 'web') {
1783: $currentstring = $token->[4];
1.147 sakharuk 1784: } elsif ($target eq 'tex') {
1.243 albertel 1785: if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
1786: if ($Apache::londefdef::DD[-1]) { &end_dd(@_);}
1.244 albertel 1787: if (!$Apache::londefdef::seenDT[-1]) {
1788: push(@{$Apache::londefdef::description[-1]},'\item[\strut] \strut \vskip 0mm ');
1789: }
1.243 albertel 1790: push(@{$Apache::londefdef::description[-1]},'');
1791: $Apache::londefdef::description[-1]->[-1].=' \strut ';
1792: $Apache::londefdef::DD[-1]++;
1.174 sakharuk 1793: &Apache::lonxml::startredirection();
1.122 albertel 1794: }
1795: return $currentstring;
1796: }
1797:
1798: sub end_dd {
1.174 sakharuk 1799: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1800: my $currentstring = '';
1801: if ($target eq 'web') {
1802: $currentstring = $token->[2];
1.174 sakharuk 1803: } elsif ($target eq 'tex') {
1.243 albertel 1804: $Apache::londefdef::description[-1]->[-1].=
1805: &Apache::lonxml::endredirection().' \vskip 0mm ';
1806: $Apache::londefdef::DD[-1]--;
1.174 sakharuk 1807: }
1.122 albertel 1808: return $currentstring;
1809: }
1810:
1.181 sakharuk 1811: #-- <table> tag (end tag required)
1.206 sakharuk 1812: #list of supported attributes: border,width,TeXwidth
1.91 sakharuk 1813: sub start_table {
1814: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.206 sakharuk 1815: my ($textwidth,$currentstring)=('','');
1.91 sakharuk 1816: if ($target eq 'web') {
1817: $currentstring = $token->[4];
1818: } elsif ($target eq 'tex') {
1819: my $aa = {};
1820: push @Apache::londefdef::table, $aa;
1821: $Apache::londefdef::table[-1]{'row_number'} = -1;
1.222 sakharuk 1822: #maximum table's width (default coincides with text line length)
1.206 sakharuk 1823: if ($#Apache::londefdef::table==0) {
1824: $textwidth=&recalc($ENV{'form.textwidth'}); #result is always in mm
1825: $textwidth=~/(\d+\.?\d*)/;
1826: $textwidth=0.95*$1; #accounts "internal" LaTeX space for table frame
1827: } else {
1828: if ($Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]=~/\d/) {
1829: #the maximum width of nested table is determined by LATeX width of parent cell
1830: $textwidth=$Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}];
1831: } else {
1832: #try to use all space not used before (minus 5% for LaTeX table internal) - rather silly
1.228 sakharuk 1833: $textwidth=$Apache::londefdef::table[-2]{'width'};
1.206 sakharuk 1834: for (my $i=0;$i<$Apache::londefdef::table[-2]{'counter_columns'};$i++) {
1835: $textwidth=$textwidth-$Apache::londefdef::table[-2]{'TeXlen'}[0][$i];
1836: }
1837: }
1838: }
1.126 sakharuk 1839: my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
1840: if (not defined $TeXwidth) {
1841: my $htmlwidth = &Apache::lonxml::get_param('width',$parstack,$safeeval,undef,1);
1842: if ($htmlwidth=~/%/) {
1.203 sakharuk 1843: $Apache::londefdef::table[-1]{'percent'}=1;
1.126 sakharuk 1844: $htmlwidth=~/(\d+)/;
1.203 sakharuk 1845: $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;;
1.126 sakharuk 1846: } else {
1847: $Apache::londefdef::table[-1]{'width'}=$textwidth;
1848: }
1849: } elsif ($TeXwidth=~/%/) {
1.203 sakharuk 1850: $Apache::londefdef::table[-1]{'percent'}=1;
1.126 sakharuk 1851: $TeXwidth=~/(\d+)/;
1.206 sakharuk 1852: $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;
1.126 sakharuk 1853: } else {
1.222 sakharuk 1854: $Apache::londefdef::table[-1]{'forcetablewidth'}=1;
1.206 sakharuk 1855: $Apache::londefdef::table[-1]{'width'}=$TeXwidth;
1.126 sakharuk 1856: }
1857: #table's border
1.206 sakharuk 1858: my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval);
1.208 sakharuk 1859: my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
1.91 sakharuk 1860: unless (defined $border) { $border = 0; }
1861: if ($border) {
1862: $Apache::londefdef::table[-1]{'hinc'} = '\hline ';
1863: $Apache::londefdef::table[-1]{'vinc'} = '&';
1864: $Apache::londefdef::table[-1]{'vvinc'} = '|';
1865: } else {
1866: $Apache::londefdef::table[-1]{'hinc'} = '';
1867: $Apache::londefdef::table[-1]{'vinc'} = '&';
1868: $Apache::londefdef::table[-1]{'vvinc'} = '';
1869: }
1.206 sakharuk 1870: if ($#Apache::londefdef::table==0) {
1.218 sakharuk 1871: $Apache::londefdef::table[-1]{'output'}='\strut\newline\strut\setlength{\tabcolsep}{1 mm}';
1.206 sakharuk 1872: }
1873: $Apache::londefdef::table[-1]{'output'}.=' \noindent \begin{tabular} ';
1874: $Apache::londefdef::table[-1]{'TeXlen'}=[];
1875: $Apache::londefdef::table[-1]{'objectlen'}=[];
1.229 sakharuk 1876: $Apache::londefdef::table[-1]{'objectsignal'}=[];
1.206 sakharuk 1877: $Apache::londefdef::table[-1]{'maxlen'}=[];
1878: $Apache::londefdef::table[-1]{'minlen'}=[];
1879: $Apache::londefdef::table[-1]{'content'}=[];
1880: $Apache::londefdef::table[-1]{'align'}=[];
1881: $currentstring='\keephidden{NEW TABLE ENTRY}';
1882: }
1.91 sakharuk 1883: return $currentstring;
1884: }
1.122 albertel 1885:
1886: sub end_table {
1887: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1888: my $currentstring = '';
1889: if ($target eq 'web') {
1890: $currentstring = $token->[2];
1891: } elsif ($target eq 'tex') {
1892: my $inmemory = '';
1893: my $output = '';
1.206 sakharuk 1894: my $WARNING='';
1895: #width of columns from TeXwidth attributes
1896: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1897: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
1898: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]<$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn]) {
1899: $Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]=$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn];
1900: }
1901: }
1902: }
1903: #free space and number of empty columns
1904: my ($available_space,$empty_columns)=($Apache::londefdef::table[-1]{'width'},0);
1.228 sakharuk 1905: if ($#Apache::londefdef::table ne 0) {$available_space=0.9*$available_space;}
1.206 sakharuk 1906: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
1907: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]==0) {
1908: $empty_columns++;
1909: } else {
1910: $available_space=$available_space-$Apache::londefdef::table[-1]{'TeXlen'}[0][$jn];
1911: }
1912: }
1913: #boundaries for contents columns
1914: my @min_len=();#columns can not be narrower
1915: my @max_len=();#maximum length of column
1916: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
1917: my ($localmin,$localmax)=(0,0);
1918: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1919: if ($localmin<$Apache::londefdef::table[-1]{'minlen'}[$in][$jn]) {
1920: $localmin=$Apache::londefdef::table[-1]{'minlen'}[$in][$jn];
1921: }
1922: if ($localmax<$Apache::londefdef::table[-1]{'maxlen'}[$in][$jn]) {
1923: $localmax=$Apache::londefdef::table[-1]{'maxlen'}[$in][$jn];
1924: }
1925: }
1926: push @min_len, $localmin;
1927: push @max_len, $localmax;
1.122 albertel 1928: }
1.206 sakharuk 1929: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
1930: my $localmin=0,;
1931: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1932: if ($localmin<$Apache::londefdef::table[-1]{'objectlen'}[$in][$jn]) {
1933: $localmin=$Apache::londefdef::table[-1]{'objectlen'}[$in][$jn];
1934: }
1935: }
1.229 sakharuk 1936: if ($max_len[$jn]<$localmin) {
1937: $max_len[$jn]=$localmin;
1938: $Apache::londefdef::table[-1]{'objectsignal'}[$jn]=1;
1939: }#object size is bigger
1940: if ($min_len[$jn]<$localmin) {
1941: $min_len[$jn]=$localmin;
1942: $Apache::londefdef::table[-1]{'objectsignal'}[$jn]=1;
1943: }#object size is bigger
1.206 sakharuk 1944: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]!=0) {
1945: $min_len[$jn]=0;
1946: $max_len[$jn]=0;
1947: }
1948: }
1949: #final adjustment of column width
1950: my @fwidth=@{$Apache::londefdef::table[-1]{'TeXlen'}[0]};#final width array
1951: my @adjust=();
1952: #step 1. adjustment by maximum value
1953: my $space_neeeded=0;
1954: for (my $jn=0;$jn<=$#max_len;$jn++) {
1955: $space_neeeded=$space_neeeded+$max_len[$jn];
1956: }
1957: if ($space_neeeded<=$available_space) {
1958: for (my $jn=0;$jn<=$#max_len;$jn++) {
1959: if ($fwidth[$jn]==0) {
1960: $fwidth[$jn]=$max_len[$jn];
1.53 sakharuk 1961: }
1.51 sakharuk 1962: }
1.206 sakharuk 1963: } else {
1964: #step 2. adjustment by minimum value (estimation)
1965: $space_neeeded=0;
1966: for (my $jn=0;$jn<=$#min_len;$jn++) {
1967: $space_neeeded+=$min_len[$jn];
1968: }
1969: if ($space_neeeded>$available_space) {
1970: $WARNING=' \textbf{NOT ENOUGH SPACE FOR TABLE} ';
1971: for (my $jn=0;$jn<=$#max_len;$jn++) {
1972: if ($fwidth[$jn]==0) {
1973: $fwidth[$jn]=$min_len[$jn];
1974: }
1975: }
1.229 sakharuk 1976: #check if we have objects which can be scaled
1977: my $how_many_to_scale=0;
1978: my @to_scale=();
1979: for (my $jn=0;$jn<=$#max_len;$jn++) {
1980: if ($Apache::londefdef::table[-1]{'objectsignal'}[$jn] eq '1') {
1981: $how_many_to_scale++;
1982: push @to_scale, $jn;
1983: }
1984: }
1985: if ($how_many_to_scale>0) {
1986: my $space_to_adjust=($space_neeeded-$available_space)/$how_many_to_scale;
1987: foreach my $jn (@to_scale) {
1988: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1989: $Apache::londefdef::table[-1]{'content'}[$in][$jn]=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/;
1990: if ($1 ne '') {
1991: my $current_length=&recalc($1);
1992: $current_length=~/(\d+\.?\d*)/;
1993: $current_length=$current_length-$space_to_adjust;
1994: $Apache::londefdef::table[-1]{'content'}[$in][$jn]=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/width=$current_length mm/;
1995: }
1996: $Apache::londefdef::table[-1]{'content'}[$in][$jn]=~m/\[(\d+\.?\d*)\s*mm\]/;
1997: if ($1 ne '') {
1998: my $current_length=$1;
1999: $current_length=$current_length-$space_to_adjust;
2000: $Apache::londefdef::table[-1]{'content'}[$in][$jn]=~s/\[(\d+\.?\d*)\s*mm\]/\[$current_length mm\]/;
2001: }
2002: }
2003: $fwidth[$jn]=$fwidth[$jn]-$space_to_adjust;
2004: }
2005: }
1.206 sakharuk 2006: } else {
2007: #step 3. adjustment over minimal + corrections
2008: my $enlarge_coef=$available_space/$space_neeeded;
2009: my $acsessive=0;
2010: for (my $jn=0;$jn<=$#min_len;$jn++) {
2011: $adjust[$jn]=$min_len[$jn]*$enlarge_coef;
2012: if ($adjust[$jn]>$max_len[$jn]) {
2013: $fwidth[$jn]=$max_len[$jn];
2014: $acsessive=$acsessive+$adjust[$jn]-$max_len[$jn];
2015: $adjust[$jn]=0;
2016: }
2017: }
2018: if ($acsessive>0) {
2019: #we have an excess of space and can redistribute it
2020: my $notempty_columns=0;
2021: for (my $jn=0;$jn<=$#min_len;$jn++) {
2022: if ($adjust[$jn]!=0) {
2023: $notempty_columns++;
2024: }
2025: }
2026: my $per_column=$acsessive/$notempty_columns;
2027: for (my $jn=0;$jn<=$#min_len;$jn++) {
2028: if ($adjust[$jn]!=0) {
2029: $adjust[$jn]+=$per_column;
2030: $fwidth[$jn]=$adjust[$jn];
2031: }
1.223 sakharuk 2032: }
2033: } else {
2034: for (my $jn=0;$jn<=$#min_len;$jn++) {
2035: $fwidth[$jn]=$adjust[$jn];
1.206 sakharuk 2036: }
2037: }
1.203 sakharuk 2038: }
2039: }
1.222 sakharuk 2040: #use all available width if it is defined in % or as TeXwidth
2041: if (($Apache::londefdef::table[-1]{'percent'}==1) || ($Apache::londefdef::table[-1]{'forcetablewidth'}==1)) {
1.203 sakharuk 2042: my $current=0;
1.206 sakharuk 2043: for (my $i=0;$i<=$#fwidth;$i++) {
2044: $current+=$fwidth[$i];
1.203 sakharuk 2045: }
2046: my $coef=$Apache::londefdef::table[-1]{'width'}/$current;
1.206 sakharuk 2047: for (my $i=0;$i<=$#fwidth;$i++) {
2048: $fwidth[$i]*=$coef;
2049: }
2050: }
2051: #removing of empty columns if allowed
1.208 sakharuk 2052: my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
1.206 sakharuk 2053: if ($permission eq 'yes') {
2054: my @cleaned_table=();
2055: my @cleaned_header=();
2056: my $colind=0;
2057: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
2058: if ($fwidth[$jn]!=0) {
2059: #we need to copy column
2060: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2061: $cleaned_table[$in][$colind]=$Apache::londefdef::table[-1]{'content'}[$in][$jn];
2062: $cleaned_header[$colind]=$fwidth[$jn];
2063: }
2064: $colind++;
2065: }
1.122 albertel 2066: }
1.206 sakharuk 2067: $Apache::londefdef::table[-1]{'content'}=\@cleaned_table;
2068: @fwidth=@cleaned_header;
1.122 albertel 2069: }
1.206 sakharuk 2070: #construct header of the table
2071: my $header_of_table = '{'.$Apache::londefdef::table[-1]{'vvinc'};
2072: for (my $in=0;$in<=$#fwidth;$in++) {
2073: $header_of_table.='p{'.$fwidth[$in].' mm}'.$Apache::londefdef::table[-1]{'vvinc'};
2074: }
2075: $header_of_table .= '}';
1.126 sakharuk 2076: #fill the table
2077: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1.206 sakharuk 2078: for (my $jn=0;$jn<=$#fwidth;$jn++) {
2079: if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
1.228 sakharuk 2080: $output.='\vspace*{-6 mm}\begin{center}';
1.206 sakharuk 2081: } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
2082: $output.=' \hfill \llap{'
2083: }
2084: $output.=$Apache::londefdef::table[-1]{'content'}[$in][$jn];
2085: if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
1.228 sakharuk 2086: $output.='\end{center}\vspace*{-6 mm}';
1.206 sakharuk 2087: } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
2088: $output.='} ';
2089: }
2090: if ($jn!=$#fwidth) {$output.=' '.$Apache::londefdef::table[-1]{'vinc'};}
2091: }
2092: $output.=' \\\\ '.$Apache::londefdef::table[-1]{'hinc'}.' ';
1.122 albertel 2093: }
1.218 sakharuk 2094: $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut\newline\strut ';
1.127 sakharuk 2095: if ($#Apache::londefdef::table > 0) {
2096: my $inmemory = $Apache::londefdef::table[-1]{'output'};
2097: pop @Apache::londefdef::table;
1.129 sakharuk 2098: push @{$Apache::londefdef::table[-1]{'include'}}, $inmemory;
1.127 sakharuk 2099: } else {
2100: $currentstring .= $Apache::londefdef::table[-1]{'output'};
2101: pop @Apache::londefdef::table;
1.143 sakharuk 2102: undef @Apache::londefdef::table;
1.127 sakharuk 2103: }
1.122 albertel 2104: }
2105: return $currentstring;
2106: }
2107:
1.166 sakharuk 2108: #-- <tr> tag (end tag optional)
1.122 albertel 2109: sub start_tr {
2110: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2111: my $currentstring = '';
2112: if ($target eq 'web') {
2113: $currentstring = $token->[4];
2114: } elsif ($target eq 'tex') {
2115: $Apache::londefdef::table[-1]{'row_number'}++;
1.206 sakharuk 2116: my $alignchar=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1.122 albertel 2117: if ($alignchar ne '') {
1.206 sakharuk 2118: push @ {$Apache::londefdef::table[-1]{'rows'} },substr($alignchar,0,1);
1.122 albertel 2119: } else {
2120: push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l';
2121: }
2122: push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'});
2123: $Apache::londefdef::table[-1]{'counter_columns'} = -1;
1.206 sakharuk 2124: push @ {$Apache::londefdef::table[-1]{'TeXlen'}}, [];
2125: push @ {$Apache::londefdef::table[-1]{'objectlen'}}, [];
2126: push @ {$Apache::londefdef::table[-1]{'minlen'}}, [];
2127: push @ {$Apache::londefdef::table[-1]{'maxlen'}}, [];
2128: push @ {$Apache::londefdef::table[-1]{'content'}}, [];
1.122 albertel 2129: }
2130: return $currentstring;
2131: }
2132:
2133: sub end_tr {
1.160 sakharuk 2134: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 2135: my $currentstring = '';
2136: if ($target eq 'web') {
2137: $currentstring = $token->[2];
2138: } elsif ($target eq 'tex') {
1.160 sakharuk 2139: if ($Apache::londefdef::TD_redirection) {
2140: &end_td_tex($parstack,$parser,$safeeval);
2141: }
1.122 albertel 2142: }
2143: return $currentstring;
2144: }
2145:
1.166 sakharuk 2146: #-- <td> tag (end tag optional)
1.122 albertel 2147: sub start_td {
2148: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2149: my $currentstring = '';
2150: if ($target eq 'web') {
2151: $currentstring = $token->[4];
2152: } elsif ($target eq 'tex') {
1.160 sakharuk 2153: $Apache::londefdef::TD_redirection = 1;
1.159 sakharuk 2154: &tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval);
1.122 albertel 2155: }
2156: return $currentstring;
2157: }
1.159 sakharuk 2158:
2159: sub tag_check {
2160: my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
1.160 sakharuk 2161: my @ar=@$parstack;
2162: for (my $i=$#ar-1;$i>=0;$i--) {
2163: if (lc($$tagstack[$i]) eq $good_tag) {
2164: &start_td_tex($parstack,$parser,$safeeval);
2165: last;
2166: } elsif (lc($$tagstack[$i]) eq $bad_tag) {
2167: splice @ar, $i+1;
2168: &end_td_tex(\@ar,$parser,$safeeval);
2169: &start_td_tex($parstack,$parser,$safeeval);
2170: last;
1.159 sakharuk 2171: }
1.160 sakharuk 2172: }
1.159 sakharuk 2173: return '';
2174: }
2175:
2176: sub start_td_tex {
2177: my ($parstack,$parser,$safeeval) = @_;
1.206 sakharuk 2178: my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
2179: if ($alignchar eq '') {
2180: $alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
1.159 sakharuk 2181: }
1.206 sakharuk 2182: push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
1.159 sakharuk 2183: $Apache::londefdef::table[-1]{'counter_columns'}++;
1.206 sakharuk 2184: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2185: if (defined $TeXwidth) {
2186: my $current_length=&recalc($TeXwidth);
2187: $current_length=~/(\d+\.?\d*)/;
2188: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
2189: }
1.159 sakharuk 2190: &Apache::lonxml::startredirection();
2191: return '';
2192: }
2193:
2194: sub end_td_tex {
2195: my ($parstack,$parser,$safeeval) = @_;
2196: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
2197: my $data=&Apache::lonxml::endredirection();
2198: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2199: if (defined $TeXwidth) {
1.206 sakharuk 2200: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2201: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2202: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
1.159 sakharuk 2203: } else {
1.206 sakharuk 2204: if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
2205: my $garbage_data=$data;
2206: my $fwidth=0;
2207: while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2208: my $current_length=&recalc($1);
2209: $current_length=~/(\d+\.?\d*)/;
2210: if ($fwidth<$1) {$fwidth=$1;}
2211: $garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2212: }
2213: while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
2214: my $current_length=$1;
2215: if ($fwidth<$current_length) {$fwidth=$current_length;}
2216: $garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
2217: }
2218: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2219: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2220: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2221: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
1.231 sakharuk 2222: } 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)*/) {
2223: my $garbage_data=$data;
2224: my $fwidth=0;
2225: while ($garbage_data=~/\\parbox\{\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)\s*\}/) {
2226: my $current_length=&recalc($1);
2227: $current_length=~/(\d+\.?\d*)/;
2228: if ($fwidth<$1) {$fwidth=$1;}
2229: $garbage_data=~s/\\parbox\{\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2230: }
2231: while ($garbage_data=~/\\epsfxsize\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2232: my $current_length=&recalc($1);
2233: $current_length=~/(\d+\.?\d*)/;
2234: if ($fwidth<$1) {$fwidth=$1;}
2235: $garbage_data=~s/\\epsfxsize\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2236: }
2237: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2238: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2239: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2240: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2241: $data=~s/\\\\\s*$//;
1.159 sakharuk 2242: } else {
1.166 sakharuk 2243: $data=~s/^\s+(\S.*)/$1/;
1.159 sakharuk 2244: $data=~s/(.*\S)\s+$/$1/;
1.166 sakharuk 2245: $data=~s/(\s)+/$1/;
1.206 sakharuk 2246: my ($current_length,$min_length)=(0,0);
1.166 sakharuk 2247: if ($data=~/\\vskip/) {
2248: my $newdata=$data;
2249: $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
2250: my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
2251: foreach my $elementdata (@newdata) {
1.206 sakharuk 2252: my $lengthnewdata=2.5*&LATEX_length($elementdata);
1.166 sakharuk 2253: if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
1.206 sakharuk 2254: my @words=split(/ /,$elementdata);
2255: foreach my $word (@words) {
2256: my $lengthword=2.5*&LATEX_length($word);
2257: if ($min_length<$lengthword) {$min_length=$lengthword;}
2258: }
1.166 sakharuk 2259: }
2260: } else {
1.206 sakharuk 2261: $current_length=2.5*&LATEX_length($data);
2262: my @words=split(/ /,$data);
2263: foreach my $word (@words) {
1.228 sakharuk 2264: my $lengthword=2*&LATEX_length($word);
1.206 sakharuk 2265: if ($min_length<$lengthword) {$min_length=$lengthword;}
2266: }
1.166 sakharuk 2267: }
1.206 sakharuk 2268: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2269: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2270: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
2271: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
1.159 sakharuk 2272: }
2273: }
2274: for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {
2275: $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
2276: }
1.206 sakharuk 2277: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
1.159 sakharuk 2278: return'';
2279: }
2280:
1.122 albertel 2281: sub end_td {
1.126 sakharuk 2282: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 2283: my $currentstring = '';
2284: if ($target eq 'web') {
2285: $currentstring = $token->[2];
2286: } elsif ($target eq 'tex') {
1.160 sakharuk 2287: $Apache::londefdef::TD_redirection =0;
1.159 sakharuk 2288: &end_td_tex($parstack,$parser,$safeeval);
1.122 albertel 2289: }
2290: return $currentstring;
2291: }
2292:
1.166 sakharuk 2293: #-- <th> tag (end tag optional)
1.122 albertel 2294: sub start_th {
2295: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2296: my $currentstring = '';
2297: if ($target eq 'web') {
2298: $currentstring = $token->[4];
2299: } elsif ($target eq 'tex') {
1.230 sakharuk 2300: $Apache::londefdef::TD_redirection = 1;
2301: &tagg_check('tr','th',$tagstack,$parstack,$parser,$safeeval);
1.122 albertel 2302: }
2303: return $currentstring;
1.130 sakharuk 2304: }
1.230 sakharuk 2305:
2306: sub tagg_check {
2307: my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
2308: my @ar=@$parstack;
2309: for (my $i=$#ar-1;$i>=0;$i--) {
2310: if (lc($$tagstack[$i]) eq $good_tag) {
2311: &start_th_tex($parstack,$parser,$safeeval);
2312: last;
2313: } elsif (lc($$tagstack[$i]) eq $bad_tag) {
2314: splice @ar, $i+1;
2315: &end_th_tex(\@ar,$parser,$safeeval);
2316: &start_th_tex($parstack,$parser,$safeeval);
2317: last;
2318: }
2319: }
2320: return '';
2321: }
2322:
2323: sub start_th_tex {
2324: my ($parstack,$parser,$safeeval) = @_;
2325: my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
2326: if ($alignchar eq '') {
2327: $alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
2328: }
2329: push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
2330: $Apache::londefdef::table[-1]{'counter_columns'}++;
2331: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2332: if (defined $TeXwidth) {
2333: my $current_length=&recalc($TeXwidth);
2334: $current_length=~/(\d+\.?\d*)/;
2335: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
2336: }
2337: &Apache::lonxml::startredirection();
2338: return '';
2339: }
2340:
2341: sub end_th_tex {
2342: my ($parstack,$parser,$safeeval) = @_;
2343: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
2344: my $data=&Apache::lonxml::endredirection();
2345: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2346: if (defined $TeXwidth) {
2347: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2348: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2349: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2350: } else {
2351: if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
2352: my $garbage_data=$data;
2353: my $fwidth=0;
2354: while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2355: my $current_length=&recalc($1);
2356: $current_length=~/(\d+\.?\d*)/;
2357: if ($fwidth<$1) {$fwidth=$1;}
2358: $garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2359: }
2360: while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
2361: my $current_length=$1;
2362: if ($fwidth<$current_length) {$fwidth=$current_length;}
2363: $garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
2364: }
2365: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2366: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2367: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2368: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2369: } else {
2370: $data=~s/^\s+(\S.*)/$1/;
2371: $data=~s/(.*\S)\s+$/$1/;
2372: $data=~s/(\s)+/$1/;
2373: my ($current_length,$min_length)=(0,0);
2374: if ($data=~/\\vskip/) {
2375: my $newdata=$data;
2376: $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
2377: my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
2378: foreach my $elementdata (@newdata) {
2379: my $lengthnewdata=2.5*&LATEX_length($elementdata);
2380: if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
2381: my @words=split(/ /,$elementdata);
2382: foreach my $word (@words) {
2383: my $lengthword=2.5*&LATEX_length($word);
2384: if ($min_length<$lengthword) {$min_length=$lengthword;}
2385: }
2386: }
2387: } else {
2388: $current_length=2.5*&LATEX_length($data);
2389: my @words=split(/ /,$data);
2390: foreach my $word (@words) {
2391: my $lengthword=2*&LATEX_length($word);
2392: if ($min_length<$lengthword) {$min_length=$lengthword;}
2393: }
2394: }
2395: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2396: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2397: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
2398: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
2399: }
2400: }
2401: for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {
2402: $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
2403: }
2404: #make data bold
2405: $data='\textbf{'.$data.'}';
2406: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
2407: return'';
2408: }
2409:
1.122 albertel 2410: sub end_th {
1.130 sakharuk 2411: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 2412: my $currentstring = '';
2413: if ($target eq 'web') {
2414: $currentstring = $token->[2];
2415: } elsif ($target eq 'tex') {
1.230 sakharuk 2416: $Apache::londefdef::TD_redirection =0;
2417: &end_th_tex($parstack,$parser,$safeeval);
1.122 albertel 2418: }
2419: return $currentstring;
2420: }
1.230 sakharuk 2421:
1.181 sakharuk 2422: #-- <img> tag (end tag forbidden)
1.122 albertel 2423: sub start_img {
2424: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2425: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,
2426: undef,1);
1.189 albertel 2427: if (not $src and ($target eq 'web' or $target eq 'tex')) {
2428: my $inside = &Apache::lonxml::get_all_text("/img",$parser);
2429: return '';
2430: }
1.122 albertel 2431: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
2432: my $currentstring = '';
2433: my $scaling = .3;
2434: if ($target eq 'web') {
2435: if ($ENV{'browser.imagesuppress'} ne 'on') {
1.158 sakharuk 2436: $currentstring.= $token->[4];
1.122 albertel 2437: } else {
2438: my $alttag= &Apache::lonxml::get_param
2439: ('alt',$parstack,$safeeval,undef,1);
2440: unless ($alttag) {
2441: $alttag=&Apache::lonmeta::alttag
2442: ($Apache::lonxml::pwd[-1],$src);
1.51 sakharuk 2443: }
1.158 sakharuk 2444: $currentstring.='[IMAGE: '.$alttag.']';
1.1 sakharuk 2445: }
1.122 albertel 2446: } elsif ($target eq 'tex') {
1.248 ! foxr 2447: #
! 2448: # The alignment will require some superstructure to be put around
! 2449: # the \includegraphics stuff. At present we can only partially
! 2450: # simulate the alignments offered by html.
! 2451: #
! 2452: #
! 2453: my $align = lc(&Apache::lonxml::get_param('align',
! 2454: $parstack,
! 2455: $safeeval,
! 2456: undef,1));
! 2457: if(!$align) {
! 2458: $align = "bottom"; # This is html's default so it's ours too.
! 2459: }
! 2460: #
! 2461: &Apache::lonxml::debug("Alignemnt = $align");
! 2462: # LaTeX's image/text wrapping is really bad since it wants to
! 2463: # make figures float.
! 2464: # The user has the optional parameter (applicable only to l/r
! 2465: # alignment to use the picins/parpic directive to get wrapped text
! 2466: # this is also imperfect.. that's why we give them a choice...
! 2467: # so they can't yell at us for our choice.
! 2468: #
! 2469: my $latex_rendering = &Apache::lonxml::get_param('TeXwrap',
! 2470: $parstack,
! 2471: $safeeval,
! 2472: undef,0);
! 2473: &Apache::lonxml::debug("LaTeX rendering = $latex_rendering");
! 2474: if(!$latex_rendering) {
! 2475: $latex_rendering = "parbox";
! 2476: }
! 2477: &Apache::lonxml::debug("LaTeX rendering = $latex_rendering");
! 2478:
1.239 sakharuk 2479: my $oldSRC=$src;
2480: $oldSRC=~s/\.(gif|jpg|png)$/\.eps/;
1.122 albertel 2481: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
2482: #if original gif/jpg/png file exist do following:
1.192 sakharuk 2483: if (-e $src) {
1.197 sakharuk 2484: #what is the image size?
1.248 ! foxr 2485: my $width_param=&image_width($src,$scaling,$parstack,$safeeval);
! 2486: my $height_param=&image_height($src,$scaling,$parstack,$safeeval);
1.197 sakharuk 2487: my ($file,$path)=&file_path($src);
1.122 albertel 2488: my $newsrc = $src;
2489: $newsrc =~ s/\.(gif|jpg|png)$/.eps/i;
1.240 albertel 2490: &Apache::lonnet::repcopy($oldSRC);
1.122 albertel 2491: $file=~s/\.(gif|jpg|png)$/.eps/i;
2492: #where can we find the picture?
2493: if (-e $newsrc) {
2494: #eps counterpart for image exist
2495: if ($path) {
1.248 ! foxr 2496: $currentstring .= '\graphicspath{{'.$path.'}}'
! 2497: .'\includegraphics[width='.$width_param.' mm,height='.$height_param.'mm]{'.$file.'} ';
1.51 sakharuk 2498: }
1.122 albertel 2499: } else {
2500: #there is no eps counterpart for image - check for ps one
2501: $newsrc =~ s/\.eps$/\.ps/;
2502: if (-e $newsrc) {
2503: #ps counterpart for image exist
2504: $file =~ s/\.eps$/\.ps/;
2505: if ($path) {
1.245 albertel 2506: $currentstring .= '\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
1.122 albertel 2507: }
1.78 sakharuk 2508: } else {
1.195 sakharuk 2509: #care about eps dynamical generation
1.245 albertel 2510: $currentstring.=&eps_generation($src,$file,$width_param);
1.122 albertel 2511: }
2512: }
1.248 ! foxr 2513: # If there's an alignment specification we need to honor it here.
! 2514: # For the horizontal alignments, we will also honor the
! 2515: # value of the latex specfication. The default is parbox,
! 2516: # and that's used for illegal values too.
! 2517: #
! 2518: # Even though we set a default alignment value, the user
! 2519: # could have given us an illegal value. In that case we
! 2520: # just use the default alignment of bottom..
! 2521: if ($align eq "top") {
! 2522: $currentstring = '\raisebox{-'.$height_param.'mm}{'.$currentstring.'}';
! 2523: } elsif (($align eq "center") || ($align eq "middle")) { # Being kind
! 2524: my $offset = $height_param/2;
! 2525: $currentstring = '\raisebox{-'.$offset.'mm}{'.$currentstring.'}';
! 2526: } elsif ($align eq "left") {
! 2527: if ($latex_rendering eq "parpic") {
! 2528: $currentstring = '\parpic[l]{'.$currentstring.'}';
! 2529: } else { # parbox rendering
! 2530: $currentstring = '\newline'."\n".'\parbox{'.$width_param.'mm}{'.$currentstring.'}';
! 2531: }
! 2532: } elsif ($align eq "right") {
! 2533: if ($latex_rendering eq "parpic") {
! 2534: $currentstring = '\parpic[r]{'.$currentstring.'}';
! 2535: } else { # parbox rendering.
! 2536: $currentstring = '\parbox{'.$width_param.'mm}{\begin{flushright}'
! 2537: .$currentstring.'\end{flushright}} \newline'."\n";
! 2538: }
! 2539: } else { # Bottom is also default.
! 2540: # $currentstring = '\raisebox{'.$height_param.'mm}{'.$currentstring.'}';
! 2541: }
1.122 albertel 2542: } else {
2543: #original image file doesn't exist so check the alt attribute
2544: my $alt =
2545: &Apache::lonxml::get_param('alt',$parstack,$safeeval,undef,1);
2546: unless ($alt) {
2547: $alt=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
2548: }
2549:
2550: if ($alt) {
2551: $currentstring .= ' '.$alt.' ';
2552: } else {
2553: #<allow> tag will care about replication
1.59 sakharuk 2554: }
2555: }
1.186 albertel 2556: } elsif ($target eq 'edit') {
2557: $currentstring .=&Apache::edit::tag_start($target,$token);
2558: $currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70).
2559: &Apache::edit::browse('src',undef,'alt').' '.
2560: &Apache::edit::search('src',undef,'alt').'<br />';
2561: $currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'<br />';
2562: $currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5);
2563: $currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'<br />';
2564: $currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5);
2565: $currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5);
1.234 albertel 2566: $currentstring .=&Apache::edit::select_arg('Alignment:','align',
2567: ['','bottom','middle','top','left','right'],$token,5);
1.186 albertel 2568: $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
2569: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval);
2570: my $alt=&Apache::lonxml::get_param('alt',$parstack,$safeeval);
2571: my $width=&Apache::lonxml::get_param('width',$parstack,$safeeval);
2572: my $height=&Apache::lonxml::get_param('height',$parstack,$safeeval);
2573: $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
2574: if ($width) { $currentstring.=' width="'.$width.'" '; }
2575: if ($height) { $currentstring.=' height="'.$height.'" '; }
2576: $currentstring .= ' />';
2577: } elsif ($target eq 'modified') {
1.210 albertel 2578: my ($osrc,$owidth,$oheight)=
2579: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
2580: my $ctag=&Apache::edit::get_new_args($token,$parstack,
1.234 albertel 2581: $safeeval,'src','alt','align',
1.210 albertel 2582: 'TeXwidth','TeXheight',
2583: 'width','height');
2584: my ($nsrc,$nwidth,$nheight)=
2585: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
2586: my $loc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$nsrc);
2587: &image_replication($loc);
2588: my ($iwidth,$iheight);
2589: if (-e $loc) {
2590: my $image = Image::Magick->new;
2591: $image->Read($loc);
2592: ($iwidth, $iheight) = ($image->Get('width'),
2593: $image->Get('height'));
2594: }
2595: if ($osrc ne $nsrc || (!$nwidth && !$nheight)) {
2596: # changed image or no size specified,
2597: # if they didn't explicitly change the
2598: # width or height use the ones from the image
2599: if ($iwidth && $iheight) {
2600: if ($owidth == $nwidth || (!$nwidth && !$nheight)) {
2601: $token->[2]{'width'} = $iwidth;$ctag=1;
2602: }
2603: if ($oheight == $nheight || (!$nwidth && !$nheight)) {
2604: $token->[2]{'height'}=$iheight;$ctag=1;
1.186 albertel 2605: }
2606: }
2607: }
1.210 albertel 2608: my ($cwidth,$cheight)=($token->[2]{'width'},$token->[2]{'height'});
2609: # if we don't have a width or height
2610: if ($iwidth && $cwidth && !$cheight) {
2611: $token->[2]{'height'}=int(($cwidth/$iwidth)*$iheight);$ctag=1;
2612: }
2613: if ($iheight && $cheight && !$cwidth) {
2614: $token->[2]{'width'}=int(($cheight/$iheight)*$iwidth);$ctag=1;
2615: }
2616: if ($ctag) {$currentstring=&Apache::edit::rebuild_tag($token);}
1.122 albertel 2617: }
2618: return $currentstring;
2619: }
2620:
2621: sub end_img {
2622: my ($target,$token) = @_;
2623: my $currentstring = '';
2624: if ($target eq 'web') {
2625: $currentstring = $token->[2];
2626: } elsif ($target eq 'tex') {
2627: $currentstring = '';
2628: }
2629: return $currentstring;
2630: }
2631:
1.181 sakharuk 2632: #-- <applet> tag (end tag required)
1.122 albertel 2633: sub start_applet {
2634: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2635:
2636: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,undef,1);
2637: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$code;
2638:
2639: my $archive=&Apache::lonxml::get_param('archive',$parstack,$safeeval,
2640: undef,1);
2641: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$archive;
2642:
2643: my $currentstring = '';
2644: if ($target eq 'web') {
2645: if ($ENV{'browser.appletsuppress'} ne 'on') {
2646: $currentstring = $token->[4];
2647: } else {
2648: my $alttag= &Apache::lonxml::get_param('alt',$parstack,
2649: $safeeval,undef,1);
2650: unless ($alttag) {
2651: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
2652: $code);
1.44 sakharuk 2653: }
1.122 albertel 2654: $currentstring='[APPLET: '.$alttag.']';
1.1 sakharuk 2655: }
1.122 albertel 2656: } elsif ($target eq 'tex') {
1.177 albertel 2657: my $alttag= &Apache::lonxml::get_param('alt',$parstack,
2658: $safeeval,undef,1);
2659: unless ($alttag) {
2660: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,
2661: undef,1);
2662: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
2663: $code);
1.175 sakharuk 2664: }
1.177 albertel 2665: $currentstring.='\begin{center} \fbox{Java Applet: '.$alttag.
2666: '.}\end{center}';
1.122 albertel 2667: }
2668: return $currentstring;
2669: }
2670:
2671: sub end_applet {
2672: my ($target,$token) = @_;
2673: my $currentstring = '';
2674: if ($target eq 'web') {
2675: $currentstring = $token->[2];
2676: } elsif ($target eq 'tex') {
2677: }
2678: return $currentstring;
2679: }
2680:
1.181 sakharuk 2681: #-- <embed> tag (end tag optional/required)
1.122 albertel 2682: sub start_embed {
2683: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2684: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
2685: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
2686: my $currentstring = '';
2687: if ($target eq 'web') {
2688: if ($ENV{'browser.embedsuppress'} ne 'on') {
2689: $currentstring = $token->[4];
2690: } else {
2691: my $alttag=&Apache::lonxml::get_param
2692: ('alt',$parstack,$safeeval,undef,1);
2693: unless ($alttag) {
2694: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
1.42 albertel 2695: }
1.122 albertel 2696: $currentstring='[EMBED: '.$alttag.']';
1.10 www 2697: }
1.122 albertel 2698: } elsif ($target eq 'tex') {
2699: }
2700: return $currentstring;
2701: }
2702:
2703: sub end_embed {
2704: my ($target,$token) = @_;
2705: my $currentstring = '';
2706: if ($target eq 'web') {
2707: $currentstring = $token->[2];
1.175 sakharuk 2708: } elsif ($target eq 'tex') {
1.122 albertel 2709: }
2710: return $currentstring;
2711: }
2712:
1.181 sakharuk 2713: #-- <param> tag (end tag forbidden)
1.122 albertel 2714: sub start_param {
2715: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2716: if (&Apache::lonxml::get_param
2717: ('name',$parstack,$safeeval,undef,1)=~/^cabbase$/i) {
2718: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
2719: &Apache::lonxml::get_param('value',$parstack,$safeeval,undef,1);
2720: }
2721: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
2722: &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
2723: my $currentstring = '';
2724: if ($target eq 'web') {
2725: $currentstring = $token->[4];
2726: } elsif ($target eq 'tex') {
2727: }
2728: return $currentstring;
2729: }
2730:
2731: sub end_param {
2732: my ($target,$token) = @_;
2733: my $currentstring = '';
2734: if ($target eq 'web') {
2735: $currentstring = $token->[2];
2736: } elsif ($target eq 'tex') {
2737: }
2738: return $currentstring;
2739: }
2740:
2741: #-- <allow> tag
2742: sub start_allow {
2743: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2744: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
2745: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
1.138 www 2746: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
2747: &Apache::lonnet::clutter($src);
1.241 albertel 2748: if ($target eq 'tex') { &image_replication($src); }
1.122 albertel 2749: my $result;
2750: if ($target eq 'edit') {
2751: $result .=&Apache::edit::tag_start($target,$token);
2752: $result .=&Apache::edit::text_arg('File Spec:','src',$token,70);
2753: $result .=&Apache::edit::end_row();#.&Apache::edit::start_spanning_row();
2754: } elsif ($target eq 'modified') {
2755: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
2756: $safeeval,'src');
2757: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
2758: }
2759: return $result;
2760: }
2761:
2762: sub end_allow {
2763: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2764: if ( $target eq 'edit') { return (&Apache::edit::end_table()); }
2765: return '';
2766: }
1.119 www 2767:
1.181 sakharuk 2768: #-- Frames (end tag required)
2769: #-- <frameset>
1.122 albertel 2770: sub start_frameset {
2771: my ($target,$token) = @_;
2772: my $currentstring = '';
2773: if ($target eq 'web') {
1.180 albertel 2774: if (!$Apache::lonxml::registered &&
2775: $ENV{'request.state'} eq 'published') {
1.122 albertel 2776: $currentstring.='<head>'.
2777: &Apache::lonmenu::registerurl(undef,$target).'</head>';
1.10 www 2778: }
1.133 www 2779: my $onLoad='';
2780: foreach my $key (keys(%{$token->[2]})) {
2781: if ($key =~ /^onload$/i) {
2782: $onLoad.=$token->[2]->{$key}.';';
2783: delete($token->[2]->{$key});
2784: }
2785: }
2786: $token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad;
2787: my $onUnload='';
2788: foreach my $key (keys(%{$token->[2]})) {
2789: if ($key =~ /^onunload$/i) {
2790: $onUnload.=$token->[2]->{$key}.';';
2791: delete($token->[2]->{$key});
2792: }
2793: }
2794: $token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents().
2795: ';'.$onUnload;
2796:
2797: $currentstring .= '<'.$token->[1];
2798: foreach (keys %{$token->[2]}) {
2799: $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
2800: }
2801: $currentstring.='>';
1.122 albertel 2802: }
2803: return $currentstring;
2804: }
2805:
2806: sub end_frameset {
2807: my ($target,$token) = @_;
2808: my $currentstring = '';
2809: if ($target eq 'web') {
2810: $currentstring = $token->[2];
2811: }
2812: return $currentstring;
2813: }
1.162 sakharuk 2814:
1.181 sakharuk 2815: #-- <xmp> (end tag required)
1.162 sakharuk 2816: sub start_xmp {
2817: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2818: my $currentstring = '';
2819: if ($target eq 'web') {
2820: $currentstring .= $token->[4];
2821: } elsif ($target eq 'tex') {
2822: $currentstring .= '\begin{verbatim}';
2823: }
2824: return $currentstring;
2825: }
2826:
2827: sub end_xmp {
2828: my ($target,$token) = @_;
2829: my $currentstring = '';
2830: if ($target eq 'web') {
2831: $currentstring .= $token->[2];
2832: } elsif ($target eq 'tex') {
2833: $currentstring .= '\end{verbatim}';
2834: }
2835: return $currentstring;
2836: }
2837:
1.181 sakharuk 2838: #-- <pre> (end tag required)
1.122 albertel 2839: sub start_pre {
1.126 sakharuk 2840: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 2841: my $currentstring = '';
2842: if ($target eq 'web') {
2843: $currentstring .= $token->[4];
2844: } elsif ($target eq 'tex') {
1.136 sakharuk 2845: $currentstring .= '\begin{verbatim}';
1.122 albertel 2846: }
2847: return $currentstring;
2848: }
2849:
2850: sub end_pre {
2851: my ($target,$token) = @_;
2852: my $currentstring = '';
2853: if ($target eq 'web') {
2854: $currentstring .= $token->[2];
2855: } elsif ($target eq 'tex') {
1.136 sakharuk 2856: $currentstring .= '\end{verbatim}';
1.122 albertel 2857: }
2858: return $currentstring;
2859: }
2860:
2861: #-- <insert>
2862: sub start_insert {
2863: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2864: my $currentstring = '';
2865: if ($target eq 'web') {
2866: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
2867: $currentstring .= '<b>'.$display.'</b>';;
2868: }
2869: return $currentstring;
2870: }
2871:
2872: sub end_insert {
2873: my ($target,$token) = @_;
2874: my $currentstring = '';
2875: if ($target eq 'web') {
2876: $currentstring .= '';
2877: }
2878: return $currentstring;
2879: }
2880:
2881: #-- <externallink>
2882: sub start_externallink {
2883: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2884: my $currentstring = '';
2885: if ($target eq 'web') {
2886: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
2887: $currentstring .= '<b>'.$display.'</b>';;
2888: }
2889: return $currentstring;
2890: }
2891:
2892: sub end_externallink {
2893: my ($target,$token) = @_;
2894: my $currentstring = '';
2895: if ($target eq 'web') {
2896: $currentstring .= '';
2897: }
2898: return $currentstring;
2899: }
2900:
2901: #-- <blankspace heigth="">
2902: sub start_blankspace {
2903: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2904: my $currentstring = '';
2905: if ($target eq 'tex') {
2906: my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval,undef,1);
2907: $currentstring .= '\vskip '.$howmuch.' ';
2908: }
2909: return $currentstring;
2910: }
2911:
2912: sub end_blankspace {
2913: my ($target,$token) = @_;
2914: my $currentstring = '';
2915: if ($target eq 'tex') {
2916: $currentstring .= '';
2917: }
2918: return $currentstring;
2919: }
2920:
1.181 sakharuk 2921: #-- <abbr> tag (end tag required)
1.122 albertel 2922: sub start_abbr {
2923: my ($target,$token) = @_;
2924: my $currentstring = '';
2925: if ($target eq 'web') {
2926: $currentstring = $token->[4];
2927: }
2928: return $currentstring;
2929: }
2930:
2931: sub end_abbr {
2932: my ($target,$token) = @_;
2933: my $currentstring = '';
2934: if ($target eq 'web') {
2935: $currentstring = $token->[2];
2936: }
2937: return $currentstring;
2938: }
2939:
1.181 sakharuk 2940: #-- <acronym> tag (end tag required)
1.122 albertel 2941: sub start_acronym {
2942: my ($target,$token) = @_;
2943: my $currentstring = '';
2944: if ($target eq 'web') {
2945: $currentstring = $token->[4];
2946: }
2947: return $currentstring;
2948: }
2949:
2950: sub end_acronym {
2951: my ($target,$token) = @_;
2952: my $currentstring = '';
2953: if ($target eq 'web') {
2954: $currentstring = $token->[2];
2955: }
2956: return $currentstring;
2957: }
2958:
1.181 sakharuk 2959: #-- <area> tag (end tag forbidden)
1.122 albertel 2960: sub start_area {
2961: my ($target,$token) = @_;
2962: my $currentstring = '';
2963: if ($target eq 'web') {
2964: $currentstring = $token->[4];
2965: }
2966: return $currentstring;
2967: }
2968:
2969: sub end_area {
2970: my ($target,$token) = @_;
2971: my $currentstring = '';
2972: if ($target eq 'web') {
2973: $currentstring = $token->[2];
2974: }
2975: return $currentstring;
2976: }
2977:
1.181 sakharuk 2978: #-- <base> tag (end tag forbidden)
1.122 albertel 2979: sub start_base {
2980: my ($target,$token) = @_;
2981: my $currentstring = '';
2982: if ($target eq 'web') {
2983: $currentstring = $token->[4];
1.161 sakharuk 2984: }
1.122 albertel 2985: return $currentstring;
2986: }
2987:
2988: sub end_base {
2989: my ($target,$token) = @_;
2990: my $currentstring = '';
2991: if ($target eq 'web') {
2992: $currentstring = $token->[2];
2993: }
2994: return $currentstring;
2995: }
2996:
1.181 sakharuk 2997: #-- <bdo> tag (end tag required)
1.122 albertel 2998: sub start_bdo {
2999: my ($target,$token) = @_;
3000: my $currentstring = '';
3001: if ($target eq 'web') {
3002: $currentstring = $token->[4];
3003: }
3004: return $currentstring;
3005: }
3006:
3007: sub end_bdo {
3008: my ($target,$token) = @_;
3009: my $currentstring = '';
3010: if ($target eq 'web') {
3011: $currentstring = $token->[2];
3012: }
3013: return $currentstring;
3014: }
3015:
1.181 sakharuk 3016: #-- <bgsound> tag (end tag optional)
1.122 albertel 3017: sub start_bgsound {
3018: my ($target,$token) = @_;
3019: my $currentstring = '';
3020: if ($target eq 'web') {
3021: $currentstring = $token->[4];
3022: }
3023: return $currentstring;
3024: }
3025:
3026: sub end_bgsound {
3027: my ($target,$token) = @_;
3028: my $currentstring = '';
3029: if ($target eq 'web') {
3030: $currentstring = $token->[2];
3031: }
3032: return $currentstring;
3033: }
3034:
1.181 sakharuk 3035: #-- <blink> tag (end tag required)
1.122 albertel 3036: sub start_blink {
3037: my ($target,$token) = @_;
3038: my $currentstring = '';
3039: if ($target eq 'web') {
3040: $currentstring = $token->[4];
3041: }
3042: return $currentstring;
3043: }
3044:
3045: sub end_blink {
3046: my ($target,$token) = @_;
3047: my $currentstring = '';
3048: if ($target eq 'web') {
3049: $currentstring = $token->[2];
3050: }
3051: return $currentstring;
3052: }
3053:
1.181 sakharuk 3054: #-- <blockquote> tag (end tag required)
1.122 albertel 3055: sub start_blockquote {
3056: my ($target,$token) = @_;
3057: my $currentstring = '';
3058: if ($target eq 'web') {
3059: $currentstring = $token->[4];
3060: }
3061: return $currentstring;
3062: }
3063:
3064: sub end_blockquote {
3065: my ($target,$token) = @_;
3066: my $currentstring = '';
3067: if ($target eq 'web') {
3068: $currentstring = $token->[2];
3069: }
3070: return $currentstring;
3071: }
3072:
1.181 sakharuk 3073: #-- <button> tag (end tag required)
1.122 albertel 3074: sub start_button {
3075: my ($target,$token) = @_;
3076: my $currentstring = '';
3077: if ($target eq 'web') {
3078: $currentstring = $token->[4];
3079: }
3080: return $currentstring;
3081: }
3082:
3083: sub end_button {
3084: my ($target,$token) = @_;
3085: my $currentstring = '';
3086: if ($target eq 'web') {
3087: $currentstring = $token->[2];
3088: }
3089: return $currentstring;
3090: }
3091:
1.181 sakharuk 3092: #-- <caption> tag (end tag required)
1.122 albertel 3093: sub start_caption {
3094: my ($target,$token) = @_;
3095: my $currentstring = '';
3096: if ($target eq 'web') {
3097: $currentstring = $token->[4];
3098: }
3099: return $currentstring;
3100: }
3101:
3102: sub end_caption {
3103: my ($target,$token) = @_;
3104: my $currentstring = '';
3105: if ($target eq 'web') {
3106: $currentstring = $token->[2];
3107: }
3108: return $currentstring;
3109: }
3110:
1.181 sakharuk 3111: #-- <col> tag (end tag forbdden)
1.122 albertel 3112: sub start_col {
3113: my ($target,$token) = @_;
3114: my $currentstring = '';
3115: if ($target eq 'web') {
3116: $currentstring = $token->[4];
3117: }
3118: return $currentstring;
3119: }
3120:
3121: sub end_col {
3122: my ($target,$token) = @_;
3123: my $currentstring = '';
3124: if ($target eq 'web') {
3125: $currentstring = $token->[2];
3126: }
3127: return $currentstring;
3128: }
3129:
1.181 sakharuk 3130: #-- <colgroup> tag (end tag optional)
1.122 albertel 3131: sub start_colgroup {
3132: my ($target,$token) = @_;
3133: my $currentstring = '';
3134: if ($target eq 'web') {
3135: $currentstring = $token->[4];
3136: }
3137: return $currentstring;
3138: }
3139:
3140: sub end_colgroup {
3141: my ($target,$token) = @_;
3142: my $currentstring = '';
3143: if ($target eq 'web') {
3144: $currentstring = $token->[2];
3145: }
3146: return $currentstring;
3147: }
3148:
1.181 sakharuk 3149: #-- <del> tag (end tag required)
1.122 albertel 3150: sub start_del {
3151: my ($target,$token) = @_;
3152: my $currentstring = '';
3153: if ($target eq 'web') {
3154: $currentstring = $token->[4];
3155: }
3156: return $currentstring;
3157: }
3158:
3159: sub end_del {
3160: my ($target,$token) = @_;
3161: my $currentstring = '';
3162: if ($target eq 'web') {
3163: $currentstring = $token->[2];
3164: }
3165: return $currentstring;
3166: }
3167:
1.181 sakharuk 3168: #-- <fieldset> tag (end tag required)
1.122 albertel 3169: sub start_fieldset {
3170: my ($target,$token) = @_;
3171: my $currentstring = '';
3172: if ($target eq 'web') {
3173: $currentstring = $token->[4];
3174: }
3175: return $currentstring;
3176: }
3177:
3178: sub end_fieldset {
3179: my ($target,$token) = @_;
3180: my $currentstring = '';
3181: if ($target eq 'web') {
3182: $currentstring = $token->[2];
3183: }
3184: return $currentstring;
3185: }
3186:
1.181 sakharuk 3187: #-- <frame> tag (end tag forbidden)
1.122 albertel 3188: sub start_frame {
3189: my ($target,$token) = @_;
3190: my $currentstring = '';
3191: if ($target eq 'web') {
3192: $currentstring = $token->[4];
3193: }
3194: return $currentstring;
3195: }
3196:
3197: sub end_frame {
3198: my ($target,$token) = @_;
3199: my $currentstring = '';
3200: if ($target eq 'web') {
3201: $currentstring = $token->[2];
3202: }
3203: return $currentstring;
3204: }
3205:
1.181 sakharuk 3206: #-- <iframe> tag (end tag required)
1.122 albertel 3207: sub start_iframe {
3208: my ($target,$token) = @_;
3209: my $currentstring = '';
3210: if ($target eq 'web') {
3211: $currentstring = $token->[4];
3212: }
3213: return $currentstring;
3214: }
3215:
3216: sub end_iframe {
3217: my ($target,$token) = @_;
3218: my $currentstring = '';
3219: if ($target eq 'web') {
3220: $currentstring = $token->[2];
3221: }
3222: return $currentstring;
3223: }
3224:
1.181 sakharuk 3225: #-- <ins> tag (end tag required)
1.122 albertel 3226: sub start_ins {
3227: my ($target,$token) = @_;
3228: my $currentstring = '';
3229: if ($target eq 'web') {
3230: $currentstring = $token->[4];
3231: }
3232: return $currentstring;
3233: }
3234:
3235: sub end_ins {
3236: my ($target,$token) = @_;
3237: my $currentstring = '';
3238: if ($target eq 'web') {
3239: $currentstring = $token->[2];
3240: }
3241: return $currentstring;
3242: }
3243:
1.181 sakharuk 3244: #-- <isindex> tag (end tag forbidden)
1.122 albertel 3245: sub start_isindex {
3246: my ($target,$token) = @_;
3247: my $currentstring = '';
3248: if ($target eq 'web') {
3249: $currentstring = $token->[4];
3250: }
3251: return $currentstring;
3252: }
3253:
3254: sub end_isindex {
3255: my ($target,$token) = @_;
3256: my $currentstring = '';
3257: if ($target eq 'web') {
3258: $currentstring = $token->[2];
3259: }
3260: return $currentstring;
3261: }
3262:
1.181 sakharuk 3263: #-- <keygen> tag (end tag forbidden)
1.122 albertel 3264: sub start_keygen {
3265: my ($target,$token) = @_;
3266: my $currentstring = '';
3267: if ($target eq 'web') {
3268: $currentstring = $token->[4];
3269: }
3270: return $currentstring;
3271: }
3272:
3273: sub end_keygen {
3274: my ($target,$token) = @_;
3275: my $currentstring = '';
3276: if ($target eq 'web') {
3277: $currentstring = $token->[2];
3278: }
3279: return $currentstring;
3280: }
3281:
3282: #-- <label> tag
3283: sub start_label {
3284: my ($target,$token) = @_;
3285: my $currentstring = '';
3286: if ($target eq 'web') {
3287: $currentstring = $token->[4];
3288: }
3289: return $currentstring;
3290: }
3291:
3292: sub end_label {
3293: my ($target,$token) = @_;
3294: my $currentstring = '';
3295: if ($target eq 'web') {
3296: $currentstring = $token->[2];
3297: }
3298: return $currentstring;
3299: }
3300:
1.181 sakharuk 3301: #-- <layer> tag (end tag required)
1.122 albertel 3302: sub start_layer {
3303: my ($target,$token) = @_;
3304: my $currentstring = '';
3305: if ($target eq 'web') {
3306: $currentstring = $token->[4];
3307: }
3308: return $currentstring;
3309: }
3310:
3311: sub end_layer {
3312: my ($target,$token) = @_;
3313: my $currentstring = '';
3314: if ($target eq 'web') {
3315: $currentstring = $token->[2];
3316: }
3317: return $currentstring;
3318: }
3319:
1.181 sakharuk 3320: #-- <legend> tag (end tag required)
1.122 albertel 3321: sub start_legend {
3322: my ($target,$token) = @_;
3323: my $currentstring = '';
3324: if ($target eq 'web') {
3325: $currentstring = $token->[4];
3326: }
3327: return $currentstring;
3328: }
3329:
3330: sub end_legend {
3331: my ($target,$token) = @_;
3332: my $currentstring = '';
3333: if ($target eq 'web') {
3334: $currentstring = $token->[2];
3335: }
3336: return $currentstring;
3337: }
3338:
1.181 sakharuk 3339: #-- <link> tag (end tag forbidden)
1.122 albertel 3340: sub start_link {
3341: my ($target,$token) = @_;
3342: my $currentstring = '';
3343: if ($target eq 'web') {
3344: $currentstring = $token->[4];
3345: }
3346: return $currentstring;
3347: }
3348:
3349: sub end_link {
3350: my ($target,$token) = @_;
3351: my $currentstring = '';
3352: if ($target eq 'web') {
3353: $currentstring = $token->[2];
3354: }
3355: return $currentstring;
3356: }
3357:
1.181 sakharuk 3358: #-- <marquee> tag (end tag optional)
1.122 albertel 3359: sub start_marquee {
3360: my ($target,$token) = @_;
3361: my $currentstring = '';
3362: if ($target eq 'web') {
3363: $currentstring = $token->[4];
3364: }
3365: return $currentstring;
3366: }
3367:
3368: sub end_marquee {
3369: my ($target,$token) = @_;
3370: my $currentstring = '';
3371: if ($target eq 'web') {
3372: $currentstring = $token->[2];
3373: }
3374: return $currentstring;
3375: }
3376:
1.179 sakharuk 3377: #-- <multicol> tag (end tag required)
3378: sub start_multicol {
1.122 albertel 3379: my ($target,$token) = @_;
3380: my $currentstring = '';
3381: if ($target eq 'web') {
3382: $currentstring = $token->[4];
3383: }
3384: return $currentstring;
3385: }
3386:
1.179 sakharuk 3387: sub end_multicol {
1.122 albertel 3388: my ($target,$token) = @_;
3389: my $currentstring = '';
3390: if ($target eq 'web') {
3391: $currentstring = $token->[2];
3392: }
3393: return $currentstring;
3394: }
3395:
1.179 sakharuk 3396: #-- <nobr> tag (end tag required)
1.122 albertel 3397: sub start_nobr {
3398: my ($target,$token) = @_;
3399: my $currentstring = '';
3400: if ($target eq 'web') {
3401: $currentstring = $token->[4];
1.179 sakharuk 3402: } elsif ($target eq 'tex') {
3403: $currentstring='\mbox{';
3404: }
1.122 albertel 3405: return $currentstring;
3406: }
3407:
3408: sub end_nobr {
3409: my ($target,$token) = @_;
3410: my $currentstring = '';
3411: if ($target eq 'web') {
3412: $currentstring = $token->[2];
1.179 sakharuk 3413: } elsif ($target eq 'tex') {
3414: $currentstring='}';
3415: }
1.122 albertel 3416: return $currentstring;
3417: }
3418:
1.179 sakharuk 3419: #-- <noembed> tag (end tag required)
1.122 albertel 3420: sub start_noembed {
3421: my ($target,$token) = @_;
3422: my $currentstring = '';
3423: if ($target eq 'web') {
3424: $currentstring = $token->[4];
3425: }
3426: return $currentstring;
3427: }
3428:
3429: sub end_noembed {
3430: my ($target,$token) = @_;
3431: my $currentstring = '';
3432: if ($target eq 'web') {
3433: $currentstring = $token->[2];
3434: }
3435: return $currentstring;
3436: }
3437:
1.179 sakharuk 3438: #-- <noframes> tag (end tag required)
1.122 albertel 3439: sub start_noframes {
3440: my ($target,$token) = @_;
3441: my $currentstring = '';
3442: if ($target eq 'web') {
3443: $currentstring = $token->[4];
3444: }
3445: return $currentstring;
3446: }
3447:
3448: sub end_noframes {
3449: my ($target,$token) = @_;
3450: my $currentstring = '';
3451: if ($target eq 'web') {
3452: $currentstring = $token->[2];
3453: }
3454: return $currentstring;
3455: }
3456:
1.179 sakharuk 3457: #-- <nolayer> tag (end tag required)
1.122 albertel 3458: sub start_nolayer {
3459: my ($target,$token) = @_;
3460: my $currentstring = '';
3461: if ($target eq 'web') {
3462: $currentstring = $token->[4];
3463: }
3464: return $currentstring;
3465: }
3466:
3467: sub end_nolayer {
3468: my ($target,$token) = @_;
3469: my $currentstring = '';
3470: if ($target eq 'web') {
3471: $currentstring = $token->[2];
3472: }
3473: return $currentstring;
3474: }
3475:
1.179 sakharuk 3476: #-- <noscript> tag (end tag required)
1.122 albertel 3477: sub start_noscript {
3478: my ($target,$token) = @_;
3479: my $currentstring = '';
3480: if ($target eq 'web') {
3481: $currentstring = $token->[4];
3482: }
3483: return $currentstring;
3484: }
3485:
3486: sub end_noscript {
3487: my ($target,$token) = @_;
3488: my $currentstring = '';
3489: if ($target eq 'web') {
3490: $currentstring = $token->[2];
3491: }
3492: return $currentstring;
3493: }
3494:
1.179 sakharuk 3495: #-- <object> tag (end tag required)
1.122 albertel 3496: sub start_object {
3497: my ($target,$token) = @_;
3498: my $currentstring = '';
3499: if ($target eq 'web') {
3500: $currentstring = $token->[4];
3501: }
3502: return $currentstring;
3503: }
3504:
3505: sub end_object {
3506: my ($target,$token) = @_;
3507: my $currentstring = '';
3508: if ($target eq 'web') {
3509: $currentstring = $token->[2];
3510: }
3511: return $currentstring;
3512: }
3513:
1.179 sakharuk 3514: #-- <optgroup> tag (end tag required)
1.122 albertel 3515: sub start_optgroup {
3516: my ($target,$token) = @_;
3517: my $currentstring = '';
3518: if ($target eq 'web') {
3519: $currentstring = $token->[4];
3520: }
3521: return $currentstring;
3522: }
3523:
3524: sub end_optgroup {
3525: my ($target,$token) = @_;
3526: my $currentstring = '';
3527: if ($target eq 'web') {
3528: $currentstring = $token->[2];
3529: }
3530: return $currentstring;
3531: }
3532:
1.179 sakharuk 3533: #-- <samp> tag (end tag required)
1.122 albertel 3534: sub start_samp {
3535: my ($target,$token) = @_;
3536: my $currentstring = '';
3537: if ($target eq 'web') {
3538: $currentstring = $token->[4];
1.179 sakharuk 3539: } elsif ($target eq 'tex') {
3540: $currentstring='\texttt{';
3541: }
1.122 albertel 3542: return $currentstring;
3543: }
3544:
3545: sub end_samp {
3546: my ($target,$token) = @_;
3547: my $currentstring = '';
3548: if ($target eq 'web') {
3549: $currentstring = $token->[2];
1.179 sakharuk 3550: } elsif ($target eq 'tex') {
3551: $currentstring='}';
3552: }
1.122 albertel 3553: return $currentstring;
3554: }
3555:
3556: #-- <server> tag
3557: sub start_server {
3558: my ($target,$token) = @_;
3559: my $currentstring = '';
3560: if ($target eq 'web') {
3561: $currentstring = $token->[4];
3562: }
3563: return $currentstring;
3564: }
3565:
3566: sub end_server {
3567: my ($target,$token) = @_;
3568: my $currentstring = '';
3569: if ($target eq 'web') {
3570: $currentstring = $token->[2];
3571: }
3572: return $currentstring;
3573: }
3574:
1.179 sakharuk 3575: #-- <spacer> tag (end tag forbidden)
1.122 albertel 3576: sub start_spacer {
3577: my ($target,$token) = @_;
3578: my $currentstring = '';
3579: if ($target eq 'web') {
3580: $currentstring = $token->[4];
3581: }
3582: return $currentstring;
3583: }
3584:
3585: sub end_spacer {
3586: my ($target,$token) = @_;
3587: my $currentstring = '';
3588: if ($target eq 'web') {
3589: $currentstring = $token->[2];
3590: }
3591: return $currentstring;
3592: }
3593:
1.179 sakharuk 3594: #-- <span> tag (end tag required)
1.122 albertel 3595: sub start_span {
3596: my ($target,$token) = @_;
3597: my $currentstring = '';
3598: if ($target eq 'web') {
3599: $currentstring = $token->[4];
3600: }
3601: return $currentstring;
3602: }
3603:
3604: sub end_span {
3605: my ($target,$token) = @_;
3606: my $currentstring = '';
3607: if ($target eq 'web') {
3608: $currentstring = $token->[2];
3609: }
3610: return $currentstring;
3611: }
3612:
1.179 sakharuk 3613: #-- <tbody> tag (end tag optional)
1.122 albertel 3614: sub start_tbody {
3615: my ($target,$token) = @_;
3616: my $currentstring = '';
3617: if ($target eq 'web') {
3618: $currentstring = $token->[4];
3619: }
3620: return $currentstring;
3621: }
3622:
3623: sub end_tbody {
3624: my ($target,$token) = @_;
3625: my $currentstring = '';
3626: if ($target eq 'web') {
3627: $currentstring = $token->[2];
3628: }
3629: return $currentstring;
3630: }
3631:
1.166 sakharuk 3632: #-- <tfoot> tag (end tag optional)
1.122 albertel 3633: sub start_tfoot {
3634: my ($target,$token) = @_;
3635: my $currentstring = '';
3636: if ($target eq 'web') {
3637: $currentstring = $token->[4];
3638: }
3639: return $currentstring;
3640: }
3641:
3642: sub end_tfoot {
3643: my ($target,$token) = @_;
3644: my $currentstring = '';
3645: if ($target eq 'web') {
3646: $currentstring = $token->[2];
3647: }
3648: return $currentstring;
3649: }
3650:
1.166 sakharuk 3651: #-- <thead> tag (end tag optional)
1.122 albertel 3652: sub start_thead {
3653: my ($target,$token) = @_;
3654: my $currentstring = '';
3655: if ($target eq 'web') {
3656: $currentstring = $token->[4];
3657: }
3658: return $currentstring;
3659: }
1.10 www 3660:
1.122 albertel 3661: sub end_thead {
3662: my ($target,$token) = @_;
3663: my $currentstring = '';
3664: if ($target eq 'web') {
3665: $currentstring = $token->[2];
3666: }
3667: return $currentstring;
3668: }
1.119 www 3669:
1.122 albertel 3670: #-- <var> tag
3671: sub start_var {
1.44 sakharuk 3672: my ($target,$token) = @_;
3673: my $currentstring = '';
3674: if ($target eq 'web') {
1.122 albertel 3675: $currentstring = $token->[4];
1.163 sakharuk 3676: } elsif ($target eq 'tex') {
3677: $currentstring = '\textit{';
3678: }
1.44 sakharuk 3679: return $currentstring;
3680: }
1.10 www 3681:
1.122 albertel 3682: sub end_var {
3683: my ($target,$token) = @_;
1.44 sakharuk 3684: my $currentstring = '';
3685: if ($target eq 'web') {
1.163 sakharuk 3686: $currentstring = $token->[2];
3687: } elsif ($target eq 'tex') {
3688: $currentstring = '}';
1.44 sakharuk 3689: }
3690: return $currentstring;
3691: }
1.119 www 3692:
1.163 sakharuk 3693: #-- <wbr> tag (end tag forbidden)
1.122 albertel 3694: sub start_wbr {
3695: my ($target,$token) = @_;
3696: my $currentstring = '';
3697: if ($target eq 'web') {
3698: $currentstring = $token->[4];
3699: }
3700: return $currentstring;
1.98 albertel 3701: }
3702:
1.122 albertel 3703: sub end_wbr {
3704: my ($target,$token) = @_;
3705: my $currentstring = '';
3706: if ($target eq 'web') {
3707: $currentstring = $token->[2];
3708: }
3709: return $currentstring;
1.98 albertel 3710: }
1.134 sakharuk 3711:
3712: #-- <hideweboutput> tag
3713: sub start_hideweboutput {
3714: my ($target,$token) = @_;
3715: if ($target eq 'web') {
3716: &Apache::lonxml::startredirection();
3717: }
3718: return '';
3719: }
3720:
3721: sub end_hideweboutput {
3722: my ($target,$token) = @_;
3723: my $currentstring = '';
3724: if ($target eq 'web') {
3725: $currentstring = &Apache::lonxml::endredirection();
3726: }
3727: return '';
3728: }
3729:
1.94 sakharuk 3730:
3731: sub image_replication {
3732: my $src = shift;
1.187 albertel 3733: if (not -e $src) { &Apache::lonnet::repcopy($src); }
3734: #replicates eps or ps
3735: my $epssrc = my $pssrc = $src;
3736: $epssrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i;
3737: $pssrc =~ s/\.(gif|jpg|jpeg|png)$/.ps/i;
3738: if (not -e $epssrc && not -e $pssrc) {
3739: my $result=&Apache::lonnet::repcopy($epssrc);
3740: if ($result ne OK) { &Apache::lonnet::repcopy($pssrc); }
1.94 sakharuk 3741: }
3742: return '';
1.195 sakharuk 3743: }
3744:
1.197 sakharuk 3745: sub image_size {
3746: my ($src,$scaling,$parstack,$safeeval)=@_;
3747: #size of image from gif/jpg/jpeg/png
3748: my $image = Image::Magick->new;
3749: my $current_figure = $image->Read($src);
3750: my $width_param = $image->Get('width') * $scaling;;
3751: my $height_param = $image->Get('height') * $scaling;;
3752: undef $image;
3753: #do we have any specified LaTeX size of the picture?
3754: my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval);
3755: my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval);
3756: #do we have any specified web size of the picture?
3757: my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval,
3758: undef,1);
3759: if ($TeXwidth ne '') {
3760: if ($TeXwidth=~/(\d+)\s*\%/) {
3761: $width_param = $1*$ENV{'form.textwidth'}/100;
3762: } else {
3763: $width_param = $TeXwidth;
3764: }
3765: } elsif ($TeXheight ne '') {
1.248 ! foxr 3766: $height_param = $TeXheight;
! 3767: $width_param = $TeXheight/$height_param*$width_param;
1.197 sakharuk 3768: } elsif ($width ne '') {
3769: $width_param = $width*$scaling;
3770: }
3771: if ($width_param > $ENV{'form.textwidth'}) {$width_param =0.95*$ENV{'form.textwidth'}}
1.248 ! foxr 3772: return ($height_param, $width_param);
! 3773: }
! 3774:
! 3775: sub image_width {
! 3776: my ($height, $width) = &image_size(@_);
! 3777: return $width;
! 3778: }
! 3779: # Not yet 100% sure this is correct in all circumstances..
! 3780: # due to my uncertainty about mods to image_size.
! 3781: #
! 3782: sub image_height {
! 3783: my ($height, $width) = &image_size(@_);
! 3784: return $height;
1.197 sakharuk 3785: }
3786:
1.195 sakharuk 3787: sub eps_generation {
3788: my ($src,$file,$width_param) = @_;
3789: my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat";
3790: my $temp_file = Apache::File->new('>>'.$filename);
3791: print $temp_file "$src\n";
3792: my $newsrc = $src;
3793: $newsrc =~ s/(\.gif|\.jpg|\.jpeg)$/\.eps/i;
3794: $newsrc=~s/\/home\/httpd\/html\/res//;
3795: $newsrc=~s/\/home\/([^\/]*)\/public_html\//\/$1\//;
3796: $newsrc=~s/\/\.\//\//;
3797: $newsrc=~s/\/([^\/]+)\.(ps|eps)/\//;
1.213 sakharuk 3798: if ($newsrc=~/\/home\/httpd\/lonUsers\//) {
3799: $newsrc=~s/\/home\/httpd\/lonUsers//;
3800: $newsrc=~s/\/([^\/]+)\/(\w)\/(\w)\/(\w)\//\/$1\//;
3801: }
1.239 sakharuk 3802: if ($newsrc=~/\/userfiles\//) {
3803: return ' \graphicspath{{'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
3804: } else {
3805: return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
3806: }
1.197 sakharuk 3807: }
3808:
3809: sub file_path {
3810: my $src=shift;
3811: my ($file,$path);
3812: if ($src =~ m!(.*)/([^/]*)$!) {
3813: $file = $2;
3814: $path = $1.'/';
3815: }
3816: return $file,$path;
1.126 sakharuk 3817: }
3818:
3819: sub recalc {
3820: my $argument = shift;
3821: if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}
1.132 sakharuk 3822: $argument=~/\s*(\d+\.?\d*)\s*(mm|cm|in|pc|pt)/;
1.126 sakharuk 3823: my $value=$1;
3824: my $units=$2;
3825: if ($units eq 'cm') {
3826: $value*=10;
3827: } elsif ($units eq 'in') {
3828: $value*=25.4;
3829: } elsif ($units eq 'pc') {
3830: $value*=(25.4*12/72.27);
3831: } elsif ($units eq 'pt') {
3832: $value*=(25.4/72.27);
3833: }
3834: return $value.' mm';
1.94 sakharuk 3835: }
1.184 sakharuk 3836:
3837: sub LATEX_length {
3838: my $garbage=shift;
1.206 sakharuk 3839: $garbage=~s/^\s+$//;
3840: $garbage=~s/^\s+(\S.*)/$1/;#space before
3841: $garbage=~s/(.*\S)\s+$/$1/;#space after
3842: $garbage=~s/(\s)+/$1/;#only one space
3843: $garbage=~s/(\\begin{([^\}]+)}|\\end{([^\}]+)})//g;#remove LaTeX \begin{...} and \end{...}
3844: $garbage=~s/(\$\_\{|\$\_|\$\^{|\$\^|\}\$)//g;#remove $_{,$_,$^{,$^,}$
3845: $garbage=~s/([^\\])\$/$1/g;#$
3846: $garbage=~s/(\\ensuremath\{\_\{|\\ensuremath\{\_|\\ensuremath\{\^{|\\ensuremath\{\^|\})//g;#remove \ensuremath{...}
3847: $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 3848: $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;
3849: $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;
3850: $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 3851: $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;
3852: $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;
3853: $garbage=~s/(\\hat{([^}]+)}|\\check{([^}]+)}|\\dot{([^}]+)}|\\breve{([^}]+)}|\\acute{([^}]+)}|\\ddot{([^}]+)}|\\grave{([^}]+)}|\\tilde{([^}]+)}|\\mathring{([^}]+)}|\\bar{([^}]+)}|\\vec{([^}]+)})/$1/g;
3854: #remove some other LaTeX command
3855: $garbage=~s|\\(\w+)\\|\\|g;
3856: $garbage=~s|\\(\w+)(\s*)|$2|g;
3857: $garbage=~s|\+|11|g;
1.184 sakharuk 3858: my $value=length($garbage);
3859: return $value;
3860: }
3861:
3862:
3863:
1.94 sakharuk 3864:
1.1 sakharuk 3865: 1;
3866: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>