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