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