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