--- loncom/xml/londefdef.pm 2006/08/16 20:14:24 1.333
+++ loncom/xml/londefdef.pm 2006/11/07 02:39:39 1.344
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Tags Default Definition Module
#
-# $Id: londefdef.pm,v 1.333 2006/08/16 20:14:24 albertel Exp $
+# $Id: londefdef.pm,v 1.344 2006/11/07 02:39:39 albertel Exp $
#
#
# Copyright Michigan State University Board of Trustees
@@ -561,8 +561,12 @@ sub end_body {
}
# \begin{center} causes a new paragprah spacing that looks odd inside
-# of a table cell
-sub center_correction { return '\vspace*{-6 mm}'; }
+# of a table cell. Same at the end of a \center but with a slightly
+# larger space .. hence center_correction and center_end_correction.
+#
+sub center_correction { return '\vspace*{-6 mm}'; }
+sub center_end_correction { return '\vspace*{-7 mm}'; }
+
#--
tag (end tag required)
sub start_center {
my ($target,$token,$tagstack) = @_;
@@ -585,6 +589,9 @@ sub end_center {
$currentstring = $token->[2];
} elsif ($target eq 'tex') {
$currentstring = '\end{center}';
+ if (&is_inside_of($tagstack, "table")) {
+ $currentstring .= ¢er_end_correction();
+ }
}
return $currentstring;
}
@@ -1210,16 +1217,19 @@ sub start_br {
#
for (my $i=$#tempo;$i>=0;$i--) {
if (($tempo[$i] eq 'b') || ($tempo[$i] eq 'strong') ||
- ($tempo[$i] eq 'ol') || ($tempo[$i] eq 'ul') ||
- ($tempo[$i] eq 'td') || ($tempo[$i] eq 'th')) {
+ ($tempo[$i] eq 'ol') || ($tempo[$i] eq 'ul')) {
$signal=1;
- last;
+ }
+ if (($tempo[$i] eq 'td') || ($tempo[$i] eq 'th')) {
+ $signal = 1;
}
}
- if ($signal) {
+ if ($signal eq 1) {
$currentstring .= ' \vskip 0 mm ';
} elsif ($$tagstack[-2] ne 'sub' && $$tagstack[-2] ne 'sup') {
$currentstring .= '\strut \\\\ \strut ';
+ } else { # Honor break in simple
+ $currentstring .= '}} \strut \\\\ \strut \ensuremath{^{';
}
}
return $currentstring;
@@ -1906,8 +1916,7 @@ sub start_table {
if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
- my $aa = {};
- push @Apache::londefdef::table, $aa;
+ push(@Apache::londefdef::table, {});
$Apache::londefdef::table[-1]{'row_number'} = -1;
#maximum table's width (default coincides with text line length)
if ($#Apache::londefdef::table==0) {
@@ -1981,7 +1990,13 @@ sub start_table {
$Apache::londefdef::table[-1]{'minlen'}=[];
$Apache::londefdef::table[-1]{'content'}=[];
$Apache::londefdef::table[-1]{'align'}=[];
- $currentstring.='\keephidden{NEW TABLE ENTRY}';
+ if (&is_inside_of($tagstack, 'sup')) {
+ $currentstring .= '}} \\\\ \ensuremath{^{ ';
+ }
+ if (&is_inside_of($tagstack, 'sub')) {
+ $currentstring .= '}} \\\\ \ensuremath{_{ ';
+ }
+ $currentstring.=' \keephidden{NEW TABLE ENTRY}';
}
@@ -2199,35 +2214,81 @@ sub end_table {
#
if ($colspan > 1) {
+ my $spanwidth = 0;
+ for (my $spancol = $jn; $spancol < $jn + $colspan; $spancol++) {
+ $spanwidth += $fwidth[$spancol];
+ }
$output .= '\multicolumn{'.
$colspan
- .'}{|l|}{';
+ ."}";
+ if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
+ $output .= '{|c|}{';
+ } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
+ $output .= '{|r|}{';
+ }
+ else {
+ $output .= "{|p{$spanwidth mm}|}{";
+ }
+
}
+ # Rowspan... if colspan is 1, and there's an alignment we'll need
+ # to kick in a multicolumn in order to get the alignment spec.
+ # this must precede the multirow or LaTex gets quite upset.
+ # Naturally if colspan > 1 we've already done that above ^
+ #
+ my $multirow_aligned = 0;
if ($rowspan > 1) {
+ if ($colspan == 1) {
+ if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
+ $output .= '\multicolumn{1}{|c|}{';
+ $multirow_aligned = 1;
+ } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
+ $output .= '\multicolumn{1}{|r|}{';
+ $multirow_aligned = 1;
+ }
+ }
$have_rowspan++;
- $output .= '\multirow{'.$rowspan.'}[0]{'.$fwidth[$jn].'mm}{';
+ $output .= '\multirow{'.$rowspan.'}[0]{*}{';
+ #
+ # If we did not throw in a multicolumn to align, then add
+ # an extra {
+ # so we close correctly without having to keep additional state
+ # around
+ #
+ if (!$multirow_aligned) {
+ $output .= '{';
+ }
}
if (($rowspan eq '^') || ($rowspan eq '_')) {
$have_rowspan++;
}
#--------------------------------------------------------------
- if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
- $output.=¢er_correction().'\begin{center}';
- } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
- $output.=' \hfill \llap{'
+
+ # For right and center alignment of single cells.
+ # we are going to use a multicolumn with a span of 1 to specify alignment.
+ #
+ if ($colspan == 1 && $rowspan == 1) {
+ if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
+ $output .= '\multicolumn{1}{|c|}{';
+ } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
+ $output .= '\multicolumn{1}{|r|}{';
+ }
}
+
$output.=$Apache::londefdef::table[-1]{'content'}[$in][$jn];
- if ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') {
- $output.='\end{center}';
- } elsif ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r') {
- $output.='} ';
+
+ if (($colspan == 1 && $rowspan == 1) &&
+ (($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'c') ||
+ ($Apache::londefdef::table[-1]{'align'}[$in][$jn] eq 'r'))) {
+ $output .= '}';
}
+
# Close off any open multirow:
if ($rowspan > 1) {
- $output .= '}';
+ $output .= '}}';
}
# Close off the colspan...
#
@@ -2790,23 +2851,24 @@ sub start_img {
#if original gif/jpg/png file exist do following:
my $origsrc=$src;
my ($path,$file) = &get_eps_image($src);
+ # &Apache::lonnet::logthis("Image source: $src result: $path $file");
$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($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]'; }
+ # Default size if not able to extract that (e.g. eps image).
+
+ # &Apache::lonnet::logthis("Size = $size");
+
$size='['.$size;
$size=~s/,$/]/;
- $currentstring .= '\graphicspath{{'.$destpath.'}}'
- .'\includegraphics'.$size.'{'.$destfile.'} ';
+ $currentstring .= '\graphicspath{{'.$path.'}}'
+ .'\includegraphics'.$size.'{'.$file.'} ';
# If there's an alignment specification we need to honor it here.
# For the horizontal alignments, we will also honor the
@@ -3358,6 +3420,9 @@ sub start_blockquote {
if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
}
+ if ($target eq 'tex') {
+ $currentstring .= '\begin{quote}';
+ }
return $currentstring;
}
@@ -3367,6 +3432,9 @@ sub end_blockquote {
if ($target eq 'web' || $target eq 'webgrade') {
$currentstring = $token->[2];
}
+ if ($target eq 'tex') {
+ $currentstring = '\end{quote}';
+ }
return $currentstring;
}
@@ -4167,7 +4235,7 @@ sub get_eps_image {
&Apache::lonnet::repcopy($orig_src); # Failure is not completely fatal.
}
&Apache::lonxml::debug("get_eps_image: Original image: $orig_src");
- my ($spath, $sname, $sext) = fileparse($src, qr/\.(gif|png|jpg|jpeg)/i);
+ my ($spath, $sname, $sext) = &fileparse($src, qr/\.(gif|png|jpg|jpeg)/i);
$src=~s/\.(gif|png|jpg|jpeg)$/\.eps/i;
$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
&Apache::lonxml::debug("Filelocation gives: $src");
@@ -4192,17 +4260,33 @@ sub get_eps_image {
my $newsrc=$orig_src;
$newsrc =~ s|(.*)/res/|/home/httpd/html/res/|;
&Apache::lonxml::debug("queueing $newsrc for dynamic eps production.");
- print FILE "$newsrc\n";
- close FILE;
+ print FILE ("$newsrc\n");
+ close(FILE);
$src=~s|/home/httpd/html/res|/home/httpd/prtspool|;
$src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|;
if ($sext ne "") { # Put the ext. back in to uniquify.
$src =~ s/\.eps$/$sext.eps/;
}
+
}
+
}
+ } else {
+ # If the postscript file has spaces in its name,
+ # LaTeX will gratuitiously vomit. Therefore
+ # queue such files for copy with " " replaced by "_".
+ # printout.pm will know them by their .ps or .eps extensions.
+ my $newsrc = $orig_src;
+ $newsrc =~ s|(.*)/res/|/home/httpd/html/res/|;
+ open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat");
+ print FILE "$src\n";
+ close FILE;
+ $src=~s|/home/httpd/html/res|/home/httpd/prtspool|;
+ $src=~s|/home/([^/]*)/public_html/|/home/httpd/prtspool/$1/|;
}
my ($path,$file)=($src=~m|(.*)/([^/]*)$|);
+ $path =~ s/ /\_/g;
+ $file =~ s/ /\_/g;
&Apache::lonxml::debug("get_eps_image returning: $path / $file
");
return ($path.'/',$file);
}