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