1: # The LearningOnline Network with CAPA
2: # Tags Default Definition Module
3: #
4: # $Id: londefdef.pm,v 1.415.4.2 2010/11/09 21:28:20 raeburn Exp $
5: #
6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
28: ## Copyright for TtHfunc and TtMfunc by Ian Hutchinson.
29: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into
30: # binary executable programs or libraries distributed by the
31: # Michigan State University (the "Licensee"), but any binaries so
32: # distributed are hereby licensed only for use in the context
33: # of a program or computational system for which the Licensee is the
34: # primary author or distributor, and which performs substantial
35: # additional tasks beyond the translation of (La)TeX into HTML.
36: # The C source of the Code may not be distributed by the Licensee
37: # to any other parties under any circumstances.
38: #
39:
40: package Apache::londefdef;
41:
42: use Apache::lonnet;
43: use strict;
44: use Apache::lonxml;
45: use Apache::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: $currentstring = $t->generate_string();
2197: &enable_para();
2198: #--------------------------------------------------------------
2199: # Old table code:
2200: #--------------------------------------------------------------
2201:
2202: if (0) {
2203:
2204: my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval);
2205: my $inmemory = '';
2206: my $output = '';
2207: my $WARNING='';
2208: #width of columns from TeXwidth attributes
2209:
2210: # Protect against unbalanced </table> tag.
2211:
2212: if (scalar(@Apache::londefdef::table) > 0) {
2213:
2214: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2215: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
2216: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]<$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn]) {
2217: $Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]=$Apache::londefdef::table[-1]{'TeXlen'}[$in][$jn];
2218: }
2219: }
2220: }
2221: #free space and number of empty columns
2222: my ($available_space,$empty_columns)=($Apache::londefdef::table[-1]{'width'},0);
2223: if ($#Apache::londefdef::table ne 0) {$available_space=0.9*$available_space;}
2224: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
2225: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]==0) {
2226: $empty_columns++;
2227: } else {
2228: $available_space=$available_space-$Apache::londefdef::table[-1]{'TeXlen'}[0][$jn];
2229: }
2230: }
2231:
2232: #boundaries for contents columns
2233: my @min_len=();#columns can not be narrower
2234: my @max_len=();#maximum length of column
2235: my $avg_max;
2236: my $avg_min;
2237: my $counter_cols = $Apache::londefdef::table[-1]{'counter_columns'};
2238: for (my $jn=0;$jn<=$counter_cols; $jn++) {
2239: my ($localmin,$localmax)=(0,0);
2240: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2241: if ($localmin<$Apache::londefdef::table[-1]{'minlen'}[$in][$jn]) {
2242: $localmin=$Apache::londefdef::table[-1]{'minlen'}[$in][$jn];
2243: }
2244: if ($localmax<$Apache::londefdef::table[-1]{'maxlen'}[$in][$jn]) {
2245: $localmax=$Apache::londefdef::table[-1]{'maxlen'}[$in][$jn];
2246: }
2247: }
2248: push @min_len, $localmin;
2249: push @max_len, $localmax;
2250: $avg_max = $localmax + $avg_max;
2251: $avg_min = $localmin + $avg_min;
2252: }
2253: # Does not really matter what the average max/min are if there are no cols.
2254: # and this prevents div 0 in that case.
2255:
2256: if ($counter_cols != 0) {
2257: $avg_max = $avg_max/$counter_cols;
2258: $avg_min = $avg_min/$counter_cols;
2259: }
2260:
2261:
2262: # I don't think the below is needed.. but just in case:
2263:
2264: if ($avg_min > $avg_max) {
2265: my $temp = $avg_min;
2266: $avg_min = $avg_max;
2267: $avg_max = $temp;
2268: }
2269:
2270:
2271: for (my $jn=0;$jn<=$counter_cols;$jn++) {
2272: my $localmin=0,;
2273: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2274: if ($localmin<$Apache::londefdef::table[-1]{'objectlen'}[$in][$jn]) {
2275: $localmin=$Apache::londefdef::table[-1]{'objectlen'}[$in][$jn];
2276: }
2277: }
2278: if ($max_len[$jn]<$localmin) {
2279: $max_len[$jn]=$localmin;
2280: $Apache::londefdef::table[-1]{'objectsignal'}[$jn]=1;
2281: }#object size is bigger
2282: if ($min_len[$jn]<$localmin) {
2283: $min_len[$jn]=$localmin;
2284: $Apache::londefdef::table[-1]{'objectsignal'}[$jn]=1;
2285: }#object size is bigger
2286: if ($Apache::londefdef::table[-1]{'TeXlen'}[0][$jn]!=0) {
2287: $min_len[$jn]=0;
2288: $max_len[$jn]=0;
2289: }
2290: # Spans seem to be really bothered by max/min = 0. So if we have one
2291: # make it an average joe max/min.
2292:
2293: if ($max_len[$jn] == 0) {
2294: $max_len[$jn] = $avg_max;
2295: }
2296: if ($min_len[$jn] == 0) {
2297: $min_len[$jn] = $avg_min;
2298: }
2299:
2300: }
2301: #final adjustment of column width
2302: my @fwidth=@{$Apache::londefdef::table[-1]{'TeXlen'}[0]};#final width array
2303: my @adjust=();
2304: #step 1. adjustment by maximum value
2305: my $space_needed=0;
2306: for (my $jn=0;$jn<=$#max_len;$jn++) {
2307: $space_needed=$space_needed+$max_len[$jn];
2308: }
2309: if ($space_needed<=$available_space) {
2310:
2311: for (my $jn=0;$jn<=$#max_len;$jn++) {
2312: if ($fwidth[$jn]==0) {
2313: $fwidth[$jn]=$max_len[$jn];
2314: }
2315: }
2316: } else {
2317: #step 2. adjustment by minimum value (estimation)
2318: $space_needed=0;
2319: for (my $jn=0;$jn<=$#min_len;$jn++) {
2320: $space_needed+=$min_len[$jn];
2321: }
2322: if ($space_needed>$available_space) {
2323: $WARNING=' \textbf{NOT ENOUGH SPACE FOR TABLE} ';
2324: for (my $jn=0;$jn<=$#max_len;$jn++) {
2325: if ($fwidth[$jn]==0) {
2326: $fwidth[$jn]=$min_len[$jn];
2327: }
2328: }
2329: #check if we have objects which can be scaled
2330: my $how_many_to_scale=0;
2331: my @to_scale=();
2332: for (my $jn=0;$jn<=$#max_len;$jn++) {
2333: if ($Apache::londefdef::table[-1]{'objectsignal'}[$jn] eq '1') {
2334: $how_many_to_scale++;
2335: push @to_scale, $jn;
2336: }
2337: }
2338: if ($how_many_to_scale>0) {
2339: my $space_to_adjust=($space_needed-$available_space)/$how_many_to_scale;
2340: foreach my $jn (@to_scale) {
2341: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2342: $Apache::londefdef::table[-1]{'content'}[$in][$jn]=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/;
2343: if ($1 ne '') {
2344: my $current_length=&recalc($1);
2345: $current_length=~/(\d+\.?\d*)/;
2346: $current_length=$current_length-$space_to_adjust;
2347: $Apache::londefdef::table[-1]{'content'}[$in][$jn]=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/width=$current_length mm/;
2348: }
2349: $Apache::londefdef::table[-1]{'content'}[$in][$jn]=~m/\[(\d+\.?\d*)\s*mm\]/;
2350: if ($1 ne '') {
2351: my $current_length=$1;
2352: $current_length=$current_length-$space_to_adjust;
2353: $Apache::londefdef::table[-1]{'content'}[$in][$jn]=~s/\[(\d+\.?\d*)\s*mm\]/\[$current_length mm\]/;
2354: }
2355: }
2356: $fwidth[$jn]=$fwidth[$jn]-$space_to_adjust;
2357: }
2358: }
2359: } else {
2360: #step 3. adjustment over minimal + corrections
2361: my $enlarge_coef=$available_space/$space_needed;
2362: my $acsessive=0;
2363: for (my $jn=0;$jn<=$#min_len;$jn++) {
2364: $adjust[$jn]=$min_len[$jn]*$enlarge_coef;
2365: if ($adjust[$jn]>$max_len[$jn]) {
2366: $fwidth[$jn]=$max_len[$jn];
2367: $acsessive=$acsessive+$adjust[$jn]-$max_len[$jn];
2368: $adjust[$jn]=0;
2369:
2370: }
2371: }
2372: if ($acsessive>0) {
2373: #we have an excess of space and can redistribute it
2374: my $notempty_columns=0;
2375: for (my $jn=0;$jn<=$#min_len;$jn++) {
2376: if ($adjust[$jn]!=0) {
2377: $notempty_columns++;
2378: }
2379: }
2380: my $per_column=$acsessive/$notempty_columns;
2381: for (my $jn=0;$jn<=$#min_len;$jn++) {
2382: if ($adjust[$jn]!=0) {
2383: $adjust[$jn]+=$per_column;
2384: $fwidth[$jn]=$adjust[$jn];
2385: }
2386: }
2387: } else {
2388: for (my $jn=0;$jn<=$#min_len;$jn++) {
2389: $fwidth[$jn]=$adjust[$jn];
2390: }
2391: }
2392: }
2393: }
2394: # use all available width or specified width as if not specified,
2395: # the specified width gets defaulted to the available width.
2396:
2397: my $current=0;
2398: for (my $i=0;$i<=$#fwidth;$i++) {
2399: $current+=$fwidth[$i];
2400: }
2401: if ($current == 0) {
2402: $current = $Apache::londefdef::table[-1]{'width'};
2403: }
2404: my $coef=$Apache::londefdef::table[-1]{'width'}/$current;
2405: for (my $i=0;$i<=$#fwidth;$i++) {
2406: $fwidth[$i]*=$coef;
2407: }
2408: #removing of empty columns if allowed
2409: my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
2410: if ($permission eq 'yes') {
2411: my @cleaned_table=();
2412: my @cleaned_header=();
2413: my $colind=0;
2414: for (my $jn=0;$jn<=$Apache::londefdef::table[-1]{'counter_columns'};$jn++) {
2415: if ($fwidth[$jn]!=0) {
2416: #we need to copy column
2417: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2418: $cleaned_table[$in][$colind]=$Apache::londefdef::table[-1]{'content'}[$in][$jn];
2419: $cleaned_header[$colind]=$fwidth[$jn];
2420: }
2421: $colind++;
2422: }
2423: }
2424: $Apache::londefdef::table[-1]{'content'}=\@cleaned_table;
2425: @fwidth=@cleaned_header;
2426: }
2427:
2428:
2429: #construct header of the table
2430: my $header_of_table = '{'.$Apache::londefdef::table[-1]{'vvinc'};
2431: for (my $in=0;$in<=$#fwidth;$in++) {
2432: $header_of_table.='p{'.$fwidth[$in].' mm}'.$Apache::londefdef::table[-1]{'vvinc'};
2433: }
2434: $header_of_table .= '}';
2435:
2436: #fill the table
2437: for (my $in=0;$in<=$Apache::londefdef::table[-1]{'row_number'};$in++) {
2438: my $have_rowspan = 0;
2439: for (my $jn=0;$jn<=$#fwidth;$jn++) {
2440:
2441: #-----------------------------------------------------------
2442: # I think this order of doing things will ensure that
2443: # single rowspan, columspan and combined row/colspans will
2444: # work correctly. LaTeX is delicate here.
2445: # RF.
2446:
2447: # Start a rowspan if necessary:
2448:
2449: my $primary_col_width = $fwidth[$jn]; # Width of primary column.
2450: my $rowspan = $Apache::londefdef::table[-1]{'rowspan'}[$in][$jn];
2451: my $colspan = $Apache::londefdef::table[-1]{'colspan'}[$in][$jn];
2452: #
2453: # Do the appropriate magic if this has a colspan
2454: #
2455:
2456: my $border_char = "";
2457: if ($border) {
2458: $border_char = "|";
2459: }
2460: my $spanwidth = 0;
2461: if ($colspan > 1) {
2462: for (my $spancol = $jn; $spancol < $jn + $colspan; $spancol++) {
2463: $spanwidth += $fwidth[$spancol];
2464: }
2465: $output .= '\multicolumn{'.
2466: $colspan
2467: ."}";
2468: if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
2469: $output .= '{'.$border_char.'c'.$border_char.'}{';
2470: } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
2471: $output .= '{'.$border_char.'r'.$border_char.'}{';
2472: }
2473: else {
2474: $output .= '{'.$border_char."p{$spanwidth mm}".$border_char.'}{';
2475: }
2476:
2477: } else {
2478: $spanwidth = $primary_col_width; # If no span width will be just colwidth
2479: }
2480:
2481: # Rowspan... if colspan is 1, and there's an alignment we'll need
2482: # to kick in a multicolumn in order to get the alignment spec.
2483: # this must precede the multirow or LaTex gets quite upset.
2484: # Naturally if colspan > 1 we've already done that above ^
2485: #
2486: my $multirow_aligned = 0;
2487: if ($rowspan > 1) {
2488: if ($colspan == 1) {
2489: if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
2490: $output .= '\multicolumn{1}{'.$border_char.'c'.$border_char.'}{';
2491: $multirow_aligned = 1;
2492: } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
2493: $output .= '\multicolumn{1}{'.$border_char.'r'.$border_char.'}{';
2494: $multirow_aligned = 1;
2495: }
2496: }
2497: $have_rowspan++;
2498: if ($multirow_aligned) {
2499: $output .= '\multirow{'.$rowspan.'}[0]{*}{';
2500: } else {
2501: $output .= '\multirow{'.$rowspan."}[0]{$spanwidth mm}{";
2502: }
2503:
2504: $Apache::londefdef::table[-1]{'content'}[$in][$jn] =~
2505: s{^\s*\\par\s*}{};
2506: $Apache::londefdef::table[-1]{'content'}[$in][$jn] =~
2507: s{\s*\\vskip\s*0pt\s*$}{};
2508:
2509: #
2510: # If we did not throw in a multicolumn to align, then add
2511: # an extra {
2512: # so we close correctly without having to keep additional state
2513: # around
2514: #
2515: if (!$multirow_aligned) {
2516: $output .= '{';
2517: }
2518: }
2519: if (($rowspan eq '^') || ($rowspan eq '_')) {
2520: $have_rowspan++;
2521: }
2522: #--------------------------------------------------------------
2523:
2524:
2525: # For right and center alignment of single cells.
2526: # we are going to use a multicolumn with a span of 1 to specify alignment.
2527: #
2528: if ($colspan == 1 && $rowspan == 1) {
2529: if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
2530: $output .= '\multicolumn{1}{'.$border_char.'c'.$border_char.'}{';
2531: } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
2532: $output .= '\multicolumn{1}{'.$border_char.'r'.$border_char.'}{';
2533: }
2534: }
2535:
2536: $output.=$Apache::londefdef::table[-1]{'content'}[$in][$jn];
2537:
2538: if (($colspan == 1 && $rowspan == 1) &&
2539: (($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') ||
2540: ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r'))) {
2541: $output .= '}';
2542: }
2543:
2544: # Close off any open multirow:
2545:
2546: if ($rowspan > 1) {
2547: $output .= '}}';
2548: }
2549: # Close off the colspan...
2550: #
2551: if ($colspan > 1) {
2552: $output .= '}';
2553: $jn += $colspan-1; # Adjust for number of rows really left.
2554: }
2555: if ($jn!=$#fwidth) {$output.=' '.$Apache::londefdef::table[-1]{'vinc'};}
2556: }
2557: # If have_rowspan > 0, and borders are on, then
2558: # we need to do more than put an \hline at the bottom of row.
2559: # we need to do the appropriate \cline to ensure that
2560: # the spanned rows don't have \hlines through them.
2561:
2562: if (($Apache::londefdef::table[-1]{'hinc'} =~ /\\hline/) && $have_rowspan) {
2563: $output .= ' \\\\ ';
2564: for (my $jn=0; $jn<=$#fwidth;$jn++) {
2565: my $rowspan = $Apache::londefdef::table[-1]{'rowspan'}[$in][$jn];
2566: if ($rowspan ne "^") {
2567: if (($rowspan <= 1) || ($rowspan eq '_')) {
2568: my $column = $jn+1;
2569: $output .= '\cline{'.$column.'-'.$column.'} ';
2570: }
2571: }
2572: }
2573:
2574: } else {
2575: $output.=' \\\\ '.$Apache::londefdef::table[-1]{'hinc'}.' ';
2576: }
2577: }
2578: # Note that \newline destroys alignment env's produced by e.g. <div>
2579: # $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut\newline\strut ';
2580: $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut'.'\\\\'."\n".'\strut ';
2581: if ($#Apache::londefdef::table > 0) {
2582: my $inmemory = $Apache::londefdef::table[-1]{'output'};
2583: # Figure out max/and min width by summing us and then
2584: # apply that to the current column of the table we nest in
2585: # if it's larger than the current width or the current width
2586: # is undefined.
2587: #
2588: my $min_nested_width = 0;
2589: my $max_nested_width = 0;
2590: for (my $col = 0; $col <= $Apache::londefdef::table[-1]{'counter_columns'}; $col++) {
2591: $min_nested_width += $min_len[$col];
2592: $max_nested_width += $max_len[$col];
2593:
2594: }
2595: # Fudge in an extra 5 mm for borders etc:
2596:
2597: $min_nested_width += 5;
2598: $max_nested_width += 5;
2599:
2600: my $outer_column = $Apache::londefdef::table[-2]{'counter_columns'};
2601: my $outer_row = $Apache::londefdef::table[-2]{'row_number'};
2602: if ($min_nested_width > $Apache::londefdef::table[-2]{'minlen'}[$outer_row][$outer_column]) {
2603: $Apache::londefdef::table[-2]{'minlen'}[$outer_row][$outer_column] = $min_nested_width;
2604: }
2605: if ($max_nested_width > $Apache::londefdef::table[-2]{'maxlen'}[$outer_row][$outer_column]) {
2606: $Apache::londefdef::table[-2]{'maxlen'}[$outer_row][$outer_column] = $max_nested_width;
2607: }
2608:
2609: pop @Apache::londefdef::table;
2610: push @{$Apache::londefdef::table[-1]{'include'}}, $inmemory;
2611: } else {
2612: $currentstring .= $Apache::londefdef::table[-1]{'output'};
2613: pop @Apache::londefdef::table;
2614: undef @Apache::londefdef::table;
2615: }
2616: }
2617: &enable_para();
2618: }
2619: }
2620: return $currentstring;
2621: }
2622:
2623: #-- <tr> tag (end tag optional)
2624: sub start_tr {
2625: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2626: my $currentstring = '';
2627: if ($target eq 'web' || $target eq 'webgrade') {
2628: $currentstring = $token->[4];
2629: } elsif ($target eq 'tex') {
2630:
2631: my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 1);
2632: $Apache::londefdef::table[-1]->start_row();
2633:
2634: if ($align ne '') {
2635: $Apache::londefdef::table[-1]->configure_row({default_halign => $align});
2636: }
2637:
2638: #---------------------------------------------------------------
2639: # Old table code.
2640: #---------------------------------------------------------------
2641:
2642: if (0) {
2643: $Apache::londefdef::table[-1]{'row_number'}++;
2644: my $alignchar=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
2645: if ($alignchar ne '') {
2646: push @ {$Apache::londefdef::table[-1]{'rows'} },substr($alignchar,0,1);
2647: } else {
2648: push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l';
2649: }
2650: push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'});
2651: #
2652: # Need to save the number of table columns to preserve the max # columns.
2653: #
2654: $Apache::londefdef::table[-1]{'prior_columns'} = $Apache::londefdef::table[-1]{'counter_columns'};
2655: $Apache::londefdef::table[-1]{'counter_columns'} = -1;
2656: push @ {$Apache::londefdef::table[-1]{'TeXlen'}}, [];
2657: push @ {$Apache::londefdef::table[-1]{'objectlen'}}, [];
2658: push @ {$Apache::londefdef::table[-1]{'minlen'}}, [];
2659: push @ {$Apache::londefdef::table[-1]{'maxlen'}}, [];
2660: push @ {$Apache::londefdef::table[-1]{'content'}}, [];
2661: }
2662: }
2663: return $currentstring;
2664: }
2665:
2666: sub end_tr {
2667: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2668: my $currentstring = &end_p(); # Close any pending <p> in the row.
2669: if ($target eq 'web' || $target eq 'webgrade') {
2670: $currentstring .= $token->[2];
2671: } elsif ($target eq 'tex') {
2672:
2673: # In case the user is missing a </td> or </th> tag:
2674:
2675: if ($Apache::londefdef::TD_redirection) {
2676: &end_td_tex($parstack,$parser,$safeeval);
2677: }
2678: $Apache::londefdef::table[-1]->end_row();
2679:
2680: #-----------------------------------------------
2681: # Old table code
2682: #-----------------------------------------------
2683:
2684: if (0) {
2685: if ($Apache::londefdef::TD_redirection) {
2686: &end_td_tex($parstack,$parser,$safeeval);
2687: }
2688: # Counter columns must be the maximum number of columns seen
2689: # in the table so far so:
2690: if ($Apache::londefdef::table[-1]{'prior_columns'} > $Apache::londefdef::table[-1]{'counter_columns'}) {
2691: $Apache::londefdef::table[-1]{'counter_columns'} = $Apache::londefdef::table[-1]{'prior_columns'};
2692: }
2693: }
2694:
2695:
2696: }
2697: return $currentstring;
2698: }
2699:
2700: #-- <td> tag (end tag optional)
2701: sub start_td {
2702: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2703: my $currentstring = '';
2704: if ($target eq 'web' || $target eq 'webgrade') {
2705: $currentstring = $token->[4];
2706: } elsif ($target eq 'tex') {
2707: $Apache::londefdef::TD_redirection = 1;
2708: &tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval);
2709: }
2710: return $currentstring;
2711: }
2712:
2713: sub tag_check {
2714: my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
2715: my @ar=@$parstack;
2716: for (my $i=$#ar-1;$i>=0;$i--) {
2717: if (lc($$tagstack[$i]) eq $good_tag) {
2718: &start_td_tex($parstack,$parser,$safeeval);
2719: last;
2720: } elsif (lc($$tagstack[$i]) eq $bad_tag) {
2721: splice @ar, $i+1;
2722: &end_td_tex(\@ar,$parser,$safeeval);
2723: &start_td_tex($parstack,$parser,$safeeval);
2724: last;
2725: }
2726: }
2727: return '';
2728: }
2729:
2730: #
2731: # Factor out cell configuration hash generation:
2732: #
2733:
2734: sub cell_config_hash {
2735: my ($align, $rowspan, $colspan, $width) = @_;
2736: my %config;
2737: if ($align ne '') {
2738: $config{'halign'} = $align;
2739: }
2740: if ($colspan ne "") {
2741: $config{'colspan'} = $colspan;
2742: }
2743: if ($rowspan ne '') {
2744: $config{'rowspan'} = $rowspan;
2745: }
2746: if ($width ne '') {
2747: $config{'width'} = $width;
2748: }
2749: return \%config;
2750: }
2751:
2752: sub start_td_tex {
2753: my ($parstack,$parser,$safeeval) = @_;
2754:
2755: # At this stage, an empty cell is created with the
2756: # appropriate rowspan/colspan and alignment
2757: # attributes, but empty of text. end_td_tex will
2758: # fetch the contents from the recursive parse and
2759: # fill the cell with them:
2760: my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval);
2761: my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval);
2762: my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval);
2763: my $width = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval);
2764: my $config = &cell_config_hash($align, $rowspan, $colspan, $width);
2765:
2766: my $table = $Apache::londefdef::table[-1];
2767: $table->add_cell('', $config);
2768:
2769:
2770: #------------------------------------------------
2771: # Old table code.
2772: #------------------------------------------------
2773:
2774: if (0) {
2775:
2776: my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
2777: if ($alignchar eq '') {
2778: $alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
2779: }
2780: push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
2781: $Apache::londefdef::table[-1]{'counter_columns'}++;
2782: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2783: if (defined $TeXwidth) {
2784: my $current_length=&recalc($TeXwidth);
2785: $current_length=~/(\d+\.?\d*)/;
2786: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
2787: }
2788: }
2789: &Apache::lonxml::startredirection();
2790: return '';
2791: }
2792:
2793: sub end_td_tex {
2794:
2795: my $text = &Apache::lonxml::endredirection();
2796: my $table = $Apache::londefdef::table[-1];
2797: $table->append_cell_text($text);
2798:
2799: #-------------------------------------------------
2800: # Old table code
2801: #-------------------------------------------------
2802:
2803: if (0) {
2804: my ($parstack,$parser,$safeeval) = @_;
2805: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
2806: my $current_column = $Apache::londefdef::table[-1]{'counter_columns'};
2807: my $data = &Apache::lonxml::endredirection();
2808:
2809: # The rowspan array of the table indicates which cells are part of a span.
2810: # n indicates the start of a span set of n rows.
2811: # ^ indicates a cell that continues a span set.
2812: # _ indicates the cell is at the bottom of a span set.
2813: # If this and subsequent cells are part of a rowspan, we must
2814: # push along the row until we find one that is not.
2815:
2816: while ((defined $Apache::londefdef::table[-1]{'rowspan'}[$current_row] [$current_column])
2817: && ($Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column] =~ /[\^\_]/)) {
2818: # Part of a span.
2819: push @ {$Apache::londefdef::table[-1]{'content'}[-1]}, '';
2820: $current_column++;
2821: }
2822: $Apache::londefdef::table[-1]{'counter_columns'} = $current_column;
2823:
2824:
2825: # Get the column and row spans.
2826: # Colspan can be done via \multicolumn if I can figure out the data structs.
2827:
2828: my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval, undef, 0);
2829: if (!$colspan) {
2830: $colspan = 1;
2831: }
2832:
2833: my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval, undef, 0);
2834: if (!$rowspan) {
2835: $rowspan = 1;
2836: }
2837:
2838:
2839:
2840: for (my $c = 0; $c < $colspan; $c++) {
2841: $Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column+$c] = $rowspan;
2842: for (my $i = 1; $i < $rowspan; $i++) {
2843: $Apache::londefdef::table[-1]{'rowspan'}[$current_row+$i][$current_column+$c] = '^';
2844: if ($i == ($rowspan-1)) {
2845: $Apache::londefdef::table[-1]{'rowspan'}[$current_row+$i][$current_column+$c] = '_';
2846: }
2847: }
2848: }
2849:
2850: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2851: if (defined $TeXwidth) {
2852: for (my $c = 0; $c < $colspan; $c++) {
2853: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2854: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2855: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2856: }
2857: } else {
2858: if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
2859: my $garbage_data=$data;
2860: my $fwidth=0;
2861: while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2862: my $current_length=&recalc($1);
2863: $current_length=~/(\d+\.?\d*)/;
2864: if ($fwidth<$1) {$fwidth=$1;}
2865: $garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2866: }
2867: while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
2868: my $current_length=$1;
2869: if ($fwidth<$current_length) {$fwidth=$current_length;}
2870: $garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
2871: }
2872: for (my $c = 0; $c < $colspan; $c++) {
2873: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2874: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2875: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2876: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2877: }
2878: } 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)*/) {
2879: my $garbage_data=$data;
2880: my $fwidth=0;
2881: while ($garbage_data=~/\\parbox\{\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)\s*\}/) {
2882: my $current_length=&recalc($1);
2883: $current_length=~/(\d+\.?\d*)/;
2884: if ($fwidth<$1) {$fwidth=$1;}
2885: $garbage_data=~s/\\parbox\{\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2886: }
2887: while ($garbage_data=~/\\epsfxsize\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2888: my $current_length=&recalc($1);
2889: $current_length=~/(\d+\.?\d*)/;
2890: if ($fwidth<$1) {$fwidth=$1;}
2891: $garbage_data=~s/\\epsfxsize\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2892: }
2893: for (my $c = 0; $c < $colspan; $c++) {
2894: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2895: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2896: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2897: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2898: }
2899: $data=~s/\\\\\s*$//;
2900: } else {
2901: $data=~s/^\s+(\S.*)/$1/;
2902: $data=~s/(.*\S)\s+$/$1/;
2903: $data=~s/(\s)+/$1/;
2904: my ($current_length,$min_length)=(0,0);
2905: if ($data=~/\\vskip/) {
2906: my $newdata=$data;
2907: $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
2908: my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
2909: foreach my $elementdata (@newdata) {
2910: my $lengthnewdata=2.5*&LATEX_length($elementdata);
2911: if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
2912: my @words=split(/ /,$elementdata);
2913: foreach my $word (@words) {
2914: my $lengthword=2.5*&LATEX_length($word);
2915: if ($min_length<$lengthword) {$min_length=$lengthword;}
2916: }
2917: }
2918: } else {
2919: $current_length=2.5*&LATEX_length($data);
2920: my @words=split(/ /,$data);
2921: foreach my $word (@words) {
2922: my $lengthword=2*&LATEX_length($word);
2923: if ($min_length<$lengthword) {$min_length=$lengthword;}
2924: }
2925: }
2926: for (my $c = 0; $c < $colspan; $c++) {
2927: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2928: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2929: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
2930: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
2931: }
2932: }
2933: }
2934: # Substitute all of the tables nested in this cell in their appropriate places.
2935:
2936:
2937: my $nested_count = $#{$Apache::londefdef::table[-1]{'include'}}; # This one is constant...
2938: for (my $in=0; $in<=$nested_count; $in++) {
2939: my $nested = shift @{$Apache::londefdef::table[-1]{'include'}};
2940: $nested =~ s/\\end\{tabular\}\\strut\\\\/\\end\{tabular\}/;
2941: # $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
2942: $data =~ s/\\keephidden\{NEW TABLE ENTRY\}/$nested/;
2943:
2944: }
2945: # Should be be killing off the 'include' elements as they're used up?
2946:
2947: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
2948:
2949:
2950:
2951:
2952: # the colspan array will indicate how many columns will be spanned by this
2953: # cell..this requires that counter_columns also be adjusted accordingly
2954: # so that the next bunch of text goes in the right cell. Note that since
2955: # counter_columns is incremented in the start_td_tex, we adjust by colspan-1.
2956: #
2957:
2958: $Apache::londefdef::table[-1]{'counter_columns'} += $colspan -1;
2959: for (my $i = 0; $i < ($colspan -1); $i++) {
2960: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },'';
2961: }
2962: for (my $r = 0; $r < $rowspan; $r++) {
2963: $Apache::londefdef::table[-1]{'colspan'}[$current_row+$r][$current_column] = $colspan;
2964: # Put empty text in spanned cols.
2965:
2966: }
2967:
2968: }
2969:
2970: return '';
2971: }
2972:
2973: sub end_td {
2974: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2975: my $currentstring = '';
2976: if ($target eq 'web' || $target eq 'webgrade') {
2977: $currentstring = $token->[2];
2978: } elsif ($target eq 'tex') {
2979: $Apache::londefdef::TD_redirection =0;
2980: &end_td_tex($parstack,$parser,$safeeval);
2981: }
2982: return $currentstring;
2983: }
2984:
2985: #-- <th> tag (end tag optional)
2986: sub start_th {
2987: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2988: my $currentstring = '';
2989: if ($target eq 'web' || $target eq 'webgrade') {
2990: $currentstring = $token->[4];
2991: } elsif ($target eq 'tex') {
2992: $Apache::londefdef::TD_redirection = 1;
2993: &tagg_check('tr','th',$tagstack,$parstack,$parser,$safeeval);
2994: }
2995: return $currentstring;
2996: }
2997:
2998: sub tagg_check {
2999: my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
3000: my @ar=@$parstack;
3001: for (my $i=$#ar-1;$i>=0;$i--) {
3002: if (lc($$tagstack[$i]) eq $good_tag) {
3003: &start_th_tex($parstack,$parser,$safeeval);
3004: last;
3005: } elsif (lc($$tagstack[$i]) eq $bad_tag) {
3006: splice @ar, $i+1;
3007: &end_th_tex(\@ar,$parser,$safeeval);
3008: &start_th_tex($parstack,$parser,$safeeval);
3009: last;
3010: }
3011: }
3012: return '';
3013: }
3014:
3015: sub start_th_tex {
3016: my ($parstack,$parser,$safeeval) = @_;
3017:
3018: my $alignment = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef,1);
3019: my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval, undef, 1);
3020: my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval, undef, 1);
3021:
3022: my $config = cell_config_hash($alignment, $rowspan, $colspan);
3023: my $table = $Apache::londefdef::table[-1];
3024: $table->add_cell('\textbf{', $config);
3025:
3026: #-------------------------------------------------------------------------------------
3027: #
3028: # Old table code.
3029: #
3030: #--------------------------------------------------------------------------------------
3031:
3032: if (0) {
3033:
3034:
3035: my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
3036: if ($alignchar eq '') {
3037: $alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
3038: }
3039: push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
3040: $Apache::londefdef::table[-1]{'counter_columns'}++;
3041: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
3042: if (defined $TeXwidth) {
3043: my $current_length=&recalc($TeXwidth);
3044: $current_length=~/(\d+\.?\d*)/;
3045: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
3046: }
3047: }
3048:
3049: # Accept xml until the </th> tag.
3050:
3051: &Apache::lonxml::startredirection();
3052: return '';
3053: }
3054:
3055: sub end_th_tex {
3056: my ($parstack,$parser,$safeeval) = @_;
3057:
3058: my $table = $Apache::londefdef::table[-1];
3059: my $text = &Apache::lonxml::endredirection();
3060: $table->append_cell_text($text.'}');
3061:
3062: #-----------------------------------------------------------------------------
3063: # Old table code:
3064: #-----------------------------------------------------------------------------
3065:
3066: if (0) {
3067: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
3068: my $data=&Apache::lonxml::endredirection();
3069: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
3070: if (defined $TeXwidth) {
3071: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
3072: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
3073: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
3074: } else {
3075: if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
3076: my $garbage_data=$data;
3077: my $fwidth=0;
3078: while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
3079: my $current_length=&recalc($1);
3080: $current_length=~/(\d+\.?\d*)/;
3081: if ($fwidth<$1) {$fwidth=$1;}
3082: $garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
3083: }
3084: while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
3085: my $current_length=$1;
3086: if ($fwidth<$current_length) {$fwidth=$current_length;}
3087: $garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
3088: }
3089: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
3090: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
3091: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
3092: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
3093: } else {
3094: $data=~s/^\s+(\S.*)/$1/;
3095: $data=~s/(.*\S)\s+$/$1/;
3096: $data=~s/(\s)+/$1/;
3097: my ($current_length,$min_length)=(0,0);
3098: if ($data=~/\\vskip/) {
3099: my $newdata=$data;
3100: $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
3101: my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
3102: foreach my $elementdata (@newdata) {
3103: my $lengthnewdata=2.5*&LATEX_length($elementdata);
3104: if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
3105: my @words=split(/ /,$elementdata);
3106: foreach my $word (@words) {
3107: my $lengthword=2.5*&LATEX_length($word);
3108: if ($min_length<$lengthword) {$min_length=$lengthword;}
3109: }
3110: }
3111: } else {
3112: $current_length=2.5*&LATEX_length($data);
3113: my @words=split(/ /,$data);
3114: foreach my $word (@words) {
3115: my $lengthword=2*&LATEX_length($word);
3116: if ($min_length<$lengthword) {$min_length=$lengthword;}
3117: }
3118: }
3119: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
3120: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
3121: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
3122: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
3123: }
3124: }
3125: for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {
3126: $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
3127: }
3128: #make data bold
3129: $data='\textbf{'.$data.'}';
3130: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
3131: }
3132: return'';
3133: }
3134:
3135: sub end_th {
3136: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3137: my $currentstring = &end_p(); # Close any open <p> in the row.
3138: if ($target eq 'web' || $target eq 'webgrade') {
3139: $currentstring .= $token->[2];
3140: } elsif ($target eq 'tex') {
3141: $Apache::londefdef::TD_redirection =0;
3142: &end_th_tex($parstack,$parser,$safeeval);
3143: }
3144: return $currentstring;
3145: }
3146:
3147: #-- <img> tag (end tag forbidden)
3148: #
3149: # Render the <IMG> tag.
3150: # <IMG> has the following attributes (in addition to the
3151: # standard HTML ones:
3152: # TeXwrap - Governs how the tex target will try to wrap text around
3153: # horizontally aligned images.
3154: # TeXwidth - The width of the image when rendered for print (mm).
3155: # TeXheight - The height of the image when rendered for print (mm)
3156: # (Note there seems to also be support for this as a % of page size)
3157: #
3158: sub start_img {
3159: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
3160: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,
3161: undef,1);
3162: if (! $src &&
3163: ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex')
3164: ) {
3165: my $inside = &Apache::lonxml::get_all_text("/img",$parser,$style);
3166: return '';
3167: }
3168: &Apache::lonxml::extlink($src);
3169: my $currentstring = '';
3170: my $scaling = .3;
3171:
3172: # Render unto browsers that which are the browser's...
3173:
3174: if ($target eq 'web' || $target eq 'webgrade') {
3175: if ($env{'browser.imagesuppress'} ne 'on') {
3176: my $enc = ('yes' eq
3177: lc(&Apache::lonxml::get_param('encrypturl',$parstack,
3178: $safeeval)));
3179: $currentstring.=&Apache::lonenc::encrypt_ref($token,{'src'=>$src},
3180: $enc);
3181: } else {
3182: my $alttag = &Apache::lonxml::get_param('alt',$parstack,$safeeval,
3183: undef,1);
3184: if (!$alttag) {
3185: $alttag = &Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
3186: $src);
3187: }
3188: $currentstring.='[IMAGE: '.$alttag.']';
3189: }
3190:
3191: # and render unto TeX that which is LaTeX
3192:
3193: } elsif ($target eq 'tex') {
3194: #
3195: # The alignment will require some superstructure to be put around
3196: # the \includegraphics stuff. At present we can only partially
3197: # simulate the alignments offered by html.
3198: #
3199: #
3200: my $align = lc(&Apache::lonxml::get_param('align',
3201: $parstack,
3202: $safeeval,
3203: undef,1));
3204: if(!$align) {
3205: $align = "bottom"; # This is html's default so it's ours too.
3206: }
3207: #
3208: &Apache::lonxml::debug("Alignemnt = $align");
3209: # LaTeX's image/text wrapping is really bad since it wants to
3210: # make figures float.
3211: # The user has the optional parameter (applicable only to l/r
3212: # alignment to use the picins/parpic directive to get wrapped text
3213: # this is also imperfect.. that's why we give them a choice...
3214: # so they can't yell at us for our choice.
3215: #
3216: my $latex_rendering = &Apache::lonxml::get_param('TeXwrap',
3217: $parstack,
3218: $safeeval,
3219: undef,0);
3220: # &Apache::lonxml::debug("LaTeX rendering = $latex_rendering");
3221: if(!$latex_rendering) {
3222: $latex_rendering = "texwrap";
3223: }
3224: # using texwrap inside a table does not work. So, if after all of this,
3225: # texwrap is on, we turn it off if we detect we're in a table:
3226: #
3227: if (($latex_rendering eq 'texwrap') && &is_inside_of($tagstack, "table")) {
3228: $latex_rendering = 'parpic';
3229: }
3230:
3231: # &Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src");
3232:
3233: #if original bmp/gif/jpg/png file exist do following:
3234: my $origsrc=$src;
3235: my ($path,$file) = &get_eps_image($src);
3236: # &Apache::lonnet::logthis("Image source: $src result: $path $file");
3237: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
3238: &Apache::lonxml::debug("path = $path file = $file src = $src");
3239: if (-e $src) {
3240: &Apache::lonxml::debug("$src exists");
3241: my ($height_param,$width_param)=
3242: &image_size($origsrc,0.3,$parstack,$safeeval);
3243: my $size;
3244: if ($width_param) { $size.='width='.$width_param.' mm,'; }
3245: if ($height_param) { $size.='height='.$height_param.' mm]'; }
3246: # Default size if not able to extract that (e.g. eps image).
3247:
3248: # &Apache::lonnet::logthis("Size = $size");
3249:
3250: $size='['.$size;
3251: $size=~s/,$/]/;
3252: $currentstring .= '\graphicspath{{'.$path.'}}'
3253: .'\includegraphics'.$size.'{'.$file.'} ';
3254: my $closure;
3255: ($currentstring, $closure) = &align_latex_image($align,
3256: $latex_rendering,
3257: $currentstring,
3258: $width_param,
3259: $height_param);
3260: $currentstring .= $closure;
3261:
3262: } else {
3263: &Apache::lonxml::debug("$src does not exist");
3264: #original image file doesn't exist so check the alt attribute
3265: my $alt =
3266: &Apache::lonxml::get_param('alt',$parstack,$safeeval,undef,1);
3267: unless ($alt) {
3268: $alt=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
3269: }
3270:
3271: if ($alt) { $currentstring .= ' '.$alt.' '; }
3272: }
3273:
3274: # And here's where the semi-quote breaks down: allow the user
3275: # to edit the beast as well by rendering the problem for edit:
3276: } elsif ($target eq 'edit') {
3277: my $only = join(',',&Apache::loncommon::filecategorytypes('Pictures'));
3278: $currentstring .=&Apache::edit::tag_start($target,$token);
3279: $currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70).
3280: &Apache::edit::browse('src',undef,'alt',$only).' '.
3281: &Apache::edit::search('src',undef,'alt').'<br />';
3282: $currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'<br />';
3283: $currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5);
3284: $currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'<br />';
3285: $currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5);
3286: $currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5);
3287: $currentstring .=&Apache::edit::select_arg('Alignment:','align',
3288: ['','bottom','middle','top','left','right'],$token,5);
3289: $currentstring .=&Apache::edit::select_arg('TeXwrap:', 'TeXwrap',
3290: ['', 'none','parbox', 'parpic', 'wrapfigure'], $token, 2);
3291: my $alt= &Apache::lonxml::get_param('alt',$parstack,$safeeval);
3292: my $enc= &Apache::lonxml::get_param('encrypturl',$parstack,$safeeval);
3293:
3294: $currentstring .=&Apache::edit::select_arg('Encrypt URL:','encrypturl',
3295: ['no','yes'], $token, 2);
3296: if (($alt=~/\S/) && (lc($enc) eq 'yes')) {
3297: $currentstring.='<br /><span class="LC_warning">'.&mt('Warning: the description "[_1]" will be available, even for encrypted URL',$alt).'</span><br />';
3298: }
3299: $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
3300: my $src= &Apache::lonxml::get_param('src',$parstack,$safeeval);
3301: my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
3302: my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
3303:
3304: if ($token->[2]{'src'}=~/\$/) {
3305: $currentstring.=&mt('Variable image source');
3306: } elsif ($token->[2]{'src'}=~/\S/) {
3307: $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
3308: if ($width) { $currentstring.=' width="'.$width.'" '; }
3309: if ($height) { $currentstring.=' height="'.$height.'" '; }
3310: $currentstring .= ' />';
3311: } else {
3312: $currentstring.=&mt("No image source specified");
3313: }
3314: } elsif ($target eq 'modified') {
3315: my ($osrc,$owidth,$oheight)=
3316: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
3317: my $ctag=&Apache::edit::get_new_args($token,$parstack,
3318: $safeeval,'src','alt','align',
3319: 'TeXwidth','TeXheight', 'TeXwrap',
3320: 'width','height','encrypturl');
3321: my ($nsrc,$nwidth,$nheight)=
3322: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
3323: my $loc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$nsrc);
3324: &image_replication($loc);
3325: my ($iwidth,$iheight);
3326: if (-e $loc) {
3327: my $image = Image::Magick->new;
3328: $image->Read($loc);
3329: ($iwidth, $iheight) = ($image->Get('width'),
3330: $image->Get('height'));
3331: }
3332: if ($osrc ne $nsrc || (!$nwidth && !$nheight)) {
3333: # changed image or no size specified,
3334: # if they didn't explicitly change the
3335: # width or height use the ones from the image
3336: if ($iwidth && $iheight) {
3337: if ($owidth == $nwidth || (!$nwidth && !$nheight)) {
3338: $token->[2]{'width'} = $iwidth;$ctag=1;
3339: }
3340: if ($oheight == $nheight || (!$nwidth && !$nheight)) {
3341: $token->[2]{'height'}=$iheight;$ctag=1;
3342: }
3343: }
3344: }
3345: my ($cwidth,$cheight)=($token->[2]{'width'},$token->[2]{'height'});
3346: # if we don't have a width or height
3347: if ($iwidth && $cwidth && !$cheight) {
3348: $token->[2]{'height'}=int(($cwidth/$iwidth)*$iheight);$ctag=1;
3349: }
3350: if ($iheight && $cheight && !$cwidth) {
3351: $token->[2]{'width'}=int(($cheight/$iheight)*$iwidth);$ctag=1;
3352: }
3353: if ($ctag) {$currentstring=&Apache::edit::rebuild_tag($token);}
3354: }
3355:
3356: return $currentstring;
3357: }
3358:
3359: sub end_img {
3360: my ($target,$token) = @_;
3361: my $currentstring = '';
3362: if ($target eq 'web' || $target eq 'webgrade') {
3363: $currentstring = $token->[2];
3364: } elsif ($target eq 'tex') {
3365: $currentstring = '';
3366: }
3367: return $currentstring;
3368: }
3369:
3370: #-- <applet> tag (end tag required)
3371: sub start_applet {
3372: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3373:
3374: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,undef,1);
3375: &Apache::lonxml::extlink($code);
3376: my $archive=&Apache::lonxml::get_param('archive',$parstack,$safeeval,
3377: undef,1);
3378: &Apache::lonxml::extlink($archive);
3379: my $currentstring = '';
3380: if ($target eq 'web' || $target eq 'webgrade') {
3381: if ($env{'browser.appletsuppress'} ne 'on') {
3382: $currentstring = &Apache::lonenc::encrypt_ref($token,
3383: {'code'=>$code,
3384: 'archive'=>$archive}
3385: );
3386: } else {
3387: my $alttag= &Apache::lonxml::get_param('alt',$parstack,
3388: $safeeval,undef,1);
3389: unless ($alttag) {
3390: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
3391: $code);
3392: }
3393: $currentstring='[APPLET: '.$alttag.']';
3394: }
3395: } elsif ($target eq 'tex') {
3396: # Turn off some stuff we can't be inside thank you LaTeX
3397:
3398:
3399: my $restart_sub = 0;
3400: my $restart_sup = 0;
3401:
3402: # Since <sub> and <sup> are simple tags it's ok to turn off/on
3403: # using the start_ stop_ functions.. those tags only care about
3404: # $target.
3405:
3406: if (&is_inside_of($tagstack, "sub")) {
3407: $restart_sub = 1;
3408: $currentstring .= &end_sub($target, $token, $tagstack,
3409: $parstack, $parser, $safeeval);
3410: }
3411: if (&is_inside_of($tagstack, "sup")) {
3412: $restart_sup = 1;
3413: $currentstring .= &end_sup($target, $token, $tagstack,
3414: $parstack, $parser, $safeeval);
3415: }
3416:
3417: # Now process the applet; just replace it with its alt attribute.
3418:
3419: my $alttag= &Apache::lonxml::get_param('alt',$parstack,
3420: $safeeval,undef,1);
3421: unless ($alttag) {
3422: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,
3423: undef,1);
3424: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
3425: $code);
3426: }
3427: $currentstring.='\begin{center} \fbox{Java Applet: '.$alttag.
3428: '.}\end{center}';
3429:
3430: # Turn stuff back on that we can't be inside of.
3431:
3432: if ($restart_sub) {
3433: $currentstring .= &start_sub($target, $token, $tagstack,
3434: $parstack, $parser, $safeeval);
3435: }
3436: if ($restart_sup) {
3437: $currentstring .= &start_sup($target, $token, $tagstack,
3438: $parstack, $parser, $safeeval);
3439: }
3440: }
3441: return $currentstring;
3442: }
3443:
3444: sub end_applet {
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: return $currentstring;
3452: }
3453:
3454: #-- <embed> tag (end tag optional/required)
3455: sub start_embed {
3456: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3457: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
3458: &Apache::lonxml::extlink($src);
3459: my $currentstring = '';
3460: if ($target eq 'web' || $target eq 'webgrade') {
3461: if ($env{'browser.embedsuppress'} ne 'on') {
3462: $currentstring=&Apache::lonenc::encrypt_ref($token,{'src'=>$src});
3463: } else {
3464: my $alttag=&Apache::lonxml::get_param
3465: ('alt',$parstack,$safeeval,undef,1);
3466: unless ($alttag) {
3467: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
3468: }
3469: $currentstring='[EMBED: '.$alttag.']';
3470: }
3471: } elsif ($target eq 'tex') {
3472: }
3473: return $currentstring;
3474: }
3475:
3476: sub end_embed {
3477: my ($target,$token) = @_;
3478: my $currentstring = '';
3479: if ($target eq 'web' || $target eq 'webgrade') {
3480: $currentstring = $token->[2];
3481: } elsif ($target eq 'tex') {
3482: }
3483: return $currentstring;
3484: }
3485:
3486: #-- <param> tag (end tag forbidden)
3487: sub start_param {
3488: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3489: if (&Apache::lonxml::get_param('name',$parstack,
3490: $safeeval,undef,1)=~/^cabbase$/i) {
3491: my $value=&Apache::lonxml::get_param('value',$parstack,
3492: $safeeval,undef,1);
3493: &Apache::lonxml::extlink($value);
3494: }
3495:
3496: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
3497: &Apache::lonxml::extlink($src);
3498: my $currentstring = '';
3499: if ($target eq 'web' || $target eq 'webgrade') {
3500: my %toconvert;
3501: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
3502: if ($src) { $toconvert{'src'}= $src; }
3503: my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval,
3504: undef,1);
3505: if ($name=~/^cabbase$/i) {
3506: $toconvert{'value'}=&Apache::lonxml::get_param('value',$parstack,
3507: $safeeval,undef,1);
3508: }
3509: $currentstring = &Apache::lonenc::encrypt_ref($token,\%toconvert);
3510: } elsif ($target eq 'tex') {
3511: }
3512: return $currentstring;
3513: }
3514:
3515: sub end_param {
3516: my ($target,$token) = @_;
3517: my $currentstring = '';
3518: if ($target eq 'web' || $target eq 'webgrade') {
3519: $currentstring = $token->[2];
3520: } elsif ($target eq 'tex') {
3521: }
3522: return $currentstring;
3523: }
3524:
3525: #-- <allow> tag
3526: sub start_allow {
3527: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3528: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
3529: &Apache::lonxml::extlink($src);
3530:
3531: if ($target eq 'tex') { &image_replication($src); }
3532: my $result;
3533: if ($target eq 'edit') {
3534: $result .=&Apache::edit::tag_start($target,$token);
3535: $result .=&Apache::edit::text_arg('File Spec:','src',$token,70);
3536: $result .=&Apache::edit::end_row();#.&Apache::edit::start_spanning_row();
3537: } elsif ($target eq 'modified') {
3538: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
3539: $safeeval,'src');
3540: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
3541: }
3542: return $result;
3543: }
3544:
3545: sub end_allow {
3546: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3547: if ( $target eq 'edit') { return (&Apache::edit::end_table()); }
3548: return '';
3549: }
3550:
3551: #-- Frames (end tag required)
3552: #-- <frameset>
3553: sub start_frameset {
3554: my ($target,$token) = @_;
3555: my $currentstring = ''; # Close any pending para.
3556: if ($target eq 'web' || $target eq 'webgrade') {
3557: $currentstring =
3558: &Apache::loncommon::start_page($Apache::londefdef::title,
3559: $Apache::londefdef::head,
3560: {'add_entries' => $token->[2],
3561: # 'no_title' => 1,
3562: 'force_register' => 1,
3563: 'frameset' => 1,});
3564:
3565: }
3566: return $currentstring;
3567: }
3568:
3569: sub end_frameset {
3570: my ($target,$token) = @_;
3571: my $currentstring = '';
3572: if ($target eq 'web' || $target eq 'webgrade') {
3573: $currentstring = $token->[2];
3574: }
3575: return $currentstring;
3576: }
3577:
3578: #-- <xmp> (end tag required)
3579: sub start_xmp {
3580: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3581: my $currentstring = '';
3582: if ($target eq 'web' || $target eq 'webgrade') {
3583: $currentstring .= $token->[4];
3584: } elsif ($target eq 'tex') {
3585: $currentstring .= '\begin{verbatim}';
3586: }
3587: return $currentstring;
3588: }
3589:
3590: sub end_xmp {
3591: my ($target,$token) = @_;
3592: my $currentstring = '';
3593: if ($target eq 'web' || $target eq 'webgrade') {
3594: $currentstring .= $token->[2];
3595: } elsif ($target eq 'tex') {
3596: $currentstring .= '\end{verbatim}';
3597: }
3598: return $currentstring;
3599: }
3600:
3601: #-- <pre> (end tag required)
3602: sub start_pre {
3603: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3604: my $currentstring = &end_p(); # close off pending <p>
3605: if ($target eq 'web' || $target eq 'webgrade') {
3606: $currentstring .= $token->[4];
3607: } elsif ($target eq 'tex') {
3608: $currentstring .= '\begin{verbatim}';
3609: &Apache::lonxml::disable_LaTeX_substitutions();
3610: }
3611: return $currentstring;
3612: }
3613:
3614: sub end_pre {
3615: my ($target,$token) = @_;
3616: my $currentstring = '';
3617: if ($target eq 'web' || $target eq 'webgrade') {
3618: $currentstring .= $token->[2];
3619: } elsif ($target eq 'tex') {
3620: $currentstring .= '\end{verbatim}';
3621: &Apache::lonxml::enable_LaTeX_substitutions();
3622: }
3623: return $currentstring;
3624: }
3625:
3626: #-- <insert>
3627: sub start_insert {
3628: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3629: my $currentstring = '';
3630: if ($target eq 'web' || $target eq 'webgrade') {
3631: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
3632: $currentstring .= '<b>'.$display.'</b>';;
3633: }
3634: return $currentstring;
3635: }
3636:
3637: sub end_insert {
3638: my ($target,$token) = @_;
3639: my $currentstring = '';
3640: if ($target eq 'web' || $target eq 'webgrade') {
3641: $currentstring .= '';
3642: }
3643: return $currentstring;
3644: }
3645:
3646: #-- <externallink>
3647: sub start_externallink {
3648: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3649: my $currentstring = '';
3650: if ($target eq 'web' || $target eq 'webgrade') {
3651: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
3652: $currentstring .= '<b>'.$display.'</b>';;
3653: }
3654: return $currentstring;
3655: }
3656:
3657: sub end_externallink {
3658: my ($target,$token) = @_;
3659: my $currentstring = '';
3660: if ($target eq 'web' || $target eq 'webgrade') {
3661: $currentstring .= '';
3662: }
3663: return $currentstring;
3664: }
3665:
3666: #-- <blankspace heigth="">
3667: sub start_blankspace {
3668: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3669: my $currentstring = &end_p(); # closes off any unclosed <p>
3670: if ($target eq 'tex') {
3671: my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval,undef,1);
3672: $currentstring .= '\vskip '.$howmuch.' ';
3673: }
3674: return $currentstring;
3675: }
3676:
3677: sub end_blankspace {
3678: my ($target,$token) = @_;
3679: my $currentstring = '';
3680: if ($target eq 'tex') {
3681: $currentstring .= '';
3682: }
3683: return $currentstring;
3684: }
3685:
3686: #-- <abbr> tag (end tag required)
3687: sub start_abbr {
3688: my ($target,$token) = @_;
3689: my $currentstring = '';
3690: if ($target eq 'web' || $target eq 'webgrade') {
3691: $currentstring = $token->[4];
3692: }
3693: return $currentstring;
3694: }
3695:
3696: sub end_abbr {
3697: my ($target,$token) = @_;
3698: my $currentstring = '';
3699: if ($target eq 'web' || $target eq 'webgrade') {
3700: $currentstring = $token->[2];
3701: }
3702: return $currentstring;
3703: }
3704:
3705: #-- <acronym> tag (end tag required)
3706: sub start_acronym {
3707: my ($target,$token) = @_;
3708: my $currentstring = '';
3709: if ($target eq 'web' || $target eq 'webgrade') {
3710: $currentstring = $token->[4];
3711: }
3712: return $currentstring;
3713: }
3714:
3715: sub end_acronym {
3716: my ($target,$token) = @_;
3717: my $currentstring = '';
3718: if ($target eq 'web' || $target eq 'webgrade') {
3719: $currentstring = $token->[2];
3720: }
3721: return $currentstring;
3722: }
3723:
3724: #-- <area> tag (end tag forbidden)
3725: sub start_area {
3726: my ($target,$token) = @_;
3727: my $currentstring = '';
3728: if ($target eq 'web' || $target eq 'webgrade') {
3729: $currentstring = $token->[4];
3730: }
3731: return $currentstring;
3732: }
3733:
3734: sub end_area {
3735: my ($target,$token) = @_;
3736: my $currentstring = '';
3737: if ($target eq 'web' || $target eq 'webgrade') {
3738: $currentstring = $token->[2];
3739: }
3740: return $currentstring;
3741: }
3742:
3743: #-- <base> tag (end tag forbidden)
3744: sub start_base {
3745: my ($target,$token) = @_;
3746: my $currentstring = '';
3747: if ($target eq 'web' || $target eq 'webgrade') {
3748: $currentstring = $token->[4];
3749: }
3750: return $currentstring;
3751: }
3752:
3753: sub end_base {
3754: my ($target,$token) = @_;
3755: my $currentstring = '';
3756: if ($target eq 'web' || $target eq 'webgrade') {
3757: $currentstring = $token->[2];
3758: }
3759: return $currentstring;
3760: }
3761:
3762: #-- <bdo> tag (end tag required)
3763: sub start_bdo {
3764: my ($target,$token) = @_;
3765: my $currentstring = '';
3766: if ($target eq 'web' || $target eq 'webgrade') {
3767: $currentstring = $token->[4];
3768: }
3769: return $currentstring;
3770: }
3771:
3772: sub end_bdo {
3773: my ($target,$token) = @_;
3774: my $currentstring = '';
3775: if ($target eq 'web' || $target eq 'webgrade') {
3776: $currentstring = $token->[2];
3777: }
3778: return $currentstring;
3779: }
3780:
3781: #-- <bgsound> tag (end tag optional)
3782: sub start_bgsound {
3783: my ($target,$token) = @_;
3784: my $currentstring = '';
3785: if ($target eq 'web' || $target eq 'webgrade') {
3786: $currentstring = $token->[4];
3787: }
3788: return $currentstring;
3789: }
3790:
3791: sub end_bgsound {
3792: my ($target,$token) = @_;
3793: my $currentstring = '';
3794: if ($target eq 'web' || $target eq 'webgrade') {
3795: $currentstring = $token->[2];
3796: }
3797: return $currentstring;
3798: }
3799:
3800: #-- <blink> tag (end tag required)
3801: sub start_blink {
3802: my ($target,$token) = @_;
3803: my $currentstring = '';
3804: if ($target eq 'web' || $target eq 'webgrade') {
3805: $currentstring = $token->[4];
3806: }
3807: return $currentstring;
3808: }
3809:
3810: sub end_blink {
3811: my ($target,$token) = @_;
3812: my $currentstring = '';
3813: if ($target eq 'web' || $target eq 'webgrade') {
3814: $currentstring = $token->[2];
3815: }
3816: return $currentstring;
3817: }
3818:
3819: #-- <blockquote> tag (end tag required)
3820: sub start_blockquote {
3821: my ($target,$token) = @_;
3822: my $currentstring = &end_p(); # Close any unclosed <p>
3823: if ($target eq 'web' || $target eq 'webgrade') {
3824: $currentstring .= $token->[4];
3825: }
3826: if ($target eq 'tex') {
3827: $currentstring .= '\begin{quote}';
3828: }
3829: return $currentstring;
3830: }
3831:
3832: sub end_blockquote {
3833: my ($target,$token) = @_;
3834: my $currentstring = '';
3835: if ($target eq 'web' || $target eq 'webgrade') {
3836: $currentstring = $token->[2];
3837: }
3838: if ($target eq 'tex') {
3839: $currentstring = '\end{quote}';
3840: }
3841: return $currentstring;
3842: }
3843:
3844: #-- <button> tag (end tag required)
3845: sub start_button {
3846: my ($target,$token) = @_;
3847: my $currentstring = '';
3848: if ($target eq 'web' || $target eq 'webgrade') {
3849: $currentstring = $token->[4];
3850: }
3851: return $currentstring;
3852: }
3853:
3854: sub end_button {
3855: my ($target,$token) = @_;
3856: my $currentstring = '';
3857: if ($target eq 'web' || $target eq 'webgrade') {
3858: $currentstring = $token->[2];
3859: }
3860: return $currentstring;
3861: }
3862:
3863: #-- <caption> tag (end tag required)
3864: sub start_caption {
3865: my ($target,$token) = @_;
3866: my $currentstring = '';
3867: if ($target eq 'web' || $target eq 'webgrade') {
3868: $currentstring = $token->[4];
3869: }
3870: return $currentstring;
3871: }
3872:
3873: sub end_caption {
3874: my ($target,$token) = @_;
3875: my $currentstring = '';
3876: if ($target eq 'web' || $target eq 'webgrade') {
3877: $currentstring = $token->[2];
3878: }
3879: return $currentstring;
3880: }
3881:
3882: #-- <col> tag (end tag forbdden)
3883: sub start_col {
3884: my ($target,$token) = @_;
3885: my $currentstring = '';
3886: if ($target eq 'web' || $target eq 'webgrade') {
3887: $currentstring = $token->[4];
3888: }
3889: return $currentstring;
3890: }
3891:
3892: sub end_col {
3893: my ($target,$token) = @_;
3894: my $currentstring = '';
3895: if ($target eq 'web' || $target eq 'webgrade') {
3896: $currentstring = $token->[2];
3897: }
3898: return $currentstring;
3899: }
3900:
3901: #-- <colgroup> tag (end tag optional)
3902: sub start_colgroup {
3903: my ($target,$token) = @_;
3904: my $currentstring = '';
3905: if ($target eq 'web' || $target eq 'webgrade') {
3906: $currentstring = $token->[4];
3907: }
3908: return $currentstring;
3909: }
3910:
3911: sub end_colgroup {
3912: my ($target,$token) = @_;
3913: my $currentstring = '';
3914: if ($target eq 'web' || $target eq 'webgrade') {
3915: $currentstring = $token->[2];
3916: }
3917: return $currentstring;
3918: }
3919:
3920: #-- <del> tag (end tag required)
3921: sub start_del {
3922: my ($target,$token) = @_;
3923: my $currentstring = '';
3924: if ($target eq 'web' || $target eq 'webgrade') {
3925: $currentstring = $token->[4];
3926: }
3927: return $currentstring;
3928: }
3929:
3930: sub end_del {
3931: my ($target,$token) = @_;
3932: my $currentstring = '';
3933: if ($target eq 'web' || $target eq 'webgrade') {
3934: $currentstring = $token->[2];
3935: }
3936: return $currentstring;
3937: }
3938:
3939: #-- <fieldset> tag (end tag required)
3940: sub start_fieldset {
3941: my ($target,$token) = @_;
3942: my $currentstring = '';
3943: if ($target eq 'web' || $target eq 'webgrade') {
3944: $currentstring = $token->[4];
3945: }
3946: return $currentstring;
3947: }
3948:
3949: sub end_fieldset {
3950: my ($target,$token) = @_;
3951: my $currentstring = '';
3952: if ($target eq 'web' || $target eq 'webgrade') {
3953: $currentstring = $token->[2];
3954: }
3955: return $currentstring;
3956: }
3957:
3958: #-- <frame> tag (end tag forbidden)
3959: sub start_frame {
3960: my ($target,$token) = @_;
3961: my $currentstring = '';
3962: if ($target eq 'web' || $target eq 'webgrade') {
3963: $currentstring = $token->[4];
3964: }
3965: return $currentstring;
3966: }
3967:
3968: sub end_frame {
3969: my ($target,$token) = @_;
3970: my $currentstring = '';
3971: if ($target eq 'web' || $target eq 'webgrade') {
3972: $currentstring = $token->[2];
3973: }
3974: return $currentstring;
3975: }
3976:
3977: #-- <iframe> tag (end tag required)
3978: sub start_iframe {
3979: my ($target,$token) = @_;
3980: my $currentstring = '';
3981: if ($target eq 'web' || $target eq 'webgrade') {
3982: $currentstring = $token->[4];
3983: }
3984: return $currentstring;
3985: }
3986:
3987: sub end_iframe {
3988: my ($target,$token) = @_;
3989: my $currentstring = '';
3990: if ($target eq 'web' || $target eq 'webgrade') {
3991: $currentstring = $token->[2];
3992: }
3993: return $currentstring;
3994: }
3995:
3996: #-- <ins> tag (end tag required)
3997: sub start_ins {
3998: my ($target,$token) = @_;
3999: my $currentstring = '';
4000: if ($target eq 'web' || $target eq 'webgrade') {
4001: $currentstring = $token->[4];
4002: }
4003: return $currentstring;
4004: }
4005:
4006: sub end_ins {
4007: my ($target,$token) = @_;
4008: my $currentstring = '';
4009: if ($target eq 'web' || $target eq 'webgrade') {
4010: $currentstring = $token->[2];
4011: }
4012: return $currentstring;
4013: }
4014:
4015: #-- <isindex> tag (end tag forbidden)
4016: sub start_isindex {
4017: my ($target,$token) = @_;
4018: my $currentstring = '';
4019: if ($target eq 'web' || $target eq 'webgrade') {
4020: $currentstring = $token->[4];
4021: }
4022: return $currentstring;
4023: }
4024:
4025: sub end_isindex {
4026: my ($target,$token) = @_;
4027: my $currentstring = '';
4028: if ($target eq 'web' || $target eq 'webgrade') {
4029: $currentstring = $token->[2];
4030: }
4031: return $currentstring;
4032: }
4033:
4034: #-- <keygen> tag (end tag forbidden)
4035: sub start_keygen {
4036: my ($target,$token) = @_;
4037: my $currentstring = '';
4038: if ($target eq 'web' || $target eq 'webgrade') {
4039: $currentstring = $token->[4];
4040: }
4041: return $currentstring;
4042: }
4043:
4044: sub end_keygen {
4045: my ($target,$token) = @_;
4046: my $currentstring = '';
4047: if ($target eq 'web' || $target eq 'webgrade') {
4048: $currentstring = $token->[2];
4049: }
4050: return $currentstring;
4051: }
4052:
4053: #-- <label> tag
4054: sub start_label {
4055: my ($target,$token) = @_;
4056: my $currentstring = '';
4057: if ($target eq 'web' || $target eq 'webgrade') {
4058: $currentstring = $token->[4];
4059: }
4060: return $currentstring;
4061: }
4062:
4063: sub end_label {
4064: my ($target,$token) = @_;
4065: my $currentstring = '';
4066: if ($target eq 'web' || $target eq 'webgrade') {
4067: $currentstring = $token->[2];
4068: }
4069: return $currentstring;
4070: }
4071:
4072: #-- <layer> tag (end tag required)
4073: sub start_layer {
4074: my ($target,$token) = @_;
4075: my $currentstring = '';
4076: if ($target eq 'web' || $target eq 'webgrade') {
4077: $currentstring = $token->[4];
4078: }
4079: return $currentstring;
4080: }
4081:
4082: sub end_layer {
4083: my ($target,$token) = @_;
4084: my $currentstring = '';
4085: if ($target eq 'web' || $target eq 'webgrade') {
4086: $currentstring = $token->[2];
4087: }
4088: return $currentstring;
4089: }
4090:
4091: #-- <legend> tag (end tag required)
4092: sub start_legend {
4093: my ($target,$token) = @_;
4094: my $currentstring = '';
4095: if ($target eq 'web' || $target eq 'webgrade') {
4096: $currentstring = $token->[4];
4097: }
4098: return $currentstring;
4099: }
4100:
4101: sub end_legend {
4102: my ($target,$token) = @_;
4103: my $currentstring = '';
4104: if ($target eq 'web' || $target eq 'webgrade') {
4105: $currentstring = $token->[2];
4106: }
4107: return $currentstring;
4108: }
4109:
4110: #-- <link> tag (end tag forbidden)
4111: sub start_link {
4112: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
4113: my $currentstring = '';
4114: if ($target eq 'web' || $target eq 'webgrade') {
4115: my $href=&Apache::lonxml::get_param('href',$parstack,$safeeval,
4116: undef,1);
4117: &Apache::lonxml::extlink($href);
4118: $currentstring = $token->[4];
4119: }
4120: return $currentstring;
4121: }
4122:
4123: sub end_link {
4124: my ($target,$token) = @_;
4125: my $currentstring = '';
4126: if ($target eq 'web' || $target eq 'webgrade') {
4127: $currentstring = $token->[2];
4128: }
4129: return $currentstring;
4130: }
4131:
4132: #-- <marquee> tag (end tag optional)
4133: sub start_marquee {
4134: my ($target,$token) = @_;
4135: my $currentstring = '';
4136: if ($target eq 'web' || $target eq 'webgrade') {
4137: $currentstring = $token->[4];
4138: }
4139: return $currentstring;
4140: }
4141:
4142: sub end_marquee {
4143: my ($target,$token) = @_;
4144: my $currentstring = '';
4145: if ($target eq 'web' || $target eq 'webgrade') {
4146: $currentstring = $token->[2];
4147: }
4148: return $currentstring;
4149: }
4150:
4151: #-- <multicol> tag (end tag required)
4152: sub start_multicol {
4153: my ($target,$token) = @_;
4154: my $currentstring = &end_p(); # Close any pending <p>
4155: if ($target eq 'web' || $target eq 'webgrade') {
4156: $currentstring .= $token->[4];
4157: }
4158: return $currentstring;
4159: }
4160:
4161: sub end_multicol {
4162: my ($target,$token) = @_;
4163: my $currentstring = '';
4164: if ($target eq 'web' || $target eq 'webgrade') {
4165: $currentstring = $token->[2];
4166: }
4167: return $currentstring;
4168: }
4169:
4170: #-- <nobr> tag (end tag required)
4171: sub start_nobr {
4172: my ($target,$token) = @_;
4173: my $currentstring = '';
4174: if ($target eq 'web' || $target eq 'webgrade') {
4175: $currentstring = $token->[4];
4176: } elsif ($target eq 'tex') {
4177: $currentstring='\mbox{';
4178: }
4179: return $currentstring;
4180: }
4181:
4182: sub end_nobr {
4183: my ($target,$token) = @_;
4184: my $currentstring = '';
4185: if ($target eq 'web' || $target eq 'webgrade') {
4186: $currentstring = $token->[2];
4187: } elsif ($target eq 'tex') {
4188: $currentstring='}';
4189: }
4190: return $currentstring;
4191: }
4192:
4193: #-- <noembed> tag (end tag required)
4194: sub start_noembed {
4195: my ($target,$token) = @_;
4196: my $currentstring = '';
4197: if ($target eq 'web' || $target eq 'webgrade') {
4198: $currentstring = $token->[4];
4199: }
4200: return $currentstring;
4201: }
4202:
4203: sub end_noembed {
4204: my ($target,$token) = @_;
4205: my $currentstring = '';
4206: if ($target eq 'web' || $target eq 'webgrade') {
4207: $currentstring = $token->[2];
4208: }
4209: return $currentstring;
4210: }
4211:
4212: #-- <noframes> tag (end tag required)
4213: sub start_noframes {
4214: my ($target,$token) = @_;
4215: my $currentstring = '';
4216: if ($target eq 'web' || $target eq 'webgrade') {
4217: $currentstring = $token->[4];
4218: }
4219: return $currentstring;
4220: }
4221:
4222: sub end_noframes {
4223: my ($target,$token) = @_;
4224: my $currentstring = '';
4225: if ($target eq 'web' || $target eq 'webgrade') {
4226: $currentstring = $token->[2];
4227: }
4228: return $currentstring;
4229: }
4230:
4231: #-- <nolayer> tag (end tag required)
4232: sub start_nolayer {
4233: my ($target,$token) = @_;
4234: my $currentstring = '';
4235: if ($target eq 'web' || $target eq 'webgrade') {
4236: $currentstring = $token->[4];
4237: }
4238: return $currentstring;
4239: }
4240:
4241: sub end_nolayer {
4242: my ($target,$token) = @_;
4243: my $currentstring = '';
4244: if ($target eq 'web' || $target eq 'webgrade') {
4245: $currentstring = $token->[2];
4246: }
4247: return $currentstring;
4248: }
4249:
4250: #-- <noscript> tag (end tag required)
4251: sub start_noscript {
4252: my ($target,$token) = @_;
4253: my $currentstring = '';
4254: if ($target eq 'web' || $target eq 'webgrade') {
4255: $currentstring = $token->[4];
4256: }
4257: return $currentstring;
4258: }
4259:
4260: sub end_noscript {
4261: my ($target,$token) = @_;
4262: my $currentstring = '';
4263: if ($target eq 'web' || $target eq 'webgrade') {
4264: $currentstring = $token->[2];
4265: }
4266: return $currentstring;
4267: }
4268:
4269: #-- <object> tag (end tag required)
4270: sub start_object {
4271: my ($target,$token) = @_;
4272: my $currentstring = '';
4273: if ($target eq 'web' || $target eq 'webgrade') {
4274: $currentstring = $token->[4];
4275: }
4276: return $currentstring;
4277: }
4278:
4279: sub end_object {
4280: my ($target,$token) = @_;
4281: my $currentstring = '';
4282: if ($target eq 'web' || $target eq 'webgrade') {
4283: $currentstring = $token->[2];
4284: }
4285: return $currentstring;
4286: }
4287:
4288: #-- <optgroup> tag (end tag required)
4289: sub start_optgroup {
4290: my ($target,$token) = @_;
4291: my $currentstring = '';
4292: if ($target eq 'web' || $target eq 'webgrade') {
4293: $currentstring = $token->[4];
4294: }
4295: return $currentstring;
4296: }
4297:
4298: sub end_optgroup {
4299: my ($target,$token) = @_;
4300: my $currentstring = '';
4301: if ($target eq 'web' || $target eq 'webgrade') {
4302: $currentstring = $token->[2];
4303: }
4304: return $currentstring;
4305: }
4306:
4307: #-- <samp> tag (end tag required)
4308: sub start_samp {
4309: my ($target,$token) = @_;
4310: my $currentstring = '';
4311: if ($target eq 'web' || $target eq 'webgrade') {
4312: $currentstring = $token->[4];
4313: } elsif ($target eq 'tex') {
4314: $currentstring='\texttt{';
4315: }
4316: return $currentstring;
4317: }
4318:
4319: sub end_samp {
4320: my ($target,$token) = @_;
4321: my $currentstring = '';
4322: if ($target eq 'web' || $target eq 'webgrade') {
4323: $currentstring = $token->[2];
4324: } elsif ($target eq 'tex') {
4325: $currentstring='}';
4326: }
4327: return $currentstring;
4328: }
4329:
4330: #-- <server> tag
4331: sub start_server {
4332: my ($target,$token) = @_;
4333: my $currentstring = '';
4334: if ($target eq 'web' || $target eq 'webgrade') {
4335: $currentstring = $token->[4];
4336: }
4337: return $currentstring;
4338: }
4339:
4340: sub end_server {
4341: my ($target,$token) = @_;
4342: my $currentstring = '';
4343: if ($target eq 'web' || $target eq 'webgrade') {
4344: $currentstring = $token->[2];
4345: }
4346: return $currentstring;
4347: }
4348:
4349: #-- <spacer> tag (end tag forbidden)
4350: sub start_spacer {
4351: my ($target,$token) = @_;
4352: my $currentstring = &end_p(); # Close off any open <p> tag.
4353: if ($target eq 'web' || $target eq 'webgrade') {
4354: $currentstring .= $token->[4];
4355: }
4356: return $currentstring;
4357: }
4358:
4359: sub end_spacer {
4360: my ($target,$token) = @_;
4361: my $currentstring = '';
4362: if ($target eq 'web' || $target eq 'webgrade') {
4363: $currentstring = $token->[2];
4364: }
4365: return $currentstring;
4366: }
4367:
4368: #-- <span> tag (end tag required)
4369: sub start_span {
4370: my ($target,$token) = @_;
4371: my $currentstring = '';
4372: if ($target eq 'web' || $target eq 'webgrade') {
4373: $currentstring = $token->[4];
4374: }
4375: return $currentstring;
4376: }
4377:
4378: sub end_span {
4379: my ($target,$token) = @_;
4380: my $currentstring = '';
4381: if ($target eq 'web' || $target eq 'webgrade') {
4382: $currentstring = $token->[2];
4383: }
4384: return $currentstring;
4385: }
4386:
4387: #-- <tbody> tag (end tag optional)
4388: sub start_tbody {
4389: my ($target,$token) = @_;
4390: my $currentstring = '';
4391: if ($target eq 'web' || $target eq 'webgrade') {
4392: $currentstring = $token->[4];
4393: }
4394: return $currentstring;
4395: }
4396:
4397: sub end_tbody {
4398: my ($target,$token) = @_;
4399: my $currentstring = '';
4400: if ($target eq 'web' || $target eq 'webgrade') {
4401: $currentstring = $token->[2];
4402: }
4403: return $currentstring;
4404: }
4405:
4406: #-- <tfoot> tag (end tag optional)
4407: sub start_tfoot {
4408: my ($target,$token) = @_;
4409: my $currentstring = '';
4410: if ($target eq 'web' || $target eq 'webgrade') {
4411: $currentstring = $token->[4];
4412: }
4413: return $currentstring;
4414: }
4415:
4416: sub end_tfoot {
4417: my ($target,$token) = @_;
4418: my $currentstring = '';
4419: if ($target eq 'web' || $target eq 'webgrade') {
4420: $currentstring = $token->[2];
4421: }
4422: return $currentstring;
4423: }
4424:
4425: #-- <thead> tag (end tag optional)
4426: sub start_thead {
4427: my ($target,$token) = @_;
4428: my $currentstring = '';
4429: if ($target eq 'web' || $target eq 'webgrade') {
4430: $currentstring = $token->[4];
4431: }
4432: return $currentstring;
4433: }
4434:
4435: sub end_thead {
4436: my ($target,$token) = @_;
4437: my $currentstring = '';
4438: if ($target eq 'web' || $target eq 'webgrade') {
4439: $currentstring = $token->[2];
4440: }
4441: return $currentstring;
4442: }
4443:
4444: #-- <var> tag
4445: sub start_var {
4446: my ($target,$token) = @_;
4447: my $currentstring = '';
4448: if ($target eq 'web' || $target eq 'webgrade') {
4449: $currentstring = $token->[4];
4450: } elsif ($target eq 'tex') {
4451: $currentstring = '\textit{';
4452: }
4453: return $currentstring;
4454: }
4455:
4456: sub end_var {
4457: my ($target,$token) = @_;
4458: my $currentstring = '';
4459: if ($target eq 'web' || $target eq 'webgrade') {
4460: $currentstring = $token->[2];
4461: } elsif ($target eq 'tex') {
4462: $currentstring = '}';
4463: }
4464: return $currentstring;
4465: }
4466:
4467: #-- <wbr> tag (end tag forbidden)
4468: sub start_wbr {
4469: my ($target,$token) = @_;
4470: my $currentstring = '';
4471: if ($target eq 'web' || $target eq 'webgrade') {
4472: $currentstring = $token->[4];
4473: }
4474: return $currentstring;
4475: }
4476:
4477: sub end_wbr {
4478: my ($target,$token) = @_;
4479: my $currentstring = '';
4480: if ($target eq 'web' || $target eq 'webgrade') {
4481: $currentstring = $token->[2];
4482: }
4483: return $currentstring;
4484: }
4485:
4486: #-- <hideweboutput> tag
4487: sub start_hideweboutput {
4488: my ($target,$token) = @_;
4489: if ($target eq 'web' || $target eq 'webgrade') {
4490: &Apache::lonxml::startredirection();
4491: }
4492: return '';
4493: }
4494:
4495: sub end_hideweboutput {
4496: my ($target,$token) = @_;
4497: my $currentstring = '';
4498: if ($target eq 'web' || $target eq 'webgrade') {
4499: $currentstring = &Apache::lonxml::endredirection();
4500: }
4501: return '';
4502: }
4503:
4504:
4505: sub image_replication {
4506: my $src = shift;
4507: if (not -e $src) { &Apache::lonnet::repcopy($src); }
4508: #replicates eps or ps
4509: my $epssrc = my $pssrc = $src;
4510: $epssrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i;
4511: $pssrc =~ s/\.(gif|jpg|jpeg|png)$/.ps/i;
4512: if (not -e $epssrc && not -e $pssrc) {
4513: my $result=&Apache::lonnet::repcopy($epssrc);
4514: if ($result ne 'ok') { &Apache::lonnet::repcopy($pssrc); }
4515: }
4516: return '';
4517: }
4518:
4519:
4520:
4521: sub resize_image {
4522: my ($height_param, $width_param, $scaling,
4523: $parstack, $safeeval, $depth, $cis) = @_;
4524:
4525: # First apply the scaling...
4526:
4527: $height_param = $height_param * $scaling;
4528: $width_param = $width_param * $scaling;
4529:
4530: #do we have any specified LaTeX size of the picture?
4531: my $toget='TeXwidth';
4532: if ($cis) {
4533: $toget=lc($toget);
4534: }
4535: my $TeXwidth = &Apache::lonxml::get_param($toget,$parstack,
4536: $safeeval,$depth,$cis);
4537: $toget='TeXheight'; if ($cis) { $toget=lc($toget); }
4538: my $TeXheight = &Apache::lonxml::get_param($toget,$parstack,
4539: $safeeval,$depth,$cis);
4540: #do we have any specified web size of the picture?
4541: my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval,
4542: $depth,1);
4543: if ($TeXwidth) {
4544: my $old_width_param=$width_param;
4545: if ($TeXwidth=~/(\d+)\s*\%/) {
4546: $width_param = $1*$env{'form.textwidth'}/100;
4547: } else {
4548: $width_param = $TeXwidth;
4549: }
4550: if ($TeXheight) {
4551: $height_param = $TeXheight;
4552: } elsif ($old_width_param) {
4553: $height_param=$TeXwidth/$old_width_param*$height_param;
4554: }
4555: } elsif ($TeXheight) {
4556: $height_param = $TeXheight;
4557: if ($height_param) {
4558: $width_param = $TeXheight/$height_param*$width_param;
4559: }
4560: } elsif ($width) {
4561: my $old_width_param=$width_param;
4562: $width_param = $width*$scaling;
4563: if ($old_width_param) {
4564: $height_param=$width_param/$old_width_param*$height_param;
4565: }
4566: }
4567: if ($width_param > $env{'form.textwidth'}) {
4568: my $old_width_param=$width_param;
4569: $width_param =0.95*$env{'form.textwidth'};
4570: if ($old_width_param) {
4571: $height_param=$width_param/$old_width_param*$height_param;
4572: }
4573: }
4574:
4575: return ($height_param, $width_param);
4576: }
4577:
4578: sub image_size {
4579: my ($src,$scaling,$parstack,$safeeval,$depth,$cis)=@_;
4580:
4581: #size of image from gif/jpg/jpeg/png
4582: my $ressrc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
4583: if (-e $ressrc) {
4584: $src = $ressrc;
4585: }
4586: my $image = Image::Magick->new;
4587: my $current_figure = $image->Read($src);
4588: my $width_param = $image->Get('width');
4589: my $height_param = $image->Get('height');
4590: &Apache::lonxml::debug("Image magick says: $src : Height = $height_param width = $width_param");
4591: undef($image);
4592:
4593: ($height_param, $width_param) = &resize_image($height_param, $width_param,
4594: $scaling, $parstack, $safeeval,
4595: $depth, $cis);
4596:
4597: return ($height_param, $width_param);
4598: }
4599:
4600: sub image_width {
4601: my ($height, $width) = &image_size(@_);
4602: return $width;
4603: }
4604: # Not yet 100% sure this is correct in all circumstances..
4605: # due to my uncertainty about mods to image_size.
4606: #
4607: sub image_height {
4608: my ($height, $width) = &image_size(@_);
4609: return $height;
4610: }
4611:
4612: sub get_eps_image {
4613: my ($src)=@_;
4614: my $orig_src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1], $src);
4615:
4616: # In order to prevent the substitution of the alt text, we need to
4617: # be sure the orig_src file is on system now so:
4618:
4619: if (! -e $orig_src) {
4620: &Apache::lonnet::repcopy($orig_src); # Failure is not completely fatal.
4621: }
4622: &Apache::lonxml::debug("get_eps_image: Original image: $orig_src");
4623: my ($spath, $sname, $sext) = &fileparse($src, qr/\.(bmp|gif|png|jpg|jpeg)/i);
4624: $src=~s/\.(bmp|gif|png|jpg|jpeg)$/\.eps/i;
4625: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
4626: &Apache::lonxml::debug("Filelocation gives: $src");
4627: if (! -e $src) {
4628: &Apache::lonxml::debug("$src does not exist");
4629: if (&Apache::lonnet::repcopy($src) ne 'ok' ) {
4630: &Apache::lonxml::debug("Repcopy of $src failed (1)");
4631: #if replication failed try to find ps file
4632: $src=~s/\.eps$/\.ps/;
4633: &Apache::lonxml::debug("Now looking for $src");
4634: #if no ps file try to replicate it.
4635: my $didrepcopy = &Apache::lonnet::repcopy($src);
4636: &Apache::lonxml::debug("repcopy of $src ... $didrepcopy");
4637: if ( (not -e $src) ||
4638: ($didrepcopy ne 'ok')) {
4639: &Apache::lonxml::debug("Failed to find or replicate $src");
4640:
4641: #if replication failed try to produce eps file dynamically
4642: $src=~s/\.ps$/\.eps/;
4643: my $temp_file;
4644: open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat");
4645: my $newsrc=$orig_src;
4646: $newsrc =~ s|(.*)/res/|/home/httpd/html/res/|;
4647: &Apache::lonxml::debug("queueing $newsrc for dynamic eps production.");
4648: print FILE ("$newsrc\n");
4649: close(FILE);
4650: $src=~s|/home/httpd/html/res|/home/httpd/prtspool|;
4651: $src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|;
4652: if ($sext ne "") { # Put the ext. back in to uniquify.
4653: $src =~ s/\.eps$/$sext.eps/;
4654: }
4655:
4656: }
4657:
4658: }
4659: } else {
4660: # If the postscript file has spaces in its name,
4661: # LaTeX will gratuitiously vomit. Therefore
4662: # queue such files for copy with " " replaced by "_".
4663: # printout.pm will know them by their .ps or .eps extensions.
4664: my $newsrc = $orig_src;
4665: $newsrc =~ s|(.*)/res/|/home/httpd/html/res/|;
4666: open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat");
4667: print FILE "$src\n";
4668: close FILE;
4669: $src=~s|/home/httpd/html/res|/home/httpd/prtspool|;
4670: $src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|;
4671: }
4672: my ($path,$file)=($src=~m|(.*)/([^/]*)$|);
4673: $path =~ s/ /\_/g;
4674: $file =~ s/ /\_/g;
4675: &Apache::lonxml::debug("get_eps_image returning: $path / $file<BR />");
4676: return ($path.'/',$file);
4677: }
4678:
4679: sub eps_generation {
4680: my ($src,$file,$width_param) = @_;
4681: my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat";
4682: my $temp_file = Apache::File->new('>>'.$filename);
4683: print $temp_file "$src\n";
4684: my $newsrc = $src;
4685: $newsrc =~ s/(\.bmp|\.gif|\.jpg|\.jpeg)$/\.eps/i;
4686: $newsrc=~s{/home/httpd/html/res}{};
4687: $newsrc=~s{/home/($LONCAPA::username_re)/public_html/}{/$1/};
4688: $newsrc=~s{/\./}{/};
4689: $newsrc=~s{/([^/]+)\.(ps|eps)}{/};
4690: if ($newsrc=~m{/home/httpd/lonUsers/}) {
4691: $newsrc=~s{/home/httpd/lonUsers}{};
4692: $newsrc=~s{/($LONCAPA::domain_re)/./././}{/$1/};
4693: }
4694: if ($newsrc=~m{/userfiles/}) {
4695: return ' \graphicspath{{'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
4696: } else {
4697: return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
4698: }
4699: }
4700:
4701: sub file_path {
4702: my $src=shift;
4703: my ($file,$path);
4704: if ($src =~ m!(.*)/([^/]*)$!) {
4705: $file = $2;
4706: $path = $1.'/';
4707: }
4708: return $file,$path;
4709: }
4710:
4711:
4712: sub recalc {
4713: my $argument = shift;
4714: if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}
4715: $argument=~/\s*(\d+\.?\d*)\s*(mm|cm|in|pc|pt)/;
4716: my $value=$1;
4717: my $units=$2;
4718: if ($units eq 'cm') {
4719: $value*=10;
4720: } elsif ($units eq 'in') {
4721: $value*=25.4;
4722: } elsif ($units eq 'pc') {
4723: $value*=(25.4*12/72.27);
4724: } elsif ($units eq 'pt') {
4725: $value*=(25.4/72.27);
4726: }
4727: return $value.' mm';
4728: }
4729:
4730: sub LATEX_length {
4731: my $garbage=shift;
4732: $garbage=~s/^\s+$//;
4733: $garbage=~s/^\s+(\S.*)/$1/;#space before
4734: $garbage=~s/(.*\S)\s+$/$1/;#space after
4735: $garbage=~s/(\s)+/$1/;#only one space
4736: $garbage=~s/(\\begin{([^\}]+)}|\\end{([^\}]+)})//g;#remove LaTeX \begin{...} and \end{...}
4737: $garbage=~s/(\$\_\{|\$\_|\$\^{|\$\^|\}\$)//g;#remove $_{,$_,$^{,$^,}$
4738: $garbage=~s/([^\\])\$/$1/g;#$
4739: $garbage=~s/(\\ensuremath\{\_\{|\\ensuremath\{\_|\\ensuremath\{\^{|\\ensuremath\{\^|\})//g;#remove \ensuremath{...}
4740: $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;
4741: $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;
4742: $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;
4743: $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;
4744: $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;
4745: $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;
4746: $garbage=~s/(\\hat{([^}]+)}|\\check{([^}]+)}|\\dot{([^}]+)}|\\breve{([^}]+)}|\\acute{([^}]+)}|\\ddot{([^}]+)}|\\grave{([^}]+)}|\\tilde{([^}]+)}|\\mathring{([^}]+)}|\\bar{([^}]+)}|\\vec{([^}]+)})/$1/g;
4747: #remove some other LaTeX command
4748: $garbage=~s|\\(\w+)\\|\\|g;
4749: $garbage=~s|\\(\w+)(\s*)|$2|g;
4750: $garbage=~s|\+|11|g;
4751: my $value=length($garbage);
4752: return $value;
4753: }
4754:
4755:
4756: sub align_latex_image {
4757: my ($align, $latex_rendering, $image, $width, $height) = @_;
4758: my $currentstring; # The 1/2 wrapped image.
4759: my $closure; # The closure of the wrappage.
4760:
4761: # if it's none just return it back
4762: if ($latex_rendering eq 'none') {
4763: return ($image,'');
4764: }
4765:
4766: # If there's an alignment specification we need to honor it here.
4767: # For the horizontal alignments, we will also honor the
4768: # value of the latex specfication. The default is parbox,
4769: # and that's used for illegal values too.
4770: #
4771: # Even though we set a default alignment value, the user
4772: # could have given us an illegal value. In that case we
4773: # just use the default alignment of bottom..
4774: $currentstring = '';
4775: if ($align eq "top") {
4776: $currentstring .= '\raisebox{-'.$height.'mm}{'.$image;
4777: $closure = '}';
4778: } elsif (($align eq "center") || ($align eq "middle")) { # Being kind
4779: my $offset = $height/2;
4780: $currentstring .= '\raisebox{-'.$offset.'mm}{'.$image;
4781: $closure = '}';
4782: } elsif ($align eq "left") {
4783: if ($latex_rendering eq "parpic") {
4784: $currentstring .= '\parpic[l]{'.$image;
4785: $closure = '}';
4786: } elsif ($latex_rendering eq "parbox") {
4787: $currentstring .= '\begin{minipage}[l]{'.$width.'mm}'
4788: .$image;
4789: $closure = '\end{minipage}';
4790: } elsif ($latex_rendering eq "wrapfigure"
4791: || $latex_rendering ne 'none') { # wrapfig render
4792: $currentstring .=
4793: '\begin{wrapfigure}{l}{'.$width.'mm}'
4794: .'\scalebox{1.0}{'.$image;
4795: $closure = '}\end{wrapfigure}';
4796: }
4797: } elsif ($align eq "right") {
4798: if ($latex_rendering eq "parpic") {
4799: $currentstring .= '\parpic[r]{'.$image;
4800: $closure = '}';
4801: } elsif ($latex_rendering eq "parbox") {
4802: $currentstring .= '\begin{minipage}[r]{'.$width.'mm}'
4803: .$image;
4804: $closure = '\end{minipage}';
4805: } elsif ($latex_rendering eq "wrapfigure"
4806: || $latex_rendering ne 'none') { # wrapfig render
4807: $currentstring .=
4808: '\begin{wrapfigure}{r}{'.$width.'mm}'
4809: .'\scalebox{1.0}{'.$image;
4810: $closure = '}\end{wrapfigure}';
4811: }
4812: } else { # Bottom is also default.
4813: # $currentstring = '\raisebox{'.$height.'mm}{'.$image.'}';
4814: $currentstring .= "{$image";
4815: $closure = '}';
4816: }
4817: return ($currentstring, $closure);
4818: }
4819:
4820:
4821: sub is_inside_of {
4822: my ($tagstack, $tag) = @_;
4823: my @stack = @$tagstack;
4824: for (my $i = ($#stack - 1); $i >= 0; $i--) {
4825: if ($stack[$i] eq $tag) {
4826: return 1;
4827: }
4828: }
4829: return 0;
4830: }
4831:
4832:
4833: #
4834: # This sub provides the typical LaTeX prefix matter for tex output:
4835: #
4836: sub latex_header {
4837: my ($mode) = @_;
4838: my $currentstring = '';
4839:
4840: $currentstring .=
4841: "\n% &Apache::lonxml::londefdef \n" .
4842: '\documentclass[letterpaper,twoside]{article}\raggedbottom';
4843: if (($env{'form.latex_type'}=~'batchmode') ||
4844: (!$env{'request.role.adv'}) ||
4845: ($mode eq 'batchmode')) {$currentstring .='\batchmode';}
4846: $currentstring .= '\newcommand{\keephidden}[1]{}'.
4847: '\renewcommand{\deg}{$^{\circ}$}'.
4848: '\usepackage{multirow}'.
4849: '\usepackage{longtable}'.
4850: '\usepackage{textcomp}'.
4851: '\usepackage{makeidx}'.
4852: '\usepackage[dvips]{graphicx}'.
4853: '\usepackage{wrapfig}'.
4854: '\usepackage{picins}'.
4855: '\usepackage[T1]{fontenc}'."\n".
4856: '\usepackage{lmodern}'."\n".
4857: '\usepackage[postscript]{ucs}'."\n".
4858: '\usepackage[utf8x]{inputenc}'."\n".
4859: '\usepackage{pifont}' ."\n".
4860: '\usepackage{latexsym}'."\n".
4861: '\usepackage{epsfig}'.
4862: "\\usepackage{xtab}\n".
4863: "\\usepackage{tabularx}\n".
4864: "\\usepackage{booktabs}\n".
4865: "\\usepackage{array}\n".
4866: "\\usepackage{colortbl}\n".
4867: "\\usepackage{xcolor}\n".
4868: '\usepackage{calc}'.
4869: '\usepackage{amsmath}'.
4870: '\usepackage{amssymb}'.
4871: '\usepackage{amsfonts}'.
4872: '\usepackage{amsthm}'.
4873: '\usepackage{amscd}'
4874: .'\usepackage{picins}\usepackage{calc}'."\n". # From lonprintout.pm
4875: '\usepackage[T1]{fontenc}'."\n".
4876: '\usepackage{lmodern}'."\n".
4877: '\usepackage[postscript]{ucs}'."\n".
4878: '\usepackage[utf8x]{inputenc}'."\n".
4879: '\usepackage{pifont}' . "\n";
4880:
4881: if($env{'form.pdfFormFields'} eq 'yes') {
4882: $currentstring .= '\usepackage{hyperref}'.
4883: '\usepackage{eforms}'.
4884: '\usepackage{tabularx}';
4885: }
4886:
4887: $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}}'.
4888: '\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}}';
4889: $currentstring .= '\begin{document}';
4890:
4891: return $currentstring;
4892:
4893: }
4894:
4895: =pod
4896:
4897: =head1 NAME
4898:
4899: Apache::londefdef.pm
4900:
4901: =head1 SYNOPSIS
4902:
4903: Tags Default Definition Module
4904:
4905: This is part of the LearningOnline Network with CAPA project
4906: described at http://www.lon-capa.org.
4907:
4908:
4909: =head1 NOTABLE SUBROUTINES
4910:
4911: =over
4912:
4913: =item start_hideweboutput()
4914:
4915: =item end_hideweboutput()
4916:
4917: =item image_replication()
4918:
4919: =item resize_image()
4920:
4921: Get correct sizing parameter for an image given
4922: it's initial ht. and wid. This allows sizing of
4923: images that are generated on-the-fly (e.g. gnuplot)
4924: as well as serving as a utility for image_size.
4925:
4926: Parameter:
4927: height_param
4928: width_param - Initial picture dimensions.
4929: scaling - A scale factor.
4930: parstack, - the current stack of tag attributes
4931: from the xml parser
4932: safeeval, - pointer to the safespace
4933: depth, - from what level in the stack to look for attributes
4934: (assumes -1 if unspecified)
4935: cis - look for attrubutes case insensitively
4936: (assumes false)
4937:
4938: Returns:
4939: height, width - new dimensions.
4940:
4941: =item image_size()
4942:
4943: =item image_width()
4944:
4945: =item image_height()
4946:
4947: =item get_eps_image()
4948:
4949: =item eps_generation()
4950:
4951: =item file_path()
4952:
4953: =item recalc()
4954:
4955: Converts a measurement in to mm from any of
4956: the other valid LaTeX units of measure.
4957: If the units of measure are missing from the
4958: parameter, it is assumed to be in and returned
4959: with mm units of measure
4960:
4961: =item LATEX_length()
4962:
4963: =item align_latex_image()
4964:
4965: Wrap image 'stuff' inside of the LaTeX required to implement
4966: alignment:
4967: align_tex_image(align, latex_rendering, image)
4968: Where:
4969: align - The HTML alignment specification.
4970: latex_rendering - rendering hint for latex.
4971: image - The LaTeX needed to insert the image itsef.
4972: width,height - dimensions of the image.
4973: Returns:
4974: The 1/2 wrapped image and the stuff required to close the
4975: wrappage. This allows e.g. randomlabel to insert more stuff
4976: into the closure.
4977:
4978:
4979: =item is_inside_of($tagstack, $tag)
4980: This sub returns true if the current state of Xml processing is inside of the tag.
4981: Parameters:
4982: tagstack - The tagstack from the parser.
4983: tag - The tag (without the <>'s.).
4984: Sample usage:
4985: if (is_inside_of($tagstack "table")) {
4986: I'm in a table....
4987: }
4988:
4989:
4990:
4991: =back
4992:
4993: =cut
4994:
4995:
4996: 1;
4997: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>