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