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