--- loncom/xml/londefdef.pm 2003/04/18 14:55:40 1.128
+++ loncom/xml/londefdef.pm 2003/06/19 19:15:59 1.142
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Tags Default Definition Module
#
-# $Id: londefdef.pm,v 1.128 2003/04/18 14:55:40 sakharuk Exp $
+# $Id: londefdef.pm,v 1.142 2003/06/19 19:15:59 sakharuk Exp $
#
#
# Copyright Michigan State University Board of Trustees
@@ -54,7 +54,7 @@ use Apache::lonmeta();
BEGIN {
- &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'));
+ &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'));
}
@@ -158,6 +158,7 @@ sub start_html {
} elsif ($target eq 'tex') {
@Apache::londefdef::table = ();
$currentstring .= '\documentclass[letterpaper]{article}
+ \batchmode
\newcommand{\keephidden}[1]{}
\renewcommand{\deg}{$^{\circ}$}
\usepackage{textcomp}
@@ -354,8 +355,7 @@ sub start_meta {
} else {
$currentstring = $token->[4];
}
- }
- if ($target eq 'meta') {
+ } elsif ($target eq 'meta') {
unless (&Apache::lonxml::get_param
('http-equiv',$parstack,$safeeval,undef,1)) {
my $name=$token->[2]->{'name'};
@@ -366,9 +366,11 @@ sub start_meta {
$currentstring='<'.$name.'>'.
&Apache::lonxml::get_param
('content',$parstack,$safeeval,undef,1).
- ''.$name.'>';
+ ''.$name.'>';
}
}
+ } elsif ($target eq 'tex') {
+ &Apache::lonxml::startredirection();
}
return $currentstring;
}
@@ -382,7 +384,10 @@ sub end_meta {
if ($args ne '') {
$currentstring = $token->[4];
}
- }
+ } elsif ($target eq 'tex') {
+ $currentstring=&Apache::lonxml::endredirection();
+ $currentstring='';
+ }
return $currentstring;
}
@@ -1133,7 +1138,7 @@ sub start_big {
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
- $currentstring .= '\large{';
+ $currentstring .= '{\large ';
} elsif ($target eq 'latexsource') {
$currentstring .= '{\Large ';
}
@@ -1696,11 +1701,11 @@ sub end_dd {
#--
tag
sub start_table {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $textwidth;
- if ($#Apache::londefdef::table==0) {
+ my $textwidth='';
+ if (not defined @Apache::londefdef::table) {
$textwidth=&recalc($ENV{'form.textwidth'});
- $textwidth=~/(\d+)/;
- $textwidth=$1;
+ $textwidth=~/(\d+\.?\d*)/;
+ $textwidth=0.95*$1;
} else {
$textwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
}
@@ -1742,7 +1747,7 @@ sub start_table {
$Apache::londefdef::table[-1]{'vvinc'} = '';
}
$Apache::londefdef::table[-1]{'output'} = ' \noindent \begin{tabular} ';
- $currentstring = '\keephidden{NEW TABLE ENTRY}';
+ $currentstring = '\keephidden{NEW TABLE ENTRY '.$textwidth.' }';
}
return $currentstring;
}
@@ -1761,8 +1766,6 @@ sub end_table {
$header_of_table .= $Apache::londefdef::table[-1]{'columns'}[$in].$Apache::londefdef::table[-1]{'vvinc'};
}
$header_of_table .= '}';
-
-
#define the length of the table cells
#always starts with TeXwidth (if defined everything else is ignored)
my @length_row_final = split(/,/,$Apache::londefdef::table[-1]{'TeXlengthrow'}[0]);
@@ -1818,7 +1821,7 @@ sub end_table {
if ($#Apache::londefdef::table > 0) {
my $inmemory = $Apache::londefdef::table[-1]{'output'};
pop @Apache::londefdef::table;
- $Apache::londefdef::table[-1]{'include'}=$inmemory;
+ push @{$Apache::londefdef::table[-1]{'include'}}, $inmemory;
} else {
$currentstring .= $Apache::londefdef::table[-1]{'output'};
pop @Apache::londefdef::table;
@@ -1896,7 +1899,7 @@ sub end_td {
} else {
if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
my $current_length=&recalc($1);
- $current_length=~/(\d+)/;
+ $current_length=~/(\d+\.?\d*)/;
$Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
$Apache::londefdef::table[-1]{'length'} .= '0,';
} else {
@@ -1908,8 +1911,10 @@ sub end_td {
$Apache::londefdef::table[-1]{'length'} .= $current_length.',';
$Apache::londefdef::table[-1]{'TeXlength'} .= '0,';
}
- }
- $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}/;
+ }
+ for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {
+ $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
+ }
@{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'};
}
return $currentstring;
@@ -1929,29 +1934,48 @@ sub start_th {
push @{ $Apache::londefdef::table[-1]{'columns'} }, $what_to_push;
$Apache::londefdef::table[-1]{'counter_columns'}++;
&Apache::lonxml::startredirection();
- ;
}
return $currentstring;
-}
-
+}
+
sub end_th {
- my ($target,$token) = @_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web') {
$currentstring = $token->[2];
} elsif ($target eq 'tex') {
my $current_row = $Apache::londefdef::table[-1]{'row_number'};
my $data=&Apache::lonxml::endredirection();
- if ($data=~m/width\s*=\s*(\d+\.*\d*\s*(mm|cm))/) {
- $Apache::londefdef::table[-1]{'length'} .= $1.',';
+ my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
+ if (defined $TeXwidth) {
+ my $current_length=&recalc($TeXwidth);
+ $current_length=~/(\d+)/;
+ $Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
+ $Apache::londefdef::table[-1]{'length'} .= '0,';
} else {
- $Apache::londefdef::table[-1]{'length'} .= '0 mm,';
- }
- @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{'.$1.'}{\textbf{'.$data.'}} '.$Apache::londefdef::table[-1]{'vinc'};
+ if ($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
+ my $current_length=&recalc($1);
+ $current_length=~/(\d+)/;
+ $Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
+ $Apache::londefdef::table[-1]{'length'} .= '0,';
+ } else {
+ $data=~/^\s*(\S.*)/;
+ $data=$1;
+ $data=~/(.*\S)\s*$/;
+ $data=$1;
+ my $current_length=2*length($data);
+ $Apache::londefdef::table[-1]{'length'} .= $current_length.',';
+ $Apache::londefdef::table[-1]{'TeXlength'} .= '0,';
+ }
+ }
+ for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {
+ $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
+ }
+ $data='\textbf{'.$data.'}';
+ @{ $Apache::londefdef::table[-1]{'rowdata'} }[$current_row] .= '\parbox{TOBECHANGEDONNUMBER}{'.$data.'} '.$Apache::londefdef::table[-1]{'vinc'};
}
return $currentstring;
}
-
#--
tag
sub start_img {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
@@ -2175,7 +2199,8 @@ sub start_allow {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src;
+ $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
+ &Apache::lonnet::clutter($src);
&image_replication($src);
my $result;
if ($target eq 'edit') {
@@ -2205,7 +2230,29 @@ sub start_frameset {
$currentstring.=''.
&Apache::lonmenu::registerurl(undef,$target).'';
}
- $currentstring .= $token->[4];
+ my $onLoad='';
+ foreach my $key (keys(%{$token->[2]})) {
+ if ($key =~ /^onload$/i) {
+ $onLoad.=$token->[2]->{$key}.';';
+ delete($token->[2]->{$key});
+ }
+ }
+ $token->[2]->{'onload'}=&Apache::lonmenu::loadevents().';'.$onLoad;
+ my $onUnload='';
+ foreach my $key (keys(%{$token->[2]})) {
+ if ($key =~ /^onunload$/i) {
+ $onUnload.=$token->[2]->{$key}.';';
+ delete($token->[2]->{$key});
+ }
+ }
+ $token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents().
+ ';'.$onUnload;
+
+ $currentstring .= '<'.$token->[1];
+ foreach (keys %{$token->[2]}) {
+ $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
+ }
+ $currentstring.='>';
}
return $currentstring;
}
@@ -2226,9 +2273,7 @@ sub start_pre {
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
- my $width = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
- if (not defined $width) {$width ='\textwidth';}
- $currentstring .= '\parbox['.$width.']{\begin{verbatim}';
+ $currentstring .= '\begin{verbatim}';
}
return $currentstring;
}
@@ -2239,7 +2284,7 @@ sub end_pre {
if ($target eq 'web') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
- $currentstring .= '\end{verbatim}}';
+ $currentstring .= '\end{verbatim}';
}
return $currentstring;
}
@@ -3083,6 +3128,26 @@ sub end_wbr {
return $currentstring;
}
+
+#-- tag
+sub start_hideweboutput {
+ my ($target,$token) = @_;
+ if ($target eq 'web') {
+ &Apache::lonxml::startredirection();
+ }
+ return '';
+}
+
+sub end_hideweboutput {
+ my ($target,$token) = @_;
+ my $currentstring = '';
+ if ($target eq 'web') {
+ $currentstring = &Apache::lonxml::endredirection();
+ }
+ return '';
+}
+
+
sub image_replication {
my $src = shift;
if (not -e $src) {
@@ -3104,7 +3169,7 @@ sub image_replication {
sub recalc {
my $argument = shift;
if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}
- $argument=~/\s*(\d+)\s*(mm|cm|in|pc|pt)/;
+ $argument=~/\s*(\d+\.?\d*)\s*(mm|cm|in|pc|pt)/;
my $value=$1;
my $units=$2;
if ($units eq 'cm') {