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