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