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