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