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