--- loncom/xml/londefdef.pm 2005/03/16 21:35:17 1.264 +++ loncom/xml/londefdef.pm 2005/07/10 21:43:35 1.278 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.264 2005/03/16 21:35:17 raeburn Exp $ +# $Id: londefdef.pm,v 1.278 2005/07/10 21:43:35 www Exp $ # # # Copyright Michigan State University Board of Trustees @@ -39,7 +39,7 @@ package Apache::londefdef; -use Apache::lonnet(); +use Apache::lonnet; use strict; use Apache::lonxml; use Apache::File(); @@ -90,7 +90,8 @@ sub start_m { $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]); #&Apache::lonxml::debug("M is evaulated to:$inside:"); } - $currentstring = &Apache::lontexconvert::converted(\$inside); + my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval); + $currentstring = &Apache::lontexconvert::converted(\$inside,$display); if ($Apache::lontexconvert::errorstring) { &Apache::lonxml::warning("tth error: ". $Apache::lontexconvert::errorstring); @@ -132,7 +133,7 @@ sub start_tthoption { if ($target eq 'web') { my $inside = &Apache::lonxml::get_all_text("/tthoption",$parser); $inside=~s/^\s*//; - if ($ENV{'browser.mathml'}) { + if ($env{'browser.mathml'}) { &tth::ttmoptions($inside); } else { &tth::tthoptions($inside); @@ -151,15 +152,14 @@ sub end_tthoption { sub start_html { my ($target,$token) = @_; my $currentstring = ''; - my $options=$ENV{'course.'.$ENV{'request.course.id'}.'.tthoptions'}; + my $options=$env{'course.'.$env{'request.course.id'}.'.tthoptions'}; &Apache::lontexconvert::init_tth(); - if ($target eq 'web' || $target eq 'edit') { + if ($target eq 'web' || $target eq 'edit' || $target eq 'webgrade' ) { $currentstring = &Apache::lonxml::xmlbegin(); } elsif ($target eq 'tex') { - @Apache::londefdef::table = (); $currentstring .= '\documentclass[letterpaper]{article}'; - if (($ENV{'form.latex_type'}=~'batchmode') || - (!$ENV{'request.role.adv'})) {$currentstring .='\batchmode';} + if (($env{'form.latex_type'}=~'batchmode') || + (!$env{'request.role.adv'})) {$currentstring .='\batchmode';} $currentstring .= '\newcommand{\keephidden}[1]{}'. '\renewcommand{\deg}{$^{\circ}$}'. '\usepackage{longtable}'. @@ -202,7 +202,7 @@ sub start_head { sub end_head { my ($target,$token) = @_; my $currentstring = ''; - if ($target eq 'web' && $ENV{'request.state'} eq 'published') { + if ($target eq 'web' && $env{'request.state'} eq 'published') { $currentstring = &Apache::lonmenu::registerurl(undef,$target). $token->[2]; } @@ -490,15 +490,15 @@ sub start_body { return ''; } if (!$Apache::lonxml::registered && - $ENV{'request.state'} eq 'published') { + $env{'request.state'} eq 'published') { $currentstring.='
'. &Apache::lonmenu::registerurl(undef,$target).''; } # Accessibility - if ($ENV{'browser.imagesuppress'} eq 'on') { + if ($env{'browser.imagesuppress'} eq 'on') { delete($token->[2]->{'background'}); } - if ($ENV{'browser.fontenhance'} eq 'on') { + if ($env{'browser.fontenhance'} eq 'on') { my $style=''; foreach my $key (keys(%{$token->[2]})) { if ($key =~ /^style$/i) { @@ -508,7 +508,7 @@ sub start_body { } $token->[2]->{'style'}=$style.'; font-size: x-large;'; } - if ($ENV{'browser.blackwhite'} eq 'on') { + if ($env{'browser.blackwhite'} eq 'on') { delete($token->[2]->{'font'}); delete($token->[2]->{'link'}); delete($token->[2]->{'alink'}); @@ -535,23 +535,21 @@ sub start_body { $token->[2]->{'onunload'}=&Apache::lonmenu::unloadevents(). ';'.$onUnload; - if ($ENV{'request.state'} ne 'construct') { - $currentstring .= '<'.$token->[1]; - } + $currentstring .= '<'.$token->[1]; foreach (keys %{$token->[2]}) { $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"'; } - if ($ENV{'request.state'} ne 'construct') { - $currentstring.='>'; - } - if ($ENV{'request.state'} ne 'published') { - my $remote=($ENV{'environment.remote'} ne 'off'); - $currentstring=&Apache::loncommon::bodytag(undef,undef, - $currentstring,$remote); + $currentstring.='>'; + if ($env{'request.state'} ne 'published') { + if ($env{'environment.remote'} eq 'off') { + $currentstring.= + &Apache::lonmenu::constspaceform(). + &Apache::lonmenu::menubuttons(1,'web',1); + } $currentstring.=(<if ($target eq 'web') { - $currentstring = &Apache::lonxml::xmlend($target,$parser); + $currentstring .= &Apache::lonxml::xmlend($target,$parser); } elsif ($target eq 'tex') { - $currentstring = '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}'; + $currentstring .= '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}'; } return $currentstring; } @@ -577,11 +575,11 @@ sub end_body { #--
is a bit strange since it does not require a closing
+# However in latex, we must often output closing stuff to end +# environments and {}'s etc. Therefore we do all the work +# of figuring out the ending strings in the start tag processing, +# and provide a mechanism to output the stop text external +# to tag processing. +# +{ + + my $closing_string = ''; # String required to close+ #--
tag (end tag optional) #optional attribute - align="center|left|right" sub start_p { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # close off prior para if in progress. if ($target eq 'web') { $currentstring .= $token->[4]; + $closing_string = '
'; # Not sure this is correct. } elsif ($target eq 'tex') { my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); if ($align eq 'center') { - $currentstring='\begin{center}\par'; + $currentstring .='\begin{center}\par'; + $closing_string = '\end{center}'; } elsif ($align eq 'right') { - $currentstring='\makebox['.$ENV{'form.textwidth'}.']{\hfill\llap{'; + $currentstring.='\makebox['.$env{'form.textwidth'}.']{\hfill\llap{'; + $closing_string= '}}'; } elsif ($align eq 'left') { - $currentstring='\noindent\makebox['.$ENV{'form.textwidth'}.']{\rlap{'; + $currentstring.='\noindent\makebox['.$env{'form.textwidth'}.']{\rlap{'; + $closing_string = '}\hfill}'; } else { - $currentstring='\par '; + $currentstring.='\par '; + $closing_string = '\strut\\\\\strut'; } my $signal=1;# does not work inside ...
- foreach my $tag (@$tagstack) {if (lc($tag) eq 'b') {$signal=0;}
- if (!$signal) {$currentstring = '';}
+ foreach my $tag (@$tagstack) {
+ if (lc($tag) eq 'b') {
+ $signal=0;
+ }
+ }
+ if (!$signal) {
+ $currentstring = &end_p; # Just close the prior? Not sure this is correct
+ $closing_string = ''; # Probably correct?
}
- }
- return $currentstring;
-}
-sub end_p {
- my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
- if ($target eq 'web') {
- $currentstring .= $token->[2];
- } elsif ($target eq 'tex') {
- my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
- if (not defined $align) {
- $currentstring.='\strut\\\\\strut ';
- } elsif ($align eq 'center') {
- $currentstring .= '\end{center}';
- } elsif ($align eq 'right') {
- $currentstring .= '}}';
- } elsif ($align eq 'left') {
- $currentstring .= '}\hfill}';
- }
}
return $currentstring;
}
+#
+# End paragraph processing just requires that we output the
+# closing string that was saved and blank it.
+sub end_p {
+ my $current_string = $closing_string;
+ $closing_string = ''; # Not in a para anymore.
+ return $current_string;
+}
+}
#--
tag (end tag forbidden)
sub start_br {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
@@ -1277,8 +1287,8 @@ sub start_font {
if ($target eq 'web') {
my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
if ($face!~/symbol/i) {
- if (($ENV{'browser.fontenhance'} eq 'on') ||
- ($ENV{'browser.blackwhite'} eq 'on')) { return ''; }
+ if (($env{'browser.fontenhance'} eq 'on') ||
+ ($env{'browser.blackwhite'} eq 'on')) { return ''; }
}
$currentstring = $token->[4];
} elsif ($target eq 'tex') {
@@ -1405,7 +1415,7 @@ sub end_sup {
#--
in the
prior to the list. if ($target eq 'web') { - $currentstring = $token->[4]; + $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring = " \\begin{itemize} "; + $currentstring .= " \\begin{itemize} "; } return $currentstring; } @@ -1653,9 +1663,9 @@ sub end_dir { #--
prior to the list. if ($target eq 'web') { - $currentstring = $token->[4]; + $currentstring .= $token->[4]; } elsif ($target eq 'tex') { $Apache::londefdef::list_index=0; my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0); @@ -1707,11 +1717,11 @@ sub end_ol { #--
unclosed prior to the list. if ($target eq 'web') { - $currentstring = $token->[4]; + $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring = '\begin{description}'; + $currentstring .= '\begin{description}'; $Apache::londefdef::DL++; push(@Apache::londefdef::description,[]); $Apache::londefdef::DD[$Apache::londefdef::DL]=0; @@ -1814,19 +1824,25 @@ sub end_dd { } #--
bodies
+#
#list of supported attributes: border,width,TeXwidth
sub start_table {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my ($textwidth,$currentstring)=('','');
+ my $textwidth = '';
+ my $currentstring = &end_p;
if ($target eq 'web') {
- $currentstring = $token->[4];
+ $currentstring .= $token->[4];
} elsif ($target eq 'tex') {
my $aa = {};
push @Apache::londefdef::table, $aa;
$Apache::londefdef::table[-1]{'row_number'} = -1;
#maximum table's width (default coincides with text line length)
if ($#Apache::londefdef::table==0) {
- $textwidth=&recalc($ENV{'form.textwidth'}); #result is always in mm
+ $textwidth=&recalc($env{'form.textwidth'}); #result is always in mm
$textwidth=~/(\d+\.?\d*)/;
$textwidth=0.95*$1; #accounts "internal" LaTeX space for table frame
} else {
@@ -1883,7 +1899,7 @@ sub start_table {
$Apache::londefdef::table[-1]{'minlen'}=[];
$Apache::londefdef::table[-1]{'content'}=[];
$Apache::londefdef::table[-1]{'align'}=[];
- $currentstring='\keephidden{NEW TABLE ENTRY}';
+ $currentstring.='\keephidden{NEW TABLE ENTRY}';
}
return $currentstring;
}
@@ -2137,9 +2153,9 @@ sub start_tr {
sub end_tr {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
+ my $currentstring = &end_p; # Close any pending in the row. if ($target eq 'web') { - $currentstring = $token->[2]; + $currentstring .= $token->[2]; } elsif ($target eq 'tex') { if ($Apache::londefdef::TD_redirection) { &end_td_tex($parstack,$parser,$safeeval); @@ -2414,9 +2430,9 @@ sub end_th_tex { sub end_th { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # Close any open in the row. if ($target eq 'web') { - $currentstring = $token->[2]; + $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $Apache::londefdef::TD_redirection =0; &end_th_tex($parstack,$parser,$safeeval); @@ -2450,7 +2466,7 @@ sub start_img { # Render unto browsers that which are the browser's... if ($target eq 'web') { - if ($ENV{'browser.imagesuppress'} ne 'on') { + if ($env{'browser.imagesuppress'} ne 'on') { $currentstring.=&Apache::lonenc::encrypt_ref($token,{'src'=>$src}); } else { my $alttag= &Apache::lonxml::get_param @@ -2498,19 +2514,25 @@ sub start_img { &Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src"); #if original gif/jpg/png file exist do following: + my $origsrc=$src; my ($path,$file) = &get_eps_image($src); $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); &Apache::lonxml::debug("path = $path file = $file src = $src"); if (-e $src) { &Apache::lonxml::debug("$src exists"); my ($height_param,$width_param)= - &image_size($src,0.3,$parstack,$safeeval); + &image_size($origsrc,0.3,$parstack,$safeeval); my $destpath = $path; $destpath =~ s/ /\_/g; # Spaces in path cause LaTex to vomit. my $destfile = $file; $destfile =~ s/ /\_/g; + my $size; + if ($width_param) { $size.='width='.$width_param.' mm,'; } + if ($height_param) { $size.='height='.$height_param.' mm]'; } + $size='['.$size; + $size=~s/,$/]/; $currentstring .= '\graphicspath{{'.$destpath.'}}' - .'\includegraphics[width='.$width_param.' mm,height='.$height_param.'mm]{'.$destfile.'} '; + .'\includegraphics'.$size.'{'.$destfile.'} '; # If there's an alignment specification we need to honor it here. # For the horizontal alignments, we will also honor the @@ -2650,7 +2672,7 @@ sub start_applet { my $currentstring = ''; if ($target eq 'web') { - if ($ENV{'browser.appletsuppress'} ne 'on') { + if ($env{'browser.appletsuppress'} ne 'on') { $currentstring = &Apache::lonenc::encrypt_ref($token, {'code'=>$code, 'archive'=>$archive} @@ -2696,7 +2718,7 @@ sub start_embed { $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src; my $currentstring = ''; if ($target eq 'web') { - if ($ENV{'browser.embedsuppress'} ne 'on') { + if ($env{'browser.embedsuppress'} ne 'on') { $currentstring=&Apache::lonenc::encrypt_ref($token,{'src'=>$src}); } else { my $alttag=&Apache::lonxml::get_param @@ -2789,10 +2811,10 @@ sub end_allow { #-- |
---|