[tex-eplain] Another improvement for the double-column macros

Oleg Katsitadze olegkat at gmail.com
Thu Sep 13 21:34:03 CEST 2007


Hi,

The attached patch is due to prodding from Gérald Tenenbaum :).  It
fixes some situations when the last column comes out spaced out.  The
big comment in the patch pretty much explains it.

I was thinking maybe I need to make \@col at extralines user-visible and
describe it in the doc.  But then, maybe not -- the description won't
make much sense if the reader is not familiar with the code.  And if
they are, then they won't need any explanation :).

Best,
Oleg
-------------- next part --------------
Index: xeplain.tex
===================================================================
RCS file: /cvsroot/eplain/eplain/xeplain.tex,v
retrieving revision 1.45
diff -u -p -r1.45 xeplain.tex
--- xeplain.tex	12 Sep 2007 20:05:08 -0000	1.45
+++ xeplain.tex	13 Sep 2007 19:02:09 -0000
@@ -3387,6 +3387,26 @@
 % When the box is processed according to 1), an underfull vbox can appear,
 % but it's not our problem, the manuscript (or it's macros) has to be fixed.
 %
+% Gather this many baselines
+\chardef\@col at extralines = 3
+% more material per each column than the combined height of the
+% columns, before attempting to break the columns.  This sometimes
+% considerably improves the last column, when it would become too
+% spaced out because TeX had to squeeze some lines into the previous
+% columns due to unfortunate column breaks.
+%
+% The larger \@col at extralines, the better, but we don't want to make
+% it too large.  If there are less than \@col at extralines * num_columns
+% lines left before we start gathering these extra lines, we'll hit
+% \@endcolumns while gathering material for this page.  If the extra
+% lines will not actually fit in the columns, we'll have to move them
+% to the next page.  But we won't move them if there are any
+% insertions on this page (see \@balancecolumns), so in such case
+% we'll stuff everything on the current page, producing an overfull
+% box, even though these extra lines could successfully be moved to
+% the next page.
+\newdimen\@col at extraheight
+%
 % Another note: all assignments are global; it is not possible to call
 % \doublecolumns in a group.
 %
@@ -3444,6 +3464,10 @@
   \multiply\count\topins by \@numcolumns
   %
   \global\vsize = \@numcolumns\vsize
+  % Gather some extra material, to improve the last column.
+  \@col at extraheight=\@col at extralines\baselineskip
+  \multiply\@col at extraheight by \@numcolumns
+  \global\advance\vsize by \@col at extraheight
 }%
 %
 % When this is invoked box 255 contains just the right amount of
@@ -3529,6 +3553,7 @@
 % 
 \def\@columnoutput{%
   \dimen@ = \ht255
+    \advance\dimen@ by -\@col at extraheight
     \divide\dimen@ by \@numcolumns
   \@columnsplit
   \@recoverclubpenalty 
@@ -3541,8 +3566,9 @@
   \penalty\outputpenalty
   %
   % The correct vsize is the original vsize times the
-  % number of columns.
+  % number of columns, plus the "extra height".
   \global\vsize = \@numcolumns\@normalvsize
+  \global\advance\vsize by \@col at extraheight
 }%
 %
 % Go back to single-column typesetting.  Assume \doublecolumns has
@@ -3568,8 +3594,9 @@
   % have to use \pagegoal for the height, otherwise the box produced
   % when splitting the columns will not fit on the page.
   \column at pagegoal = \pagegoal
-  \ifdim \pagetotal > \pagegoal
-    \column at vsize = \pagegoal
+  \advance\column at pagegoal by-\@col at extraheight
+  \ifdim \pagetotal > \column at pagegoal
+    \column at vsize = \column at pagegoal
   \else
     \column at vsize = \pagetotal
   \fi


More information about the tex-eplain mailing list