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