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