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