--- loncom/xml/londefdef.pm 2005/03/16 21:35:17 1.264 +++ loncom/xml/londefdef.pm 2005/08/02 15:22:56 1.283 @@ -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.283 2005/08/02 15:22:56 albertel 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(); @@ -47,7 +47,7 @@ use Image::Magick; use Apache::lonmenu(); use Apache::lonmeta(); use Apache::Constants qw(:common); - +use File::Basename; BEGIN { @@ -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 { #--
sub start_b {
my ($target,$token) = @_;
my $currentstring = '';
if ($target eq 'web') {
$currentstring = $token->[4];
} elsif ($target eq 'tex') {
- $currentstring = '\textbf{';
+ &disable_para();
+ $currentstring .= '\textbf{';
}
return $currentstring;
}
@@ -615,18 +615,21 @@ sub end_b {
if ($target eq 'web') {
$currentstring = $token->[2];
} elsif ($target eq 'tex') {
- $currentstring = '}';
+ &enable_para();
+ $currentstring = '}';
}
return $currentstring;
}
#-- tag (end tag required)
+# NOTE: in TeX mode disables internal
sub start_strong {
my ($target,$token) = @_;
my $currentstring = '';
if ($target eq 'web') {
$currentstring = $token->[4];
} elsif ($target eq 'tex') {
+ &disable_para();
$currentstring = '\textbf{';
}
return $currentstring;
@@ -638,6 +641,7 @@ sub end_strong {
if ($target eq 'web') {
$currentstring = $token->[2];
} elsif ($target eq 'tex') {
+ &enable_para();
$currentstring = '}';
}
return $currentstring;
@@ -646,7 +650,7 @@ sub end_strong {
#-- is a bit strange since it does not require a closing
+
+# Some tags are fragile meaning that inside of them
+# does not work within TeX mode. This is managed via the
+# counter below:
+#
+
+ my $para_disabled = 0;
+
+sub disable_para {
+ $para_disabled++;
+}
+sub enable_para {
+ $para_disabled--;
+}
+
+
#-- tag (end tag optional)
#optional attribute - align="center|left|right"
sub start_p {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web') {
+ $currentstring .= &end_p(); # close off prior para if in progress.
$currentstring .= $token->[4];
- } elsif ($target eq 'tex') {
+ if (! ($currentstring =~ /\//)) {
+ $closing_string = ' does not work inside ...
- foreach my $tag (@$tagstack) {if (lc($tag) eq 'b') {$signal=0;}
- if (!$signal) {$currentstring = '';}
- }
+
}
return $currentstring;
}
-
+#
+# End paragraph processing just requires that we output the
+# closing string that was saved and blank it.
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}';
- }
+ # Note only 'tex' mode uses disable_para and enable_para
+ # so we don't need to know the target in the check below:
+
+ if (!$para_disabled) {
+ my $current_string = $closing_string;
+ $closing_string = ''; # Not in a para anymore.
+ return $current_string;
+ } else {
+ return '';
}
- return $currentstring;
-}
+}
+}
#-- 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 +1722,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 +1776,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 +1883,25 @@ sub end_dd {
}
#-- that is not closed.
+# but, unless I allow 's to nest, that's the
+# only way I could think of to allow in
+# 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 +2493,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 +2529,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 +2577,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 +2735,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 +2781,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 +2874,10 @@ sub end_allow {
#-- tag (end tag required)
sub start_h1 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
+ my $currentstring = &end_p(); # Close off any prior para.
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
@@ -661,9 +665,9 @@ sub start_h1 {
}
my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
if (not defined $TeXsize) {$TeXsize="large";}
- $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
+ $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
} elsif ($target eq 'meta') {
- $currentstring='
tag
sub start_h2 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
+ my $currentstring = &end_p(); # Close off any prior para.
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
@@ -710,7 +714,7 @@ sub start_h2 {
}
my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
if (not defined $TeXsize) {$TeXsize="large";}
- $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
+ $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
}
return $currentstring;
}
@@ -738,7 +742,7 @@ sub end_h2 {
#--
tag
sub start_h3 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
+ my $currentstring = &end_p(); # Close off any prior para.
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
@@ -753,7 +757,7 @@ sub start_h3 {
}
my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
if (not defined $TeXsize) {$TeXsize="large";}
- $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
+ $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
}
return $currentstring;
}
@@ -781,7 +785,7 @@ sub end_h3 {
#--
tag
sub start_h4 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
+ my $currentstring = &end_p(); # Close off any prior para.
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
@@ -796,7 +800,7 @@ sub start_h4 {
}
my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
if (not defined $TeXsize) {$TeXsize="large";}
- $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
+ $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
}
return $currentstring;
}
@@ -824,7 +828,7 @@ sub end_h4 {
#--
tag
sub start_h5 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
+ my $currentstring = &end_p(); # Close off any prior paras.
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
@@ -839,7 +843,7 @@ sub start_h5 {
}
my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
if (not defined $TeXsize) {$TeXsize="large";}
- $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
+ $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
}
return $currentstring;
}
@@ -867,7 +871,7 @@ sub end_h5 {
#--
tag
sub start_h6 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
+ my $currentstring = &end_p(); # Close off any prior paras.
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
@@ -882,7 +886,7 @@ sub start_h6 {
}
my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
if (not defined $TeXsize) {$TeXsize="large";}
- $currentstring .= $pre.'{\\'.$TeXsize.' \textbf{';
+ $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
}
return $currentstring;
}
@@ -1114,52 +1118,80 @@ sub end_q {
return $currentstring;
}
+#
tag (end tag forbidden)
sub start_br {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
@@ -1277,8 +1309,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 +1437,7 @@ sub end_sup {
#--
tag (end tag forbidden)
sub start_hr {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
+ my $currentstring = &end_p(); # End enclosing para.
if ($target eq 'web') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
@@ -1443,12 +1475,44 @@ sub end_hr {
}
#-- tag (end tag required)
sub start_ul {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
+ my $currentstring = &end_p(); # Close off enclosing list.
if ($target eq 'web') {
- $currentstring = $token->[4];
+ $currentstring .= $token->[4];
} elsif ($target eq 'tex') {
my $TeXtype=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
$Apache::londefdef::list_index=0;
@@ -1630,11 +1699,11 @@ sub end_menu {
#--
tag (end tag required)
sub start_ol {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
- my $currentstring = '';
+ my $currentstring = &end_p(); # In case there's a
tag (end tag required)
sub start_dl {
my ($target,$token) = @_;
- my $currentstring = '';
+ my $currentstring = &end_p(); # In case there's a
tag (end tag required)
+#
also ends any prior
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 {
@@ -1873,7 +1948,9 @@ sub start_table {
$Apache::londefdef::table[-1]{'vvinc'} = '';
}
if ($#Apache::londefdef::table==0) {
- $Apache::londefdef::table[-1]{'output'}='\strut\newline\strut\setlength{\tabcolsep}{1 mm}';
+ # Note that \newline seems to destroy the alignment envs.
+ # $Apache::londefdef::table[-1]{'output'}='\strut\newline\strut\setlength{\tabcolsep}{1 mm}';
+ $Apache::londefdef::table[-1]{'output'}='\strut'.'\\\\'."\n".'\strut\setlength{\tabcolsep}{1 mm}';
}
$Apache::londefdef::table[-1]{'output'}.=' \noindent \begin{tabular} ';
$Apache::londefdef::table[-1]{'TeXlen'}=[];
@@ -1883,7 +1960,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;
}
@@ -2096,7 +2173,9 @@ sub end_table {
}
$output.=' \\\\ '.$Apache::londefdef::table[-1]{'hinc'}.' ';
}
- $Apache::londefdef::table[-1]{'output'} .= $header_of_table.$Apache::londefdef::table[-1]{'hinc'}.$output.'\end{tabular}\strut\newline\strut ';
+ # Note that \newline destroys alignment env's produced by e.g.