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