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