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