--- loncom/xml/londefdef.pm 2003/05/12 20:13:36 1.133 +++ loncom/xml/londefdef.pm 2003/08/26 21:32:23 1.158.4.2 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.133 2003/05/12 20:13:36 www Exp $ +# $Id: londefdef.pm,v 1.158.4.2 2003/08/26 21:32:23 albertel Exp $ # # # Copyright Michigan State University Board of Trustees @@ -25,8 +25,7 @@ # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ -# -# Copyright for TtHfunc and TtMfunc by Ian Hutchinson. +## Copyright for TtHfunc and TtMfunc by Ian Hutchinson. # TtHfunc and TtMfunc (the "Code") may be compiled and linked into # binary executable programs or libraries distributed by the # Michigan State University (the "Licensee"), but any binaries so @@ -54,7 +53,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')); } @@ -157,9 +156,11 @@ sub start_html { &Apache::lonxml::fontsettings(); } elsif ($target eq 'tex') { @Apache::londefdef::table = (); - $currentstring .= '\documentclass[letterpaper]{article} - \newcommand{\keephidden}[1]{} + $currentstring .= '\documentclass[letterpaper]{article}'; + if ($ENV{'form.latex_type'}=~'batchmode') {$currentstring .='\batchmode';} + $currentstring .= '\newcommand{\keephidden}[1]{} \renewcommand{\deg}{$^{\circ}$} + \usepackage{longtable} \usepackage{textcomp} \usepackage[dvips]{graphicx} \usepackage{epsfig}\usepackage{calc} @@ -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'}; @@ -363,18 +363,38 @@ sub start_meta { $name=~s/\s/\_/gs; $name=~s/\W//gs; if ($name) { - $currentstring='<'.$name.'>'. + $currentstring='<'.$name; + my $display=&Apache::lonxml::get_param + ('display',$parstack,$safeeval,undef,1); + if ($display) { + $display=~s/\"/\'/g; + $currentstring.=' display="'.$display.'"'; + } + $currentstring.='>'. &Apache::lonxml::get_param ('content',$parstack,$safeeval,undef,1). - ''.$name.'>'; + ''.$name.'>'; } + my $display=&Apache::lonxml::get_param + ('display',$parstack,$safeeval,undef,1); + if ($display) { + $display=&HTML::Entities::encode($display); + $currentstring.='<'.$name.'.display>'.$display. + ''.$name.'.display>'; + } + } + } elsif ($target eq 'tex') { + my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval); + my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval); + if ((not defined $content) && (not defined $name)) { + &Apache::lonxml::startredirection(); } } return $currentstring; } sub end_meta { - my ($target,$token,$tagstack,$parstack,$parser) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web') { my $args=''; @@ -382,7 +402,13 @@ sub end_meta { if ($args ne '') { $currentstring = $token->[4]; } - } + } elsif ($target eq 'tex') { + my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval); + my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval); + if ((not defined $content) && (not defined $name)) { + &Apache::lonxml::startredirection(); + } + } return $currentstring; } @@ -440,6 +466,29 @@ sub start_body { $currentstring.='
'. &Apache::lonmenu::registerurl(undef,$target).''; } +# Accessibility + if ($ENV{'browser.imagesuppress'} eq 'on') { + delete($token->[2]->{'background'}); + } + if ($ENV{'browser.fontenhance'} eq 'on') { + my $style=''; + foreach my $key (keys(%{$token->[2]})) { + if ($key =~ /^style$/i) { + $style.=$token->[2]->{$key}.';'; + delete($token->[2]->{$key}); + } + } + $token->[2]->{'style'}=$style.'; font-size: x-large;'; + } + if ($ENV{'browser.blackwhite'} eq 'on') { + delete($token->[2]->{'font'}); + delete($token->[2]->{'link'}); + delete($token->[2]->{'alink'}); + delete($token->[2]->{'vlink'}); + delete($token->[2]->{'bgcolor'}); + delete($token->[2]->{'background'}); + } +# Overload loads my $onLoad=''; foreach my $key (keys(%{$token->[2]})) { if ($key =~ /^onload$/i) { @@ -497,9 +546,7 @@ sub start_center { $currentstring = $token->[4]; } elsif ($target eq 'tex') { $currentstring = '\begin{center}'; - } elsif ($target eq 'latexsource') { - $currentstring = '\begin{center}'; - } + } return $currentstring; } @@ -510,9 +557,7 @@ sub end_center { $currentstring = $token->[2]; } elsif ($target eq 'tex') { $currentstring = '\end{center}'; - } elsif ($target eq 'latexsource') { - $currentstring = '\end{center}'; - } + } return $currentstring; } @@ -524,8 +569,6 @@ sub start_b { $currentstring = $token->[4]; } elsif ($target eq 'tex') { $currentstring = '\textbf{'; - } elsif ($target eq 'latexsource') { - $currentstring = '\textbf{'; } return $currentstring; } @@ -537,8 +580,6 @@ sub end_b { $currentstring = $token->[2]; } elsif ($target eq 'tex') { $currentstring = '}'; - } elsif ($target eq 'latexsource') { - $currentstring = '}'; } return $currentstring; } @@ -551,8 +592,6 @@ sub start_strong { $currentstring = $token->[4]; } elsif ($target eq 'tex') { $currentstring = '\textbf{'; - } elsif ($target eq 'latexsource') { - $currentstring = '\textbf{'; } return $currentstring; } @@ -565,9 +604,7 @@ sub end_strong { $currentstring = $token->[2]; } elsif ($target eq 'tex') { $currentstring = '}'; - } elsif ($target eq 'latexsource') { - $currentstring = '}'; - } + } return $currentstring; } @@ -843,9 +880,7 @@ sub start_cite { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= "\\textit{"; - } elsif ($target eq 'latexsource') { - $currentstring .= "\\textit{"; - } + } return $currentstring; } @@ -856,9 +891,7 @@ sub end_cite { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= "}"; - } elsif ($target eq 'latexsource') { - $currentstring .= "}"; - } + } return $currentstring; } @@ -870,9 +903,7 @@ sub start_i { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= '\textit{'; - } elsif ($target eq 'latexsource') { - $currentstring .= '\textit{'; - } + } return $currentstring; } @@ -883,8 +914,6 @@ sub end_i { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= '}'; - } elsif ($target eq 'latexsource') { - $currentstring .= '}'; } return $currentstring; } @@ -897,9 +926,7 @@ sub start_address { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= "\\textit{"; - } elsif ($target eq 'latexsource') { - $currentstring .= "\\textit{"; - } + } return $currentstring; } @@ -910,8 +937,6 @@ sub end_address { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= "}"; - } elsif ($target eq 'latexsource') { - $currentstring .= "}"; } return $currentstring; } @@ -924,8 +949,6 @@ sub start_dfn { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= "\\textit{"; - } elsif ($target eq 'latexsource') { - $currentstring .= "\\textit{"; } return $currentstring; } @@ -937,9 +960,7 @@ sub end_dfn { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= "}"; - } elsif ($target eq 'latexsource') { - $currentstring .= "}"; - } + } return $currentstring; } @@ -951,9 +972,7 @@ sub start_tt { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= '\texttt{'; - } elsif ($target eq 'latexsource') { - $currentstring .= '\texttt{'; - } + } return $currentstring; } @@ -964,8 +983,6 @@ sub end_tt { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= '}'; - } elsif ($target eq 'latexsource') { - $currentstring .= '}'; } return $currentstring; } @@ -978,9 +995,7 @@ sub start_kbd { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= "\\texttt"; - } elsif ($target eq 'latexsource') { - $currentstring .= "\\texttt{"; - } + } return $currentstring; } @@ -991,9 +1006,7 @@ sub end_kbd { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= "}"; - } elsif ($target eq 'latexsource') { - $currentstring .= "}"; - } + } return $currentstring; } @@ -1028,9 +1041,7 @@ sub start_em { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= '\emph{'; - } elsif ($target eq 'latexsource') { - $currentstring .= '\emph{'; - } + } return $currentstring; } @@ -1041,9 +1052,7 @@ sub end_em { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= '}'; - } elsif ($target eq 'latexsource') { - $currentstring .= '}'; - } + } return $currentstring; } @@ -1055,8 +1064,6 @@ sub start_q { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $currentstring .= "\\emph{"; - } elsif ($target eq 'latexsource') { - $currentstring .= "\\emph{"; } return $currentstring; } @@ -1068,23 +1075,21 @@ sub end_q { $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $currentstring .= "}"; - } elsif ($target eq 'latexsource') { - $currentstring .= "}"; - } + } return $currentstring; } #-- tag
sub start_p {
- my ($target,$token) = @_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
- $currentstring .= '{\par ';
- } elsif ($target eq 'latexsource') {
- $currentstring .= '{\par ';
- }
+ my $signal=1;
+ foreach my $tag (@$tagstack) {if (lc($tag) eq 'b') {$signal=0;}}
+ if ($signal) {$currentstring .= '\par ';}
+ }
return $currentstring;
}
@@ -1093,10 +1098,6 @@ sub end_p {
my $currentstring = '';
if ($target eq 'web') {
$currentstring .= $token->[2];
- } elsif ($target eq 'tex') {
- $currentstring .= '}';
- } elsif ($target eq 'latexsource') {
- $currentstring .= '}';
}
return $currentstring;
}
@@ -1109,11 +1110,9 @@ sub start_br {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
if ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') {
- $currentstring .= '\vskip 0.2 mm';
+ $currentstring .= '\vskip 0.2 mm ';
}
- } elsif ($target eq 'latexsource') {
- $currentstring .= '\\';
- }
+ }
return $currentstring;
}
@@ -1133,10 +1132,8 @@ sub start_big {
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
- $currentstring .= '\large{';
- } elsif ($target eq 'latexsource') {
- $currentstring .= '{\Large ';
- }
+ $currentstring .= '{\large ';
+ }
return $currentstring;
}
@@ -1147,8 +1144,6 @@ sub end_big {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring .= '}';
- } elsif ($target eq 'latexsource') {
- $currentstring .= '}';
}
return $currentstring;
}
@@ -1161,9 +1156,7 @@ sub start_small {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '{\footnotesize ';
- } elsif ($target eq 'latexsource') {
- $currentstring .= '{\footnotesize ';
- }
+ }
return $currentstring;
}
@@ -1174,8 +1167,6 @@ sub end_small {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring .= '}';
- } elsif ($target eq 'latexsource') {
- $currentstring .= '}';
}
return $currentstring;
}
@@ -1215,7 +1206,12 @@ sub start_font {
my $currentstring = '';
if ($target eq 'web') {
my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
- if ($face=~/symbol/i) {$Apache::lonxml::prevent_entity_encode++;}
+ if ($face=~/symbol/i) {
+ $Apache::lonxml::prevent_entity_encode++;
+ } else {
+ if (($ENV{'browser.fontenhance'} eq 'on') ||
+ ($ENV{'browser.blackwhite'} eq 'on')) { return ''; }
+ }
$currentstring = $token->[4];
} elsif ($target eq 'tex') {
my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
@@ -1347,14 +1343,14 @@ sub start_hr {
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
- my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,0);
+ my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
if (defined $LaTeXwidth) {
if ($LaTeXwidth=~/^%/) {
substr($LaTeXwidth,0,1)='';
$LaTeXwidth=($LaTeXwidth/100).'\textwidth';
}
} else {
- $LaTeXwidth ='0.95\textwidth';
+ $LaTeXwidth ='0.9\textwidth';
}
my ($pre,$post);
my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
@@ -1365,7 +1361,7 @@ sub start_hr {
} elsif ($align eq 'right') {
$pre=' \hfill \llap{'; $post='}';
}
- $currentstring .= ' \vskip 0 mm \noindent\makebox[\textwidth]{'.$pre.'\makebox['.
+ $currentstring .= ' \vskip 0 mm \noindent\makebox['.$LaTeXwidth.']{'.$pre.'\makebox['.
$LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm ';
}
return $currentstring;
@@ -1376,8 +1372,7 @@ sub end_hr {
my $currentstring = '';
if ($target eq 'web') {
$currentstring .= $token->[2];
- } elsif ($target eq 'tex') {
- }
+ }
return $currentstring;
}
@@ -1402,50 +1397,43 @@ sub end_div {
#-- tag
sub start_a {
- my ($target,$token) = @_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
+ my $a=&Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1);
+ $a=~s/([^\\])%/$1\\\%/g;
+ $currentstring .= '\ref{'.$a.'}';
}
return $currentstring;
}
sub end_a {
- my ($target,$token,$tagstack,$stackref) = @_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web') {
$currentstring .= $token->[2];
- } elsif ($target eq 'tex') {
- my $tempor_var = $stackref->[$#$stackref];
- if (index($tempor_var,'name') != -1 ) {
- $tempor_var =~ s/name=([^,]*),/$1/g;
- } elsif (index($tempor_var,'href') != -1 ) {
- $tempor_var =~ s/href=([^,]*),/$1/g;
- $currentstring .= " \\ref{$tempor_var}";
- }
}
return $currentstring;
}
#-- tag
sub start_table {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $textwidth;
+ 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 +1736,7 @@ sub start_table {
$Apache::londefdef::table[-1]{'vvinc'} = '';
}
$Apache::londefdef::table[-1]{'output'} = ' \noindent \begin{tabular} ';
- $currentstring = '\keephidden{NEW TABLE ENTRY '.$textwidth.'}';
+ $currentstring = '\keephidden{NEW TABLE ENTRY}';
}
return $currentstring;
}
@@ -1820,6 +1814,7 @@ sub end_table {
} else {
$currentstring .= $Apache::londefdef::table[-1]{'output'};
pop @Apache::londefdef::table;
+ undef @Apache::londefdef::table;
}
}
return $currentstring;
@@ -1897,17 +1892,15 @@ sub end_td {
$current_length=~/(\d+\.?\d*)/;
$Apache::londefdef::table[-1]{'TeXlength'} .= $1.',';
$Apache::londefdef::table[-1]{'length'} .= '0,';
- } else {
- $data=~/^\s*(\S.*)/;
- $data=$1;
- $data=~/(.*\S)\s*$/;
- $data=$1;
+ } else {
+ $data=~s/^\s+(\S.*)/$1/;
+ $data=~s/(.*\S)\s+$/$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++) {
+ 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'};
@@ -1981,10 +1974,9 @@ sub start_img {
my $width_param = '';
my $height_param = '';
my $scaling = .3;
-
if ($target eq 'web') {
if ($ENV{'browser.imagesuppress'} ne 'on') {
- $currentstring = $token->[4];
+ $currentstring.= $token->[4];
} else {
my $alttag= &Apache::lonxml::get_param
('alt',$parstack,$safeeval,undef,1);
@@ -1992,12 +1984,11 @@ sub start_img {
$alttag=&Apache::lonmeta::alttag
($Apache::lonxml::pwd[-1],$src);
}
- $currentstring='[IMAGE: '.$alttag.']';
+ $currentstring.='[IMAGE: '.$alttag.']';
}
} elsif ($target eq 'tex') {
$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
&image_replication($src);
-
#if original gif/jpg/png file exist do following:
if (-e $src) {
#defines the default size of image
@@ -2022,6 +2013,7 @@ sub start_img {
} elsif ($width ne '') {
$width_param = $width*$scaling;
}
+ if ($width_param > $ENV{'form.textwidth'}) {$width_param =0.95*$ENV{'form.textwidth'}}
my $file;
my $path;
if ($src =~ m!(.*)/([^/]*)$!) {
@@ -2194,7 +2186,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') {
@@ -2267,9 +2260,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;
}
@@ -2280,7 +2271,7 @@ sub end_pre {
if ($target eq 'web') {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
- $currentstring .= '\end{verbatim}}';
+ $currentstring .= '\end{verbatim}';
}
return $currentstring;
}
@@ -3124,6 +3115,26 @@ sub end_wbr {
return $currentstring;
}
+
+#--