Annotation of loncom/xml/londefdef.pm, revision 1.336
1.1 sakharuk 1: # The LearningOnline Network with CAPA
2: # Tags Default Definition Module
3: #
1.336 ! foxr 4: # $Id: londefdef.pm,v 1.335 2006/09/02 18:49:37 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')) {
1.336 ! foxr 1217: $signal = 1;
1.227 sakharuk 1218: }
1219: }
1.334 albertel 1220: if ($signal eq 1) {
1.219 sakharuk 1221: $currentstring .= ' \vskip 0 mm ';
1222: } elsif ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') {
1223: $currentstring .= '\strut \\\\ \strut ';
1.1 sakharuk 1224: }
1.144 sakharuk 1225: }
1.122 albertel 1226: return $currentstring;
1227: }
1228:
1229: sub end_br {
1230: my ($target,$token) = @_;
1231: my $currentstring = '';
1.325 albertel 1232: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1233: $currentstring .= $token->[2];
1234: }
1235: return $currentstring;
1236: }
1237:
1.181 sakharuk 1238: #-- <big> tag (end tag required)
1.122 albertel 1239: sub start_big {
1240: my ($target,$token) = @_;
1241: my $currentstring = '';
1.325 albertel 1242: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1243: $currentstring .= $token->[4];
1244: } elsif ($target eq 'tex') {
1.137 sakharuk 1245: $currentstring .= '{\large ';
1.144 sakharuk 1246: }
1.122 albertel 1247: return $currentstring;
1248: }
1249:
1250: sub end_big {
1251: my ($target,$token) = @_;
1252: my $currentstring = '';
1.325 albertel 1253: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1254: $currentstring .= $token->[2];
1255: } elsif ($target eq 'tex') {
1256: $currentstring .= '}';
1257: }
1258: return $currentstring;
1259: }
1260:
1.181 sakharuk 1261: #-- <small> tag (end tag required)
1.122 albertel 1262: sub start_small {
1263: my ($target,$token) = @_;
1264: my $currentstring = '';
1.325 albertel 1265: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1266: $currentstring .= $token->[4];
1267: } elsif ($target eq 'tex') {
1268: $currentstring .= '{\footnotesize ';
1.144 sakharuk 1269: }
1.122 albertel 1270: return $currentstring;
1271: }
1272:
1273: sub end_small {
1274: my ($target,$token) = @_;
1275: my $currentstring = '';
1.325 albertel 1276: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1277: $currentstring .= $token->[2];
1278: } elsif ($target eq 'tex') {
1279: $currentstring .= '}';
1280: }
1281: return $currentstring;
1282: }
1283:
1.181 sakharuk 1284: #-- <basefont> tag (end tag forbidden)
1.122 albertel 1285: sub start_basefont {
1.126 sakharuk 1286: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.122 albertel 1287: my $currentstring = '';
1.325 albertel 1288: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1289: $currentstring = $token->[4];
1.126 sakharuk 1290: } elsif ($target eq 'tex') {
1291: my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1292: if (defined $basesize) {
1293: $currentstring = '{\\'.$basesize.' ';
1294: }
1295: }
1.122 albertel 1296: return $currentstring;
1297: }
1298:
1299: sub end_basefont {
1.126 sakharuk 1300: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1301: my $currentstring = '';
1.325 albertel 1302: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1303: $currentstring = $token->[4];
1.126 sakharuk 1304: } elsif ($target eq 'tex') {
1305: my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1306: if (defined $basesize) {
1307: $currentstring = '}';
1308: }
1309: }
1.122 albertel 1310: return $currentstring;
1311: }
1312:
1.181 sakharuk 1313: #-- <font> tag (end tag required)
1.122 albertel 1314: sub start_font {
1315: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1316: my $currentstring = '';
1.325 albertel 1317: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1318: my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
1.204 albertel 1319: if ($face!~/symbol/i) {
1.267 albertel 1320: if (($env{'browser.fontenhance'} eq 'on') ||
1321: ($env{'browser.blackwhite'} eq 'on')) { return ''; }
1.155 www 1322: }
1.122 albertel 1323: $currentstring = $token->[4];
1.126 sakharuk 1324: } elsif ($target eq 'tex') {
1325: my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1326: if (defined $fontsize) {
1327: $currentstring = '{\\'.$fontsize.' ';
1328: }
1329: }
1.122 albertel 1330: return $currentstring;
1331: }
1332:
1333: sub end_font {
1334: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1335: my $currentstring = '';
1.325 albertel 1336: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1337: $currentstring = $token->[2];
1.126 sakharuk 1338: } elsif ($target eq 'tex') {
1339: my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1340: if (defined $fontsize) {
1341: $currentstring = '}';
1342: }
1343: }
1.122 albertel 1344: return $currentstring;
1345: }
1346:
1.181 sakharuk 1347: #-- <strike> tag (end tag required)
1.122 albertel 1348: sub start_strike {
1349: my ($target,$token) = @_;
1350: my $currentstring = '';
1.325 albertel 1351: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1352: $currentstring .= $token->[4];
1353: } elsif ($target eq 'tex') {
1354: &Apache::lonxml::startredirection();
1355: }
1356: return $currentstring;
1357: }
1358:
1359: sub end_strike {
1360: my ($target,$token) = @_;
1361: my $currentstring = '';
1.325 albertel 1362: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1363: $currentstring .= $token->[2];
1364: } elsif ($target eq 'tex') {
1365: $currentstring=&Apache::lonxml::endredirection();
1366: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1367: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1368: $currentstring=~s/(\S)\s*$/$1\}/;
1369: }
1370: return $currentstring;
1371: }
1372:
1.181 sakharuk 1373: #-- <s> tag (end tag required)
1.122 albertel 1374: sub start_s {
1375: my ($target,$token) = @_;
1376: my $currentstring = '';
1.325 albertel 1377: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1378: $currentstring .= $token->[4];
1379: } elsif ($target eq 'tex') {
1380: &Apache::lonxml::startredirection();
1381: }
1382: return $currentstring;
1383: }
1384:
1385: sub end_s {
1386: my ($target,$token) = @_;
1387: my $currentstring = '';
1.325 albertel 1388: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1389: $currentstring .= $token->[2];
1390: } elsif ($target eq 'tex') {
1391: $currentstring=&Apache::lonxml::endredirection();
1392: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1393: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1394: $currentstring=~s/(\S)\s*$/$1\}/;
1395: }
1396: return $currentstring;
1397: }
1398:
1.181 sakharuk 1399: #-- <sub> tag (end tag required)
1.122 albertel 1400: sub start_sub {
1401: my ($target,$token) = @_;
1402: my $currentstring = '';
1.325 albertel 1403: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1404: $currentstring .= $token->[4];
1405: } elsif ($target eq 'tex') {
1.202 sakharuk 1406: $currentstring .= '\ensuremath{_{';
1.122 albertel 1407: }
1408: return $currentstring;
1409: }
1410:
1411: sub end_sub {
1412: my ($target,$token) = @_;
1413: my $currentstring = '';
1.325 albertel 1414: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1415: $currentstring .= $token->[2];
1416: } elsif ($target eq 'tex') {
1.202 sakharuk 1417: $currentstring .= '}}';
1.122 albertel 1418: }
1419: return $currentstring;
1420: }
1421:
1.181 sakharuk 1422: #-- <sup> tag (end tag required)
1.122 albertel 1423: sub start_sup {
1424: my ($target,$token) = @_;
1425: my $currentstring = '';
1.325 albertel 1426: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1427: $currentstring .= $token->[4];
1428: } elsif ($target eq 'tex') {
1.202 sakharuk 1429: $currentstring .= '\ensuremath{^{';
1.122 albertel 1430: }
1431: return $currentstring;
1432: }
1433:
1434: sub end_sup {
1435: my ($target,$token) = @_;
1436: my $currentstring = '';
1.325 albertel 1437: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1438: $currentstring .= $token->[2];
1439: } elsif ($target eq 'tex') {
1.202 sakharuk 1440: $currentstring .= '}}';
1.122 albertel 1441: }
1442: return $currentstring;
1443: }
1444:
1.181 sakharuk 1445: #-- <hr> tag (end tag forbidden)
1.122 albertel 1446: sub start_hr {
1.124 sakharuk 1447: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.279 foxr 1448: my $currentstring = &end_p(); # End enclosing para.
1.325 albertel 1449: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1450: $currentstring .= $token->[4];
1451: } elsif ($target eq 'tex') {
1.149 sakharuk 1452: my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
1.124 sakharuk 1453: if (defined $LaTeXwidth) {
1454: if ($LaTeXwidth=~/^%/) {
1455: substr($LaTeXwidth,0,1)='';
1456: $LaTeXwidth=($LaTeXwidth/100).'\textwidth';
1457: }
1458: } else {
1.148 sakharuk 1459: $LaTeXwidth ='0.9\textwidth';
1.124 sakharuk 1460: }
1461: my ($pre,$post);
1462: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1463: if (($align eq 'center') || (not defined $align)) {
1464: $pre=''; $post='';
1465: } elsif ($align eq 'left') {
1466: $pre='\rlap{'; $post='} \hfill';
1467: } elsif ($align eq 'right') {
1468: $pre=' \hfill \llap{'; $post='}';
1469: }
1.148 sakharuk 1470: $currentstring .= ' \vskip 0 mm \noindent\makebox['.$LaTeXwidth.']{'.$pre.'\makebox['.
1.124 sakharuk 1471: $LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm ';
1.122 albertel 1472: }
1473: return $currentstring;
1474: }
1475:
1476: sub end_hr {
1477: my ($target,$token) = @_;
1478: my $currentstring = '';
1.325 albertel 1479: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1480: $currentstring .= $token->[2];
1.148 sakharuk 1481: }
1.122 albertel 1482: return $currentstring;
1483: }
1484:
1.181 sakharuk 1485: #-- <div> tag (end tag required)
1.280 foxr 1486: {
1487:
1488: # Since div can be nested, the stack below is used
1489: # in 'tex' mode to store the ending strings
1490: # for the div stack.
1491:
1492: my @div_end_stack;
1493:
1.122 albertel 1494: sub start_div {
1.280 foxr 1495: my ($target,$token, $tagstack, $parstack, $parser, $safeeval) = @_;
1.279 foxr 1496: my $currentstring = &end_p(); # Close enclosing para.
1.325 albertel 1497: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1498: $currentstring .= $token->[4];
1499: }
1.280 foxr 1500: if ($target eq 'tex') {
1501: # 4 possible alignments: left, right, center, and -missing-.
1502:
1503: my $endstring = '';
1504:
1505: my $align = lc(&Apache::lonxml::get_param('align', $parstack,
1506: $safeeval, undef, 1));
1507: if ($align eq 'center') {
1508: $currentstring .= '\begin{center}';
1509: $endstring = '\end{center}';
1.309 albertel 1510: if (&is_inside_of($tagstack, "table")) {
1511: $currentstring = ¢er_correction().$currentstring;
1512: }
1.280 foxr 1513: }
1514: elsif ($align eq 'right') {
1515: $currentstring .= '\begin{flushright}';
1516: $endstring .= '\end{flushright}';
1517: } elsif ($align eq 'left') {
1518: $currentstring .= '\begin{flushleft}';
1519: $endstring = '\end{flushleft}';
1520: } else {
1521:
1522: }
1523: $currentstring .= "\n"; # For human readability.
1524: $endstring = "\n$endstring\n"; # For human readability
1525: push(@div_end_stack, $endstring);
1526: }
1.122 albertel 1527: return $currentstring;
1528: }
1529:
1530: sub end_div {
1531: my ($target,$token) = @_;
1532: my $currentstring = '';
1.325 albertel 1533: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1534: $currentstring .= $token->[2];
1.280 foxr 1535: }
1536: if ($target eq 'tex') {
1537: my $endstring = pop @div_end_stack;
1538: $currentstring .= $endstring;
1539: }
1.122 albertel 1540: return $currentstring;
1541: }
1.280 foxr 1542: }
1.122 albertel 1543:
1.181 sakharuk 1544: #-- <a> tag (end tag required)
1.122 albertel 1545: sub start_a {
1.149 sakharuk 1546: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1547: my $currentstring = '';
1.325 albertel 1548: if ($target eq 'web' || $target eq 'webgrade') {
1.250 albertel 1549: my $href=&Apache::lonxml::get_param('href',$parstack,$safeeval,
1550: undef,1);
1551: $currentstring=&Apache::lonenc::encrypt_ref($token,{'href'=>$href});
1.122 albertel 1552: } elsif ($target eq 'tex') {
1.149 sakharuk 1553: my $a=&Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1);
1.161 sakharuk 1554: my $b=&Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1);
1555: if ($a=~/\S/) {
1556: $a=~s/([^\\])%/$1\\\%/g;
1557: $currentstring .= '\ref{URI: '.$a.'}';
1558: } elsif ($b=~/\S/) {
1559: $currentstring .= '\ref{Anchor: '.$b.'}';
1560: } else {
1561: $currentstring.='';
1562: }
1.122 albertel 1563: }
1564: return $currentstring;
1565: }
1566:
1567: sub end_a {
1.168 albertel 1568: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1569: my $currentstring = '';
1.325 albertel 1570: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1571: $currentstring .= $token->[2];
1572: }
1573: return $currentstring;
1574: }
1575:
1.181 sakharuk 1576: #-- <li> tag (end tag optional)
1.122 albertel 1577: sub start_li {
1.168 albertel 1578: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1579: my $currentstring = '';
1.325 albertel 1580: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1581: $currentstring = $token->[4];
1582: } elsif ($target eq 'tex') {
1.237 sakharuk 1583: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1584: my $value=&Apache::lonxml::get_param('value',$parstack,$safeeval,undef,0);
1.238 albertel 1585: #FIXME need to support types i and I
1586: if ($type=~/disc/) {
1587: $currentstring .= ' \item[$\bullet$] ';
1588: } elsif ($type=~/circle/) {
1589: $currentstring .= ' \item[$\circ$] ';
1.146 sakharuk 1590: } elsif ($type=~/square/) {
1.238 albertel 1591: $currentstring .= ' \item[$\diamond$] ';
1592: } elsif ($type eq '1') {
1593: $currentstring .= ' \item['.($Apache::londefdef::list_index+1).'.]';
1.237 sakharuk 1594: } elsif ($type eq 'A') {
1.238 albertel 1595: $currentstring .= ' \item['.('A'..'Z')[$Apache::londefdef::list_index].'.]';
1.237 sakharuk 1596: } elsif ($type eq 'a') {
1.238 albertel 1597: $currentstring .= ' \item['.('a'..'z')[$Apache::londefdef::list_index].'.]';
1.237 sakharuk 1598: } elsif ($value ne '') {
1599: $currentstring .= ' \item['.$value.'] ';
1.122 albertel 1600: } else {
1.146 sakharuk 1601: $currentstring .= ' \item ';
1.122 albertel 1602: }
1.238 albertel 1603: $Apache::londefdef::list_index++;
1604: }
1.122 albertel 1605: return $currentstring;
1606: }
1607:
1608: sub end_li {
1609: my ($target,$token) = @_;
1.279 foxr 1610: my $currentstring = &end_p(); # In case there's a <p> in the <li>
1.325 albertel 1611: if ($target eq 'web' || $target eq 'webgrade') {
1.277 foxr 1612: $currentstring .= $token->[2];
1.122 albertel 1613: }
1614: return $currentstring;
1615: }
1616:
1.181 sakharuk 1617: #-- <u> tag (end tag required)
1.122 albertel 1618: sub start_u {
1619: my ($target,$token) = @_;
1620: my $currentstring = '';
1.325 albertel 1621: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1622: $currentstring .= $token->[4];
1623: } elsif ($target eq 'tex') {
1624: &Apache::lonxml::startredirection();
1625: }
1626: return $currentstring;
1627: }
1628:
1629: sub end_u {
1630: my ($target,$token) = @_;
1631: my $currentstring = '';
1.325 albertel 1632: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1633: $currentstring .= $token->[2];
1634: } elsif ($target eq 'tex') {
1635: $currentstring=&Apache::lonxml::endredirection();
1636: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1637: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1638: $currentstring=~s/(\S)\s*$/$1\}/;
1639: }
1640: return $currentstring;
1641: }
1642:
1.181 sakharuk 1643: #-- <ul> tag (end tag required)
1.122 albertel 1644: sub start_ul {
1.125 sakharuk 1645: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.279 foxr 1646: my $currentstring = &end_p(); # Close off enclosing list.
1.325 albertel 1647: if ($target eq 'web' || $target eq 'webgrade') {
1.277 foxr 1648: $currentstring .= $token->[4];
1.122 albertel 1649: } elsif ($target eq 'tex') {
1.125 sakharuk 1650: my $TeXtype=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1.238 albertel 1651: $Apache::londefdef::list_index=0;
1.125 sakharuk 1652: if ($TeXtype eq 'disc') {
1.222 sakharuk 1653: $currentstring .= '\renewcommand{\labelitemi}{$\bullet$}'.
1654: '\renewcommand{\labelitemii}{$\bullet$}'.
1655: '\renewcommand{\labelitemiii}{$\bullet$}'.
1656: '\renewcommand{\labelitemiv}{$\bullet$}';
1.125 sakharuk 1657: } elsif ($TeXtype eq 'circle') {
1.222 sakharuk 1658: $currentstring .= '\renewcommand{\labelitemi}{$\circ$}'.
1659: '\renewcommand{\labelitemii}{$\circ$}'.
1660: '\renewcommand{\labelitemiii}{$\circ$}'.
1661: '\renewcommand{\labelitemiv}{$\circ$}';
1.125 sakharuk 1662: } elsif ($TeXtype eq 'square') {
1.222 sakharuk 1663: $currentstring .= '\renewcommand{\labelitemi}{$\diamond$}'.
1664: '\renewcommand{\labelitemii}{$\diamond$}'.
1665: '\renewcommand{\labelitemiii}{$\diamond$}'.
1666: '\renewcommand{\labelitemiv}{$\diamond$}';
1.125 sakharuk 1667: }
1.222 sakharuk 1668: $currentstring .= '\strut \begin{itemize}';
1.122 albertel 1669: }
1670: return $currentstring;
1671: }
1672:
1673: sub end_ul {
1674: my ($target,$token) = @_;
1675: my $currentstring = '';
1.325 albertel 1676: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1677: $currentstring = $token->[2];
1678: } elsif ($target eq 'tex') {
1.222 sakharuk 1679: $currentstring = '\end{itemize} \renewcommand{\labelitemi}{$\bullet$}'.
1680: '\renewcommand{\labelitemii}{$\bullet$}'.
1681: '\renewcommand{\labelitemiii}{$\bullet$}'.
1682: '\renewcommand{\labelitemiv}{$\bullet$}\strut ';
1.122 albertel 1683: }
1684: return $currentstring;
1685: }
1686:
1.181 sakharuk 1687: #-- <menu> tag (end tag required)
1.122 albertel 1688: sub start_menu {
1689: my ($target,$token) = @_;
1690: my $currentstring = '';
1.325 albertel 1691: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1692: $currentstring = $token->[4];
1693: } elsif ($target eq 'tex') {
1694: $currentstring = " \\begin{itemize} ";
1695: }
1696: return $currentstring;
1697: }
1698:
1699: sub end_menu {
1700: my ($target,$token) = @_;
1701: my $currentstring = '';
1.325 albertel 1702: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1703: $currentstring = $token->[2];
1704: } elsif ($target eq 'tex') {
1705: $currentstring = " \\end{itemize}";
1706: }
1707: return $currentstring;
1708: }
1709:
1.181 sakharuk 1710: #-- <dir> tag (end tag required)
1.122 albertel 1711: sub start_dir {
1712: my ($target,$token) = @_;
1.279 foxr 1713: my $currentstring = &end_p(); # In case there's a <p> prior to the list.
1.325 albertel 1714: if ($target eq 'web' || $target eq 'webgrade') {
1.277 foxr 1715: $currentstring .= $token->[4];
1.122 albertel 1716: } elsif ($target eq 'tex') {
1.277 foxr 1717: $currentstring .= " \\begin{itemize} ";
1.122 albertel 1718: }
1719: return $currentstring;
1720: }
1721:
1722: sub end_dir {
1723: my ($target,$token) = @_;
1724: my $currentstring = '';
1.325 albertel 1725: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1726: $currentstring = $token->[2];
1727: } elsif ($target eq 'tex') {
1728: $currentstring = " \\end{itemize}";
1729: }
1730: return $currentstring;
1731: }
1732:
1.181 sakharuk 1733: #-- <ol> tag (end tag required)
1.122 albertel 1734: sub start_ol {
1.125 sakharuk 1735: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.279 foxr 1736: my $currentstring = &end_p(); # In case there's a <p> prior to the list.
1.325 albertel 1737: if ($target eq 'web' || $target eq 'webgrade') {
1.277 foxr 1738: $currentstring .= $token->[4];
1.122 albertel 1739: } elsif ($target eq 'tex') {
1.238 albertel 1740: $Apache::londefdef::list_index=0;
1.125 sakharuk 1741: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1742: if ($type eq '1') {
1.222 sakharuk 1743: $currentstring .= '\renewcommand{\labelenumi}{\arabic{enumi}.}'.
1744: '\renewcommand{\labelenumii}{\arabic{enumii}.}'.
1745: '\renewcommand{\labelenumiii}{\arabic{enumiii}.}'.
1746: '\renewcommand{\labelenumiv}{\arabic{enumiv}.}';
1.125 sakharuk 1747: } elsif ($type eq 'A') {
1.222 sakharuk 1748: $currentstring .= '\renewcommand{\labelenumi}{\Alph{enumi}.}'.
1749: '\renewcommand{\labelenumii}{\Alph{enumii}.}'.
1750: '\renewcommand{\labelenumiii}{\Alph{enumiii}.}'.
1751: '\renewcommand{\labelenumiv}{\Alph{enumiv}.}';
1.125 sakharuk 1752: } elsif ($type eq 'a') {
1.222 sakharuk 1753: $currentstring .= '\renewcommand{\labelenumi}{\alph{enumi}.}'.
1754: '\renewcommand{\labelenumii}{\alph{enumii}.}'.
1755: '\renewcommand{\labelenumiii}{\alph{enumiii}.}'.
1756: '\renewcommand{\labelenumiv}{\alph{enumiv}.}';
1.125 sakharuk 1757: } elsif ($type eq 'i') {
1.222 sakharuk 1758: $currentstring .= '\renewcommand{\labelenumi}{\roman{enumi}.}'.
1759: '\renewcommand{\labelenumii}{\roman{enumii}.}'.
1760: '\renewcommand{\labelenumiii}{\roman{enumiii}.}'.
1761: '\renewcommand{\labelenumiv}{\roman{enumiv}.}';
1.125 sakharuk 1762: } elsif ($type eq 'I') {
1.222 sakharuk 1763: $currentstring .= '\renewcommand{\labelenumi}{\Roman{enumi}.}'.
1764: '\renewcommand{\labelenumii}{\Roman{enumii}.}'.
1765: '\renewcommand{\labelenumiii}{\Roman{enumiii}.}'.
1766: '\renewcommand{\labelenumiv}{\Roman{enumiv}.}';
1.125 sakharuk 1767: }
1.222 sakharuk 1768: $currentstring .= '\strut \begin{enumerate}';
1.122 albertel 1769: }
1770: return $currentstring;
1771: }
1772:
1773: sub end_ol {
1774: my ($target,$token) = @_;
1775: my $currentstring = '';
1.325 albertel 1776: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1777: $currentstring = $token->[2];
1778: } elsif ($target eq 'tex') {
1.222 sakharuk 1779: $currentstring = '\end{enumerate}\renewcommand{\labelenumi}{\arabic{enumi}.}'.
1780: '\renewcommand{\labelenumii}{\arabic{enumii}.}'.
1781: '\renewcommand{\labelenumiii}{\arabic{enumiii}.}'.
1782: '\renewcommand{\labelenumiv}{\arabic{enumiv}.}\strut ';
1.122 albertel 1783: }
1784: return $currentstring;
1785: }
1786:
1.181 sakharuk 1787: #-- <dl> tag (end tag required)
1.122 albertel 1788: sub start_dl {
1789: my ($target,$token) = @_;
1.279 foxr 1790: my $currentstring = &end_p(); # In case there's a <p> unclosed prior to the list.
1.325 albertel 1791: if ($target eq 'web' || $target eq 'webgrade') {
1.277 foxr 1792: $currentstring .= $token->[4];
1.122 albertel 1793: } elsif ($target eq 'tex') {
1.277 foxr 1794: $currentstring .= '\begin{description}';
1.243 albertel 1795: $Apache::londefdef::DL++;
1796: push(@Apache::londefdef::description,[]);
1797: $Apache::londefdef::DD[$Apache::londefdef::DL]=0;
1798: $Apache::londefdef::DT[$Apache::londefdef::DL]=0;
1.244 albertel 1799: $Apache::londefdef::seenDT[$Apache::londefdef::DL]=0;
1.122 albertel 1800: }
1801: return $currentstring;
1802: }
1803:
1804: sub end_dl {
1.174 sakharuk 1805: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1806: my $currentstring = '';
1.325 albertel 1807: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1808: $currentstring = $token->[2];
1809: } elsif ($target eq 'tex') {
1.243 albertel 1810: if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
1811: if ($Apache::londefdef::DD[-1]) { &end_dd(@_); }
1812: foreach my $element (@{$Apache::londefdef::description[-1]}) {
1.174 sakharuk 1813: $currentstring.=' '.$element.' ';
1814: }
1.243 albertel 1815: pop(@Apache::londefdef::description);
1.174 sakharuk 1816: $currentstring.='\end{description}';
1.243 albertel 1817: delete($Apache::londefdef::DD[$Apache::londefdef::DL]);
1818: delete($Apache::londefdef::DT[$Apache::londefdef::DL]);
1.244 albertel 1819: delete($Apache::londefdef::seenDT[$Apache::londefdef::DL]);
1.243 albertel 1820: $Apache::londefdef::DL--;
1.122 albertel 1821: }
1822: return $currentstring;
1823: }
1824:
1.172 sakharuk 1825: #-- <dt> tag (end tag optional)
1.122 albertel 1826: sub start_dt {
1.172 sakharuk 1827: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1828: my $currentstring='';
1.325 albertel 1829: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1830: $currentstring = $token->[4];
1831: } elsif ($target eq 'tex') {
1.243 albertel 1832: if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
1833: if ($Apache::londefdef::DD[-1]) { &end_dd(@_); }
1.174 sakharuk 1834: &Apache::lonxml::startredirection();
1.243 albertel 1835: $Apache::londefdef::DT[-1]++;
1.244 albertel 1836: $Apache::londefdef::seenDT[-1]=1;
1.122 albertel 1837: }
1838: return $currentstring;
1839: }
1840:
1841: sub end_dt {
1.172 sakharuk 1842: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1843: my $currentstring = '';
1.325 albertel 1844: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1845: $currentstring = $token->[2];
1846: } elsif ($target eq 'tex') {
1.243 albertel 1847: if ($Apache::londefdef::DT[-1]) {
1848: my $data=&item_cleanup();
1.244 albertel 1849: push(@{$Apache::londefdef::description[-1]},'\item['.$data.'] \strut \vskip 0mm');
1.243 albertel 1850: $Apache::londefdef::DT[-1]--;
1851: }
1.122 albertel 1852: }
1853: return $currentstring;
1854: }
1855:
1.173 sakharuk 1856: sub item_cleanup {
1.174 sakharuk 1857: my $item=&Apache::lonxml::endredirection();
1.173 sakharuk 1858: $item=~s/\\begin{center}//g;
1859: $item=~s/\\end{center}//g;
1860: return $item;
1861: }
1862:
1.181 sakharuk 1863: #-- <dd> tag (end tag optional)
1.122 albertel 1864: sub start_dd {
1.147 sakharuk 1865: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1866: my $currentstring = '';
1.325 albertel 1867: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1868: $currentstring = $token->[4];
1.147 sakharuk 1869: } elsif ($target eq 'tex') {
1.243 albertel 1870: if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
1871: if ($Apache::londefdef::DD[-1]) { &end_dd(@_);}
1.244 albertel 1872: if (!$Apache::londefdef::seenDT[-1]) {
1873: push(@{$Apache::londefdef::description[-1]},'\item[\strut] \strut \vskip 0mm ');
1874: }
1.243 albertel 1875: push(@{$Apache::londefdef::description[-1]},'');
1876: $Apache::londefdef::description[-1]->[-1].=' \strut ';
1877: $Apache::londefdef::DD[-1]++;
1.174 sakharuk 1878: &Apache::lonxml::startredirection();
1.122 albertel 1879: }
1880: return $currentstring;
1881: }
1882:
1883: sub end_dd {
1.174 sakharuk 1884: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 1885: my $currentstring = '';
1.325 albertel 1886: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1887: $currentstring = $token->[2];
1.174 sakharuk 1888: } elsif ($target eq 'tex') {
1.243 albertel 1889: $Apache::londefdef::description[-1]->[-1].=
1890: &Apache::lonxml::endredirection().' \vskip 0mm ';
1891: $Apache::londefdef::DD[-1]--;
1.174 sakharuk 1892: }
1.122 albertel 1893: return $currentstring;
1894: }
1895:
1.181 sakharuk 1896: #-- <table> tag (end tag required)
1.277 foxr 1897: # <table> also ends any prior <p> that is not closed.
1898: # but, unless I allow <p>'s to nest, that's the
1899: # only way I could think of to allow <p> in
1900: # <tr> <th> bodies
1901: #
1.206 sakharuk 1902: #list of supported attributes: border,width,TeXwidth
1.91 sakharuk 1903: sub start_table {
1904: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.277 foxr 1905: my $textwidth = '';
1.279 foxr 1906: my $currentstring = &end_p();
1.325 albertel 1907: if ($target eq 'web' || $target eq 'webgrade') {
1.277 foxr 1908: $currentstring .= $token->[4];
1.91 sakharuk 1909: } elsif ($target eq 'tex') {
1910: my $aa = {};
1911: push @Apache::londefdef::table, $aa;
1912: $Apache::londefdef::table[-1]{'row_number'} = -1;
1.222 sakharuk 1913: #maximum table's width (default coincides with text line length)
1.206 sakharuk 1914: if ($#Apache::londefdef::table==0) {
1.267 albertel 1915: $textwidth=&recalc($env{'form.textwidth'}); #result is always in mm
1.206 sakharuk 1916: $textwidth=~/(\d+\.?\d*)/;
1917: $textwidth=0.95*$1; #accounts "internal" LaTeX space for table frame
1918: } else {
1919: if ($Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]=~/\d/) {
1920: #the maximum width of nested table is determined by LATeX width of parent cell
1921: $textwidth=$Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}];
1922: } else {
1923: #try to use all space not used before (minus 5% for LaTeX table internal) - rather silly
1.228 sakharuk 1924: $textwidth=$Apache::londefdef::table[-2]{'width'};
1.206 sakharuk 1925: for (my $i=0;$i<$Apache::londefdef::table[-2]{'counter_columns'};$i++) {
1926: $textwidth=$textwidth-$Apache::londefdef::table[-2]{'TeXlen'}[0][$i];
1927: }
1928: }
1929: }
1.294 foxr 1930:
1931: # width either comes forced from the TeXwidth or the width parameters.
1932: # in either case it can be a percentage or absolute width.
1.311 albertel 1933: # in the width case we ignore absolute width
1.126 sakharuk 1934: my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
1.308 albertel 1935: if (!defined($TeXwidth)) {
1.311 albertel 1936: my $htmlwidth = &Apache::lonxml::get_param('width',$parstack,
1937: $safeeval,undef,1);
1938: if ($htmlwidth =~ /%/) {
1939: $TeXwidth = $htmlwidth;
1940: } else {
1941: $TeXwidth = $textwidth;
1942: }
1.294 foxr 1943: } else {
1944: $Apache::londefdef::table[-1]{'forcedtablewidth'} = 1;
1945: }
1946: if ($TeXwidth=~/%/) {
1.203 sakharuk 1947: $Apache::londefdef::table[-1]{'percent'}=1;
1.126 sakharuk 1948: $TeXwidth=~/(\d+)/;
1.206 sakharuk 1949: $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;
1.126 sakharuk 1950: } else {
1.206 sakharuk 1951: $Apache::londefdef::table[-1]{'width'}=$TeXwidth;
1.316 foxr 1952: }
1953: # In the end, however the table width cannot be wider than $textwidth...
1954:
1955: if ($Apache::londefdef::table[-1]{'width'} > $textwidth) {
1956: $Apache::londefdef::table[-1]{'width'} = $textwidth;
1957: }
1.294 foxr 1958:
1.126 sakharuk 1959: #table's border
1.206 sakharuk 1960: my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval);
1.208 sakharuk 1961: my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
1.91 sakharuk 1962: unless (defined $border) { $border = 0; }
1963: if ($border) {
1964: $Apache::londefdef::table[-1]{'hinc'} = '\hline ';
1965: $Apache::londefdef::table[-1]{'vinc'} = '&';
1966: $Apache::londefdef::table[-1]{'vvinc'} = '|';
1967: } else {
1968: $Apache::londefdef::table[-1]{'hinc'} = '';
1969: $Apache::londefdef::table[-1]{'vinc'} = '&';
1970: $Apache::londefdef::table[-1]{'vvinc'} = '';
1971: }
1.206 sakharuk 1972: if ($#Apache::londefdef::table==0) {
1.281 foxr 1973: # Note that \newline seems to destroy the alignment envs.
1974: # $Apache::londefdef::table[-1]{'output'}='\strut\newline\strut\setlength{\tabcolsep}{1 mm}';
1975: $Apache::londefdef::table[-1]{'output'}='\strut'.'\\\\'."\n".'\strut\setlength{\tabcolsep}{1 mm}';
1.206 sakharuk 1976: }
1977: $Apache::londefdef::table[-1]{'output'}.=' \noindent \begin{tabular} ';
1978: $Apache::londefdef::table[-1]{'TeXlen'}=[];
1979: $Apache::londefdef::table[-1]{'objectlen'}=[];
1.229 sakharuk 1980: $Apache::londefdef::table[-1]{'objectsignal'}=[];
1.206 sakharuk 1981: $Apache::londefdef::table[-1]{'maxlen'}=[];
1982: $Apache::londefdef::table[-1]{'minlen'}=[];
1983: $Apache::londefdef::table[-1]{'content'}=[];
1984: $Apache::londefdef::table[-1]{'align'}=[];
1.277 foxr 1985: $currentstring.='\keephidden{NEW TABLE ENTRY}';
1.295 foxr 1986:
1.294 foxr 1987:
1988: }
1.91 sakharuk 1989: return $currentstring;
1990: }
1.122 albertel 1991:
1992: sub end_table {
1993: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1994: my $currentstring = '';
1.325 albertel 1995: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 1996: $currentstring = $token->[2];
1997: } elsif ($target eq 'tex') {
1998: my $inmemory = '';
1999: my $output = '';
1.206 sakharuk 2000: my $WARNING='';
2001: #width of columns from TeXwidth attributes
1.294 foxr 2002:
1.206 sakharuk 2003: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2004: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
2005: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]<$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn]) {
2006: $Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]=$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn];
2007: }
2008: }
2009: }
2010: #free space and number of empty columns
2011: my ($available_space,$empty_columns)=($Apache::londefdef::table[-1]{'width'},0);
1.228 sakharuk 2012: if ($#Apache::londefdef::table ne 0) {$available_space=0.9*$available_space;}
1.206 sakharuk 2013: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
2014: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]==0) {
2015: $empty_columns++;
2016: } else {
2017: $available_space=$available_space-$Apache::londefdef::table[-1]{'TeXlen'}[0][$jn];
2018: }
2019: }
2020: #boundaries for contents columns
2021: my @min_len=();#columns can not be narrower
2022: my @max_len=();#maximum length of column
2023: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
2024: my ($localmin,$localmax)=(0,0);
2025: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2026: if ($localmin<$Apache::londefdef::table[-1]{'minlen'}[$in][$jn]) {
2027: $localmin=$Apache::londefdef::table[-1]{'minlen'}[$in][$jn];
2028: }
2029: if ($localmax<$Apache::londefdef::table[-1]{'maxlen'}[$in][$jn]) {
2030: $localmax=$Apache::londefdef::table[-1]{'maxlen'}[$in][$jn];
2031: }
2032: }
2033: push @min_len, $localmin;
2034: push @max_len, $localmax;
1.122 albertel 2035: }
1.206 sakharuk 2036: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
2037: my $localmin=0,;
2038: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2039: if ($localmin<$Apache::londefdef::table[-1]{'objectlen'}[$in][$jn]) {
2040: $localmin=$Apache::londefdef::table[-1]{'objectlen'}[$in][$jn];
2041: }
2042: }
1.229 sakharuk 2043: if ($max_len[$jn]<$localmin) {
2044: $max_len[$jn]=$localmin;
2045: $Apache::londefdef::table[-1]{'objectsignal'}[$jn]=1;
2046: }#object size is bigger
2047: if ($min_len[$jn]<$localmin) {
2048: $min_len[$jn]=$localmin;
2049: $Apache::londefdef::table[-1]{'objectsignal'}[$jn]=1;
2050: }#object size is bigger
1.206 sakharuk 2051: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]!=0) {
2052: $min_len[$jn]=0;
2053: $max_len[$jn]=0;
2054: }
2055: }
2056: #final adjustment of column width
2057: my @fwidth=@{$Apache::londefdef::table[-1]{'TeXlen'}[0]};#final width array
2058: my @adjust=();
2059: #step 1. adjustment by maximum value
2060: my $space_neeeded=0;
2061: for (my $jn=0;$jn<=$#max_len;$jn++) {
2062: $space_neeeded=$space_neeeded+$max_len[$jn];
2063: }
2064: if ($space_neeeded<=$available_space) {
2065: for (my $jn=0;$jn<=$#max_len;$jn++) {
2066: if ($fwidth[$jn]==0) {
2067: $fwidth[$jn]=$max_len[$jn];
1.53 sakharuk 2068: }
1.51 sakharuk 2069: }
1.206 sakharuk 2070: } else {
2071: #step 2. adjustment by minimum value (estimation)
2072: $space_neeeded=0;
2073: for (my $jn=0;$jn<=$#min_len;$jn++) {
2074: $space_neeeded+=$min_len[$jn];
2075: }
2076: if ($space_neeeded>$available_space) {
2077: $WARNING=' \textbf{NOT ENOUGH SPACE FOR TABLE} ';
2078: for (my $jn=0;$jn<=$#max_len;$jn++) {
2079: if ($fwidth[$jn]==0) {
2080: $fwidth[$jn]=$min_len[$jn];
2081: }
2082: }
1.229 sakharuk 2083: #check if we have objects which can be scaled
2084: my $how_many_to_scale=0;
2085: my @to_scale=();
2086: for (my $jn=0;$jn<=$#max_len;$jn++) {
2087: if ($Apache::londefdef::table[-1]{'objectsignal'}[$jn] eq '1') {
2088: $how_many_to_scale++;
2089: push @to_scale, $jn;
2090: }
2091: }
2092: if ($how_many_to_scale>0) {
2093: my $space_to_adjust=($space_neeeded-$available_space)/$how_many_to_scale;
2094: foreach my $jn (@to_scale) {
2095: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2096: $Apache::londefdef::table[-1]{'content'}[$in][$jn]=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/;
2097: if ($1 ne '') {
2098: my $current_length=&recalc($1);
2099: $current_length=~/(\d+\.?\d*)/;
2100: $current_length=$current_length-$space_to_adjust;
2101: $Apache::londefdef::table[-1]{'content'}[$in][$jn]=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/width=$current_length mm/;
2102: }
2103: $Apache::londefdef::table[-1]{'content'}[$in][$jn]=~m/\[(\d+\.?\d*)\s*mm\]/;
2104: if ($1 ne '') {
2105: my $current_length=$1;
2106: $current_length=$current_length-$space_to_adjust;
2107: $Apache::londefdef::table[-1]{'content'}[$in][$jn]=~s/\[(\d+\.?\d*)\s*mm\]/\[$current_length mm\]/;
2108: }
2109: }
2110: $fwidth[$jn]=$fwidth[$jn]-$space_to_adjust;
2111: }
2112: }
1.206 sakharuk 2113: } else {
2114: #step 3. adjustment over minimal + corrections
2115: my $enlarge_coef=$available_space/$space_neeeded;
2116: my $acsessive=0;
2117: for (my $jn=0;$jn<=$#min_len;$jn++) {
2118: $adjust[$jn]=$min_len[$jn]*$enlarge_coef;
2119: if ($adjust[$jn]>$max_len[$jn]) {
2120: $fwidth[$jn]=$max_len[$jn];
2121: $acsessive=$acsessive+$adjust[$jn]-$max_len[$jn];
2122: $adjust[$jn]=0;
2123: }
2124: }
2125: if ($acsessive>0) {
2126: #we have an excess of space and can redistribute it
2127: my $notempty_columns=0;
2128: for (my $jn=0;$jn<=$#min_len;$jn++) {
2129: if ($adjust[$jn]!=0) {
2130: $notempty_columns++;
2131: }
2132: }
2133: my $per_column=$acsessive/$notempty_columns;
2134: for (my $jn=0;$jn<=$#min_len;$jn++) {
2135: if ($adjust[$jn]!=0) {
2136: $adjust[$jn]+=$per_column;
2137: $fwidth[$jn]=$adjust[$jn];
2138: }
1.223 sakharuk 2139: }
2140: } else {
2141: for (my $jn=0;$jn<=$#min_len;$jn++) {
2142: $fwidth[$jn]=$adjust[$jn];
1.206 sakharuk 2143: }
2144: }
1.203 sakharuk 2145: }
2146: }
1.222 sakharuk 2147: #use all available width if it is defined in % or as TeXwidth
2148: if (($Apache::londefdef::table[-1]{'percent'}==1) || ($Apache::londefdef::table[-1]{'forcetablewidth'}==1)) {
1.203 sakharuk 2149: my $current=0;
1.206 sakharuk 2150: for (my $i=0;$i<=$#fwidth;$i++) {
2151: $current+=$fwidth[$i];
1.203 sakharuk 2152: }
2153: my $coef=$Apache::londefdef::table[-1]{'width'}/$current;
1.206 sakharuk 2154: for (my $i=0;$i<=$#fwidth;$i++) {
2155: $fwidth[$i]*=$coef;
2156: }
2157: }
2158: #removing of empty columns if allowed
1.208 sakharuk 2159: my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
1.206 sakharuk 2160: if ($permission eq 'yes') {
2161: my @cleaned_table=();
2162: my @cleaned_header=();
2163: my $colind=0;
2164: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
2165: if ($fwidth[$jn]!=0) {
2166: #we need to copy column
2167: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2168: $cleaned_table[$in][$colind]=$Apache::londefdef::table[-1]{'content'}[$in][$jn];
2169: $cleaned_header[$colind]=$fwidth[$jn];
2170: }
2171: $colind++;
2172: }
1.122 albertel 2173: }
1.206 sakharuk 2174: $Apache::londefdef::table[-1]{'content'}=\@cleaned_table;
2175: @fwidth=@cleaned_header;
1.122 albertel 2176: }
1.206 sakharuk 2177: #construct header of the table
2178: my $header_of_table = '{'.$Apache::londefdef::table[-1]{'vvinc'};
2179: for (my $in=0;$in<=$#fwidth;$in++) {
2180: $header_of_table.='p{'.$fwidth[$in].' mm}'.$Apache::londefdef::table[-1]{'vvinc'};
2181: }
2182: $header_of_table .= '}';
1.126 sakharuk 2183: #fill the table
2184: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
1.306 foxr 2185: my $have_rowspan = 0;
1.206 sakharuk 2186: for (my $jn=0;$jn<=$#fwidth;$jn++) {
1.320 foxr 2187:
2188: #-----------------------------------------------------------
2189: # I think this order of doing things will ensure that
2190: # single rowspan, columspan and combined row/colspans will
2191: # work correctly. LaTeX is delicate here.
2192: # RF.
2193:
2194: # Start a rowspan if necessary:
2195:
2196: my $rowspan = $Apache::londefdef::table[-1]{'rowspan'}[$in][$jn];
2197: my $colspan = $Apache::londefdef::table[-1]{'colspan'}[$in][$jn];
1.304 foxr 2198: #
2199: # Do the appropriate magic if this has a colspan
2200: #
1.320 foxr 2201:
1.304 foxr 2202: if ($colspan > 1) {
1.336 ! foxr 2203: my $spanwidth = 0;
! 2204: for (my $spancol = $jn; $spancol < $jn + $colspan; $spancol++) {
! 2205: $spanwidth += $fwidth[$spancol];
! 2206: }
1.304 foxr 2207: $output .= '\multicolumn{'.
2208: $colspan
1.336 ! foxr 2209: ."}{|p{$spanwidth mm}|}{";
1.304 foxr 2210: }
1.306 foxr 2211:
2212: if ($rowspan > 1) {
2213: $have_rowspan++;
2214: $output .= '\multirow{'.$rowspan.'}[0]{'.$fwidth[$jn].'mm}{';
2215: }
2216: if (($rowspan eq '^') || ($rowspan eq '_')) {
2217: $have_rowspan++;
2218: }
1.320 foxr 2219: #--------------------------------------------------------------
1.306 foxr 2220:
1.206 sakharuk 2221: if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
1.309 albertel 2222: $output.=¢er_correction().'\begin{center}';
1.206 sakharuk 2223: } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
2224: $output.=' \hfill \llap{'
2225: }
2226: $output.=$Apache::londefdef::table[-1]{'content'}[$in][$jn];
2227: if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
1.314 albertel 2228: $output.='\end{center}';
1.206 sakharuk 2229: } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
2230: $output.='} ';
2231: }
1.306 foxr 2232: # Close off any open multirow:
2233:
2234: if ($rowspan > 1) {
2235: $output .= '}';
2236: }
1.304 foxr 2237: # Close off the colspan...
2238: #
2239: if ($colspan > 1) {
2240: $output .= '}';
2241: $jn += $colspan-1; # Adjust for number of rows really left.
2242: }
1.206 sakharuk 2243: if ($jn!=$#fwidth) {$output.=' '.$Apache::londefdef::table[-1]{'vinc'};}
2244: }
1.306 foxr 2245: # If have_rowspan > 0, and borders are on, then
2246: # we need to do more than put an \hline at the bottom of row.
2247: # we need to do the appropriate \cline to ensure that
2248: # the spanned rows don't have \hlines through them.
2249:
2250: if (($Apache::londefdef::table[-1]{'hinc'} =~ /\\hline/) && $have_rowspan) {
2251: $output .= ' \\\\ ';
2252: for (my $jn=0; $jn<=$#fwidth;$jn++) {
2253: my $rowspan = $Apache::londefdef::table[-1]{'rowspan'}[$in][$jn];
1.320 foxr 2254: if ($rowspan ne "^") {
2255: if (($rowspan <= 1) || ($rowspan eq '_')) {
2256: my $column = $jn+1;
2257: $output .= '\cline{'.$column.'-'.$column.'} ';
2258: }
1.306 foxr 2259: }
2260: }
2261:
2262: } else {
2263: $output.=' \\\\ '.$Apache::londefdef::table[-1]{'hinc'}.' ';
2264: }
1.122 albertel 2265: }
1.281 foxr 2266: # Note that \newline destroys alignment env's produced by e.g. <div>
2267: # $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut\newline\strut ';
2268: $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut'.'\\\\'."\n".'\strut ';
1.127 sakharuk 2269: if ($#Apache::londefdef::table > 0) {
2270: my $inmemory = $Apache::londefdef::table[-1]{'output'};
1.294 foxr 2271: # Figure out max/and min width by summing us and then
2272: # apply that to the current column of the table we nest in
2273: # if it's larger than the current width or the current width
2274: # is undefined.
2275: #
2276: my $min_nested_width = 0;
2277: my $max_nested_width = 0;
2278: for (my $col = 0; $col <= $Apache::londefdef::table[-1]{'counter_columns'}; $col++) {
2279: $min_nested_width += $min_len[$col];
2280: $max_nested_width += $max_len[$col];
1.300 foxr 2281:
1.294 foxr 2282: }
2283: # Fudge in an extra 5 mm for borders etc:
2284:
2285: $min_nested_width += 5;
2286: $max_nested_width += 5;
2287:
2288: my $outer_column = $Apache::londefdef::table[-2]{'counter_columns'};
2289: my $outer_row = $Apache::londefdef::table[-2]{'row_number'};
2290: if ($min_nested_width > $Apache::londefdef::table[-2]{'minlen'}[$outer_row][$outer_column]) {
2291: $Apache::londefdef::table[-2]{'minlen'}[$outer_row][$outer_column] = $min_nested_width;
2292: }
2293: if ($max_nested_width > $Apache::londefdef::table[-2]{'maxlen'}[$outer_row][$outer_column]) {
2294: $Apache::londefdef::table[-2]{'maxlen'}[$outer_row][$outer_column] = $max_nested_width;
2295: }
2296:
1.127 sakharuk 2297: pop @Apache::londefdef::table;
1.129 sakharuk 2298: push @{$Apache::londefdef::table[-1]{'include'}}, $inmemory;
1.127 sakharuk 2299: } else {
2300: $currentstring .= $Apache::londefdef::table[-1]{'output'};
2301: pop @Apache::londefdef::table;
1.143 sakharuk 2302: undef @Apache::londefdef::table;
1.127 sakharuk 2303: }
1.122 albertel 2304: }
2305: return $currentstring;
2306: }
2307:
1.166 sakharuk 2308: #-- <tr> tag (end tag optional)
1.122 albertel 2309: sub start_tr {
2310: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2311: my $currentstring = '';
1.325 albertel 2312: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 2313: $currentstring = $token->[4];
2314: } elsif ($target eq 'tex') {
2315: $Apache::londefdef::table[-1]{'row_number'}++;
1.206 sakharuk 2316: my $alignchar=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1.122 albertel 2317: if ($alignchar ne '') {
1.206 sakharuk 2318: push @ {$Apache::londefdef::table[-1]{'rows'} },substr($alignchar,0,1);
1.122 albertel 2319: } else {
2320: push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l';
2321: }
2322: push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'});
1.300 foxr 2323: #
2324: # Need to save the number of table columns to preserve the max # columns.
2325: #
2326: $Apache::londefdef::table[-1]{'prior_columns'} = $Apache::londefdef::table[-1]{'counter_columns'};
1.122 albertel 2327: $Apache::londefdef::table[-1]{'counter_columns'} = -1;
1.206 sakharuk 2328: push @ {$Apache::londefdef::table[-1]{'TeXlen'}}, [];
2329: push @ {$Apache::londefdef::table[-1]{'objectlen'}}, [];
2330: push @ {$Apache::londefdef::table[-1]{'minlen'}}, [];
2331: push @ {$Apache::londefdef::table[-1]{'maxlen'}}, [];
2332: push @ {$Apache::londefdef::table[-1]{'content'}}, [];
1.122 albertel 2333: }
2334: return $currentstring;
2335: }
2336:
2337: sub end_tr {
1.160 sakharuk 2338: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.279 foxr 2339: my $currentstring = &end_p(); # Close any pending <p> in the row.
1.325 albertel 2340: if ($target eq 'web' || $target eq 'webgrade') {
1.277 foxr 2341: $currentstring .= $token->[2];
1.122 albertel 2342: } elsif ($target eq 'tex') {
1.160 sakharuk 2343: if ($Apache::londefdef::TD_redirection) {
2344: &end_td_tex($parstack,$parser,$safeeval);
2345: }
1.300 foxr 2346: # Counter columns must be the maximum number of columns seen
2347: # in the table so far so:
2348: if ($Apache::londefdef::table[-1]{'prior_columns'} > $Apache::londefdef::table[-1]{'counter_columns'}) {
2349: $Apache::londefdef::table[-1]{'counter_columns'} = $Apache::londefdef::table[-1]{'prior_columns'};
2350: }
1.295 foxr 2351:
2352:
1.294 foxr 2353:
1.122 albertel 2354: }
2355: return $currentstring;
2356: }
2357:
1.166 sakharuk 2358: #-- <td> tag (end tag optional)
1.122 albertel 2359: sub start_td {
2360: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2361: my $currentstring = '';
1.325 albertel 2362: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 2363: $currentstring = $token->[4];
2364: } elsif ($target eq 'tex') {
1.160 sakharuk 2365: $Apache::londefdef::TD_redirection = 1;
1.159 sakharuk 2366: &tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval);
1.122 albertel 2367: }
2368: return $currentstring;
2369: }
1.159 sakharuk 2370:
2371: sub tag_check {
2372: my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
1.160 sakharuk 2373: my @ar=@$parstack;
2374: for (my $i=$#ar-1;$i>=0;$i--) {
2375: if (lc($$tagstack[$i]) eq $good_tag) {
2376: &start_td_tex($parstack,$parser,$safeeval);
2377: last;
2378: } elsif (lc($$tagstack[$i]) eq $bad_tag) {
2379: splice @ar, $i+1;
2380: &end_td_tex(\@ar,$parser,$safeeval);
2381: &start_td_tex($parstack,$parser,$safeeval);
2382: last;
1.159 sakharuk 2383: }
1.160 sakharuk 2384: }
1.159 sakharuk 2385: return '';
2386: }
2387:
2388: sub start_td_tex {
2389: my ($parstack,$parser,$safeeval) = @_;
1.206 sakharuk 2390: my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
2391: if ($alignchar eq '') {
2392: $alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
1.159 sakharuk 2393: }
1.206 sakharuk 2394: push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
1.159 sakharuk 2395: $Apache::londefdef::table[-1]{'counter_columns'}++;
1.206 sakharuk 2396: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2397: if (defined $TeXwidth) {
2398: my $current_length=&recalc($TeXwidth);
2399: $current_length=~/(\d+\.?\d*)/;
2400: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
2401: }
1.159 sakharuk 2402: &Apache::lonxml::startredirection();
2403: return '';
2404: }
2405:
2406: sub end_td_tex {
2407: my ($parstack,$parser,$safeeval) = @_;
1.304 foxr 2408: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
2409: my $current_column = $Apache::londefdef::table[-1]{'counter_columns'};
1.303 foxr 2410: my $data = &Apache::lonxml::endredirection();
2411:
1.305 foxr 2412: # The rowspan array of the table indicates which cells are part of a span.
2413: # n indicates the start of a span set of n rows.
2414: # ^ indicates a cell that continues a span set.
1.306 foxr 2415: # _ indicates the cell is at the bottom of a span set.
1.305 foxr 2416: # If this and subsequent cells are part of a rowspan, we must
2417: # push along the row until we find one that is not.
2418:
2419: while ((defined $Apache::londefdef::table[-1]{'rowspan'}[$current_row] [$current_column])
1.306 foxr 2420: && ($Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column] =~ /[\^\_]/)) {
1.305 foxr 2421: # Part of a span.
2422: push @ {$Apache::londefdef::table[-1]{'content'}[-1]}, '';
2423: $current_column++;
2424: }
2425: $Apache::londefdef::table[-1]{'counter_columns'} = $current_column;
2426:
2427:
1.320 foxr 2428: # Get the column and row spans.
2429: # Colspan can be done via \multicolumn if I can figure out the data structs.
2430:
2431: my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval, undef, 0);
2432: if (!$colspan) {
2433: $colspan = 1;
2434: }
1.305 foxr 2435:
2436: my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval, undef, 0);
2437: if (!$rowspan) {
2438: $rowspan = 1;
2439: }
2440:
1.303 foxr 2441:
1.305 foxr 2442:
1.320 foxr 2443: for (my $c = 0; $c < $colspan; $c++) {
2444: $Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column+$c] = $rowspan;
2445: for (my $i = 1; $i < $rowspan; $i++) {
2446: $Apache::londefdef::table[-1]{'rowspan'}[$current_row+$i][$current_column+$c] = '^';
2447: if ($i == ($rowspan-1)) {
2448: $Apache::londefdef::table[-1]{'rowspan'}[$current_row+$i][$current_column+$c] = '_';
2449: }
1.306 foxr 2450: }
1.305 foxr 2451: }
1.304 foxr 2452:
1.159 sakharuk 2453: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2454: if (defined $TeXwidth) {
1.206 sakharuk 2455: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2456: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2457: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
1.159 sakharuk 2458: } else {
1.206 sakharuk 2459: if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
2460: my $garbage_data=$data;
2461: my $fwidth=0;
2462: while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2463: my $current_length=&recalc($1);
2464: $current_length=~/(\d+\.?\d*)/;
2465: if ($fwidth<$1) {$fwidth=$1;}
2466: $garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2467: }
2468: while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
2469: my $current_length=$1;
2470: if ($fwidth<$current_length) {$fwidth=$current_length;}
2471: $garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
2472: }
2473: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2474: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2475: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2476: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
1.231 sakharuk 2477: } 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)*/) {
2478: my $garbage_data=$data;
2479: my $fwidth=0;
2480: while ($garbage_data=~/\\parbox\{\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)\s*\}/) {
2481: my $current_length=&recalc($1);
2482: $current_length=~/(\d+\.?\d*)/;
2483: if ($fwidth<$1) {$fwidth=$1;}
2484: $garbage_data=~s/\\parbox\{\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2485: }
2486: while ($garbage_data=~/\\epsfxsize\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2487: my $current_length=&recalc($1);
2488: $current_length=~/(\d+\.?\d*)/;
2489: if ($fwidth<$1) {$fwidth=$1;}
2490: $garbage_data=~s/\\epsfxsize\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2491: }
2492: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2493: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2494: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2495: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2496: $data=~s/\\\\\s*$//;
1.159 sakharuk 2497: } else {
1.166 sakharuk 2498: $data=~s/^\s+(\S.*)/$1/;
1.159 sakharuk 2499: $data=~s/(.*\S)\s+$/$1/;
1.166 sakharuk 2500: $data=~s/(\s)+/$1/;
1.206 sakharuk 2501: my ($current_length,$min_length)=(0,0);
1.166 sakharuk 2502: if ($data=~/\\vskip/) {
2503: my $newdata=$data;
2504: $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
2505: my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
2506: foreach my $elementdata (@newdata) {
1.206 sakharuk 2507: my $lengthnewdata=2.5*&LATEX_length($elementdata);
1.166 sakharuk 2508: if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
1.206 sakharuk 2509: my @words=split(/ /,$elementdata);
2510: foreach my $word (@words) {
2511: my $lengthword=2.5*&LATEX_length($word);
2512: if ($min_length<$lengthword) {$min_length=$lengthword;}
2513: }
1.166 sakharuk 2514: }
2515: } else {
1.206 sakharuk 2516: $current_length=2.5*&LATEX_length($data);
2517: my @words=split(/ /,$data);
2518: foreach my $word (@words) {
1.228 sakharuk 2519: my $lengthword=2*&LATEX_length($word);
1.206 sakharuk 2520: if ($min_length<$lengthword) {$min_length=$lengthword;}
2521: }
1.166 sakharuk 2522: }
1.206 sakharuk 2523: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2524: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2525: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
2526: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
1.159 sakharuk 2527: }
2528: }
1.302 foxr 2529: # Substitute all of the tables nested in this cell in their appropriate places.
2530:
2531:
2532: my $nested_count = $#{$Apache::londefdef::table[-1]{'include'}}; # This one is constant...
2533: for (my $in=0; $in<=$nested_count; $in++) {
1.301 foxr 2534: my $nested = shift @{$Apache::londefdef::table[-1]{'include'}};
2535: $nested =~ s/\\end\{tabular\}\\strut\\\\/\\end\{tabular\}/;
2536: # $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
2537: $data =~ s/\\keephidden\{NEW TABLE ENTRY\}/$nested/;
2538:
2539: }
2540: # Should be be killing off the 'include' elements as they're used up?
1.305 foxr 2541:
1.206 sakharuk 2542: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
1.305 foxr 2543:
1.304 foxr 2544:
2545:
2546:
2547: # the colspan array will indicate how many columns will be spanned by this
2548: # cell..this requires that counter_columns also be adjusted accordingly
2549: # so that the next bunch of text goes in the right cell. Note that since
2550: # counter_columns is incremented in the start_td_tex, we adjust by colspan-1.
2551: #
2552:
2553: $Apache::londefdef::table[-1]{'counter_columns'} += $colspan -1;
2554: for (my $i = 0; $i < ($colspan -1); $i++) {
2555: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },'';
2556: }
1.320 foxr 2557: for (my $r = 0; $r < $rowspan; $r++) {
2558: $Apache::londefdef::table[-1]{'colspan'}[$current_row+$r][$current_column] = $colspan;
2559: # Put empty text in spanned cols.
2560:
2561: }
2562:
1.304 foxr 2563:
2564:
1.301 foxr 2565: return '';
1.159 sakharuk 2566: }
2567:
1.122 albertel 2568: sub end_td {
1.126 sakharuk 2569: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 2570: my $currentstring = '';
1.325 albertel 2571: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 2572: $currentstring = $token->[2];
2573: } elsif ($target eq 'tex') {
1.160 sakharuk 2574: $Apache::londefdef::TD_redirection =0;
1.159 sakharuk 2575: &end_td_tex($parstack,$parser,$safeeval);
1.122 albertel 2576: }
2577: return $currentstring;
2578: }
2579:
1.166 sakharuk 2580: #-- <th> tag (end tag optional)
1.122 albertel 2581: sub start_th {
2582: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2583: my $currentstring = '';
1.325 albertel 2584: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 2585: $currentstring = $token->[4];
2586: } elsif ($target eq 'tex') {
1.230 sakharuk 2587: $Apache::londefdef::TD_redirection = 1;
2588: &tagg_check('tr','th',$tagstack,$parstack,$parser,$safeeval);
1.122 albertel 2589: }
2590: return $currentstring;
1.130 sakharuk 2591: }
1.230 sakharuk 2592:
2593: sub tagg_check {
2594: my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
2595: my @ar=@$parstack;
2596: for (my $i=$#ar-1;$i>=0;$i--) {
2597: if (lc($$tagstack[$i]) eq $good_tag) {
2598: &start_th_tex($parstack,$parser,$safeeval);
2599: last;
2600: } elsif (lc($$tagstack[$i]) eq $bad_tag) {
2601: splice @ar, $i+1;
2602: &end_th_tex(\@ar,$parser,$safeeval);
2603: &start_th_tex($parstack,$parser,$safeeval);
2604: last;
2605: }
2606: }
2607: return '';
2608: }
2609:
2610: sub start_th_tex {
2611: my ($parstack,$parser,$safeeval) = @_;
2612: my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
2613: if ($alignchar eq '') {
2614: $alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
2615: }
2616: push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
2617: $Apache::londefdef::table[-1]{'counter_columns'}++;
2618: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2619: if (defined $TeXwidth) {
2620: my $current_length=&recalc($TeXwidth);
2621: $current_length=~/(\d+\.?\d*)/;
2622: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
2623: }
2624: &Apache::lonxml::startredirection();
2625: return '';
2626: }
2627:
2628: sub end_th_tex {
2629: my ($parstack,$parser,$safeeval) = @_;
2630: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
2631: my $data=&Apache::lonxml::endredirection();
2632: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2633: if (defined $TeXwidth) {
2634: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2635: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2636: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2637: } else {
2638: if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
2639: my $garbage_data=$data;
2640: my $fwidth=0;
2641: while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2642: my $current_length=&recalc($1);
2643: $current_length=~/(\d+\.?\d*)/;
2644: if ($fwidth<$1) {$fwidth=$1;}
2645: $garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2646: }
2647: while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
2648: my $current_length=$1;
2649: if ($fwidth<$current_length) {$fwidth=$current_length;}
2650: $garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
2651: }
2652: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2653: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2654: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2655: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2656: } else {
2657: $data=~s/^\s+(\S.*)/$1/;
2658: $data=~s/(.*\S)\s+$/$1/;
2659: $data=~s/(\s)+/$1/;
2660: my ($current_length,$min_length)=(0,0);
2661: if ($data=~/\\vskip/) {
2662: my $newdata=$data;
2663: $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
2664: my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
2665: foreach my $elementdata (@newdata) {
2666: my $lengthnewdata=2.5*&LATEX_length($elementdata);
2667: if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
2668: my @words=split(/ /,$elementdata);
2669: foreach my $word (@words) {
2670: my $lengthword=2.5*&LATEX_length($word);
2671: if ($min_length<$lengthword) {$min_length=$lengthword;}
2672: }
2673: }
2674: } else {
2675: $current_length=2.5*&LATEX_length($data);
2676: my @words=split(/ /,$data);
2677: foreach my $word (@words) {
2678: my $lengthword=2*&LATEX_length($word);
2679: if ($min_length<$lengthword) {$min_length=$lengthword;}
2680: }
2681: }
2682: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2683: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2684: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
2685: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
2686: }
2687: }
2688: for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {
2689: $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
2690: }
2691: #make data bold
2692: $data='\textbf{'.$data.'}';
2693: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
2694: return'';
2695: }
2696:
1.122 albertel 2697: sub end_th {
1.130 sakharuk 2698: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.279 foxr 2699: my $currentstring = &end_p(); # Close any open <p> in the row.
1.325 albertel 2700: if ($target eq 'web' || $target eq 'webgrade') {
1.277 foxr 2701: $currentstring .= $token->[2];
1.122 albertel 2702: } elsif ($target eq 'tex') {
1.230 sakharuk 2703: $Apache::londefdef::TD_redirection =0;
2704: &end_th_tex($parstack,$parser,$safeeval);
1.122 albertel 2705: }
2706: return $currentstring;
2707: }
1.230 sakharuk 2708:
1.181 sakharuk 2709: #-- <img> tag (end tag forbidden)
1.249 foxr 2710: #
2711: # Render the <IMG> tag.
2712: # <IMG> has the following attributes (in addition to the
2713: # standard HTML ones:
2714: # TeXwrap - Governs how the tex target will try to wrap text around
2715: # horizontally aligned images.
2716: # TeXwidth - The width of the image when rendered for print (mm).
2717: # TeXheight - The height of the image when rendered for print (mm)
2718: # (Note there seems to also be support for this as a % of page size)
2719: #
1.122 albertel 2720: sub start_img {
1.299 albertel 2721: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
1.122 albertel 2722: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,
2723: undef,1);
1.325 albertel 2724: if (! $src &&
2725: ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex')
2726: ) {
1.299 albertel 2727: my $inside = &Apache::lonxml::get_all_text("/img",$parser,$style);
1.189 albertel 2728: return '';
2729: }
1.290 albertel 2730: &Apache::lonxml::extlink($src);
1.122 albertel 2731: my $currentstring = '';
2732: my $scaling = .3;
1.249 foxr 2733:
2734: # Render unto browsers that which are the browser's...
2735:
1.325 albertel 2736: if ($target eq 'web' || $target eq 'webgrade') {
1.267 albertel 2737: if ($env{'browser.imagesuppress'} ne 'on') {
1.322 albertel 2738: my $enc = ('yes' eq
2739: lc(&Apache::lonxml::get_param('encrypturl',$parstack,
2740: $safeeval)));
2741: $currentstring.=&Apache::lonenc::encrypt_ref($token,{'src'=>$src},
2742: $enc);
1.122 albertel 2743: } else {
1.322 albertel 2744: my $alttag = &Apache::lonxml::get_param('alt',$parstack,$safeeval,
2745: undef,1);
2746: if (!$alttag) {
2747: $alttag = &Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
2748: $src);
1.51 sakharuk 2749: }
1.158 sakharuk 2750: $currentstring.='[IMAGE: '.$alttag.']';
1.1 sakharuk 2751: }
1.249 foxr 2752:
2753: # and render unto TeX that which is LaTeX
2754:
1.122 albertel 2755: } elsif ($target eq 'tex') {
1.248 foxr 2756: #
2757: # The alignment will require some superstructure to be put around
2758: # the \includegraphics stuff. At present we can only partially
2759: # simulate the alignments offered by html.
2760: #
2761: #
2762: my $align = lc(&Apache::lonxml::get_param('align',
2763: $parstack,
2764: $safeeval,
2765: undef,1));
2766: if(!$align) {
1.287 foxr 2767: $align = "bottom"; # This is html's default so it's ours too.
1.248 foxr 2768: }
2769: #
2770: &Apache::lonxml::debug("Alignemnt = $align");
2771: # LaTeX's image/text wrapping is really bad since it wants to
2772: # make figures float.
2773: # The user has the optional parameter (applicable only to l/r
2774: # alignment to use the picins/parpic directive to get wrapped text
2775: # this is also imperfect.. that's why we give them a choice...
2776: # so they can't yell at us for our choice.
2777: #
2778: my $latex_rendering = &Apache::lonxml::get_param('TeXwrap',
2779: $parstack,
2780: $safeeval,
2781: undef,0);
1.312 foxr 2782: # &Apache::lonxml::debug("LaTeX rendering = $latex_rendering");
1.248 foxr 2783: if(!$latex_rendering) {
1.312 foxr 2784: $latex_rendering = "texwrap";
2785: }
2786: # using texwrap inside a table does not work. So, if after all of this,
2787: # texwrap is on, we turn it off if we detect we're in a table:
2788: #
2789: if (($latex_rendering eq 'texwrap') && &is_inside_of($tagstack, "table")) {
2790: $latex_rendering = 'parpic';
1.248 foxr 2791: }
1.323 foxr 2792:
1.312 foxr 2793: # &Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src");
1.248 foxr 2794:
1.256 albertel 2795: #if original gif/jpg/png file exist do following:
1.266 albertel 2796: my $origsrc=$src;
1.256 albertel 2797: my ($path,$file) = &get_eps_image($src);
1.122 albertel 2798: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
1.261 foxr 2799: &Apache::lonxml::debug("path = $path file = $file src = $src");
1.192 sakharuk 2800: if (-e $src) {
1.261 foxr 2801: &Apache::lonxml::debug("$src exists");
1.256 albertel 2802: my ($height_param,$width_param)=
1.266 albertel 2803: &image_size($origsrc,0.3,$parstack,$safeeval);
1.262 foxr 2804: my $destpath = $path;
1.263 foxr 2805: $destpath =~ s/ /\_/g; # Spaces in path cause LaTex to vomit.
2806: my $destfile = $file;
2807: $destfile =~ s/ /\_/g;
1.266 albertel 2808: my $size;
2809: if ($width_param) { $size.='width='.$width_param.' mm,'; }
2810: if ($height_param) { $size.='height='.$height_param.' mm]'; }
2811: $size='['.$size;
2812: $size=~s/,$/]/;
1.262 foxr 2813: $currentstring .= '\graphicspath{{'.$destpath.'}}'
1.266 albertel 2814: .'\includegraphics'.$size.'{'.$destfile.'} ';
1.256 albertel 2815:
1.248 foxr 2816: # If there's an alignment specification we need to honor it here.
2817: # For the horizontal alignments, we will also honor the
2818: # value of the latex specfication. The default is parbox,
2819: # and that's used for illegal values too.
2820: #
2821: # Even though we set a default alignment value, the user
2822: # could have given us an illegal value. In that case we
2823: # just use the default alignment of bottom..
2824: if ($align eq "top") {
2825: $currentstring = '\raisebox{-'.$height_param.'mm}{'.$currentstring.'}';
2826: } elsif (($align eq "center") || ($align eq "middle")) { # Being kind
2827: my $offset = $height_param/2;
2828: $currentstring = '\raisebox{-'.$offset.'mm}{'.$currentstring.'}';
2829: } elsif ($align eq "left") {
2830: if ($latex_rendering eq "parpic") {
2831: $currentstring = '\parpic[l]{'.$currentstring.'}';
1.286 foxr 2832: } else { # wrapfig render
2833: $currentstring = '\begin{wrapfigure}{l}{'.$width_param.'mm}'
2834: .'\scalebox{1.0}{'.$currentstring.'}\end{wrapfigure}';
1.248 foxr 2835: }
2836: } elsif ($align eq "right") {
2837: if ($latex_rendering eq "parpic") {
2838: $currentstring = '\parpic[r]{'.$currentstring.'}';
1.286 foxr 2839: } else { # wrapfig rendering
2840: $currentstring = '\begin{wrapfigure}{r}{'.$width_param.'mm}'
2841: .'\scalebox{1.0}{'.$currentstring.'}\end{wrapfigure}';
2842:
1.248 foxr 2843: }
2844: } else { # Bottom is also default.
2845: # $currentstring = '\raisebox{'.$height_param.'mm}{'.$currentstring.'}';
2846: }
1.122 albertel 2847: } else {
1.261 foxr 2848: &Apache::lonxml::debug("$src does not exist");
1.122 albertel 2849: #original image file doesn't exist so check the alt attribute
2850: my $alt =
2851: &Apache::lonxml::get_param('alt',$parstack,$safeeval,undef,1);
2852: unless ($alt) {
2853: $alt=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
2854: }
2855:
1.256 albertel 2856: if ($alt) { $currentstring .= ' '.$alt.' '; }
1.59 sakharuk 2857: }
1.249 foxr 2858:
2859: # And here's where the semi-quote breaks down: allow the user
2860: # to edit the beast as well by rendering the problem for edit:
1.186 albertel 2861: } elsif ($target eq 'edit') {
2862: $currentstring .=&Apache::edit::tag_start($target,$token);
2863: $currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70).
2864: &Apache::edit::browse('src',undef,'alt').' '.
2865: &Apache::edit::search('src',undef,'alt').'<br />';
2866: $currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'<br />';
2867: $currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5);
2868: $currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'<br />';
2869: $currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5);
2870: $currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5);
1.234 albertel 2871: $currentstring .=&Apache::edit::select_arg('Alignment:','align',
2872: ['','bottom','middle','top','left','right'],$token,5);
1.249 foxr 2873: $currentstring .=&Apache::edit::select_arg('TeXwrap:', 'TeXwrap',
2874: ['', 'parbox', 'parpic'], $token, 2);
1.332 www 2875: $currentstring .=&Apache::edit::select_arg('Encrypt URL:','encrypturl',
1.322 albertel 2876: ['no','yes'], $token, 2);
1.186 albertel 2877: $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.249 foxr 2878: my $src= &Apache::lonxml::get_param('src',$parstack,$safeeval);
2879: my $alt= &Apache::lonxml::get_param('alt',$parstack,$safeeval);
2880: my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
2881: my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
2882:
2883:
1.186 albertel 2884: $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
2885: if ($width) { $currentstring.=' width="'.$width.'" '; }
2886: if ($height) { $currentstring.=' height="'.$height.'" '; }
2887: $currentstring .= ' />';
2888: } elsif ($target eq 'modified') {
1.210 albertel 2889: my ($osrc,$owidth,$oheight)=
2890: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
2891: my $ctag=&Apache::edit::get_new_args($token,$parstack,
1.234 albertel 2892: $safeeval,'src','alt','align',
1.249 foxr 2893: 'TeXwidth','TeXheight', 'TeXwrap',
1.322 albertel 2894: 'width','height','encrypturl');
1.210 albertel 2895: my ($nsrc,$nwidth,$nheight)=
2896: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
2897: my $loc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$nsrc);
2898: &image_replication($loc);
2899: my ($iwidth,$iheight);
2900: if (-e $loc) {
2901: my $image = Image::Magick->new;
2902: $image->Read($loc);
2903: ($iwidth, $iheight) = ($image->Get('width'),
2904: $image->Get('height'));
2905: }
2906: if ($osrc ne $nsrc || (!$nwidth && !$nheight)) {
2907: # changed image or no size specified,
2908: # if they didn't explicitly change the
2909: # width or height use the ones from the image
2910: if ($iwidth && $iheight) {
2911: if ($owidth == $nwidth || (!$nwidth && !$nheight)) {
2912: $token->[2]{'width'} = $iwidth;$ctag=1;
2913: }
2914: if ($oheight == $nheight || (!$nwidth && !$nheight)) {
2915: $token->[2]{'height'}=$iheight;$ctag=1;
1.186 albertel 2916: }
2917: }
2918: }
1.210 albertel 2919: my ($cwidth,$cheight)=($token->[2]{'width'},$token->[2]{'height'});
2920: # if we don't have a width or height
2921: if ($iwidth && $cwidth && !$cheight) {
2922: $token->[2]{'height'}=int(($cwidth/$iwidth)*$iheight);$ctag=1;
2923: }
2924: if ($iheight && $cheight && !$cwidth) {
2925: $token->[2]{'width'}=int(($cheight/$iheight)*$iwidth);$ctag=1;
2926: }
2927: if ($ctag) {$currentstring=&Apache::edit::rebuild_tag($token);}
1.122 albertel 2928: }
1.261 foxr 2929:
1.122 albertel 2930: return $currentstring;
2931: }
2932:
2933: sub end_img {
2934: my ($target,$token) = @_;
2935: my $currentstring = '';
1.325 albertel 2936: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 2937: $currentstring = $token->[2];
2938: } elsif ($target eq 'tex') {
2939: $currentstring = '';
2940: }
2941: return $currentstring;
2942: }
2943:
1.181 sakharuk 2944: #-- <applet> tag (end tag required)
1.122 albertel 2945: sub start_applet {
2946: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2947:
2948: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,undef,1);
1.290 albertel 2949: &Apache::lonxml::extlink($code);
1.122 albertel 2950: my $archive=&Apache::lonxml::get_param('archive',$parstack,$safeeval,
2951: undef,1);
1.290 albertel 2952: &Apache::lonxml::extlink($archive);
1.122 albertel 2953: my $currentstring = '';
1.325 albertel 2954: if ($target eq 'web' || $target eq 'webgrade') {
1.267 albertel 2955: if ($env{'browser.appletsuppress'} ne 'on') {
1.250 albertel 2956: $currentstring = &Apache::lonenc::encrypt_ref($token,
2957: {'code'=>$code,
2958: 'archive'=>$archive}
2959: );
1.122 albertel 2960: } else {
2961: my $alttag= &Apache::lonxml::get_param('alt',$parstack,
2962: $safeeval,undef,1);
2963: unless ($alttag) {
2964: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
2965: $code);
1.44 sakharuk 2966: }
1.122 albertel 2967: $currentstring='[APPLET: '.$alttag.']';
1.1 sakharuk 2968: }
1.122 albertel 2969: } elsif ($target eq 'tex') {
1.177 albertel 2970: my $alttag= &Apache::lonxml::get_param('alt',$parstack,
2971: $safeeval,undef,1);
2972: unless ($alttag) {
2973: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,
2974: undef,1);
2975: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
2976: $code);
1.175 sakharuk 2977: }
1.177 albertel 2978: $currentstring.='\begin{center} \fbox{Java Applet: '.$alttag.
2979: '.}\end{center}';
1.122 albertel 2980: }
2981: return $currentstring;
2982: }
2983:
2984: sub end_applet {
2985: my ($target,$token) = @_;
2986: my $currentstring = '';
1.325 albertel 2987: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 2988: $currentstring = $token->[2];
2989: } elsif ($target eq 'tex') {
2990: }
2991: return $currentstring;
2992: }
2993:
1.181 sakharuk 2994: #-- <embed> tag (end tag optional/required)
1.122 albertel 2995: sub start_embed {
2996: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2997: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
1.290 albertel 2998: &Apache::lonxml::extlink($src);
1.122 albertel 2999: my $currentstring = '';
1.325 albertel 3000: if ($target eq 'web' || $target eq 'webgrade') {
1.267 albertel 3001: if ($env{'browser.embedsuppress'} ne 'on') {
1.250 albertel 3002: $currentstring=&Apache::lonenc::encrypt_ref($token,{'src'=>$src});
1.122 albertel 3003: } else {
3004: my $alttag=&Apache::lonxml::get_param
3005: ('alt',$parstack,$safeeval,undef,1);
3006: unless ($alttag) {
3007: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
1.42 albertel 3008: }
1.122 albertel 3009: $currentstring='[EMBED: '.$alttag.']';
1.10 www 3010: }
1.122 albertel 3011: } elsif ($target eq 'tex') {
3012: }
3013: return $currentstring;
3014: }
3015:
3016: sub end_embed {
3017: my ($target,$token) = @_;
3018: my $currentstring = '';
1.325 albertel 3019: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3020: $currentstring = $token->[2];
1.175 sakharuk 3021: } elsif ($target eq 'tex') {
1.122 albertel 3022: }
3023: return $currentstring;
3024: }
3025:
1.181 sakharuk 3026: #-- <param> tag (end tag forbidden)
1.122 albertel 3027: sub start_param {
3028: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.290 albertel 3029: if (&Apache::lonxml::get_param('name',$parstack,
3030: $safeeval,undef,1)=~/^cabbase$/i) {
3031: my $value=&Apache::lonxml::get_param('value',$parstack,
3032: $safeeval,undef,1);
3033: &Apache::lonxml::extlink($value);
3034: }
3035:
3036: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
3037: &Apache::lonxml::extlink($src);
1.122 albertel 3038: my $currentstring = '';
1.325 albertel 3039: if ($target eq 'web' || $target eq 'webgrade') {
1.250 albertel 3040: my %toconvert;
3041: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
3042: if ($src) { $toconvert{'src'}= $src; }
3043: my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval,
3044: undef,1);
1.251 albertel 3045: if ($name=~/^cabbase$/i) {
3046: $toconvert{'value'}=&Apache::lonxml::get_param('value',$parstack,
3047: $safeeval,undef,1);
3048: }
1.250 albertel 3049: $currentstring = &Apache::lonenc::encrypt_ref($token,\%toconvert);
1.122 albertel 3050: } elsif ($target eq 'tex') {
3051: }
3052: return $currentstring;
3053: }
3054:
3055: sub end_param {
3056: my ($target,$token) = @_;
3057: my $currentstring = '';
1.325 albertel 3058: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3059: $currentstring = $token->[2];
3060: } elsif ($target eq 'tex') {
3061: }
3062: return $currentstring;
3063: }
3064:
3065: #-- <allow> tag
3066: sub start_allow {
3067: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3068: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
1.290 albertel 3069: &Apache::lonxml::extlink($src);
3070:
1.241 albertel 3071: if ($target eq 'tex') { &image_replication($src); }
1.122 albertel 3072: my $result;
3073: if ($target eq 'edit') {
3074: $result .=&Apache::edit::tag_start($target,$token);
3075: $result .=&Apache::edit::text_arg('File Spec:','src',$token,70);
3076: $result .=&Apache::edit::end_row();#.&Apache::edit::start_spanning_row();
3077: } elsif ($target eq 'modified') {
3078: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
3079: $safeeval,'src');
3080: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
3081: }
3082: return $result;
3083: }
3084:
3085: sub end_allow {
3086: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3087: if ( $target eq 'edit') { return (&Apache::edit::end_table()); }
3088: return '';
3089: }
1.119 www 3090:
1.181 sakharuk 3091: #-- Frames (end tag required)
3092: #-- <frameset>
1.122 albertel 3093: sub start_frameset {
3094: my ($target,$token) = @_;
1.277 foxr 3095: my $currentstring = ''; # Close any pending para.
1.325 albertel 3096: if ($target eq 'web' || $target eq 'webgrade') {
1.328 albertel 3097: $currentstring =
3098: &Apache::loncommon::start_page($Apache::londefdef::title,
3099: $Apache::londefdef::head,
3100: {'add_entries' => $token->[2],
3101: 'no_title' => 1,
3102: 'force_register' => 1,
3103: 'frameset' => 1,});
3104:
1.122 albertel 3105: }
3106: return $currentstring;
3107: }
3108:
3109: sub end_frameset {
3110: my ($target,$token) = @_;
3111: my $currentstring = '';
1.325 albertel 3112: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3113: $currentstring = $token->[2];
3114: }
3115: return $currentstring;
3116: }
1.162 sakharuk 3117:
1.181 sakharuk 3118: #-- <xmp> (end tag required)
1.162 sakharuk 3119: sub start_xmp {
3120: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3121: my $currentstring = '';
1.325 albertel 3122: if ($target eq 'web' || $target eq 'webgrade') {
1.162 sakharuk 3123: $currentstring .= $token->[4];
3124: } elsif ($target eq 'tex') {
3125: $currentstring .= '\begin{verbatim}';
3126: }
3127: return $currentstring;
3128: }
3129:
3130: sub end_xmp {
3131: my ($target,$token) = @_;
3132: my $currentstring = '';
1.325 albertel 3133: if ($target eq 'web' || $target eq 'webgrade') {
1.162 sakharuk 3134: $currentstring .= $token->[2];
3135: } elsif ($target eq 'tex') {
3136: $currentstring .= '\end{verbatim}';
3137: }
3138: return $currentstring;
3139: }
3140:
1.181 sakharuk 3141: #-- <pre> (end tag required)
1.122 albertel 3142: sub start_pre {
1.126 sakharuk 3143: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.279 foxr 3144: my $currentstring = &end_p(); # close off pending <p>
1.325 albertel 3145: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3146: $currentstring .= $token->[4];
3147: } elsif ($target eq 'tex') {
1.136 sakharuk 3148: $currentstring .= '\begin{verbatim}';
1.319 albertel 3149: &Apache::lonxml::disable_LaTeX_substitutions();
1.122 albertel 3150: }
3151: return $currentstring;
3152: }
3153:
3154: sub end_pre {
3155: my ($target,$token) = @_;
3156: my $currentstring = '';
1.325 albertel 3157: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3158: $currentstring .= $token->[2];
3159: } elsif ($target eq 'tex') {
1.136 sakharuk 3160: $currentstring .= '\end{verbatim}';
1.319 albertel 3161: &Apache::lonxml::enable_LaTeX_substitutions();
1.122 albertel 3162: }
3163: return $currentstring;
3164: }
3165:
3166: #-- <insert>
3167: sub start_insert {
3168: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3169: my $currentstring = '';
1.325 albertel 3170: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3171: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
3172: $currentstring .= '<b>'.$display.'</b>';;
3173: }
3174: return $currentstring;
3175: }
3176:
3177: sub end_insert {
3178: my ($target,$token) = @_;
3179: my $currentstring = '';
1.325 albertel 3180: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3181: $currentstring .= '';
3182: }
3183: return $currentstring;
3184: }
3185:
3186: #-- <externallink>
3187: sub start_externallink {
3188: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3189: my $currentstring = '';
1.325 albertel 3190: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3191: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
3192: $currentstring .= '<b>'.$display.'</b>';;
3193: }
3194: return $currentstring;
3195: }
3196:
3197: sub end_externallink {
3198: my ($target,$token) = @_;
3199: my $currentstring = '';
1.325 albertel 3200: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3201: $currentstring .= '';
3202: }
3203: return $currentstring;
3204: }
3205:
3206: #-- <blankspace heigth="">
3207: sub start_blankspace {
3208: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.279 foxr 3209: my $currentstring = &end_p(); # closes off any unclosed <p>
1.122 albertel 3210: if ($target eq 'tex') {
3211: my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval,undef,1);
3212: $currentstring .= '\vskip '.$howmuch.' ';
3213: }
3214: return $currentstring;
3215: }
3216:
3217: sub end_blankspace {
3218: my ($target,$token) = @_;
3219: my $currentstring = '';
3220: if ($target eq 'tex') {
3221: $currentstring .= '';
3222: }
3223: return $currentstring;
3224: }
3225:
1.181 sakharuk 3226: #-- <abbr> tag (end tag required)
1.122 albertel 3227: sub start_abbr {
3228: my ($target,$token) = @_;
3229: my $currentstring = '';
1.325 albertel 3230: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3231: $currentstring = $token->[4];
3232: }
3233: return $currentstring;
3234: }
3235:
3236: sub end_abbr {
3237: my ($target,$token) = @_;
3238: my $currentstring = '';
1.325 albertel 3239: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3240: $currentstring = $token->[2];
3241: }
3242: return $currentstring;
3243: }
3244:
1.181 sakharuk 3245: #-- <acronym> tag (end tag required)
1.122 albertel 3246: sub start_acronym {
3247: my ($target,$token) = @_;
3248: my $currentstring = '';
1.325 albertel 3249: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3250: $currentstring = $token->[4];
3251: }
3252: return $currentstring;
3253: }
3254:
3255: sub end_acronym {
3256: my ($target,$token) = @_;
3257: my $currentstring = '';
1.325 albertel 3258: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3259: $currentstring = $token->[2];
3260: }
3261: return $currentstring;
3262: }
3263:
1.181 sakharuk 3264: #-- <area> tag (end tag forbidden)
1.122 albertel 3265: sub start_area {
3266: my ($target,$token) = @_;
3267: my $currentstring = '';
1.325 albertel 3268: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3269: $currentstring = $token->[4];
3270: }
3271: return $currentstring;
3272: }
3273:
3274: sub end_area {
3275: my ($target,$token) = @_;
3276: my $currentstring = '';
1.325 albertel 3277: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3278: $currentstring = $token->[2];
3279: }
3280: return $currentstring;
3281: }
3282:
1.181 sakharuk 3283: #-- <base> tag (end tag forbidden)
1.122 albertel 3284: sub start_base {
3285: my ($target,$token) = @_;
3286: my $currentstring = '';
1.325 albertel 3287: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3288: $currentstring = $token->[4];
1.161 sakharuk 3289: }
1.122 albertel 3290: return $currentstring;
3291: }
3292:
3293: sub end_base {
3294: my ($target,$token) = @_;
3295: my $currentstring = '';
1.325 albertel 3296: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3297: $currentstring = $token->[2];
3298: }
3299: return $currentstring;
3300: }
3301:
1.181 sakharuk 3302: #-- <bdo> tag (end tag required)
1.122 albertel 3303: sub start_bdo {
3304: my ($target,$token) = @_;
3305: my $currentstring = '';
1.325 albertel 3306: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3307: $currentstring = $token->[4];
3308: }
3309: return $currentstring;
3310: }
3311:
3312: sub end_bdo {
3313: my ($target,$token) = @_;
3314: my $currentstring = '';
1.325 albertel 3315: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3316: $currentstring = $token->[2];
3317: }
3318: return $currentstring;
3319: }
3320:
1.181 sakharuk 3321: #-- <bgsound> tag (end tag optional)
1.122 albertel 3322: sub start_bgsound {
3323: my ($target,$token) = @_;
3324: my $currentstring = '';
1.325 albertel 3325: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3326: $currentstring = $token->[4];
3327: }
3328: return $currentstring;
3329: }
3330:
3331: sub end_bgsound {
3332: my ($target,$token) = @_;
3333: my $currentstring = '';
1.325 albertel 3334: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3335: $currentstring = $token->[2];
3336: }
3337: return $currentstring;
3338: }
3339:
1.181 sakharuk 3340: #-- <blink> tag (end tag required)
1.122 albertel 3341: sub start_blink {
3342: my ($target,$token) = @_;
3343: my $currentstring = '';
1.325 albertel 3344: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3345: $currentstring = $token->[4];
3346: }
3347: return $currentstring;
3348: }
3349:
3350: sub end_blink {
3351: my ($target,$token) = @_;
3352: my $currentstring = '';
1.325 albertel 3353: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3354: $currentstring = $token->[2];
3355: }
3356: return $currentstring;
3357: }
3358:
1.181 sakharuk 3359: #-- <blockquote> tag (end tag required)
1.122 albertel 3360: sub start_blockquote {
3361: my ($target,$token) = @_;
1.279 foxr 3362: my $currentstring = &end_p(); # Close any unclosed <p>
1.325 albertel 3363: if ($target eq 'web' || $target eq 'webgrade') {
1.277 foxr 3364: $currentstring .= $token->[4];
1.122 albertel 3365: }
3366: return $currentstring;
3367: }
3368:
3369: sub end_blockquote {
3370: my ($target,$token) = @_;
3371: my $currentstring = '';
1.325 albertel 3372: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3373: $currentstring = $token->[2];
3374: }
3375: return $currentstring;
3376: }
3377:
1.181 sakharuk 3378: #-- <button> tag (end tag required)
1.122 albertel 3379: sub start_button {
3380: my ($target,$token) = @_;
3381: my $currentstring = '';
1.325 albertel 3382: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3383: $currentstring = $token->[4];
3384: }
3385: return $currentstring;
3386: }
3387:
3388: sub end_button {
3389: my ($target,$token) = @_;
3390: my $currentstring = '';
1.325 albertel 3391: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3392: $currentstring = $token->[2];
3393: }
3394: return $currentstring;
3395: }
3396:
1.181 sakharuk 3397: #-- <caption> tag (end tag required)
1.122 albertel 3398: sub start_caption {
3399: my ($target,$token) = @_;
3400: my $currentstring = '';
1.325 albertel 3401: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3402: $currentstring = $token->[4];
3403: }
3404: return $currentstring;
3405: }
3406:
3407: sub end_caption {
3408: my ($target,$token) = @_;
3409: my $currentstring = '';
1.325 albertel 3410: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3411: $currentstring = $token->[2];
3412: }
3413: return $currentstring;
3414: }
3415:
1.181 sakharuk 3416: #-- <col> tag (end tag forbdden)
1.122 albertel 3417: sub start_col {
3418: my ($target,$token) = @_;
3419: my $currentstring = '';
1.325 albertel 3420: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3421: $currentstring = $token->[4];
3422: }
3423: return $currentstring;
3424: }
3425:
3426: sub end_col {
3427: my ($target,$token) = @_;
3428: my $currentstring = '';
1.325 albertel 3429: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3430: $currentstring = $token->[2];
3431: }
3432: return $currentstring;
3433: }
3434:
1.181 sakharuk 3435: #-- <colgroup> tag (end tag optional)
1.122 albertel 3436: sub start_colgroup {
3437: my ($target,$token) = @_;
3438: my $currentstring = '';
1.325 albertel 3439: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3440: $currentstring = $token->[4];
3441: }
3442: return $currentstring;
3443: }
3444:
3445: sub end_colgroup {
3446: my ($target,$token) = @_;
3447: my $currentstring = '';
1.325 albertel 3448: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3449: $currentstring = $token->[2];
3450: }
3451: return $currentstring;
3452: }
3453:
1.181 sakharuk 3454: #-- <del> tag (end tag required)
1.122 albertel 3455: sub start_del {
3456: my ($target,$token) = @_;
3457: my $currentstring = '';
1.325 albertel 3458: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3459: $currentstring = $token->[4];
3460: }
3461: return $currentstring;
3462: }
3463:
3464: sub end_del {
3465: my ($target,$token) = @_;
3466: my $currentstring = '';
1.325 albertel 3467: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3468: $currentstring = $token->[2];
3469: }
3470: return $currentstring;
3471: }
3472:
1.181 sakharuk 3473: #-- <fieldset> tag (end tag required)
1.122 albertel 3474: sub start_fieldset {
3475: my ($target,$token) = @_;
3476: my $currentstring = '';
1.325 albertel 3477: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3478: $currentstring = $token->[4];
3479: }
3480: return $currentstring;
3481: }
3482:
3483: sub end_fieldset {
3484: my ($target,$token) = @_;
3485: my $currentstring = '';
1.325 albertel 3486: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3487: $currentstring = $token->[2];
3488: }
3489: return $currentstring;
3490: }
3491:
1.181 sakharuk 3492: #-- <frame> tag (end tag forbidden)
1.122 albertel 3493: sub start_frame {
3494: my ($target,$token) = @_;
3495: my $currentstring = '';
1.325 albertel 3496: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3497: $currentstring = $token->[4];
3498: }
3499: return $currentstring;
3500: }
3501:
3502: sub end_frame {
3503: my ($target,$token) = @_;
3504: my $currentstring = '';
1.325 albertel 3505: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3506: $currentstring = $token->[2];
3507: }
3508: return $currentstring;
3509: }
3510:
1.181 sakharuk 3511: #-- <iframe> tag (end tag required)
1.122 albertel 3512: sub start_iframe {
3513: my ($target,$token) = @_;
3514: my $currentstring = '';
1.325 albertel 3515: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3516: $currentstring = $token->[4];
3517: }
3518: return $currentstring;
3519: }
3520:
3521: sub end_iframe {
3522: my ($target,$token) = @_;
3523: my $currentstring = '';
1.325 albertel 3524: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3525: $currentstring = $token->[2];
3526: }
3527: return $currentstring;
3528: }
3529:
1.181 sakharuk 3530: #-- <ins> tag (end tag required)
1.122 albertel 3531: sub start_ins {
3532: my ($target,$token) = @_;
3533: my $currentstring = '';
1.325 albertel 3534: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3535: $currentstring = $token->[4];
3536: }
3537: return $currentstring;
3538: }
3539:
3540: sub end_ins {
3541: my ($target,$token) = @_;
3542: my $currentstring = '';
1.325 albertel 3543: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3544: $currentstring = $token->[2];
3545: }
3546: return $currentstring;
3547: }
3548:
1.181 sakharuk 3549: #-- <isindex> tag (end tag forbidden)
1.122 albertel 3550: sub start_isindex {
3551: my ($target,$token) = @_;
3552: my $currentstring = '';
1.325 albertel 3553: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3554: $currentstring = $token->[4];
3555: }
3556: return $currentstring;
3557: }
3558:
3559: sub end_isindex {
3560: my ($target,$token) = @_;
3561: my $currentstring = '';
1.325 albertel 3562: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3563: $currentstring = $token->[2];
3564: }
3565: return $currentstring;
3566: }
3567:
1.181 sakharuk 3568: #-- <keygen> tag (end tag forbidden)
1.122 albertel 3569: sub start_keygen {
3570: my ($target,$token) = @_;
3571: my $currentstring = '';
1.325 albertel 3572: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3573: $currentstring = $token->[4];
3574: }
3575: return $currentstring;
3576: }
3577:
3578: sub end_keygen {
3579: my ($target,$token) = @_;
3580: my $currentstring = '';
1.325 albertel 3581: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3582: $currentstring = $token->[2];
3583: }
3584: return $currentstring;
3585: }
3586:
3587: #-- <label> tag
3588: sub start_label {
3589: my ($target,$token) = @_;
3590: my $currentstring = '';
1.325 albertel 3591: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3592: $currentstring = $token->[4];
3593: }
3594: return $currentstring;
3595: }
3596:
3597: sub end_label {
3598: my ($target,$token) = @_;
3599: my $currentstring = '';
1.325 albertel 3600: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3601: $currentstring = $token->[2];
3602: }
3603: return $currentstring;
3604: }
3605:
1.181 sakharuk 3606: #-- <layer> tag (end tag required)
1.122 albertel 3607: sub start_layer {
3608: my ($target,$token) = @_;
3609: my $currentstring = '';
1.325 albertel 3610: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3611: $currentstring = $token->[4];
3612: }
3613: return $currentstring;
3614: }
3615:
3616: sub end_layer {
3617: my ($target,$token) = @_;
3618: my $currentstring = '';
1.325 albertel 3619: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3620: $currentstring = $token->[2];
3621: }
3622: return $currentstring;
3623: }
3624:
1.181 sakharuk 3625: #-- <legend> tag (end tag required)
1.122 albertel 3626: sub start_legend {
3627: my ($target,$token) = @_;
3628: my $currentstring = '';
1.325 albertel 3629: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3630: $currentstring = $token->[4];
3631: }
3632: return $currentstring;
3633: }
3634:
3635: sub end_legend {
3636: my ($target,$token) = @_;
3637: my $currentstring = '';
1.325 albertel 3638: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3639: $currentstring = $token->[2];
3640: }
3641: return $currentstring;
3642: }
3643:
1.181 sakharuk 3644: #-- <link> tag (end tag forbidden)
1.122 albertel 3645: sub start_link {
1.292 albertel 3646: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1.122 albertel 3647: my $currentstring = '';
1.324 albertel 3648: if ($target eq 'web' || $target eq 'webgrade') {
1.291 albertel 3649: my $href=&Apache::lonxml::get_param('href',$parstack,$safeeval,
3650: undef,1);
3651: &Apache::lonxml::extlink($href);
1.122 albertel 3652: $currentstring = $token->[4];
3653: }
3654: return $currentstring;
3655: }
3656:
3657: sub end_link {
3658: my ($target,$token) = @_;
3659: my $currentstring = '';
1.325 albertel 3660: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3661: $currentstring = $token->[2];
3662: }
3663: return $currentstring;
3664: }
3665:
1.181 sakharuk 3666: #-- <marquee> tag (end tag optional)
1.122 albertel 3667: sub start_marquee {
3668: my ($target,$token) = @_;
3669: my $currentstring = '';
1.325 albertel 3670: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3671: $currentstring = $token->[4];
3672: }
3673: return $currentstring;
3674: }
3675:
3676: sub end_marquee {
3677: my ($target,$token) = @_;
3678: my $currentstring = '';
1.325 albertel 3679: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3680: $currentstring = $token->[2];
3681: }
3682: return $currentstring;
3683: }
3684:
1.179 sakharuk 3685: #-- <multicol> tag (end tag required)
3686: sub start_multicol {
1.122 albertel 3687: my ($target,$token) = @_;
1.279 foxr 3688: my $currentstring = &end_p(); # Close any pending <p>
1.325 albertel 3689: if ($target eq 'web' || $target eq 'webgrade') {
1.277 foxr 3690: $currentstring .= $token->[4];
1.122 albertel 3691: }
3692: return $currentstring;
3693: }
3694:
1.179 sakharuk 3695: sub end_multicol {
1.122 albertel 3696: my ($target,$token) = @_;
3697: my $currentstring = '';
1.325 albertel 3698: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3699: $currentstring = $token->[2];
3700: }
3701: return $currentstring;
3702: }
3703:
1.179 sakharuk 3704: #-- <nobr> tag (end tag required)
1.122 albertel 3705: sub start_nobr {
3706: my ($target,$token) = @_;
3707: my $currentstring = '';
1.325 albertel 3708: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3709: $currentstring = $token->[4];
1.179 sakharuk 3710: } elsif ($target eq 'tex') {
3711: $currentstring='\mbox{';
3712: }
1.122 albertel 3713: return $currentstring;
3714: }
3715:
3716: sub end_nobr {
3717: my ($target,$token) = @_;
3718: my $currentstring = '';
1.325 albertel 3719: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3720: $currentstring = $token->[2];
1.179 sakharuk 3721: } elsif ($target eq 'tex') {
3722: $currentstring='}';
3723: }
1.122 albertel 3724: return $currentstring;
3725: }
3726:
1.179 sakharuk 3727: #-- <noembed> tag (end tag required)
1.122 albertel 3728: sub start_noembed {
3729: my ($target,$token) = @_;
3730: my $currentstring = '';
1.325 albertel 3731: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3732: $currentstring = $token->[4];
3733: }
3734: return $currentstring;
3735: }
3736:
3737: sub end_noembed {
3738: my ($target,$token) = @_;
3739: my $currentstring = '';
1.325 albertel 3740: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3741: $currentstring = $token->[2];
3742: }
3743: return $currentstring;
3744: }
3745:
1.179 sakharuk 3746: #-- <noframes> tag (end tag required)
1.122 albertel 3747: sub start_noframes {
3748: my ($target,$token) = @_;
3749: my $currentstring = '';
1.325 albertel 3750: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3751: $currentstring = $token->[4];
3752: }
3753: return $currentstring;
3754: }
3755:
3756: sub end_noframes {
3757: my ($target,$token) = @_;
3758: my $currentstring = '';
1.325 albertel 3759: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3760: $currentstring = $token->[2];
3761: }
3762: return $currentstring;
3763: }
3764:
1.179 sakharuk 3765: #-- <nolayer> tag (end tag required)
1.122 albertel 3766: sub start_nolayer {
3767: my ($target,$token) = @_;
3768: my $currentstring = '';
1.325 albertel 3769: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3770: $currentstring = $token->[4];
3771: }
3772: return $currentstring;
3773: }
3774:
3775: sub end_nolayer {
3776: my ($target,$token) = @_;
3777: my $currentstring = '';
1.325 albertel 3778: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3779: $currentstring = $token->[2];
3780: }
3781: return $currentstring;
3782: }
3783:
1.179 sakharuk 3784: #-- <noscript> tag (end tag required)
1.122 albertel 3785: sub start_noscript {
3786: my ($target,$token) = @_;
3787: my $currentstring = '';
1.325 albertel 3788: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3789: $currentstring = $token->[4];
3790: }
3791: return $currentstring;
3792: }
3793:
3794: sub end_noscript {
3795: my ($target,$token) = @_;
3796: my $currentstring = '';
1.325 albertel 3797: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3798: $currentstring = $token->[2];
3799: }
3800: return $currentstring;
3801: }
3802:
1.179 sakharuk 3803: #-- <object> tag (end tag required)
1.122 albertel 3804: sub start_object {
3805: my ($target,$token) = @_;
3806: my $currentstring = '';
1.325 albertel 3807: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3808: $currentstring = $token->[4];
3809: }
3810: return $currentstring;
3811: }
3812:
3813: sub end_object {
3814: my ($target,$token) = @_;
3815: my $currentstring = '';
1.325 albertel 3816: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3817: $currentstring = $token->[2];
3818: }
3819: return $currentstring;
3820: }
3821:
1.179 sakharuk 3822: #-- <optgroup> tag (end tag required)
1.122 albertel 3823: sub start_optgroup {
3824: my ($target,$token) = @_;
3825: my $currentstring = '';
1.325 albertel 3826: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3827: $currentstring = $token->[4];
3828: }
3829: return $currentstring;
3830: }
3831:
3832: sub end_optgroup {
3833: my ($target,$token) = @_;
3834: my $currentstring = '';
1.325 albertel 3835: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3836: $currentstring = $token->[2];
3837: }
3838: return $currentstring;
3839: }
3840:
1.179 sakharuk 3841: #-- <samp> tag (end tag required)
1.122 albertel 3842: sub start_samp {
3843: my ($target,$token) = @_;
3844: my $currentstring = '';
1.325 albertel 3845: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3846: $currentstring = $token->[4];
1.179 sakharuk 3847: } elsif ($target eq 'tex') {
3848: $currentstring='\texttt{';
3849: }
1.122 albertel 3850: return $currentstring;
3851: }
3852:
3853: sub end_samp {
3854: my ($target,$token) = @_;
3855: my $currentstring = '';
1.325 albertel 3856: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3857: $currentstring = $token->[2];
1.179 sakharuk 3858: } elsif ($target eq 'tex') {
3859: $currentstring='}';
3860: }
1.122 albertel 3861: return $currentstring;
3862: }
3863:
3864: #-- <server> tag
3865: sub start_server {
3866: my ($target,$token) = @_;
3867: my $currentstring = '';
1.325 albertel 3868: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3869: $currentstring = $token->[4];
3870: }
3871: return $currentstring;
3872: }
3873:
3874: sub end_server {
3875: my ($target,$token) = @_;
3876: my $currentstring = '';
1.325 albertel 3877: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3878: $currentstring = $token->[2];
3879: }
3880: return $currentstring;
3881: }
3882:
1.179 sakharuk 3883: #-- <spacer> tag (end tag forbidden)
1.122 albertel 3884: sub start_spacer {
3885: my ($target,$token) = @_;
1.279 foxr 3886: my $currentstring = &end_p(); # Close off any open <p> tag.
1.325 albertel 3887: if ($target eq 'web' || $target eq 'webgrade') {
1.277 foxr 3888: $currentstring .= $token->[4];
1.122 albertel 3889: }
3890: return $currentstring;
3891: }
3892:
3893: sub end_spacer {
3894: my ($target,$token) = @_;
3895: my $currentstring = '';
1.325 albertel 3896: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3897: $currentstring = $token->[2];
3898: }
3899: return $currentstring;
3900: }
3901:
1.179 sakharuk 3902: #-- <span> tag (end tag required)
1.122 albertel 3903: sub start_span {
3904: my ($target,$token) = @_;
3905: my $currentstring = '';
1.325 albertel 3906: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3907: $currentstring = $token->[4];
3908: }
3909: return $currentstring;
3910: }
3911:
3912: sub end_span {
3913: my ($target,$token) = @_;
3914: my $currentstring = '';
1.325 albertel 3915: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3916: $currentstring = $token->[2];
3917: }
3918: return $currentstring;
3919: }
3920:
1.179 sakharuk 3921: #-- <tbody> tag (end tag optional)
1.122 albertel 3922: sub start_tbody {
3923: my ($target,$token) = @_;
3924: my $currentstring = '';
1.325 albertel 3925: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3926: $currentstring = $token->[4];
3927: }
3928: return $currentstring;
3929: }
3930:
3931: sub end_tbody {
3932: my ($target,$token) = @_;
3933: my $currentstring = '';
1.325 albertel 3934: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3935: $currentstring = $token->[2];
3936: }
3937: return $currentstring;
3938: }
3939:
1.166 sakharuk 3940: #-- <tfoot> tag (end tag optional)
1.122 albertel 3941: sub start_tfoot {
3942: my ($target,$token) = @_;
3943: my $currentstring = '';
1.325 albertel 3944: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3945: $currentstring = $token->[4];
3946: }
3947: return $currentstring;
3948: }
3949:
3950: sub end_tfoot {
3951: my ($target,$token) = @_;
3952: my $currentstring = '';
1.325 albertel 3953: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3954: $currentstring = $token->[2];
3955: }
3956: return $currentstring;
3957: }
3958:
1.166 sakharuk 3959: #-- <thead> tag (end tag optional)
1.122 albertel 3960: sub start_thead {
3961: my ($target,$token) = @_;
3962: my $currentstring = '';
1.325 albertel 3963: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3964: $currentstring = $token->[4];
3965: }
3966: return $currentstring;
3967: }
1.10 www 3968:
1.122 albertel 3969: sub end_thead {
3970: my ($target,$token) = @_;
3971: my $currentstring = '';
1.325 albertel 3972: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3973: $currentstring = $token->[2];
3974: }
3975: return $currentstring;
3976: }
1.119 www 3977:
1.122 albertel 3978: #-- <var> tag
3979: sub start_var {
1.44 sakharuk 3980: my ($target,$token) = @_;
3981: my $currentstring = '';
1.325 albertel 3982: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 3983: $currentstring = $token->[4];
1.163 sakharuk 3984: } elsif ($target eq 'tex') {
3985: $currentstring = '\textit{';
3986: }
1.44 sakharuk 3987: return $currentstring;
3988: }
1.10 www 3989:
1.122 albertel 3990: sub end_var {
3991: my ($target,$token) = @_;
1.44 sakharuk 3992: my $currentstring = '';
1.325 albertel 3993: if ($target eq 'web' || $target eq 'webgrade') {
1.163 sakharuk 3994: $currentstring = $token->[2];
3995: } elsif ($target eq 'tex') {
3996: $currentstring = '}';
1.44 sakharuk 3997: }
3998: return $currentstring;
3999: }
1.119 www 4000:
1.163 sakharuk 4001: #-- <wbr> tag (end tag forbidden)
1.122 albertel 4002: sub start_wbr {
4003: my ($target,$token) = @_;
4004: my $currentstring = '';
1.325 albertel 4005: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 4006: $currentstring = $token->[4];
4007: }
4008: return $currentstring;
1.98 albertel 4009: }
4010:
1.122 albertel 4011: sub end_wbr {
4012: my ($target,$token) = @_;
4013: my $currentstring = '';
1.325 albertel 4014: if ($target eq 'web' || $target eq 'webgrade') {
1.122 albertel 4015: $currentstring = $token->[2];
4016: }
4017: return $currentstring;
1.98 albertel 4018: }
1.134 sakharuk 4019:
4020: #-- <hideweboutput> tag
4021: sub start_hideweboutput {
4022: my ($target,$token) = @_;
1.325 albertel 4023: if ($target eq 'web' || $target eq 'webgrade') {
1.134 sakharuk 4024: &Apache::lonxml::startredirection();
4025: }
4026: return '';
4027: }
4028:
4029: sub end_hideweboutput {
4030: my ($target,$token) = @_;
4031: my $currentstring = '';
1.325 albertel 4032: if ($target eq 'web' || $target eq 'webgrade') {
1.134 sakharuk 4033: $currentstring = &Apache::lonxml::endredirection();
4034: }
4035: return '';
4036: }
4037:
1.94 sakharuk 4038:
4039: sub image_replication {
4040: my $src = shift;
1.187 albertel 4041: if (not -e $src) { &Apache::lonnet::repcopy($src); }
4042: #replicates eps or ps
4043: my $epssrc = my $pssrc = $src;
4044: $epssrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i;
4045: $pssrc =~ s/\.(gif|jpg|jpeg|png)$/.ps/i;
4046: if (not -e $epssrc && not -e $pssrc) {
4047: my $result=&Apache::lonnet::repcopy($epssrc);
1.264 raeburn 4048: if ($result ne 'ok') { &Apache::lonnet::repcopy($pssrc); }
1.94 sakharuk 4049: }
4050: return '';
1.195 sakharuk 4051: }
1.275 foxr 4052: #
4053: # Get correct sizing parameter for an image given
4054: # it's initial ht. and wid. This allows sizing of
4055: # images that are generated on-the-fly (e.g. gnuplot)
4056: # as well as serving as a utility for image_size.
4057: #
4058: # Parameter:
4059: # height_param
4060: # width_param - Initial picture dimensions.
4061: # scaling - A scale factor.
4062: # parstack, - the current stack of tag attributes
4063: # from the xml parser
4064: # safeeval, - pointer to the safespace
4065: # depth, - from what level in the stack to look for attributes
4066: # (assumes -1 if unspecified)
4067: # cis - look for attrubutes case insensitively
4068: # (assumes false)
4069: #
4070: # Returns:
4071: # height, width - new dimensions.
4072: #
4073: sub resize_image {
4074: my ($height_param, $width_param, $scaling,
4075: $parstack, $safeeval, $depth, $cis) = @_;
4076:
4077: # First apply the scaling...
1.271 foxr 4078:
1.275 foxr 4079: $height_param = $height_param * $scaling;
4080: $width_param = $width_param * $scaling;
1.261 foxr 4081:
1.197 sakharuk 4082: #do we have any specified LaTeX size of the picture?
1.261 foxr 4083: my $toget='TeXwidth';
4084: if ($cis) {
4085: $toget=lc($toget);
4086: }
1.256 albertel 4087: my $TeXwidth = &Apache::lonxml::get_param($toget,$parstack,
4088: $safeeval,$depth,$cis);
4089: $toget='TeXheight'; if ($cis) { $toget=lc($toget); }
4090: my $TeXheight = &Apache::lonxml::get_param($toget,$parstack,
4091: $safeeval,$depth,$cis);
1.197 sakharuk 4092: #do we have any specified web size of the picture?
4093: my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval,
1.256 albertel 4094: $depth,1);
4095: if ($TeXwidth) {
1.252 matthew 4096: my $old_width_param=$width_param;
1.197 sakharuk 4097: if ($TeXwidth=~/(\d+)\s*\%/) {
1.267 albertel 4098: $width_param = $1*$env{'form.textwidth'}/100;
1.197 sakharuk 4099: } else {
4100: $width_param = $TeXwidth;
4101: }
1.266 albertel 4102: if ($TeXheight) {
4103: $height_param = $TeXheight;
4104: } elsif ($old_width_param) {
4105: $height_param=$TeXwidth/$old_width_param*$height_param;
4106: }
1.256 albertel 4107: } elsif ($TeXheight) {
1.248 foxr 4108: $height_param = $TeXheight;
1.266 albertel 4109: if ($height_param) {
4110: $width_param = $TeXheight/$height_param*$width_param;
4111: }
1.256 albertel 4112: } elsif ($width) {
1.252 matthew 4113: my $old_width_param=$width_param;
1.256 albertel 4114: $width_param = $width*$scaling;
1.266 albertel 4115: if ($old_width_param) {
4116: $height_param=$width_param/$old_width_param*$height_param;
4117: }
1.252 matthew 4118: }
1.267 albertel 4119: if ($width_param > $env{'form.textwidth'}) {
1.252 matthew 4120: my $old_width_param=$width_param;
1.267 albertel 4121: $width_param =0.95*$env{'form.textwidth'};
1.266 albertel 4122: if ($old_width_param) {
4123: $height_param=$width_param/$old_width_param*$height_param;
4124: }
1.197 sakharuk 4125: }
1.275 foxr 4126:
4127: return ($height_param, $width_param);
4128: }
4129:
4130: sub image_size {
4131: my ($src,$scaling,$parstack,$safeeval,$depth,$cis)=@_;
4132:
4133: #size of image from gif/jpg/jpeg/png
4134: my $ressrc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
4135: if (-e $ressrc) {
4136: $src = $ressrc;
4137: }
4138: my $image = Image::Magick->new;
4139: my $current_figure = $image->Read($src);
4140: my $width_param = $image->Get('width');
4141: my $height_param = $image->Get('height');
4142: &Apache::lonxml::debug("Image magick says: $src : Height = $height_param width = $width_param");
4143: undef($image);
4144:
4145: ($height_param, $width_param) = &resize_image($height_param, $width_param,
4146: $scaling, $parstack, $safeeval,
4147: $depth, $cis);
4148:
1.248 foxr 4149: return ($height_param, $width_param);
4150: }
4151:
4152: sub image_width {
4153: my ($height, $width) = &image_size(@_);
4154: return $width;
4155: }
4156: # Not yet 100% sure this is correct in all circumstances..
4157: # due to my uncertainty about mods to image_size.
4158: #
4159: sub image_height {
4160: my ($height, $width) = &image_size(@_);
4161: return $height;
1.197 sakharuk 4162: }
4163:
1.256 albertel 4164: sub get_eps_image {
4165: my ($src)=@_;
1.261 foxr 4166: my $orig_src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1], $src);
1.285 foxr 4167:
4168: # In order to prevent the substitution of the alt text, we need to
4169: # be sure the orig_src file is on system now so:
4170:
4171: if (! -e $orig_src) {
4172: &Apache::lonnet::repcopy($orig_src); # Failure is not completely fatal.
4173: }
1.275 foxr 4174: &Apache::lonxml::debug("get_eps_image: Original image: $orig_src");
1.282 foxr 4175: my ($spath, $sname, $sext) = fileparse($src, qr/\.(gif|png|jpg|jpeg)/i);
1.256 albertel 4176: $src=~s/\.(gif|png|jpg|jpeg)$/\.eps/i;
4177: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
1.275 foxr 4178: &Apache::lonxml::debug("Filelocation gives: $src");
1.256 albertel 4179: if (! -e $src) {
1.261 foxr 4180: &Apache::lonxml::debug("$src does not exist");
1.264 raeburn 4181: if (&Apache::lonnet::repcopy($src) ne 'ok' ) {
1.261 foxr 4182: &Apache::lonxml::debug("Repcopy of $src failed (1)");
1.256 albertel 4183: #if replication failed try to find ps file
4184: $src=~s/\.eps$/\.ps/;
1.261 foxr 4185: &Apache::lonxml::debug("Now looking for $src");
1.270 foxr 4186: #if no ps file try to replicate it.
4187: my $didrepcopy = &Apache::lonnet::repcopy($src);
4188: &Apache::lonxml::debug("repcopy of $src ... $didrepcopy");
4189: if ( (not -e $src) ||
4190: ($didrepcopy ne 'ok')) {
1.261 foxr 4191: &Apache::lonxml::debug("Failed to find or replicate $src");
4192:
1.256 albertel 4193: #if replication failed try to produce eps file dynamically
4194: $src=~s/\.ps$/\.eps/;
4195: my $temp_file;
1.267 albertel 4196: open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat");
1.256 albertel 4197: my $newsrc=$orig_src;
4198: $newsrc =~ s|(.*)/res/|/home/httpd/html/res/|;
1.275 foxr 4199: &Apache::lonxml::debug("queueing $newsrc for dynamic eps production.");
1.256 albertel 4200: print FILE "$newsrc\n";
1.261 foxr 4201: close FILE;
1.256 albertel 4202: $src=~s|/home/httpd/html/res|/home/httpd/prtspool|;
4203: $src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|;
1.283 albertel 4204: if ($sext ne "") { # Put the ext. back in to uniquify.
4205: $src =~ s/\.eps$/$sext.eps/;
4206: }
1.256 albertel 4207: }
4208: }
4209: }
4210: my ($path,$file)=($src=~m|(.*)/([^/]*)$|);
1.261 foxr 4211: &Apache::lonxml::debug("get_eps_image returning: $path / $file<BR />");
1.256 albertel 4212: return ($path.'/',$file);
4213: }
4214:
1.195 sakharuk 4215: sub eps_generation {
4216: my ($src,$file,$width_param) = @_;
1.267 albertel 4217: my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat";
1.195 sakharuk 4218: my $temp_file = Apache::File->new('>>'.$filename);
4219: print $temp_file "$src\n";
4220: my $newsrc = $src;
4221: $newsrc =~ s/(\.gif|\.jpg|\.jpeg)$/\.eps/i;
4222: $newsrc=~s/\/home\/httpd\/html\/res//;
4223: $newsrc=~s/\/home\/([^\/]*)\/public_html\//\/$1\//;
4224: $newsrc=~s/\/\.\//\//;
4225: $newsrc=~s/\/([^\/]+)\.(ps|eps)/\//;
1.213 sakharuk 4226: if ($newsrc=~/\/home\/httpd\/lonUsers\//) {
4227: $newsrc=~s/\/home\/httpd\/lonUsers//;
4228: $newsrc=~s/\/([^\/]+)\/(\w)\/(\w)\/(\w)\//\/$1\//;
4229: }
1.239 sakharuk 4230: if ($newsrc=~/\/userfiles\//) {
4231: return ' \graphicspath{{'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
4232: } else {
4233: return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
4234: }
1.197 sakharuk 4235: }
4236:
4237: sub file_path {
4238: my $src=shift;
4239: my ($file,$path);
4240: if ($src =~ m!(.*)/([^/]*)$!) {
4241: $file = $2;
4242: $path = $1.'/';
4243: }
4244: return $file,$path;
1.126 sakharuk 4245: }
1.294 foxr 4246: # Converts a measurement in to mm from any of
4247: # the other valid LaTeX units of measure.
4248: # If the units of measure are missing from the
4249: # parameter, it is assumed to be in and returned
4250: # with mm units of measure
1.126 sakharuk 4251: sub recalc {
4252: my $argument = shift;
4253: if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}
1.132 sakharuk 4254: $argument=~/\s*(\d+\.?\d*)\s*(mm|cm|in|pc|pt)/;
1.126 sakharuk 4255: my $value=$1;
4256: my $units=$2;
4257: if ($units eq 'cm') {
4258: $value*=10;
4259: } elsif ($units eq 'in') {
4260: $value*=25.4;
4261: } elsif ($units eq 'pc') {
4262: $value*=(25.4*12/72.27);
4263: } elsif ($units eq 'pt') {
4264: $value*=(25.4/72.27);
4265: }
4266: return $value.' mm';
1.94 sakharuk 4267: }
1.184 sakharuk 4268:
4269: sub LATEX_length {
4270: my $garbage=shift;
1.206 sakharuk 4271: $garbage=~s/^\s+$//;
4272: $garbage=~s/^\s+(\S.*)/$1/;#space before
4273: $garbage=~s/(.*\S)\s+$/$1/;#space after
4274: $garbage=~s/(\s)+/$1/;#only one space
4275: $garbage=~s/(\\begin{([^\}]+)}|\\end{([^\}]+)})//g;#remove LaTeX \begin{...} and \end{...}
4276: $garbage=~s/(\$\_\{|\$\_|\$\^{|\$\^|\}\$)//g;#remove $_{,$_,$^{,$^,}$
4277: $garbage=~s/([^\\])\$/$1/g;#$
4278: $garbage=~s/(\\ensuremath\{\_\{|\\ensuremath\{\_|\\ensuremath\{\^{|\\ensuremath\{\^|\})//g;#remove \ensuremath{...}
4279: $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 4280: $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;
4281: $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;
4282: $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 4283: $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;
4284: $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;
4285: $garbage=~s/(\\hat{([^}]+)}|\\check{([^}]+)}|\\dot{([^}]+)}|\\breve{([^}]+)}|\\acute{([^}]+)}|\\ddot{([^}]+)}|\\grave{([^}]+)}|\\tilde{([^}]+)}|\\mathring{([^}]+)}|\\bar{([^}]+)}|\\vec{([^}]+)})/$1/g;
4286: #remove some other LaTeX command
4287: $garbage=~s|\\(\w+)\\|\\|g;
4288: $garbage=~s|\\(\w+)(\s*)|$2|g;
4289: $garbage=~s|\+|11|g;
1.184 sakharuk 4290: my $value=length($garbage);
4291: return $value;
4292: }
4293:
4294:
1.287 foxr 4295: # is_inside_of $tagstack $tag
4296: # This sub returns true if the current state of Xml processing
4297: # is inside of the tag.
4298: # Parameters:
4299: # tagstack - The tagstack from the parser.
4300: # tag - The tag (without the <>'s.).
4301: # Sample usage:
4302: # if (is_inside_of($tagstack "table")) {
4303: # # I'm in a table....
4304: # }
4305: sub is_inside_of {
4306: my ($tagstack, $tag) = @_;
4307: my @stack = @$tagstack;
4308: for (my $i = ($#stack - 1); $i >= 0; $i--) {
4309: if ($stack[$i] eq $tag) {
4310: return 1;
4311: }
4312: }
4313: return 0;
4314: }
1.184 sakharuk 4315:
1.94 sakharuk 4316:
1.1 sakharuk 4317: 1;
4318: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>