From 3c85b55e2f245fb7edac7e445f107e6d0bb423ae Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Thu, 16 Nov 2006 01:02:47 +0000
Subject: context update

git-svn-id: svn://tug.org/texlive/trunk@2444 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/tex/context/base/page-mul.tex | 182 ++++++++++++++++--------
 1 file changed, 125 insertions(+), 57 deletions(-)

(limited to 'Master/texmf-dist/tex/context/base/page-mul.tex')

diff --git a/Master/texmf-dist/tex/context/base/page-mul.tex b/Master/texmf-dist/tex/context/base/page-mul.tex
index c68a4dcf280..991e7532d30 100644
--- a/Master/texmf-dist/tex/context/base/page-mul.tex
+++ b/Master/texmf-dist/tex/context/base/page-mul.tex
@@ -27,7 +27,7 @@
 \let\OTRMULsetvsize            \OTRONEsetvsize
 \let\OTRMULsethsize            \OTRONEsethsize
 \let\OTRMULdopagecontents      \OTRONEdopagecontents
-\let\OTRMULfinalsidefloatoutput\OTRONEfinalsidefloatoutput
+\let\OTRMULfinalsidefloatoutput\OTRONEfinalsidefloatoutput % ???
 \let\OTRMULflushfloatbox       \OTRONEflushfloatbox
 
 \let\OTRMULdosettopinserts   \relax
@@ -37,6 +37,9 @@
 \let\OTRMULdosetbothinserts  \relax
 \let\OTRMULflushsavedfloats  \relax
 
+\let\OTRMULflushsidefloats      \forgetsidefloats % \relax
+\let\OTRMULsynchronizesidefloats\forgetsidefloats % \relax
+
 \newtoks \OTRMULoutput
 
 \def\OTRMULgotonextpage
@@ -476,7 +479,7 @@
    \fi
    \appendtoks\topskip1\topskip\to\everybodyfont
    \the\everybodyfont % ugly here
-\saveinterlinespace % uglu here
+   \saveinterlinespace % ugly here
    \initializecolumns\nofcolumns
    \hangafter\zerocount
    \hangindent\zeropoint
@@ -632,7 +635,9 @@
         \edef\maxcolumndepth{\the\dp\currentcolumnbox}%
       \fi}}
 
-\def\flushcolumnedpage
+\chardef\columnedtopflushmethod\plusone
+
+\def\flushcolumnedpage#1%
   {\bgroup
    \forgetall
    \setmulticolumnsout
@@ -698,20 +703,48 @@
    \global\precolumnboxheight\zeropoint
    \setvsize
    \dosomebreak\nobreak
-   % wrong, but keep it as a reminder
-   % \ifgridsnapping \else
-   %   \scratchdimen\topskip
-   %   \advance\scratchdimen -\openstrutheight
-   %   \nointerlineskip
-   %   \vskip-\scratchdimen
-   % \fi
-   % so that we don't add it again
+   \ifgridsnapping \else
+     \ifcase\columnedtopflushmethod
+       % sometimes method 1 goes wrong, so we need a way out; best sort this out
+       % when we run into it again
+     \or
+       % \input tufte \startcolumns \showbaselines \input tufte \stopcolumns \input tufte
+       \scratchdimen\topskip
+       \advance\scratchdimen -\openstrutheight
+       \nointerlineskip
+       \vskip-\scratchdimen
+     \or
+       % untested but maybe handy
+       \scratchdimen\topskip
+       \advance\scratchdimen -\openstrutheight
+       \nointerlineskip
+       \vskip-\scratchdimen
+       \vskip-\lineheight
+       \vbox{\strut}%
+     \fi
+   \fi
    \prevdepth\openstrutdepth
    \nointerlineskip
    \dp\columnpagebox\zeropoint
    \global\finalcolumnheights\ht\columnpagebox
    \getnoflines\finalcolumnheights
    \global\finalcolumnlines\noflines
+   \ifcase#1\else
+     % messy correction, we need to rewrite this module (newcolumns)
+     \setbox\columnpagebox\vbox
+       {\offinterlineskip
+        \scratchdimen\ht\columnpagebox
+        \advance\scratchdimen\dp\columnpagebox % we probably lost that one already
+        \box\columnpagebox
+        \vskip-\scratchdimen}%
+     \scratchdimen\noflines\openlineheight
+     \advance\scratchdimen-\openstrutdepth
+     \advance\scratchdimen-\openlineheight
+     \advance\scratchdimen\topskip
+     \ht\columnpagebox\scratchdimen
+     \dp\columnpagebox\openstrutdepth
+     % end of mess
+   \fi
    \box\columnpagebox
    \egroup}
 
@@ -984,7 +1017,7 @@
    \getmulticolumnlines
    \dimen0=\nofcolumnlines\openlineheight
    \dohandleallcolumns
-     {\splitcurrentcolumn from \box\normalpagebox to \dimen0}
+     {\splitcurrentcolumn from \box\normalpagebox to \dimen0}%
    \setbox\restofpage\vbox{\unvbox\normalpagebox}%
    \ifinheritcolumns
      \ifr@ggedbottom % vreemd
@@ -1021,7 +1054,7 @@
      \dohandleallcolumns
        {\global\ht\currentcolumnbox\dimen0}%
    \fi
-   \setbox\precolumnbox\vbox{\flushcolumnedpage}%
+   \setbox\precolumnbox\vbox{\flushcolumnedpage\zerocount}%
    \finaloutput\box\precolumnbox
    \sethsize
    \setvsize
@@ -1038,6 +1071,8 @@
 %D \type{\box4} garantees a more robust check when skips are
 %D used.
 
+\def\multicolumnsbalancemax{250} % 100 is too small when floats are involved
+
 \def\balancedmulticolumnsout
   {\bgroup
    \setmulticolumnsout
@@ -1083,49 +1118,58 @@
        \dimen2=\onepoint % RUBISH
        \dimen2=\spacingfactor\dimen2
      \fi
-     \loop
-       \advance\count255 \plusone
-       \global\setbox\restofpage\copy0\relax
-       \splitfirstcolumn from \box\restofpage to \dimen0
-       \dohandlemidcolumns
-         {\splitcurrentcolumn from \box\restofpage to \dimen0}%
-       \splitlastcolumn from \box\restofpage to \dimen0
-       \setbox2\vbox{\unvcopy\firstcolumnbox}%
-       \dimen4\zeropoint
-       \dohandleallcolumns
-         {\setbox4\vbox
-            {\unvcopy\currentcolumnbox
-            %rather new, test this on pdftex-z.tex
-             \unpenalty\unskip\unpenalty\unskip}% maybe better in main splitter
-            %\writestatus{balance}{\the\currentcolumnbox: \the\ht4}%
-             \dimen6\ht4
-             \ifdim\dimen6>\dimen4 \dimen4=\dimen6 \fi}%
-       \advance\dimen4 -.0005pt % get rid of accurracy problem, pretty new
-       \ifnum\count255>100
-         \donefalse
-       \else\ifdim\dimen4>\ht2
-         \donetrue
-       \else
-         \donefalse
-       \fi\fi
-       \ifdone
-         \advance\dimen0 \dimen2\relax
-     \repeat
+     \doloop
+       {\advance\count255 \plusone
+        \global\setbox\restofpage\copy0\relax
+        \splitfirstcolumn from \box\restofpage to \dimen0
+        \dohandlemidcolumns
+          {\splitcurrentcolumn from \box\restofpage to \dimen0}%
+        \splitlastcolumn from \box\restofpage to \dimen0
+        \setbox2\vbox{\unvcopy\firstcolumnbox}%
+        \dimen4\zeropoint
+        \dohandleallcolumns
+          {\setbox4\vbox
+             {\unvcopy\currentcolumnbox
+             %rather new, test this on pdftex-z.tex
+              \unpenalty\unskip\unpenalty\unskip}% maybe better in main splitter
+          %\writestatus{balance}{\the\currentcolumnbox: \the\ht4}%
+%            \dimen6\ht4 \ifdim\dimen6>\dimen4 \dimen4=\dimen6 \fi}%
+           \ifdim\ht4>\dimen4 \dimen4=\ht4 \fi}%
+        \advance\dimen4 -.0005pt % get rid of accurracy problem, pretty new
+        \ifnum\count255>\multicolumnsbalancemax\relax
+          \exitloop
+        \else\ifdim\dimen4>\ht2
+          \advance\dimen0 \dimen2\relax
+        \else
+          \exitloop
+        \fi\fi}%
      \dohandleallcolumns
        {\global\setbox\currentcolumnbox\vbox{\unvcopy\currentcolumnbox}}% NIEUW
-     \ifnum\count255>100\relax
+     \ifnum\count255>\multicolumnsbalancemax\relax
        \showmessage\m!columns7\empty
      \else
        \showmessage\m!columns8{\the\count255\space}%
      \fi
      \egroup
      \ifinheritcolumns
-       \dimen0\ht\firstcolumnbox
-       \dimen2\ht\firstcolumnbox
+       % We cannot assume that the first column is the tallest, if
+       % only because we may have an aborted balance (one line in the
+       % first column and a graphic in the second one).
+       %
+       % \dimen0\ht\firstcolumnbox
+       % \dimen2\ht\firstcolumnbox
+       %
+       \dimen0=\zeropoint
+       \dohandleallcolumns
+         {\ifdim\ht\currentcolumnbox>\dimen0
+            \dimen0=\ht\currentcolumnbox
+          \fi}%
+       \dimen2\dimen0
+       % so far
        \advance\dimen2 -\openlineheight
        \dohandleallcolumns
          {\dimen4\ht\currentcolumnbox
-          \dimen6=10\openlineheight
+          \dimen6=10\openlineheight % funny value
           \global\setbox\currentcolumnbox\vbox to \dimen0
             {\unvbox\currentcolumnbox
              \ifdim\dimen4>\dimen6
@@ -1174,10 +1218,17 @@
    \fi
    \global\output{\balancingerror}%
    \b@selinebottomtrue % forces depth in separation rule
-   \flushcolumnedpage
-   \allowbreak
+   \flushcolumnedpage\plusone
+   \multicolumnseject
    \egroup}
 
+\def\multicolumnseject
+  {\ifdim\pagetotal>\textheight
+     \eject % new
+   \else
+     \allowbreak
+   \fi}
+
 %D The multicolumn mechanism is incorporated in a \CONTEXT\
 %D interface, which acts like:
 %D
@@ -1238,8 +1289,7 @@
    \let\flushcolumnfloats\noflushcolumnfloats}
 
 \def\setlocalcolumnfloats
-  {\everypar
-     {\flushnotes\flushcolumnfloat\flushmargincontents\checkindentation}%
+  {\everypar{\flushnotes\flushcolumnfloat\flushmargincontents\checkindentation}%
    \let\flushcolumnfloat\doflushcolumnfloat
   %\let\doroomfloat\docolumnroomfloat
    \let\docheckiffloatfits\docolumnroomfloat
@@ -1490,6 +1540,24 @@
      \egroup
    \fi}
 
+%D The next macro can be used to flush floats in the current
+%D stream. No width checking is (yet) done.
+
+\def\insertcolumnfloats
+  {\doloop
+     {\ifsomefloatwaiting
+        \bgroup
+        \forgetall
+        % no check for width
+        \dogetfloat
+        \blank[\@@bkspacebefore]
+        \snaptogrid\vbox{\copy\floatbox}
+        \blank[\@@bkspaceafter]
+        \egroup
+      \else
+        \exitloop
+      \fi}}
+
 %D This were the multi||column routines. They can and need to
 %D be improved but at the moment their behaviour is acceptable.
 %D
@@ -1511,8 +1579,8 @@
 % \stopcolumns
 
 \newif\ifinsidecolumns
-\newif\if@@klbalanceren
-\newif\if@@kluitlijnen
+% \newif\if@@klbalanceren
+% \newif\if@@kluitlijnen
 
 \insidecolumnsfalse
 
@@ -1632,11 +1700,11 @@
   {\goodbreak}
 
 \installcolumnbreakhandler {MUL} \v!yes
-  {\par                                              % todo: since
+  {\par                                             % todo: since
    {\testrulewidth\zeropoint\ruledvskip\textheight} % we misuse a
-   \penalty-200                                      % side effect
+   \penalty-200                                     % side effect
    \vskip-\textheight
-   \prevdepth-\thousandpoint} % signals top of column to \blank
+   }% bugged : \prevdepth-\thousandpoint} % signals top of column to \blank
 
 \setupcolumns
   [\c!n=2,
@@ -1645,14 +1713,14 @@
    \c!direction=\v!right,
    \c!rule=\v!off,
    \c!tolerance=\v!tolerant,
-   \c!distance=1.5\korpsgrootte, % influenced by switching
+   \c!distance=1.5\bodyfontsize, % influenced by switching
    \c!height=,
    \c!balance=\v!yes,
    \c!align=\v!text,
    \c!blank={\v!line,\v!fixed},
    \c!option=,
    \c!rulethickness=\linewidth,
-   \c!offset=.5\korpsgrootte]
+   \c!offset=.5\bodyfontsize]
 
 %D Undocumented and still under development.
 
@@ -1663,7 +1731,7 @@
   {\bgroup
    \nopenalties
    \getparameters[\??kl]
-     [\c!width=\hsize,\c!distance=1.5\korpsgrootte,%
+     [\c!width=\hsize,\c!distance=1.5\bodyfontsize,%
       \c!n=2,\c!lines=0,#1]%
    \let\rigidcolumnlines\@@kllines
    \setrigidcolumnhsize\@@klwidth\@@kldistance\@@kln
-- 
cgit v1.2.3

