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