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