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