texlive[60736] Master/texmf-dist: sttools (11oct21)

commits+karl at tug.org commits+karl at tug.org
Mon Oct 11 22:25:23 CEST 2021


Revision: 60736
          http://tug.org/svn/texlive?view=revision&revision=60736
Author:   karl
Date:     2021-10-11 22:25:22 +0200 (Mon, 11 Oct 2021)
Log Message:
-----------
sttools (11oct21)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/sttools/README.md
    trunk/Master/texmf-dist/doc/latex/sttools/cuted.pdf
    trunk/Master/texmf-dist/doc/latex/sttools/floatpag.pdf
    trunk/Master/texmf-dist/doc/latex/sttools/flushend.pdf
    trunk/Master/texmf-dist/doc/latex/sttools/midfloat.pdf
    trunk/Master/texmf-dist/doc/latex/sttools/stabular.pdf
    trunk/Master/texmf-dist/doc/latex/sttools/stfloats.pdf
    trunk/Master/texmf-dist/doc/latex/sttools/sttools.pdf
    trunk/Master/texmf-dist/doc/latex/sttools/texsort.pdf
    trunk/Master/texmf-dist/source/latex/sttools/cuted.dtx
    trunk/Master/texmf-dist/source/latex/sttools/floatpag.dtx
    trunk/Master/texmf-dist/source/latex/sttools/flushend.dtx
    trunk/Master/texmf-dist/source/latex/sttools/midfloat.dtx
    trunk/Master/texmf-dist/source/latex/sttools/stabular.dtx
    trunk/Master/texmf-dist/source/latex/sttools/stfloats.dtx
    trunk/Master/texmf-dist/source/latex/sttools/sttools.dtx
    trunk/Master/texmf-dist/source/latex/sttools/sttools.ins
    trunk/Master/texmf-dist/source/latex/sttools/texsort.dtx
    trunk/Master/texmf-dist/tex/latex/sttools/cuted.sty
    trunk/Master/texmf-dist/tex/latex/sttools/floatpag.sty
    trunk/Master/texmf-dist/tex/latex/sttools/flushend.sty
    trunk/Master/texmf-dist/tex/latex/sttools/midfloat.sty
    trunk/Master/texmf-dist/tex/latex/sttools/stabular.sty
    trunk/Master/texmf-dist/tex/latex/sttools/stfloats.sty
    trunk/Master/texmf-dist/tex/latex/sttools/texsort.sty

Modified: trunk/Master/texmf-dist/doc/latex/sttools/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/sttools/README.md	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/doc/latex/sttools/README.md	2021-10-11 20:25:22 UTC (rev 60736)
@@ -1,4 +1,4 @@
-README for sttools, v2.1 2020/10/16
+README for sttools, v3.0 2021/10/04
 
 INTRODUCTION
 ============
@@ -9,50 +9,56 @@
 PACKAGES
 ========
 
-* cuted.sty, v1.5 2012/10/04:
-  – puts some material page width wide at any place on twocolumn page
-    with existing text reformatted under inserted material; 
-  TODO: add optional rules to separate from text;
+* cuted.sty, v2.0 2021/10/04:  
+  – puts some material page width wide at any place on twocolumn page  
+    with existing text reformatted under inserted material;  
+    \preCutedStrip{h... i} and \postCutedStrip{h... i} can be used to add  
+    extra stuff before and after the strip;  
+    (2021/10/04): rewrite with new balance algorithm and options.  
 
-* floatpag.sty, v1.1 2012/05/29:
-  – sets pagestyle for floats page;
+* floatpag.sty, v2.0 2021/10/04:  
+  – sets pagestyle for floats page;  
+    (2021/10/04): removed latex209 compatibility; added rotated dblfloat  
+                  support;  
 
-* flushend.sty, v3.5 2017/10/16:
-  – balances page in twocolumn mode;
-   (2014/03/03): totally rewritten with new algorithm to support footnotes,
-        top floats and column break before one line section title;
-   (2014/04/24): bugfix version;
-   (2015/04/08): bugfix version with improved funcionality:
-                 - spreaded or fixed right column height;
-                 - optional old algorithm for backward compatability;
-   (2015/04/14): set debug option off by default; keeplastbox modified;
-   (2016/06/21): bugfix compatibility with luatexja package;
-   (2017/03/27): bugfix version with new options for some checks on/off;
-   (2020/10/14): bugfix development and test;
-   (2020/10/16): bugfix version: modern with noautobase;
+* flushend.sty, v4.0 2021/10/04:  
+  – balances page in twocolumn mode;  
+    (2014/03/03): totally rewritten with new algorithm to support footnotes,  
+                  top floats and column break before one line section title;  
+    (2014/04/24): bugfix version;  
+    (2015/04/08): bugfix version with improved funcionality:  
+                  - spreaded or fixed right column height;  
+                  - optional old algorithm for backward compatability;  
+    (2015/04/14): set debug option off by default; keeplastbox modified;  
+    (2016/06/21): bugfix compatibility with luatexja package;  
+    (2017/03/27): bugfix version with new options for some checks on/off;  
+    (2020/10/14): bugfix development and test;  
+    (2020/10/16): bugfix version: modern with noautobase;  
+    (2021/10/04): another rewrite with new balance algorithm and options;  
 
-* marginal.sty, v1.1 2012/05/29:
-  – enlarges room for marginal inserts;
-   (2016/06/28): removed from the bundle;
+* marginal.sty, v1.1 2012/05/29:  
+  – enlarges room for marginal inserts;  
+    (2016/06/28): removed from the bundle;  
 
-* midfloat.sty, v1.1 2012/05/29:
-  – inserts onecolumn stuff in twocolumn page; 
-  TODO: extend to work on both columns;
+* midfloat.sty, v1.1 2012/05/29:  
+  – inserts onecolumn stuff in twocolumn page;  
+  TODO: extend to work on both columns;  
 
-* stabular.sty, v2.0 2014/03/20:
-  – modifies tabular environment; 
-  (2014/03/20): removed extra stuff and left only possibility to break 
-       on page boundary;
-       added tabular variant from array package;
+* stabular.sty, v2.1 2021/10/04:  
+  – modifies tabular environment;  
+    (2014/03/20): removed extra stuff and left only possibility to break  
+                  on page boundary;  
+                  added tabular variant from array package;  
+    (2021/10/04): sync with array bugfix version for tabular;  
 
-* stfloats.sty, v3.3 2017/03/27:
-  – enriches floats output mechanism; 
-   (2016/06/28): compatibility bugfix with 2015 latexrelease;
-   (2017/03/27): compatibility bugfix with 2017-05-01 latexrelease;
+* stfloats.sty, v3.3 2017/03/27:  
+  – enriches floats output mechanism;  
+   (2016/06/28): compatibility bugfix with 2015 latexrelease;  
+   (2017/03/27): compatibility bugfix with 2017-05-01 latexrelease;  
 
-* texsort.sty, v1.1 2012/05/29:
-  - sorts numerical values;
-  TODO: extend (rewrite) to support alphanumerical values 
+* texsort.sty, v1.1 2012/05/29:  
+  - sorts numerical values;  
+  TODO: extend (rewrite) to support alphanumerical values  
         for sorting.
 
 INSTALLATION
@@ -74,7 +80,7 @@
 
 LICENSE
 =======
-
+```
 This work may be distributed and/or modified under the
 conditions of the LaTeX Project Public License, either version 1.3
 of this license or (at your option) any later version.
@@ -82,6 +88,6 @@
   http://www.latex-project.org/lppl.txt
 and version 1.3 or later is part of all distributions of LaTeX
 version 2005/12/01 or later.
+```
 
 
-

Modified: trunk/Master/texmf-dist/doc/latex/sttools/cuted.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/sttools/floatpag.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/sttools/flushend.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/sttools/midfloat.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/sttools/stabular.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/sttools/stfloats.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/sttools/sttools.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/sttools/texsort.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/latex/sttools/cuted.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/sttools/cuted.dtx	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/source/latex/sttools/cuted.dtx	2021-10-11 20:25:22 UTC (rev 60736)
@@ -1,6 +1,6 @@
-% \iffalse meta-comment
+% \iffalse meta-comment/*%    \end{macrocode}*/
 %
-% Copyright (C) 2012 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+% Copyright (C) 2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
 % ---------------------------------------------------------------------------
 % This work may be distributed and/or modified under the
 % conditions of the LaTeX Project Public License, either version 1.3
@@ -20,13 +20,35 @@
 % \fi
 %
 % \iffalse
+%<*internal>
+\begingroup
+%</internal>
+%<*batchfile>
+\input docstrip.tex
+\keepsilent\askforoverwritefalse
+\preamble
+%%
+%% This is file `cuted.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% cuted.dtx  (with options: `package')
+%% 
+\endpreamble
+\generate{\file{cuted.sty}{\from{cuted.dtx}{package}}}
+%</batchfile>
+%<batchfile>\endbatchfile
+%<*internal>
+\generate{\file{cuted.ins}{\from{cuted.dtx}{batchfile}}}
+\endgroup
+%</internal>
 %<*driver>
 \ProvidesFile{cuted.dtx}
 %</driver>
 %<*package>
-%% Copyright (C) 1997-2012 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
-%% VTeX Ltd., Akademijos 4, Vilnius, Lithuania
-%% http://www.vtex.lt/tex/download/macros/
+%% Copyright (C) 1997-2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+%% UAB VTeX, Mokslininkų 2A, LT-08412 Vilnius, Lithuania
 %% --------------------------------------------------------------------------
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3
@@ -42,15 +64,16 @@
 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
 %<package>\ProvidesPackage{cuted}
 %<*package>
-    [2012/10/04 v1.5 Mixing onecolumn and twocolumn modes]
+    [2021/10/04 v2.0 Mixing onecolumn and twocolumn modes]
 %</package>
 %
 %<*driver>
 \documentclass{ltxdoc}
-\usepackage{cuted}[2012/10/04]
+\usepackage{cuted}[2021/10/04]
 \EnableCrossrefs
 \CodelineIndex
 \RecordChanges
+\OnlyDescription
 \begin{document}
   \DocInput{cuted.dtx}
   \PrintChanges
@@ -89,6 +112,7 @@
 % \changes{}{2000/01/18}{pakeistas \cs{@outputdblcol}}
 % \changes{}{2002/06/11}{added options unskipbreak and autobase}
 % \changes{v1.4}{2012/05/29}{Converted to DTX file}
+% \changes{v2.0}{2021/10/04}{rewrite with new balance algorithm and options}
 %
 % \DoNotIndex{\newcommand,\newenvironment}
 %
@@ -102,52 +126,83 @@
 %
 % \section{Introduction}
 %
-%   It is denoted to place some material in full-width at any place 
-%   on double-column page (|\twocolumn| mode). The part of material
-%   can be placed on the next page. Existing text is placed
-%   under inserted material in two columns (it is reformatted).
+% It is denoted to place some material in full-width at any place 
+% on double-column page (|\twocolumn| mode). The part of material
+% can be placed on the next page. Existing text is placed
+% under inserted material in two columns (it is reformatted).
 %
+% To compare with the previous version the package is rewritten
+% with new cropped balancing algorithm version and new options
+% from |flushend.sty, v4.0|. 
+%
 % \section{Usage}
 %
-%
 % \DescribeMacro{strip}
 % Provides new environment:
+% \begin{verbatim}
+%     \begin{strip} 
+%     <wide onecolumn material> 
+%     \end{strip}
+% \end{verbatim}
+% Puts |\vbox|\marg{wide onecolumn material} in full-width on
+% double-column page.
 %
-%  \begin{verbatim}
-%    \begin{strip} 
-%      <wide onecolumn material> 
-%    \end{strip}
-%  \end{verbatim}
+% \medskip
+% It can be problems with floats and footnotes. In the case of 
+% problems with footnotes it is possible to correct the situation
+% using commands |\footnotemark| and |\footnotetext|.
 %
-%   Puts |\vbox|\marg{wide onecolumn material} in full-width on
-%   double-column page.
+% \medskip
+% \DescribeMacro{preCutedStrip}\marg{tokens}
+% \\\noindent Before the strip |\stripsep| glue and |\the\preCutedStrip| token list \meta{tokens} are added.   
 %
-%   \medskip
-%   Adds |\stripsep| glue before and after
-%   (by default: |15pt plus2pt minus 2pt|).
+% \medskip
+% \DescribeMacro{postCutedStrip}\marg{tokens}
+% \\\noindent After the strip |\the\postCutedStrip| token list \meta{tokens} and |\stripsep| glue are added.
+% 
+% \medskip
+% \DescribeMacro{stripsep}
+% By default: |\stripsep=15pt plus2pt minus 2pt|.
 %
-%   \medskip
-%   It can be problems with floats and footnotes. In the case of 
-%   problems with footnotes it is possible to correct the situation
-%   using commands |\footnotemark| and |\footnotetext|.
-%
 % \medskip
 % \DescribeMacro{\oldcolsbreak}
 % \marg{adds}
+% \\\noindent Adds \meta{adds} in place of original column break if strip is placed 
+% on the right column. Seems, it should be unnecessary as current version
+% uses |pagediscards| dimensions to restore original vertical skip.
 %
-%   Adds \meta{adds} in place of original column break if strip is placed 
-%   on the right column.
-%
 % \subsection{Package options}
 %
-% \DescribeMacro{unskipbreak}
-%   \indent It is used to change |\hbox{}| to |\unskip| after leftcolumn break on striped page.
+% \begin{description}
+% 
+% \item[\meta{|spread|}]
+%   \texttt{[default]} It enables columns spreading trying to balance.
 %
+% \item[\meta{|nospread|}]
+%   It disables columns spreading trying to balance.
+%
+% \item[\meta{|shrink|}]
+%   \texttt{[default]} It enables columns shrinking trying to balance.
+%
+% \item[\meta{|noshrink|}]
+%   It disables columns shrinking trying to balance.
+%
 % \medskip
-% \DescribeMacro{autobase}
-%   It is used to guess |\baselineskip| value on original columns break.
+%   \textit{Similiar options exist for single column separatly}: 
 %
+%   |lspread|, |nolspread|, |lshrink|, |nolshrink| -- for left column  
 %
+%   |rspread|, |norspread|, |rshrink|, |norshrink| -- for right column  
+%
+% \item[\meta{|debug|}]
+%   Adds rules to the bottom of columns (just for debugging)
+%   and some additional log info.
+%
+% \item[\meta{|nodebug|}]
+%   \texttt{[default]} Skips putting debuging lines and additional info.
+%
+% \end{description}
+%
 % \StopEventually{}
 %
 % \section{Implementation}
@@ -156,479 +211,529 @@
 %<*package>
 % \fi
 %
-%
-% \begin{macro}{unskipbreak}
+%/*%    \begin{macrocode}*/
 %    \begin{macrocode}
-\def\on at stripcols@break{\hbox{}}
-\DeclareOption{unskipbreak}{\gdef\on at stripcols@break{\unskip}}
-%    \end{macrocode}
-% \end{macro}
 %
-% \begin{macro}{autobase}
-%    \begin{macrocode}
-\newif\if at flushend@auto at baselineskip
-\DeclareOption{autobase}{\global\@flushend at auto@baselineskiptrue}
+
+\newif\if at right@column at spread \@right at column@spreadtrue
+\newif\if at right@column at shrink \@right at column@shrinktrue
+\newif\if at left@column at spread \@left at column@spreadtrue
+\newif\if at left@column at shrink \@left at column@shrinktrue
+\newif\ifcuted@@debug \cuted@@debugfalse
+
+\DeclareOption{spread}{%
+    \global\@left at column@spreadtrue
+    \global\@right at column@spreadtrue
+    }
+\DeclareOption{nospread}{%
+    \global\@left at column@spreadfalse
+    \global\@right at column@spreadfalse
+    }
+\DeclareOption{lspread}{\global\@left at column@spreadtrue}
+\DeclareOption{nolspread}{\global\@left at column@spreadfalse}
+\DeclareOption{rspread}{\global\@right at column@spreadtrue}
+\DeclareOption{norspread}{\global\@right at column@spreadfalse}
+
+\DeclareOption{shrink}{%
+    \global\@left at column@shrinktrue
+    \global\@right at column@shrinktrue
+    }
+\DeclareOption{noshrink}{%
+    \global\@left at column@shrinkfalse
+    \global\@right at column@shrinkfalse
+    }
+\DeclareOption{lshrink}{\global\@left at column@shrinktrue}
+\DeclareOption{nolshrink}{\global\@left at column@shrinkfalse}
+\DeclareOption{rshrink}{\global\@right at column@shrinktrue}
+\DeclareOption{norshrink}{\global\@right at column@shrinkfalse}
+
+\DeclareOption{debug}{\global\cuted@@debugtrue}
+\DeclareOption{nodebug}{\global\cutted@@debugfalse}
+
 \ProcessOptions
 
+\newif\if at lastviper \@lastviperfalse
 \newtoks\At at ViperColsBreak \At at ViperColsBreak{}
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\oldcolsbreak}
-%    \begin{macrocode}
+\newtoks\preCutedStrip \preCutedStrip{}
+\newtoks\postCutedStrip \postCutedStrip{}
+\newbox\cuted@@tempbox at a
+\newbox\cuted@@tempbox at c
+\newbox\cuted@@tempbox at var
+\@ifundefined{hold at viper}
+    {\newbox\hold at viper}{}
+\@ifundefined{@viper}
+    {\newbox\@viper}{}
+\newbox\cuted@@varbox at a
+\newbox\cuted@@varbox at c
+\newdimen\cuted@@tempdim at spread
+\newdimen\cuted@@tempdim at a
+\newdimen\cuted@@tempdim at b
+\newdimen\ht at hold@viper
+\newdimen\ht at viper
+\newdimen\var@@pagediscards at ht \var@@pagediscards at ht=\z@
+\@ifundefined{stripsep}
+    {\newskip\stripsep \stripsep 15\p@ plus 2\p@ minus 2\p@}{}
+\newcount\viper at penalty
+\mathchardef\@Mv=10005
+\def\cuted@@column at badness{101}
+\def\cuted@@page at rule{\z@}
+\savingvdiscards=\@ne
+
+\def\cuted@@wlog at debug#1{\ifcuted@@debug \wlog{#1}\fi}
+
+\def\set at split@topskip at to#1{%
+    \splittopskip=#1\relax
+    \vfuzz=\maxdimen
+    \vbadness=\maxdimen
+    }
+
 \def\oldcolsbreak#1{\global\At at ViperColsBreak{#1}}
-\def\viper at top@hook{\splittopskip0pt plus 2pt}
 
-%    \end{macrocode}
-% \end{macro}
-%
-%    \begin{macrocode}
-\newbox\v at aaa
-\newbox\v at ccc
-\@ifundefined{lastskip at a}{\newskip\lastskip at a}{}
-\@ifundefined{lastskip at b}{\newskip\lastskip at b}{}
-\@ifundefined{lastskip at d}{\newskip\lastskip at d}{}
-\@ifundefined{lastbox at a}{\newbox\lastbox at a}{}
-\@ifundefined{stripsep}{\newskip\stripsep \stripsep 15pt plus 2pt minus 2pt}{}
+\def\on at stripcols@break{%
+    %%
+    %% adds original vertical page break skip
+    %%
+    \begingroup
+        \setbox\cuted@@tempbox at var\vbox{\pagediscards}%
+        \ifvoid\cuted@@tempbox at var
+        \else
+            \global\var@@pagediscards at ht=\ht\cuted@@tempbox at var
+            \global\advance\var@@pagediscards at ht by\dp\cuted@@tempbox at var
+        \fi
+    \endgroup
+    \ifdim\var@@pagediscards at ht=\z@
+    \else
+        \vskip\var@@pagediscards at ht
+    \fi
+    }
 
-\@ifundefined{@viper}{\newbox\@viper}{}
-\newif\if at lastviper \@lastviperfalse
-%    \end{macrocode}
-%
-%
-% \begin{macro}{\@outputdblcol}
-%    \begin{macrocode}
 \def\@outputdblcol{%
-  \if at firstcolumn
-    \global \@firstcolumnfalse
-    \global \setbox\@leftcolumn \box\@outputbox
-  \else
-    \global \@firstcolumntrue
-    \setbox\@outputbox \vbox {%
-                         \hb at xt@\textwidth {%
-                           \hb at xt@\columnwidth {%
-                             \box\@leftcolumn \hss}%
-                           \hfil
-                           \vrule \@width\columnseprule
-                           \hfil
-                           \hb at xt@\columnwidth {%
-                             \box\@outputbox \hss}%
-                                             }%
-                              }%
-    \ifvoid\hold at viper
+    \if at firstcolumn
+        \global\@firstcolumnfalse
+        \global\setbox\@leftcolumn\copy\@outputbox
+        \splitmaxdepth\maxdimen
+        \vbadness\maxdimen
+        \setbox\@outputbox\vbox{\unvbox\@outputbox\unskip}%
+        \setbox\@outputbox\vsplit\@outputbox to\maxdimen
+        \toks@\expandafter{\topmark}%
+        \xdef\@firstcoltopmark{\the\toks@}%
+        \toks@\expandafter{\splitfirstmark}%
+        \xdef\@firstcolfirstmark{\the\toks@}%
+        \ifx\@firstcolfirstmark\@empty
+            \global\let\@setmarks\relax
+        \else
+          \gdef\@setmarks{%
+              \let\firstmark\@firstcolfirstmark
+              \let\topmark\@firstcoltopmark
+              }%
+        \fi
     \else
-      \setbox\@outputbox \vbox to\textheight{%
-                             \box\hold at viper
-                             \box\@outputbox 
-                             \vss
-                             }%
+        \global\@firstcolumntrue
+        \setbox\@outputbox\vbox{%
+            \hb at xt@\textwidth{%
+                \hb at xt@\columnwidth{\box\@leftcolumn \hss}%
+                \hfil
+                {\normalcolor\vrule \@width\columnseprule}%
+                \hfil
+                \hb at xt@\columnwidth{\box\@outputbox \hss}%
+                }%
+            }%
+        \ifvoid\hold at viper
+        \else
+              \setbox\@outputbox\vbox to\textheight{%
+                  \box\hold at viper
+                  \box\@outputbox
+                  \vss
+                  }%
+        \fi
+        \@combinedblfloats
+        \@setmarks
+        \@outputpage
+        \begingroup
+            \@dblfloatplacement
+            \@startdblcolumn
+            \@whilesw\if at fcolmade \fi
+                {\@outputpage \@startdblcolumn}%
+            \ifvoid\@viper
+            \else
+                \global\setbox\@viper\vbox{%
+                    \vskip-\stripsep
+                    \unvbox\@viper
+                    }%
+                \@viperoutput
+            \fi
+        \endgroup
     \fi
-    \@combinedblfloats
-    \@outputpage
-    \begingroup
-      \@dblfloatplacement
-      \@startdblcolumn
-      \@whilesw\if at fcolmade \fi
-        {\@outputpage
-         \@startdblcolumn}%
-      \ifvoid\@viper
-      \else
-        \global\setbox\@viper\vbox{%
-                   \vskip-\stripsep
-                   \unvbox\@viper
-                   }%
-        \@viperoutput
-      \fi
-    \endgroup
-  \fi
-  }
-%    \end{macrocode}
-% \end{macro}
-%
-%    \begin{macrocode}
-\mathchardef\@Mv=10005
-\newcount\viper at penalty
-%    \end{macrocode}
-%
-% \begin{macro}{\strip}
-%    \begin{macrocode}
+    }
 \def\strip{%
-  \ifinner
-     \@parmoderr\viper at penalty\z@
-  \else
-     \viper at penalty=-\@Mv\relax
-  \fi
-  \global \setbox\@viper\vbox\bgroup%
+    \ifinner
+        \@parmoderr
+        \viper at penalty\z@
+    \else
+        \viper at penalty=-\@Mv
+    \fi
+    \global\setbox\@viper\vbox\bgroup
         \hsize\textwidth
         \@parboxrestore
-        \col at number \@ne
+        \col at number=\@ne
         \vrule height\topskip width\z@ depth\z@
-  }
-%    \end{macrocode}
-% \end{macro}
-%
-%
-% \begin{macro}{\endstrip}
-%    \begin{macrocode}
+    }
 \def\endstrip{%
     \egroup
-    \ifnum\viper at penalty <-\@Mii
-      \penalty -\@Miv
-      \ifvmode
-        \@tempdima\prevdepth    %% saving and restoring \prevdepth added
-        \vbox{}%                %% 26 May 87 to prevent extra vertical
-        \prevdepth\@tempdima   %% space when used in vertical mode
-        \penalty-\@Mv\relax
-      \else
-        \par
-        \penalty-\@Mv\relax
-        \noindent
-      \fi
+    \ifnum\viper at penalty<-\@Mii
+        \penalty-\@Miv
+        \ifvmode
+            \@tempdima\prevdepth
+            \vbox{}%
+            \prevdepth\@tempdima
+            \penalty-\@Mv\relax
+        \else
+            \par
+            \penalty-\@Mv
+            \noindent
+        \fi
     \fi
     }
-%    \end{macrocode}
-% \end{macro}
-%
-%
-% \begin{macro}{\@viperoutput}
-%    \begin{macrocode}
 \gdef\@viperoutput{%
-               \global \setbox\@holdpg \vbox{%
-                      \unvbox\@holdpg
-                      \unvbox\@cclv
-                      \setbox\@tempboxa \lastbox
-                      \unskip
-                                     }%
-               \@pagedp \dp\@holdpg
-               \@pageht \ht\@holdpg
-               \ifvoid\@viper\else
-                   \advance \@pageht \@pagedp
-                   \ifvoid\footins \else
-                     \advance \@pageht \ht\footins
-                     \advance \@pageht \skip\footins
-                     \advance \@pageht \dp\footins
-                   \fi
-                   \ifvbox \@kludgeins
-                     \ifdim \wd\@kludgeins=\z@
-                       \advance \@pageht \ht\@kludgeins
-                     \fi
-                   \fi
-                   \@reinserts
-                   \@addviper
-               \fi
-  }
-%    \end{macrocode}
-% \end{macro}
-%
-%
-% \begin{macro}{\@specialoutput}
-%    \begin{macrocode}
+    \global\setbox\@holdpg\vbox{%
+        \unvbox\@holdpg
+        \unvbox\@cclv
+        \setbox\@tempboxa\lastbox
+        \unskip
+        }%
+    \@pagedp=\dp\@holdpg
+    \@pageht=\ht\@holdpg
+    \ifvoid\@viper
+    \else
+        \advance\@pageht by\@pagedp
+        \ifvoid\footins 
+        \else
+            \advance\@pageht by\ht\footins
+            \advance\@pageht by\skip\footins
+            \advance\@pageht by\dp\footins
+        \fi
+        \ifvbox\@kludgeins
+            \ifdim\wd\@kludgeins=\z@
+                \advance\@pageht by\ht\@kludgeins
+            \fi
+        \fi
+        \@reinserts
+        \@addviper
+    \fi
+    }
 \gdef\@specialoutput{%
-   \ifnum \outputpenalty>-\@Mii
-     \@doclearpage
-   \else
-     \ifnum \outputpenalty<-\@Miii
-       \ifnum \outputpenalty<-\@MM \deadcycles \z@ \fi
-       \ifnum \outputpenalty=-\@Mv
-              \@viperoutput
-               \ifnum \outputpenalty<\z@
-                 \if at nobreak
-                 \else
-                   \addpenalty \interlinepenalty
-                 \fi
-               \fi
-       \else
-              \global \setbox\@holdpg \vbox {\unvbox\@cclv}%
-       \fi
-     \else
-       \global \setbox\@holdpg \vbox{%
-                      \unvbox\@holdpg
-                      \unvbox\@cclv
-                      \setbox\@tempboxa \lastbox
-                      \unskip
-                                     }%
-       \@pagedp \dp\@holdpg
-       \@pageht \ht\@holdpg
-       \unvbox \@holdpg
-       \@next\@currbox\@currlist{%
-         \ifnum \count\@currbox>\z@
-           \advance \@pageht \@pagedp
-           \ifvoid\footins \else
-             \advance \@pageht \ht\footins
-             \advance \@pageht \skip\footins
-             \advance \@pageht \dp\footins
-           \fi
-           \ifvbox \@kludgeins
-             \ifdim \wd\@kludgeins=\z@
-               \advance \@pageht \ht\@kludgeins
-             \fi
-           \fi
-           \@reinserts
-           \@addtocurcol
-         \else
-           \@reinserts
-           \@addmarginpar
-         \fi
-         }\@latexbug
-       \ifnum \outputpenalty<\z@
-         \if at nobreak
-         \else
-           \addpenalty \interlinepenalty
-         \fi
-       \fi
-     \fi
+    \ifnum\outputpenalty>-\@Mii
+        \@doclearpage
+    \else
+        \ifnum\outputpenalty<-\@Miii
+            \ifnum\outputpenalty<-\@MM \deadcycles \z@ \fi
+            \ifnum\outputpenalty=-\@Mv
+                \@viperoutput
+                \ifnum\outputpenalty<\z@
+                    \if at nobreak
+                    \else
+                        \addpenalty \interlinepenalty
+                    \fi
+                \fi
+            \else
+                \global\setbox\@holdpg\vbox{\unvbox\@cclv}%
+            \fi
+        \else
+            \global\setbox\@holdpg\vbox{%
+                \unvbox\@holdpg
+                \unvbox\@cclv
+                \setbox\@tempboxa\lastbox
+                \unskip
+                }%
+            \@pagedp=\dp\@holdpg
+            \@pageht=\ht\@holdpg
+            \unvbox\@holdpg
+            \@next\@currbox\@currlist{%
+                \ifnum\count\@currbox>\z@
+                    \advance \@pageht \@pagedp
+                    \ifvoid\footins
+                    \else
+                        \advance\@pageht by\ht\footins
+                        \advance\@pageht by\skip\footins
+                        \advance\@pageht by\dp\footins
+                    \fi
+                    \ifvbox\@kludgeins
+                        \ifdim\wd\@kludgeins=\z@
+                            \advance\@pageht by\ht\@kludgeins
+                        \fi
+                    \fi
+                    \@reinserts
+                    \@addtocurcol
+                \else
+                    \@reinserts
+                    \@addmarginpar
+                \fi
+                }\@latexbug
+            \ifnum\outputpenalty<\z@
+                \if at nobreak
+                \else
+                    \addpenalty \interlinepenalty
+                \fi
+            \fi
+        \fi
    \fi
   }
-%    \end{macrocode}
-% \end{macro}
-%
-%    \begin{macrocode}
-\@ifundefined{hold at viper}{\newbox\hold at viper}{}
-\newdimen\ht at viper 
-%    \end{macrocode}
-%
-% \begin{macro}{\@addviper}
-%    \begin{macrocode}
-\def \@addviper {%
-   \if at firstcolumn
-     \@insertfalse
-     \@reqcolroom .5\@pageht
-     \ht at viper\@reqcolroom
-     \advance \@reqcolroom \ht\@viper
-     \advance \@reqcolroom \stripsep
-     \ifvoid\hold at viper\@tempdima=\z@\else\@tempdima\ht\hold at viper\fi
-%%
-     \@tempdimb \ht at viper
-     \loop
-     \setbox\v at aaa\copy\@holdpg
-     \setbox\v at ccc\vbox to\@tempdimb{%
-                \vsplit\v at aaa to\@tempdimb\vss\vsplit\v at aaa to\@tempdimb}%
-     \wlog{Extra height:\the\ht\v at aaa\space when \the\@tempdimb}%
-     \ifvoid\v at aaa \else \advance\@tempdimb 1pt \repeat
-     \loop
-     \setbox\v at aaa\copy\@holdpg
-     \setbox\v at ccc\vbox to\@tempdimb{%
-                \vsplit\v at aaa to\@tempdimb\vss}%
-     \wlog{(2)Left:\the\ht\v at ccc\space Right:\the\ht\v at aaa\space Output:\the\@tempdimb}%
-     \ifdim \ht\v at ccc<\ht\v at aaa \@tempdimb \the\ht\v at aaa \repeat
-     \wlog{- LAST -^^JLeft:\the\ht\v at ccc^^JRight:\the\ht\v at aaa^^JOutput:\the\@tempdimb}%
-     \setbox\v at ccc\vbox to\@tempdimb{%
-                \vsplit\@holdpg to\@tempdimb\vss}%
-%%
-     \setbox\@tempboxa \vbox {%
-        \hb at xt@\textwidth {%
-                \hb at xt@\columnwidth {%
-                    \vbox to\ht at viper{\box\v at ccc\vss} \hss}%
-                    \hfil
-                    \vrule \@width\columnseprule
-                    \hfil
-                    \hb at xt@\columnwidth {%
-                    \vbox to\ht at viper{\box\@holdpg\vss} \hss}%
-                          }%
-                       }%
-     \ifvoid\hold at viper
-        \global\setbox\hold at viper \vbox {%
-                \unvbox\@tempboxa
-                \penalty\interlinepenalty
-                \vskip\stripsep
-                \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
-                \outputpenalty \z@
+\def\@addviper{%
+    \@insertfalse
+    \def\var@@thecol at num{2}%
+    \if at firstcolumn
+        \def\var@@thecol at num{1}%
+        \@reqcolroom=.5\@pageht
+        \ht at viper=\@reqcolroom
+        \advance\@reqcolroom by\ht\@viper
+        \advance\@reqcolroom by\stripsep
+    \else
+        \@reqcolroom=\@colht
+        \advance\@reqcolroom by\@pageht
+        \ht at viper.5\@reqcolroom
+        \@reqcolroom=\ht at viper
+        \advance\@reqcolroom by\ht\@viper
+        \advance\@reqcolroom by\stripsep
+        \global\setbox\@holdpg\vbox{%
+            \setbox\cuted@@tempbox at a\vbox{%
+                \aftergroup\unvbox
+                \unvcopy\@leftcolumn
+                \unskip\unkern\unpenalty
+                \setbox\@tempboxa\lastbox
+                \ifdim\dimexpr\ht\@tempboxa+\wd\@tempboxa+\dp\@tempboxa>\z@
+                    %% keeps lastbox
+                    \aftergroup\@leftcolumn
+                \else
+                    %% removes lastbox
+                    \aftergroup\cuted@@tempbox at a
+                \fi
+                }%
+            \unskip\unkern\unpenalty
+            \on at stripcols@break
+            \the\At at ViperColsBreak
+            \unvbox\@holdpg
+            }%
+        \global\At at ViperColsBreak{}%
+        \ht at viper=.5\ht\@holdpg
+        \ifdim\ht at viper>\@colht
+            \ht at viper=\@colht
+        \fi
+    \fi
+    %%
+    %% calculations for breaking
+    %%
+    \ifvoid\hold at viper
+        \ht at hold@viper=\z@
+    \else
+        \ht at hold@viper=\ht\hold at viper
+    \fi
+    \cuted@@tempdim at b\ht at viper
+    \set at split@topskip at to\topskip
+    \loop
+        \xdef\saved at tempdimb{\the\cuted@@tempdim at b}%
+        \setbox\cuted@@varbox at a\copy\@holdpg
+        \setbox\cuted@@tempbox at a\vsplit\cuted@@varbox at a to\cuted@@tempdim at b
+        %% set leftcolumn boxes
+        \setbox\cuted@@tempbox at c\vbox{\unvbox\cuted@@tempbox at a}%
+        \setbox\cuted@@tempbox at a\vbox to\cuted@@tempdim at b{\unvcopy\cuted@@tempbox at c}%
+        \xdef\var@@leftcolumn at badness{\the\badness}%
+        %% set rightcolumn boxes
+        \setbox\cuted@@varbox at c\vbox{\unvbox\cuted@@varbox at a}%
+        \setbox\cuted@@varbox at a\vbox to\cuted@@tempdim at b{\unvcopy\cuted@@varbox at c}%
+        \xdef\var@@rightcolumn at badness{\the\badness}%
+        %% analyzing split goodness
+        \cuted@@tempdim at spread=\ht\cuted@@tempbox at c
+        \advance\cuted@@tempdim at spread by\dp\cuted@@tempbox at c
+        \advance\cuted@@tempdim at spread by-\ht\cuted@@varbox at c
+        \advance\cuted@@tempdim at spread by-\dp\cuted@@varbox at c
+        \cuted@@wlog at debug{CUTED [-----]%
+              ^^JLeft: \the\ht\cuted@@tempbox at c
+              +\the\dp\cuted@@tempbox at c\space/\var@@leftcolumn at badness
+              ^^JRight: \the\ht\cuted@@varbox at c
+              +\the\dp\cuted@@varbox at c\space/\var@@rightcolumn at badness
+              ^^JSplit: \the\cuted@@tempdim at b
+              ^^JExtra height: \the\cuted@@tempdim at spread
+             }%
+        \ifnum\var@@leftcolumn at badness<\cuted@@column at badness
+            \ifnum\var@@rightcolumn at badness<\cuted@@column at badness
+                \cuted@@tempdim at spread=\z@
+            \fi
+        \fi
+        \ifdim\cuted@@tempdim at spread<\z@
+            \if at left@column at spread
+                \if at right@column at shrink
+                    \ifdim\dimexpr\cuted@@tempdim at spread+\pageshrink>\z@
+                        \cuted@@tempdim at a=\dimexpr\ht\cuted@@tempbox at c-0.5\cuted@@tempdim at spread\relax
+                    \else
+                        \cuted@@tempdim at a=-\dimexpr\cuted@@tempdim at spread+.5\pageshrink\relax
+                    \fi
+                    \setbox\cuted@@varbox at a\vbox to\cuted@@tempdim at a{\unvcopy\cuted@@tempbox at c}%
+                    \ifnum\badness<\cuted@@column at badness
+                        \cuted@@tempdim at b=\cuted@@tempdim at a
+                        \cuted@@tempdim at spread=\z@
+                    \fi
+                    \cuted@@wlog at debug{CUTED [leftcolumn badness]: \number\badness\space on \the\cuted@@tempdim at a}%
+                    \setbox\cuted@@varbox at a\vbox to\cuted@@tempdim at a{\unvcopy\cuted@@varbox at c}%
+                    \cuted@@wlog at debug{CUTED [rightcolumn badness]: \number\badness\space on \the\cuted@@tempdim at a}%
+                \else
+                    \setbox\cuted@@varbox at a\vbox to\ht\cuted@@varbox at c{%
+                        \unvcopy\cuted@@tempbox at c
                         }%
-     \else
-        \global\setbox\hold at viper \vbox {%
-                \unvbox\hold at viper
-                \unvbox\@tempboxa
-                \penalty\interlinepenalty
-                \vskip\stripsep
-                \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
-                \outputpenalty \z@
+                    \ifnum\badness<\cuted@@column at badness
+                        \@tempdimb=\ht\cuted@@varbox at c
+                        \cuted@@tempdim at spread=\z@
+                    \fi
+                    \cuted@@wlog at debug{CUTED [leftcolumn badness]: \number\badness on \the\ht\cuted@@varbox at c}%
+                    \setbox\cuted@@varbox at a\vbox to\ht\cuted@@varbox at c{%
+                        \unvcopy\cuted@@varbox at c
                         }%
-     \fi
-     \ifdim \@colroom>\@reqcolroom
-        \global\setbox\hold at viper \vbox {%
-                \unvbox\hold at viper
-                \box\@viper
-                \penalty\interlinepenalty
-                \vskip\stripsep
-                \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
-                \outputpenalty \z@
-                        }%
-        \@inserttrue
-        \advance\@tempdima by-\ht\hold at viper
-        \global \advance \@colht \@tempdima
-        \ifdim \@colht<2.5\baselineskip
-           \@latex at warning@no at line {Optional argument of \noexpand\twocolumn
-                too tall on page \thepage (1 stulpelis)}%
-           \@emptycol
-           \if at firstcolumn
-           \else
-             \@emptycol
-           \fi
-           \global\@lastvipertrue
+                    \cuted@@wlog at debug{CUTED [rightcolumn badness]: \number\badness on \the\ht\cuted@@varbox at c}%
+                \fi
+            \else
+                \if at right@column at shrink
+                    \ifdim\dimexpr\cuted@@tempdim at spread+\pageshrink<\z@
+                    \else
+                        \cuted@@tempdim at b=\ht\cuted@@tempbox at c
+                        \cuted@@tempdim at spread=\z@
+                    \fi
+                \fi
+            \fi
         \else
-           \global \vsize \@colht
-           \global \@colroom \@colht
-           \check at floats
-           \ifdim\@tempdima>\z@
-                   \global\advance\@colroom by-\@tempdima
-           \fi
-           \ifdim\@colroom<\z@
-                   \global\@colroom 1pt
-                   \ifdim\@tempdima>\@colht
-                      \@latex at warning@no at line {TOP ir/ar BOT FLOAT's
-                                 netelpa lape \thepage (1 stulpelis)}%
-                   \fi
-                   \@emptycol
-                   \if at firstcolumn
-                   \else
-                     \@emptycol
-                   \fi
-                   \global\@lastvipertrue
-           \fi
+            \ifdim\cuted@@tempdim at spread>\z@
+                \ifdim\dimexpr\@tempdimb+\p@\relax>\@colht
+                    \cuted@@tempdim at b=\@colht
+                    \cuted@@tempdim at spread=\z@
+                \fi
+            \fi
         \fi
-     \fi
-   \else
-     \@insertfalse
-     \@reqcolroom\@colht
-     \advance\@reqcolroom \@pageht
-     \ht at viper.5\@reqcolroom
-     \@reqcolroom\ht at viper
-     \advance \@reqcolroom \ht\@viper
-     \advance \@reqcolroom \stripsep
-      \if at flushend@auto at baselineskip
-        \setbox\@tempboxa\vbox{\unvcopy\@leftcolumn
-          \global\lastskip at d\lastskip
-          \global\lastskip at b\lastskip
-          \loop
-            \global\lastskip at a\lastskip at b
-            \unskip\unpenalty
-            \global\lastskip at b\lastskip
-            \global\advance\lastskip at d by\lastskip
-          \ifdim\lastskip at b=-\lastskip at a
-            \global\advance\lastskip at d by-\lastskip
-          \else
-          \repeat
-          \ifdim\lastskip at b=-\lastskip at a
-            \ifdim\lastskip at b=\z@
-              \setbox\lastbox at a\lastbox
-              \global\advance\lastskip at d by\ht\lastbox at a
-              \global\advance\lastskip at d by\lastskip
-              \unskip\unpenalty
-              \setbox\lastbox at a\lastbox
-              \global\advance\lastskip at d by\dp\lastbox at a
+    \ifdim\cuted@@tempdim at spread<\z@
+        \advance\cuted@@tempdim at b 1\p@
+    \repeat
+    \wlog{CUTED [- LAST -]%
+          ^^JExtra skip:\the\cuted@@tempdim at spread
+          ^^JLeft:\the\ht\cuted@@tempbox at c/\the\dp\cuted@@tempbox at c
+          ^^JRight:\the\ht\cuted@@varbox at c/\the\dp\cuted@@varbox at c
+          ^^JSplit: \saved at tempdimb
+          ^^JOutput:\the\cuted@@tempdim at b
+          ^^JPageshrink: \the\pageshrink
+          ^^JPagestretch: \the\pagestretch
+          ^^J at colht:\the\@colht
+          }%
+    %%
+    %% final construction of the cuted page above strip
+    %%
+    \setbox\cuted@@tempbox at c\vsplit\@holdpg to\saved at tempdimb
+    \setbox\cuted@@tempbox at a\vbox to\cuted@@tempdim at b{%
+        \cuted@@tempdim at a=\dimexpr
+            \cuted@@tempdim at b-\ht\cuted@@tempbox at c
+            \relax
+        \cuted@@tempdim at spread=\dp\cuted@@tempbox at c
+        \unvbox\cuted@@tempbox at c
+        \ifdim\cuted@@tempdim at spread>\dp\strutbox
+        \else
+            \vskip-\cuted@@tempdim at spread
+        \fi
+        \prevdepth\z@
+        \hrule\@height\cuted@@page at rule width\textwidth
+        \vskip-\cuted@@page at rule
+        \ifdim\cuted@@tempdim at a>\z@
+            \if at left@column at spread
             \else
-              \global\lastskip at d\lastskip
-              \global\advance\lastskip at d by\topskip
+                \vss
             \fi
-          \fi
-          \global\advance\lastskip at d by-\topskip
-          }%
-       \ifdim\ht\@holdpg>\@colht
-         \global\setbox\@holdpg\vbox{\unvbox\@leftcolumn\unskip\unpenalty
-           \par\eject
-           \vbox to \@colht{\unvbox\@holdpg\unskip}%
-           }%
-       \else
-         \global\setbox\@holdpg\vbox{%
-           \unvbox\@leftcolumn\unskip\unpenalty
-           \vskip\lastskip at d
-           \the\At at ViperColsBreak
-           \unvbox\@holdpg
-           \unskip
-           }%
-       \fi
-     \else
-       \global\setbox\@holdpg\vbox{%
-                \unvbox\@leftcolumn
-                \setbox\@tempboxa\lastbox
-                \on at stripcols@break
-                \the\At at ViperColsBreak
-                \unvbox\@holdpg
-                }%
-     \fi
-     \global\At at ViperColsBreak{}%
-     \ht at viper .5\ht\@holdpg
-     \ifdim \ht at viper>\@colht
-        \ht at viper \@colht
-     \fi
-     \ifvoid\hold at viper\@tempdima=\z@\else\@tempdima\ht\hold at viper\fi
-%    \end{macrocode}
-%%
-%    \begin{macrocode}
-     \@tempdimb \ht at viper
-     \loop
-       \setbox\v at aaa\copy\@holdpg
-       \setbox\v at ccc\vbox to\@tempdimb{%
-                \vsplit\v at aaa to\@tempdimb
+        \else
+            \ifdim\cuted@@tempdim at a<\z@
+                \if at left@column at shrink
+                \else
+                    \vss
+                \fi
+            \fi
+        \fi
+        }%
+    \wlog{CUTED [output]: \the\cuted@@tempdim at b
+          ^^JCUTED [leftcolumn badness]: \number\badness
+         }%
+    \setbox\cuted@@varbox at a\vbox to\cuted@@tempdim at b{%
+        \cuted@@tempdim at a=\dimexpr
+            \cuted@@tempdim at b-\ht\@holdpg
+            \relax
+        \unvbox\@holdpg
+        \ifdim\cuted@@tempdim at a>\z@
+            \if at right@column at spread
+            \else
                 \vss
-                \vsplit\v at aaa to\@tempdimb
+            \fi
+        \else
+            \ifdim\cuted@@tempdim at a<\z@
+                \if at right@column at shrink
+                \else
+                    \vss
+                \fi
+            \fi
+        \fi
+        }%
+    \wlog{CUTED [rightcolumn badness]: \number\badness}%
+    \setbox\cuted@@tempbox at var\vbox{%
+        \hb at xt@\textwidth{%
+            \hb at xt@\columnwidth{%
+                \vbox to\ht at viper{\box\cuted@@tempbox at a\vss}%
+                \hss
                 }%
-       \wlog{Extra height:\the\ht\v at aaa\space when \the\@tempdimb}%
-     \ifvoid\v at aaa 
-     \else 
-       \advance\@tempdimb 1\p@ 
-     \repeat
-     \loop
-       \setbox\v at aaa\copy\@holdpg
-       \setbox\v at ccc\vbox to\@tempdimb{\vsplit\v at aaa to\@tempdimb\vss}%
-       \wlog{(2)Left:\the\ht\v at ccc\space
-               Right:\the\ht\v at aaa\space 
-              Output:\the\@tempdimb
-            }%
-     \ifdim\ht\v at ccc<\ht\v at aaa 
-       \@tempdimb \the\ht\v at aaa 
-     \repeat
-     \wlog{- LAST -^^JLeft:\the\ht\v at ccc
-                  ^^JRight:\the\ht\v at aaa
-                 ^^JOutput:\the\@tempdimb
-          }%
-     \setbox\v at ccc\vbox to\@tempdimb{\vsplit\@holdpg to\@tempdimb\vss}%
-%    \end{macrocode}
-%
-%    \begin{macrocode}
-     \setbox\@tempboxa\vbox{%
-        \hb at xt@\textwidth {%
-            \hb at xt@\columnwidth{\vbox to\ht at viper{\box\v at ccc\vss} \hss}%
             \hfil
-            \vrule \@width\columnseprule
+            {\normalcolor\vrule \@width\columnseprule}%
             \hfil
-            \hb at xt@\columnwidth {\vbox to\ht at viper{\box\@holdpg\vss} \hss}%
+            \hb at xt@\columnwidth{%
+                \vbox to\ht at viper{\box\cuted@@varbox at a\vss}%
+                \hss
+                }%
             }%
         }%
-     \ifvoid\hold at viper
-        \global\setbox\hold at viper \vbox {%
-                \unvbox\@tempboxa
-                \penalty\interlinepenalty
-                \vskip\stripsep
-                \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
-                \outputpenalty \z@
-                        }%
-     \else
-        \global\setbox\hold at viper \vbox {%
-                \unvbox\hold at viper       
-                \unvbox\@tempboxa
-                \penalty\interlinepenalty
-                \vskip\stripsep
-                \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
-                \outputpenalty \z@
-                        }%
-     \fi
-     \ifdim \@colht>\@reqcolroom
-        \global\setbox\hold at viper \vbox {%
-                \unvbox\hold at viper
-                \box\@viper
-                \penalty\interlinepenalty
-                \vskip\stripsep
-                \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
-                \outputpenalty \z@
-                        }%
+    %%
+    %% finalize cuted page
+    %%
+    \ifvoid\hold at viper
+        \global\setbox\hold at viper\vbox{%
+            \unvbox\cuted@@tempbox at var
+            \penalty\interlinepenalty
+            \vskip\stripsep
+            \the\preCutedStrip
+            \ifnum\outputpenalty<-\@Mii
+                \vskip -\parskip
+            \fi
+            \outputpenalty\z@
+            }%
+    \else
+        \global\setbox\hold at viper\vbox{%
+             \unvbox\hold at viper
+             \cuted@@tempbox at var
+             \penalty\interlinepenalty
+             \vskip\stripsep
+             \the\preCutedStrip
+             \ifnum\outputpenalty<-\@Mii
+                 \vskip -\parskip
+             \fi
+             \outputpenalty\z@
+             }%
+    \fi
+    \ifdim\@colht>\@reqcolroom
+        \global\setbox\hold at viper\vbox{%
+             \unvbox\hold at viper
+             \box\@viper
+             \penalty\interlinepenalty
+             \the\postCutedStrip
+             \vskip\stripsep
+             \ifnum\outputpenalty<-\@Mii
+                 \vskip -\parskip
+             \fi
+             \outputpenalty\z@
+             }%
         \@inserttrue
         \global\@firstcolumntrue
-        \advance\@tempdima by-\ht\hold at viper
-        \global \advance \@colht \@tempdima
-        \ifdim \@colht<2.5\baselineskip
+        \advance\ht at hold@viper by-\ht\hold at viper
+        \global\advance\@colht by\ht at hold@viper
+        \ifdim\@colht<2.5\baselineskip
             \@latex at warning@no at line {Optional argument of \noexpand\twocolumn
-                                     too tall on page \thepage (2 stulpelis)}%
+                                     too tall on page \thepage (\var@@thecol at num column)}%
             \@emptycol
             \if at firstcolumn
             \else
@@ -636,17 +741,17 @@
             \fi
             \global\@lastvipertrue
         \else
-            \global \vsize \@colht
-            \global \@colroom \@colht
-            \check at floats
-            \ifdim\@tempdima>\z@
-                \global\advance\@colroom by-\@tempdima
+            \global\vsize\@colht
+            \global\@colroom\@colht
+            \check at floats\cuted@@tempdim at a
+            \ifdim\cuted@@tempdim at a>\z@
+                \global\advance\@colroom by-\cuted@@tempdim at a
             \fi
             \ifdim\@colroom<\z@
-                \global\@colroom 1pt
-                \ifdim\@tempdima>\@colht
-                \@latex at warning@no at line {TOP ir/ar BOT FLOAT's
-                                 netelpa lape \thepage (2 stulpelis)}%
+                \global\@colroom1\p@
+                \ifdim\cuted@@tempdim at a>\@colht
+                    \@latex at warning@no at line{TOP and/or BOT FLOAT's
+                        to large on \thepage (\var@@thecol at num column)}%
                 \fi
                 \@emptycol
                 \if at firstcolumn
@@ -656,96 +761,82 @@
                 \global\@lastvipertrue
             \fi
         \fi
-      \fi
-  \fi
-  \if at insert
-  \else
-      \advance\@tempdima by-\ht\hold at viper
-      \global \advance \@colht \@tempdima
-      \global\setbox\hold at viper \vbox {%
-                                       \unvbox\hold at viper
-                                       \csname viper at top@hook\endcsname
-                                       \vsplit\@viper to \@colht
-                                       \vss
-                                      }%
-      \vbox{}%
-      \global\@firstcolumnfalse
-      \newpage
-  \fi
-  }
-%    \end{macrocode}
-% \end{macro}
-%
-%
-% \begin{macro}{\check at floats}
-%    \begin{macrocode}
-
-\def\check at floats{%
-    \global\@tempdima\z@
-    \let\@elt\ht at comflelt
-    \ifx\@toplist\@empty \else \@toplist \fi
-    \ifx\@botlist\@empty \else \@botlist \fi
+    \fi
+    \if at insert
+    \else
+        \advance\ht at hold@viper by-\ht\hold at viper
+        \global\advance\@colht by\ht at hold@viper
+        \global\setbox\hold at viper\vbox{%
+            \unvbox\hold at viper
+            \set at split@topskip at to{\z@ plus2\p@}%
+            \vsplit\@viper to\@colht
+            \vss
+            }%
+        \vbox{}%
+        \global\@firstcolumnfalse
+        \newpage
+    \fi
     }
-%    \end{macrocode}
-% \end{macro}
-%
-%
-% \begin{macro}{\ht at comflelt}
-%    \begin{macrocode}
-\def\ht at comflelt#1{%
-  \setbox\@tempboxa\vbox{\copy #1\vskip\floatsep}%
-  \global\advance\@tempdima  by\ht\@tempboxa
-  }
-%    \end{macrocode}
-% \end{macro}
-% \begin{macro}{output}
-%    \begin{macrocode}
-\output {%
-  \let \par \@@par
-  \ifnum \outputpenalty<-\@M
-    \@specialoutput
-  \else
-    \@makecol
-    \@opcol
-    \@startcolumn
-    \@whilesw \if at fcolmade \fi
-      {%
-       \@opcol\@startcolumn}%
-  \fi
-  \ifnum \outputpenalty>-\@Miv
-    \ifdim \@colroom<1.5\baselineskip
-      \ifdim \@colroom<\textheight
-        \@latex at warning@no at line {Text page \thepage\space
-                               contains only floats}%
-        \if at lastviper\else\@emptycol\fi
-        \if at twocolumn
-          \if at firstcolumn
-          \else
-            \@emptycol
-          \fi
-        \fi
-        \global\@lastviperfalse
-      \else
-        \global \vsize \@colroom
-      \fi
+\def\check at floats#1{%
+    \begingroup
+        \global#1\z@
+        \def\@elt##1{%
+            \setbox\@tempboxa\vbox{\copy #1\vskip\floatsep}%
+            \global\advance##1 by\ht\@tempboxa
+            }%
+        \ifx\@toplist\@empty \else \@toplist \fi
+        \ifx\@botlist\@empty \else \@botlist \fi
+    \endgroup
+    }
+\output{%
+    \let\par\@@par
+    \ifnum\outputpenalty<-\@M
+        \@specialoutput
     \else
-      \global \vsize \@colroom
+        \@makecol
+        \@opcol
+        \@startcolumn
+        \@whilesw\if at fcolmade\fi
+            {\@opcol \@startcolumn}%
     \fi
-  \else
-    \ifnum\outputpenalty<-100005
-      \global \vsize \maxdimen
+    \ifnum\outputpenalty>-\@Miv
+        \ifdim\@colroom<1.5\baselineskip
+            \ifdim\@colroom<\textheight
+                \@latex at warning@no at line{%
+                    Text page \thepage\space contains only floats%
+                    }%
+                \if at lastviper
+                \else
+                    \@emptycol
+                \fi
+                \if at twocolumn
+                    \if at firstcolumn
+                    \else
+                        \@emptycol
+                    \fi
+                \fi
+                \global\@lastviperfalse
+            \else
+                \global\vsize\@colroom
+            \fi
+        \else
+            \global\vsize\@colroom
+        \fi
     \else
-      \global \vsize \@colroom
+        \ifnum\outputpenalty<-\@Mv
+            \global\vsize\maxdimen
+        \else
+            \global\vsize\@colroom
+        \fi
     \fi
-  \fi
-  }
+    }
+\ifcuted@@debug
+    \xdef\cuted@@page at rule{.4\p@}
+\else
+    \xdef\cuted@@page at rule{\z@}
+\fi
 %    \end{macrocode}
-% \end{macro}
 %
-%    \begin{macrocode} 
-%\endinput 
-%    \end{macrocode} 
-%
 % \iffalse
 %</package>
 % \fi

Modified: trunk/Master/texmf-dist/source/latex/sttools/floatpag.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/sttools/floatpag.dtx	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/source/latex/sttools/floatpag.dtx	2021-10-11 20:25:22 UTC (rev 60736)
@@ -1,6 +1,7 @@
-% \iffalse meta-comment
+% \iffalse meta-comment/*%    \end{macrocode}*/
 %
 % Copyright (C) 1999-2012 by Vytas Statulevi\v{c}ius <vytas at vtex.lt>
+% Copyright (C) 2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
 % ---------------------------------------------------------------------------
 % This work may be distributed and/or modified under the
 % conditions of the LaTeX Project Public License, either version 1.3
@@ -20,12 +21,35 @@
 % \fi
 %
 % \iffalse
+%<*internal>
+\begingroup
+%</internal>
+%<*batchfile>
+\input docstrip.tex
+\keepsilent\askforoverwritefalse
+\preamble
+%%
+%% This is file `floatpag.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% floatpag.dtx  (with options: `package')
+%% 
+\endpreamble
+\generate{\file{floatpag.sty}{\from{floatpag.dtx}{package}}}
+%</batchfile>
+%<batchfile>\endbatchfile
+%<*internal>
+\generate{\file{floatpag.ins}{\from{floatpag.dtx}{batchfile}}}
+\endgroup
+%</internal>
 %<*driver>
 \ProvidesFile{floatpag.dtx}
 %</driver>
 %% Copyright (C) 1999-2012 by Vytas Statulevi\v{c}ius <vytas at vtex.lt>
-%% VTeX Ltd., Akademijos 4, Vilnius, Lithuania
-%% http://www.vtex.lt/tex/download/macros/
+%% Copyright (C) 2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+%% UAB VTeX, Mokslininkų 2A, LT-08412 Vilnius, Lithuania
 %% --------------------------------------------------------------------------
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3
@@ -46,12 +70,13 @@
 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
 %<package>\ProvidesPackage{floatpag}
 %<*package>
-    [2012/05/29 v1.1 Different pagestyles on float pages]
+    [2021/10/04 v2.0 Different pagestyles on float pages]
+
 %</package>
 %
 %<*driver>
 \documentclass{ltxdoc}
-\usepackage{floatpag}[2012/05/29]
+\usepackage{floatpag}[2021/10/04]
 \EnableCrossrefs
 \CodelineIndex
 \RecordChanges
@@ -63,7 +88,7 @@
 %</driver>
 % \fi
 %
-% \CheckSum{304}
+% \CheckSum{216}
 %
 % \CharacterTable
 %  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
@@ -83,6 +108,7 @@
 %
 %
 % \changes{v1.1}{2012/05/29}{Converted to DTX file}
+% \changes{v2.0}{2021/10/04}{Removed latex209 compatibility; added rotated dblfloat support}
 %
 % \DoNotIndex{\newcommand,\newenvironment}
 %
@@ -126,8 +152,8 @@
 % |\@xfloat|, |\@vtryfc|.
 %
 % \medskip
-% The following command from the rotating.sty  was redefined:
-% |\@xrotfloat|.
+% The following commands from the rotating.sty  was redefined:
+% |\@xrotfloat|, |\@rotxdblfloat|.
 %
 % \StopEventually{}
 %
@@ -137,13 +163,6 @@
 %<*package>
 % \fi
 %
-%    \begin{macrocode}
-\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{floatpag}
-             [1999/04/29
-                 FLOAT PAGESTYLE]
-%    \end{macrocode}
-%
 % \begin{macro}{\floatpagestyle}
 %    \begin{macrocode}
 \def\floatpagestyle#1{\gdef\at at float@page{\thispagestyle{#1}}}
@@ -153,10 +172,7 @@
 %
 % \begin{macro}{\rotfloatpagestyle}
 %    \begin{macrocode}
-\def\rotfloatpagestyle#1{%
-  \gdef\@r at f@pagestyle{#1}%
-  \gdef\at at rotfloat@page{\thispagestyle{#1}}%
-  }
+\def\rotfloatpagestyle#1{\gdef\@r at f@pagestyle{#1}}
 %    \end{macrocode}
 % \end{macro}
 %
@@ -169,8 +185,7 @@
 %
 %    \begin{macrocode}
 \def\thisfloatpagestyle#1{%
-  \expandafter\expandafter\expandafter\gdef\expandafter
-    \csname\number\@currbox @float\endcsname{\thispagestyle{#1}}\relax
+  \global\@namedef{\number\@currbox @float}{\thispagestyle{#1}}\relax
   }
 %    \end{macrocode}
 % \end{macro}
@@ -215,28 +230,27 @@
              \else
                \advance \@tempcnta \@ne
              \fi
-           \fi
-           \if \reserved at a t%
+           \else\if \reserved at a t%
              \@setfpsbit \tw@
-           \fi
-           \if \reserved at a b%
+           \else\if \reserved at a b%
              \@setfpsbit 4%
-           \fi
-           \if \reserved at a p%
+           \else\if \reserved at a p%
              \@setfpsbit 8%
-           \fi
-           \if \reserved at a !%
+           \else\if \reserved at a !%
              \ifnum \@tempcnta>15
                \advance\@tempcnta -\sixt@@n\relax
              \fi
-           \fi
+           \else
+             \@latex at error{Unknown float option `\reserved at a'}%
+             {Option `\reserved at a' ignored and `p' used.}%
+             \@setfpsbit 8%
+           \fi\fi\fi\fi\fi
            }%
        \@tempcntb \csname ftype@\@captype \endcsname
        \multiply \@tempcntb \@xxxii
        \advance \@tempcnta \@tempcntb
        \global \count\@currbox \@tempcnta
-       \expandafter\expandafter\expandafter\gdef\expandafter
-         \csname\number\@currbox @float\endcsname{\at at float@page}\relax
+       \global\@namedef{\number\@currbox @float}{\at at float@page}\relax
        }%
     \@fltovf
   \fi
@@ -252,11 +266,11 @@
 % \end{macro}
 %
 %
-% \begin{macro}{\e at xrotfloat}
+% \begin{macro}{\floatpag@@xrotfloat}
 %
-%% 2e rotating.sty v. 2.10: 
+% rotating.sty v. $>$2.10: 
 %    \begin{macrocode}
-\def\e at xrotfloat#1[#2]{%
+\def\floatpag@@xrotfloat#1[#2]{%
   \@float{#1}[#2]%
   \thisfloatpagestyle{\@r at f@pagestyle}%
   \begin{lrbox}\rot at float@box
@@ -266,49 +280,27 @@
 % \end{macro}
 %
 %
-% \begin{macro}{\n at xrotfloat}
-%% 2.09 rotating.sty v. 1.6
+% \begin{macro}{\floatpag@@rotxdblfloat}
+%
+% rotating.sty v. $>$2.10: 
 %    \begin{macrocode}
-\def\n at xrotfloat#1[#2]{%
-  \ifhmode 
-    \@bsphack
-    \@floatpenalty -\@Mii
-  \else
-   \@floatpenalty-\@Miii
-  \fi
-  \def\@captype{#1}%
-  \ifinner
-    \@parmoderr\@floatpenalty\z@
-  \else
-    \@next\@currbox\@freelist{\@tempcnta\csname ftype@#1\endcsname
-      \multiply\@tempcnta\@xxxii\advance\@tempcnta\sixt@@n
-      \@tfor \@tempa :=#2\do{%
-        \if\@tempa h\advance\@tempcnta \@ne\fi
-        \if\@tempa t\advance\@tempcnta \tw@\fi
-        \if\@tempa b\advance\@tempcnta 4\relax\fi
-        \if\@tempa p\advance\@tempcnta 8\relax\fi
-        }%
-      \global\count\@currbox\@tempcnta
-      }%
-    \@fltovf
-  \fi
-  \expandafter\expandafter\expandafter\gdef\expandafter
-    \csname\number\@currbox @float\endcsname{\at at rotfloat@page}\relax
-  \global\setbox\@currbox\vbox\bgroup
-    \hsize\textheight 
-    \@parboxrestore
-  }
+\def\floatpag@@rotxdblfloat#1[#2]{%
+  \@float{#1}[#2]%
+  \thisfloatpagestyle{\@r at f@pagestyle}%
+  \hsize\textwidth\linewidth\textwidth
+  \begin{lrbox}\rot at float@box
+  \begin{minipage}\textheight
+}
 %    \end{macrocode}
+% \end{macro}
 %
-%% Check for |rotating| version: 2e ar 209:
-%% 1999.02.08 To be sure check at begin document.
+%
 %    \begin{macrocode}
 \AtBeginDocument{%
-\@ifpackageloaded{rotating}%
-{\let\@xrotfloat\e at xrotfloat\let\n at xrotfloat\relax}%
-{\let\@xrotfloat\n at xrotfloat\let\e at xrotfloat\relax}}%
+  \let\@xrotfloat\floatpag@@xrotfloat
+  \let\@rotxdblfloat\floatpag@@rotxdblfloat
+  }%
 %    \end{macrocode}
-% \end{macro}
 %
 %
 % \begin{macro}{\spec at float}
@@ -315,8 +307,9 @@
 %
 %% "Hook" in the output procedure.
 %    \begin{macrocode}
-\def\spec at float#1{\expandafter\csname\number#1 at float\endcsname
-  \expandafter\expandafter\expandafter\gdef\expandafter\csname\number#1 at float\endcsname{}%
+\def\spec at float#1{%
+  \@nameuse{\number#1 at float}%
+  \global\@namedef{\number#1 at float}{}%
   }
 %    \end{macrocode}
 % \end{macro}

Modified: trunk/Master/texmf-dist/source/latex/sttools/flushend.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/sttools/flushend.dtx	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/source/latex/sttools/flushend.dtx	2021-10-11 20:25:22 UTC (rev 60736)
@@ -1,6 +1,6 @@
 % \iffalse meta-comment/*%    \end{macrocode}*/
 %
-% Copyright (C) 2020 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+% Copyright (C) 2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
 % ---------------------------------------------------------------------------
 % This work may be distributed and/or modified under the
 % conditions of the LaTeX Project Public License, either version 1.3
@@ -47,8 +47,8 @@
 \ProvidesFile{flushend.dtx}
 %</driver>
 %<*package>
-%% Copyright (C) 1997-2020 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
-%% VTeX Ltd., Mokslinink\k{u} 2a, Vilnius, Lithuania
+%% Copyright (C) 1997-2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+%% UAB VTeX, Mokslininkų 2A, LT-08412 Vilnius, Lithuania
 %% --------------------------------------------------------------------------
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3
@@ -64,16 +64,19 @@
 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
 %<package>\ProvidesPackage{flushend}
 %<*package>
-    [2020/10/16 v3.5 Balancing columns in twocolumn mode]
+    [2021/10/04 v4.0 Balancing columns in twocolumn mode]
 %</package>
 %
 %<*driver>
 \documentclass{ltxdoc}
-\usepackage{flushend}[2020/10/16]
+\usepackage{flushend}[2021/10/04]
+\usepackage{geometry}
+\geometry{a4paper}
+\setlength\marginparwidth{5pc}
 \EnableCrossrefs
 \CodelineIndex
 %%\RecordChanges
-%\OnlyDescription
+\OnlyDescription
 \begin{document}
   \DocInput{flushend.dtx}
   %%\PrintChanges
@@ -117,6 +120,7 @@
 % \changes{v3.3}{2017/03/27}{bugfix for get@@footnoterule@@box; options for some checks on/off}
 % \changes{v3.4}{2020/10/14}{bugfix development and test}
 % \changes{v3.5}{2020/10/16}{bugfix version: modern with noautobase}
+% \changes{v4.0}{2021/10/04}{another rewrite with new balance algorithm and options}
 %
 % \DoNotIndex{\newcommand,\newenvironment}
 %
@@ -132,9 +136,12 @@
 %
 % The package is used to balance columns on any page in twocolumn
 % mode. By default it is switched on at the end of document. It is
-% expected to work with footnotes, top floats and column break
-% before one line section title.
+% expected to work with leftcolumn footnotes (option checkfootnote)
+% and rightcolumn top floats (option checkfloat).
 %
+% To compare with the previous version the package is completely rewritten
+% with new balancing algorithm and new options, removed dependency on other packages.
+%
 % \section{Usage}
 %
 % Just load the package to balance the last page: that's all.
@@ -142,118 +149,119 @@
 % \cs{flushcolsend} at that page.
 %
 % \medskip
-% \DescribeMacro{\flushend}
+% \leftline{\textbf{\textit{Available commands}}:}
 %
+% \begin{description}
+%
+% \item[\cs{flushend}]
 % This macro switches on column balancing on the last page. It is used
 % by default.
 %
-% \medskip
-% \DescribeMacro{\raggedend}
-%
+% \item[\cs{raggedend}]
 % This macro switches off column balancing on the last page.
 %
-% \medskip
-% \DescribeMacro{\flushcolsend}
-%
+% \item[\cs{flushcolsend}]
 % This macro switches on column balancing on the current page.
 %
-% \medskip
-% \DescribeMacro{\raggedcolsend}
-%
+% \item[\cs{raggedcolsend}]
 % This macro switches off column balancing on the current page.
 %
-% \medskip
-% \DescribeMacro{\atColsBreak}
-% \marg{tokens}
-%
+% \item[\cs{atColsBreak}\meta{tokens}]
 % Adds \meta{tokens} in place of the original column break (made without balancing).
 %
 % \medskip
 % \textit{Example}: |\atColsBreak{\vskip-2pt}|
 %
-% \medskip
-% \DescribeMacro{\atColsEnd}
-% \marg{tokens}
-%
+% \item[\cs{atColsEnd}\meta{tokens}]
 % Adds \meta{tokens} at the end of right column.
 %
-% \medskip
-% \textit{Example}: |\atColsEnd{\vfil}|.
+% \item[\cs{showcolsendrule}]
+% It can be used just for debugging: adds rule to the bottom of columns.
 %
-% \medskip
-% \DescribeMacro{\showcolsendrule}
+% \end{description}
 %
-% It can be used just for debugging: adds rule to the bottom of columns.
-%
 % \subsection{Package options}
 %
-% \medskip
-% \DescribeMacro{ancient}
-%   It is used to switch on old version of balancing algorithm.
-%   This version is not so accurate or "clever" but quite safe.
+% \begin{description}
+% 
+% \item[\meta{|spread|}]
+%   \texttt{[default]} It enables columns spreading trying to balance.
 %
-% \medskip
-% \DescribeMacro{modern}
-%   [default] It is used to switch on new version of balancing algorithm.
-%   This version has some heuristic guesses for footnotes, floats
-%   and section like head skip. So it is more dangerous in the case
-%   for text misplace or disappear.
+% \item[\meta{|nospread|}]
+%   It disables columns spreading trying to balance.
 %
-% \medskip
-% \DescribeMacro{autobase}
-%   [default] It is used to guess |\baselineskip| value on original columns
-%   break. On failure just use |\atColsBreak{...}|.
+% \item[\meta{|shrink|}]
+%   \texttt{[default]} It enables columns shrinking trying to balance.
 %
-% \medskip
-% \DescribeMacro{noautobase}
-%   It is used to switch off the previous option behaviour.
+% \item[\meta{|noshrink|}]
+%   It disables columns shrinking trying to balance.
 %
 % \medskip
-% \DescribeMacro{spread}
-%   [default] It adds extra glue to the rightcolumn trying to balance.
+%   \textit{Similiar options exist for single column separatly}: 
 %
-% \medskip
-% \DescribeMacro{nospread}
-%   It skips adding extra glue to the last column.
+%   |lspread|, |nolspread|, |lshrink|, |nolshrink| -- for left column  
 %
-% \medskip
-% \DescribeMacro{removelastbox}
-%   [default] It tries to remove an empty box (some more material) from the last column bottom.
+%   |rspread|, |norspread|, |rshrink|, |norshrink| -- for right column  
 %
-% \medskip
-% \DescribeMacro{keeplastbox}
-%   It skips removing anything from the last column. As example it is usefull and can be used
-%   then document ends by reference item and last line of text should be with indend.
+% \item[\meta{|checkfootnote|}]
+%   \texttt{[default]} Adds guess and checking for possible footnote on left column.
 %
-% \medskip
-% \DescribeMacro{checkfootnote}
-%   [default] Adds guess for footnote on left column then modern balancing algorithm is in use.
+% \item[\meta{|nocheckfootnote|}]
+%   Skips guess for possible footnote and ignores any existing one.
 %
-% \medskip
-% \DescribeMacro{nocheckfootnote}
-%   Skips guess for footnote then modern balansing algorithm is in use.
+% \item[\meta{|checkfloat|}]
+%   Adds guess for top float on right column. Any box with height bigger then 5|\topskip|
+%   is considered as float. There are no user interface to change this limit except 
+%   internal macro definition: |\gdef\top@@floatbox at min@default{5\topskip}|
 %
-% \medskip
-% \DescribeMacro{checkfloat}
-%   [default] Adds guess for top float on right column then modern balancing algorithm is in use.
+%   As guess is too brutal, not accurate, and somehow dangerous in case for text misplacement
+%   it is switched off by default.
 %
-% \medskip
-% \DescribeMacro{nocheckfloat}
-%   Skips guess for top float on right column then modern balancing algorithm is in use.
+% \item[\meta{|nocheckfloat|}]
+%   \texttt{[default]} Skips guess for top float on right column.
 %
-% \medskip
-% \DescribeMacro{debug}
+% \item[\meta{|debug|}]
 %   Adds rules to the bottom of columns (just for debugging) and leftcolumn break place.
 %   Adds some additional log info.
 %
-% \medskip
-% \DescribeMacro{nodebug}
-%   [default] Skips putting debuging lines.
+% \item[\meta{|nodebug|}]
+%   \texttt{[default]} Skips putting debuging lines and additional info.
 %
-% \StopEventually{}
+% \end{description}
 %
 % \section{Implementation}
 %
+% Improved balancing (at least it is expected so) is based on using possible spread and shrink
+% in both columns checking constructed columns badness.
+% Hard coded limit for badness is |101|. Available only as internal macro: |\def\flushend@@column at badness{101}|.
+% |\pagediscards| material dimensions are used to restore original vertical skip at original columns break.  
+%
+% \bigskip
+% \leftline{\textbf{\textit{Expected usecase}} \texttt{(with options [checkfootnote,checkfloat])}:}
+%
+% \begin{verbatim}
+%
+% --------------------------            --------------------------
+% |xxxxxxxxxx    ++++++++++|            |xxxxxxxxxx    ++++++++++|                       
+% |xxxxxxxxxx    +        +|            |xxxxxxxxxx    +        +| 
+% |xxxxxxxxxx    +        +|            |xxxxxxxxxx    +        +|
+% |xxxxxxxxxx    ++++++++++|            |xxxxxxxxxx    ++++++++++|                          
+% |xxxxxxxxxx    figure    |            |xxxxxxxxxx    figure    |
+% |                        |            |                        |
+% |section       xxxxxxxxxx|            |section       yyyyyyyyyy|
+% |              xxxxxxxxxx|   ----->   |              yyyyyyyyyy|
+% |xxxxxxxxxx    xxxxxxxxxx|            |xxxxxxxxxx    xxxxxxxxxx|
+% |xxxxxxxxxx    xxxxxxxxxx|            |xxxxxxxxxx    xxxxxxxxxx|
+% |yyyyyyyyyy    xxxxxxxxxx|            |              xxxxxxxxxx|
+% |yyyyyyyyyy              |            |---           xxxxxxxxxx|
+% |                        |            |footnote      xxxxxxxxxx|
+% |---                     |            |                        |
+% |footnote                |            |                        |
+% --------------------------            --------------------------
+%
+% \end{verbatim}
+% \StopEventually{}
+%
 % \iffalse
 %<*package>
 % \fi
@@ -260,27 +268,48 @@
 %
 %/*%    \begin{macrocode}*/
 %    \begin{macrocode}
-\newif\if at auto@baselineskip \@auto at baselineskiptrue
-\newif\if at ancient@balance at version \@ancient at balance@versionfalse
+
+\newif\if at footnote@check \@footnote at checktrue
 \newif\if at right@column at spread \@right at column@spreadtrue
-\newif\if at remove@lastbox at at@balancing \@remove at lastbox@at at balancingtrue
+\newif\if at right@column at shrink \@right at column@shrinktrue
+\newif\if at left@column at spread \@left at column@spreadtrue
+\newif\if at left@column at shrink \@left at column@shrinktrue
 \newif\if at balance@debug \@balance at debugfalse
-\DeclareOption{autobase}{\global\@auto at baselineskiptrue}
-\DeclareOption{noautobase}{\global\@auto at baselineskipfalse}
-\DeclareOption{ancient}{\global\@ancient at balance@versiontrue}
-\DeclareOption{modern}{\global\@ancient at balance@versionfalse}
-\DeclareOption{spread}{\global\@right at column@spreadtrue}
-\DeclareOption{nospread}{\global\@right at column@spreadfalse}
-\DeclareOption{removelastbox}{\global\@remove at lastbox@at at balancingtrue}
-\DeclareOption{keeplastbox}{\global\@remove at lastbox@at at balancingfalse}
+
+\DeclareOption{spread}{%
+    \global\@left at column@spreadtrue
+    \global\@right at column@spreadtrue
+    }
+\DeclareOption{nospread}{%
+    \global\@left at column@spreadfalse
+    \global\@right at column@spreadfalse
+    }
+\DeclareOption{lspread}{\global\@left at column@spreadtrue}
+\DeclareOption{nolspread}{\global\@left at column@spreadfalse}
+\DeclareOption{rspread}{\global\@right at column@spreadtrue}
+\DeclareOption{norspread}{\global\@right at column@spreadfalse}
+\DeclareOption{shrink}{%
+    \global\@left at column@shrinktrue
+    \global\@right at column@shrinktrue
+    }
+\DeclareOption{noshrink}{%
+    \global\@left at column@shrinkfalse
+    \global\@right at column@shrinkfalse
+    }
+\DeclareOption{lshrink}{\global\@left at column@shrinktrue}
+\DeclareOption{nolshrink}{\global\@left at column@shrinkfalse}
+\DeclareOption{rshrink}{\global\@right at column@shrinktrue}
+\DeclareOption{norshrink}{\global\@right at column@shrinkfalse}
 \DeclareOption{checkfootnote}{%
     \AtEndOfPackage{%
         \let\check@@footnoterule@@box\initial at check@@footnoterule@@box
+        \@footnote at checktrue
         }%
     }
 \DeclareOption{nocheckfootnote}{%
     \AtEndOfPackage{%
         \let\check@@footnoterule@@box\@gobblethree
+        \@footnote at checkfalse
         }%
     }
 \DeclareOption{checkfloat}{%
@@ -295,218 +324,138 @@
     }
 \DeclareOption{debug}{\global\@balance at debugtrue}
 \DeclareOption{nodebug}{\global\@balance at debugfalse}
+
 \ProcessOptions
-%    \end{macrocode}
-%
-%    \begin{macrocode}
+
 \newskip\flushend@@lastskip at a
 \newskip\flushend@@lastskip at b
-\newskip\flushend@@lastskip at c
-\newcount\flushend@@penalty at a
+\newcount\flushend@@lastnode
 \newcount\var@@loop at iter
-\newdimen\flushend@@lastkern at a
 \newdimen\var@@temp at spread
 \newdimen\var@@temp at a
 \newdimen\var@@temp at loop
-\def\top@@skip@@limit{.7\topskip}
 \newdimen\flushend@@page at rule \flushend@@page at rule\z@
 \def\showcolsendrule{\global\flushend@@page at rule=.4\p@}
-%    \end{macrocode}
-%
-% \begin{macro}{\top@@floatbox at min}\marg{float size}
-% This value is used to catch possible float on right column top.
-%    \begin{macrocode}
-\gdef\top@@floatbox at min@default{4\topskip}
-\let\top@@floatbox at min\top@@floatbox at min@default
-%    \end{macrocode}
-% \end{macro}
-%
-%    \begin{macrocode}
+\gdef\top@@floatbox at min@default{5\topskip}
+\let\top@@floatbox at min\maxdimen
+\def\flushend@@column at badness{101}
+\newbox\flushend@@varbox at lastpage
 \newbox\flushend@@varbox at a
 \newbox\flushend@@varbox at c
 \newbox\flushend@@tempbox at a
 \newbox\flushend@@tempbox at c
+\newbox\flushend@@floatbox
 \@ifundefined{@viper}{\newbox\@viper}{}
 \@ifundefined{hold at viper}{\newbox\hold at viper}{}
-%    \end{macrocode}
-%
-%    \begin{macrocode}
 \newtoks\atColsBreak \atColsBreak={}
 \newtoks\atColsEnd   \atColsEnd={}
-%    \end{macrocode}
-%
-%    \begin{macrocode}
 \@ifundefined{fmt at box@adds}{\def\fmt at box@adds#1{#1}}{}
 \@ifundefined{fmt at vbox@adds}{\def\fmt at vbox@adds[#1]#2{#2}}{}
-%    \end{macrocode}
-%
-% \begin{macro}{\remove at lastbox@at at balancing}
-% It is used to remove empty box at the right column end.
-%    \begin{macrocode}
+\def\wlog at balance@debug#1{\if at balance@debug \wlog{#1}\fi}
+\def\log at box@info#1{<box\the#1>(\the\ht#1+\the\dp#1)x\the\wd#1}
+
 \def\unskip at three@kern at penalty{%
     \unskip\unkern\unpenalty
     \unskip\unkern\unpenalty
     \unskip\unkern\unpenalty
     }
-\gdef\remove at lastbox@at at balancing{%
-    \unskip at three@kern at penalty
-    \if at remove@lastbox at at@balancing
-    \else
-        \expandafter\null
-    \fi
-    \bgroup
+
+\gdef\remove at empty@lastbox at at@balancing#1{%
+    %%
+    %% Removes lastbox without dimensions.
+    %% Removes latest skip, kern, penalty.
+    %% Cuts the lastbox's depth bigger then strutbox's depth.
+    %%
+    \var@@temp at a=\z@
+    \setbox\flushend@@tempbox at a\vbox{%
+        \unvcopy#1%
+        \unskip at three@kern at penalty
+        \global\flushend@@lastnode=\lastnodetype
+        }%
+    \setbox#1\vbox{%
+        \unvcopy\flushend@@tempbox at a
         \setbox\z@\lastbox
-        \ifdim\wd\z@>\z@
-            \box\z@
+        \ifdim\dimexpr\ht\z at +\dp\z at +\wd\z@\relax>\z@
+            %% not empty lastbox - store depth of the lastbox
+            \global\var@@temp at a=\dp\z@
         \else
-            \aftergroup\unskip at three@kern at penalty
+            %% empty lastbox
+            \setbox\z@\box\flushend@@tempbox at a
+            \expandafter\unskip at three@kern at penalty
         \fi
-    \egroup
+        }%
+    \ifvoid\flushend@@tempbox at a\else
+        %% not empty lastbox - restore original
+        \setbox#1\box\flushend@@tempbox at a
+    \fi
+    \ifdim\var@@temp at a>\z@
+        %% cut the depth of the lastbox with the negative skip
+        \ifdim\var@@temp at a>\dp\strutbox
+        %% it is something more than single line depth
+        \else
+            \setbox#1\vbox{\unvbox#1\vskip-\var@@temp at a}%
+        \fi
+    \fi
     }
+
 \def\set at split@topskip at to#1{%
-    \splittopskip#1\relax \vfuzz\maxdimen \vbadness\maxdimen
+    \splittopskip=#1\relax 
+    \vfuzz=\maxdimen
+    \vbadness=\maxdimen
     }
-%    \end{macrocode}
-% \end{macro}
-%
-% Macros used in debug mode.
-%
-%    \begin{macrocode}
-\def\show@@box#1{%
-    \bgroup
-        \showboxbreadth=20000\showboxdepth=20000%
-        \showbox#1\relax
-    \egroup
-    }
-\def\wlog at balance@debug#1{\if at balance@debug \wlog{#1}\fi}
-\def\log at box@info#1{<box\the#1>(\the\ht#1+\the\dp#1)x\the\wd#1}
-\let\show@@box at next\@gobble
-%    \end{macrocode}
-%
-% To get more or less proper result we need to know about footnotes at
-% the left column end, top floats at the right column top, skips and
-% so on. This part of the package is responsible for such analysis.
-%
-%    \begin{macrocode}
-\gdef\analyze at lastbox@box#1{%
-    \setbox\flushend@@varbox at a\vbox{%
-        \unvbox#1%
-        \global\flushend@@lastskip at a\lastskip
-        \unskip
-        \global\var@@temp at a\lastkern
-        \unkern
-        \global\flushend@@penalty at a\lastpenalty
-        \unpenalty
-        \ifdim\lastskip>\z@
-            \global\flushend@@lastskip at a\lastskip
-        \fi
-        \unskip
-        \ifdim\lastkern>\z@
-            \global\var@@temp at a\lastkern
-        \fi
-        \unkern
-        \ifnum\lastpenalty>\z@
-            \global\flushend@@penalty at a\lastpenalty
-        \fi
-        \unpenalty
-        \global\setbox\flushend@@tempbox at a\lastbox
-        }%
-    \wlog at balance@debug{^^J::analyze at lastbox@box::\log at box@info{#1}%
-                        ^^J ::unvbox: \log at box@info{\flushend@@varbox at a}%
-                        ^^J::lastbox: \log at box@info{\flushend@@tempbox at a}%
-                        ^^J::lastskip: \the\flushend@@lastskip at a;
-                            lastkern: \the\var@@temp at a;
-                         lastpenalty: \the\flushend@@penalty at a
-                       }%
-    }
-%    \end{macrocode}
-%
-% \begin{macro}{\analyze at leftcolumn@box}\marg{box}
-%
-% Fills:
-% \begin{itemize}
-%   \item baselineskip skip from the last boxes to |\flushend@@lastskip at c|
-%   \item leftcolumn height without the footnote to |\main at box@height|
-%   \item footnote skip to |\main at box@skip|
-% \end{itemize}
-%
-%    \begin{macrocode}
+
 \gdef\analyze at leftcolumn@box#1{%
+    %%
+    %% Try to find footnotes on the leftcolumn
+    %%
     \set at split@topskip at to\z@
     \flushend@@lastskip at b\ht#1%
-    \wlog at balance@debug{^^Jmainbox: \log at box@info{#1}}%
+    \advance\flushend@@lastskip at b\dp#1%
     \setbox\flushend@@varbox at a\vbox{%
         \unvbox#1%
         \global\flushend@@lastskip at a\lastskip
-        \unskip
-        \global\flushend@@lastkern at a\lastkern
-        \unkern
-        \global\flushend@@penalty at a\lastpenalty
-        \unpenalty
+        \unskip\unkern\unpenalty
         \global\setbox\flushend@@tempbox at a\lastbox
         }%
     \advance\flushend@@lastskip at b -\ht\flushend@@varbox at a
     \advance\flushend@@lastskip at b -\ht\flushend@@tempbox at a
-    \wlog at balance@debug{.-box: \log at box@info{\flushend@@varbox at a}%
-                 ^^J.-lastbox: \log at box@info{\flushend@@tempbox at a}%
-                ^^J.-lastskip: \the\flushend@@lastskip at a;
-                     lastkern: \the\flushend@@lastkern at a;
-                  lastpenalty: \the\flushend@@penalty at a
-                    ^^J.-diff: \the\flushend@@lastskip at b
-        }%
-    \check@@footnoterule@@box\flushend@@tempbox at a\flushend@@lastskip at b\flushend@@varbox at a
-    \check@@baselineskip@@skip
-        \flushend@@lastskip at a
-        \flushend@@lastskip at b
-        \flushend@@lastskip at c
-    \ifx\check@@footnoterule@@box\check@@baselineskip@@skip
-    \else
-        \ifvoid\flushend@@tempbox at a
-            \ifdim\ht\flushend@@varbox at a>\topskip
-                \flushend@@lastskip at b\ht\flushend@@varbox at a
-                \var@@temp at a\ht\flushend@@varbox at a
-                \loop
-                    \setbox\flushend@@tempbox at c\vsplit\flushend@@varbox at a to\var@@temp at a
-                    \ifvoid\flushend@@varbox at a
-                        \setbox\flushend@@varbox at a\vbox{\unvbox\flushend@@tempbox at c}%
-                        \advance \var@@temp at a -3\p@
-                    \else
-                        \var@@temp at a=-1\p@
-                    \fi
-                \ifdim \var@@temp at a>\z@
-                \repeat
-                \setbox\flushend@@varbox at a\vbox{\unvbox\flushend@@varbox at a}%
-                \setbox\flushend@@tempbox at c\vbox{\unvbox\flushend@@tempbox at c}%
-                \advance\flushend@@lastskip at b -\ht\flushend@@varbox at a
-                \advance\flushend@@lastskip at b -\ht\flushend@@tempbox at c
-                \wlog at balance@debug{..--box: \log at box@info{\flushend@@tempbox at c}%
-                             ^^J..--lastbox: \log at box@info{\flushend@@varbox at a}%
-                                ^^J..--diff: \the\flushend@@lastskip at b
-                    }%
-                \check@@footnoterule@@box\flushend@@varbox at a\flushend@@lastskip at b
-                    \flushend@@tempbox at c
-                \check@@baselineskip@@skip\flushend@@lastskip at a\flushend@@lastskip at b
-                    \flushend@@lastskip at c
-                \ifx\check@@footnoterule@@box\check@@baselineskip@@skip
+    \ifvoid\flushend@@tempbox at a
+        \ifdim\ht\flushend@@varbox at a>\topskip
+            \flushend@@lastskip at b\ht\flushend@@varbox at a
+            \var@@temp at a\ht\flushend@@varbox at a
+            \loop
+                \setbox\flushend@@tempbox at c\vsplit\flushend@@varbox at a to\var@@temp at a
+                \ifvoid\flushend@@varbox at a
+                    \setbox\flushend@@varbox at a\vbox{\unvbox\flushend@@tempbox at c}%
+                    \advance\var@@temp at a -3\p@
                 \else
-                    \ifdim\ht\flushend@@varbox at a>.5\topskip
-                        \analyze at lastbox@box\flushend@@varbox at a
-                    \fi
-                    \setbox\flushend@@varbox at a\vbox{\unvbox\flushend@@tempbox at c}%
+                    \var@@temp at a=-1\p@
                 \fi
-            \else
-                \wlog at balance@debug{lastbox: \log at box@info{\flushend@@varbox at a}}%
-            \fi
+            \ifdim \var@@temp at a>\z@
+            \repeat
+            \setbox\flushend@@varbox at a\vbox{\unvbox\flushend@@varbox at a}%
+            \setbox\flushend@@tempbox at c\vbox{\unvbox\flushend@@tempbox at c}%
+            \advance\flushend@@lastskip at b -\ht\flushend@@varbox at a
+            \advance\flushend@@lastskip at b -\ht\flushend@@tempbox at c
+            \check@@footnoterule@@box\flushend@@varbox at a\flushend@@lastskip at b
+                \flushend@@tempbox at c
+            \setbox\flushend@@varbox at a\vbox{\unvbox\flushend@@tempbox at c}%
+        \else
+            \global\@footnote at checkfalse
         \fi
+    \else
+        \check@@footnoterule@@box\flushend@@tempbox at a\flushend@@lastskip at b\flushend@@varbox at a
+    \fi
+    \if at footnote@check
         \ifdim\var@@temp at loop=\ht\flushend@@varbox at a\relax
-           \global\advance\var@@loop at iter\@ne
+            \global\advance\var@@loop at iter\@ne
         \fi
         \var@@temp at loop=\ht\flushend@@varbox at a\relax
         \ifnum\var@@loop at iter<3\relax
-            \wlog at balance@debug{analyze left col: iteration \number\var@@loop at iter; ht \the\var@@temp at loop}%
+            %% next iteration
         \else
-            \wlog at balance@debug{analyze left col loop limit!}%
-            \ht\flushend@@varbox at a\z@
+            %% loop limit, break loop
+            \ht\flushend@@varbox at a=\z@
         \fi
         \ifdim\ht\flushend@@varbox at a>\topskip
             \expandafter\analyze at leftcolumn@box\expandafter\flushend@@varbox at a
@@ -513,22 +462,13 @@
         \fi
     \fi
     }
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\get@@footnoterule@@box}
-%
-% Gets dimensions of the box made by |footnoterule| and writes to:
-% |\footnoterule@@box@@ht|, |\footnoterule@@box@@dp|, |\footnoterule@@box@@wd|.
-%
-%    \begin{macrocode}
+
 \def\get@@footnoterule@@box{%
     \set at split@topskip at to\z@
     \setbox\flushend@@varbox at a\vbox{\strut
         \vskip\z@
         \footnoterule
-        \unskip\unkern\unpenalty
-        \unskip\unkern\unpenalty
+        \unskip at three@kern at penalty
         }%
     \setbox\flushend@@tempbox at c\vsplit\flushend@@varbox at a to\p@
     \xdef\footnoterule@@box@@ht{\the\ht\flushend@@varbox at a}%
@@ -537,19 +477,9 @@
     \wlog at balance@debug{:footnoterule: \log at box@info{\flushend@@varbox at a}}%
     \setbox\flushend@@tempbox at c\vbox{\unvbox\flushend@@varbox at a}%
     }
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\check@@footnoterule@@box}\marg{box1}\marg{skip}\marg{box2}
-%
-% Checks if \marg{box1} dimensions equals to |footnoterule| box dimensions.
-% If so and if \marg{skip} is not |\topskip| we guess it is footnote.
-% In that case we define |leftcolumn| height without |footnote| as 
-% \marg{box2} height and save it as |\main at box@height|. Skip from text to
-% footnote define as |\main at box@skip|.
-%
-%    \begin{macrocode}
+
 \long\def\@gobblethree#1#2#3{}
+
 \def\check@@footnoterule@@box#1#2#3{%
     \ifdim\ht#1=\footnoterule@@box@@ht
         \ifdim\dp#1=\footnoterule@@box@@dp
@@ -557,6 +487,7 @@
                 \ifdim#2=\topskip
                 \else
                     \xdef\main at box@height{\the\ht#3}%
+                    \xdef\main at box@depth{\the\dp#3}%
                     \xdef\main at box@skip{\the#2}%
                     \wlog at balance@debug{^^J:footnoterule found:
                                         main at box <ht=\main at box@height,
@@ -563,62 +494,25 @@
                                         skip=\main at box@skip>
                                        }%
                     \global\let\check@@footnoterule@@box\@gobblethree
-                    \global\let\check@@baselineskip@@skip\reset at check@@baselineskip@@skip
+                    \global\@footnote at checkfalse
                 \fi
             \fi
         \fi
     \fi
     }
+
 \let\initial at check@@footnoterule@@box\check@@footnoterule@@box
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\check@@baselineskip@@skip}\marg{dimension1}\marg{dimension2}\marg{var}
-%
-% If both dimensions: \marg{dimension1} and \marg{dimension2} are positive we
-% define by \marg{var} value of \marg{dimension1} as last skip between text lines
-% and deactivate |\check@@baselineskip@@skip| itself.
-%
-%    \begin{macrocode}
-\def\check@@baselineskip@@skip#1#2#3{%
-    \ifdim#1>\z@
-        \ifdim#2>\z@
-            \global#3=\the#1%
-            \global\let\check@@baselineskip@@skip\@gobblethree
-        \fi
-    \fi
-    }
-\let\initial at check@@baselineskip@@skip\check@@baselineskip@@skip
-%    \end{macrocode}
-%
-% In the case we found footnote it is necessary to look for the last skip
-% between text lines again. For that we use
-% |\reset at check@@baselineskip@@skip|. It activates |\check@@baselineskip@@skip|.
-%
-%    \begin{macrocode}
-\def\reset at check@@baselineskip@@skip#1#2#3{%
-    \global#3=\z@
-    \global\let\check@@baselineskip@@skip\initial at check@@baselineskip@@skip
-    }
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\analyze at rightcolumn@box}\marg{box}
-%
-% Some guess of possible float or section title at the top of right column.\break
-% Fills:
-% \begin{itemize}
-%    \item float height to |\top@@floatbox at ht|
-%    \item float skip to |\top@@floatbox at skip|
-%    \item head skip to |\top@@section at skip|
-% \end{itemize}
-%
-%    \begin{macrocode}
+
 \def\analyze at rightcolumn@box#1{%
+    %%
+    %% Looking for the top floats on the right column.
+    %%
+    %% Top box is considered as float if box's height 
+    %% is larger then \top@@floatbox at min.
+    %% So, it is a dangerous feature to be used carefully.
+    %%
     \bgroup
         \xdef\top@@floatbox at ht{\z@}%
-        \xdef\top@@floatbox at skip{\z@}%
-        \xdef\top@@section at skip{\z@}%
         \set at split@topskip at to\z@
         \setbox\flushend@@varbox at a\vbox{\strut
             \vskip\z@
@@ -625,388 +519,368 @@
             \unvcopy#1%
             }%
         \setbox\flushend@@tempbox at c\vsplit\flushend@@varbox at a to\p@
-        \wlog at balance@debug{^^J(R)mainbox: \log at box@info{#1}}%
         \flushend@@lastskip at a\ht\flushend@@varbox at a
         \advance\flushend@@lastskip at a\dp\flushend@@varbox at a
         \ifdim\flushend@@lastskip at a>\z@
-            \analyze at nonempty@rightcolumn at box
-        \fi
-    \egroup
-    }
-\def\analyze at nonempty@rightcolumn at box{%
-    \bgroup
-        \var@@temp at a3\p@
-        \loop
-            \flushend@@lastskip at b\ht\flushend@@varbox at a
-            \advance\flushend@@lastskip at b\dp\flushend@@varbox at a
-            \setbox\flushend@@tempbox at c\vsplit\flushend@@varbox at a to\var@@temp at a
-            \ifvoid\flushend@@tempbox at c
-                \advance \var@@temp at a 3\p@
-                \ifdim\var@@temp at a>\flushend@@lastskip at b
-                    \var@@temp at a=-1\p@
-                \fi
-            \else
-                \setbox\flushend@@tempbox at c\vbox{\unvbox\flushend@@tempbox at c}%
-                \ifdim\ht\flushend@@tempbox at c>\top@@floatbox at min
-                    \advance\flushend@@lastskip at b -\ht\flushend@@tempbox at c
-                    \advance\flushend@@lastskip at b -\dp\flushend@@tempbox at c
-                    \advance\flushend@@lastskip at b -\ht\flushend@@varbox at a
-                    \advance\flushend@@lastskip at b -\dp\flushend@@varbox at a
-                    \xdef\top@@floatbox at skip{\the\flushend@@lastskip at b}%
-                    \flushend@@lastskip at b\flushend@@lastskip at a
-                    \advance\flushend@@lastskip at b -\ht\flushend@@varbox at a
-                    \advance\flushend@@lastskip at b -\top@@floatbox at skip
-                    \xdef\top@@floatbox at ht{\the\flushend@@lastskip at b}%
-                    \var@@temp at a=3\p@
+            %% analyze non empty rightcolumn box
+            \var@@temp at a=3\p@
+            \loop
+                \setbox\flushend@@tempbox at c\vsplit\flushend@@varbox at a to\var@@temp at a
+                \flushend@@lastskip at b\ht\flushend@@varbox at a
+                \advance\flushend@@lastskip at b\dp\flushend@@varbox at a
+                \ifvoid\flushend@@tempbox at c
+                    \advance\var@@temp at a by3\p@
+                    \ifdim\var@@temp at a>\flushend@@lastskip at b
+                        %% reach column end, break loop
+                        \var@@temp at a=-1\p@
+                    \fi
                 \else
-                    \advance\flushend@@lastskip at b -\ht\flushend@@tempbox at c
-                    \advance\flushend@@lastskip at b -\dp\flushend@@tempbox at c
-                    \advance\flushend@@lastskip at b -\ht\flushend@@varbox at a
-                    \advance\flushend@@lastskip at b -\dp\flushend@@varbox at a
-                    \ifdim\ht\flushend@@tempbox at c>\topskip
-                    \else
-                        \xdef\top@@section at skip{\the\flushend@@lastskip at b}%
-                    \fi
-                    \var@@temp at a=-1\p@
-                \fi
-            \fi
-        \ifdim \var@@temp at a>\z@
-        \repeat
-        \ifvoid\flushend@@tempbox at c
-        \else
-            \ifdim\top@@section at skip>\z@
-            \else
-                \ifdim\ht\flushend@@tempbox at c>\z@
-                    \setbox\flushend@@varbox at a\vbox{\unvbox\flushend@@tempbox at c}%
-                \fi
-                \flushend@@lastskip at b\ht\flushend@@varbox at a
-                \var@@temp at a=3\p@
-                \loop
-                    \setbox\flushend@@tempbox at c\vsplit\flushend@@varbox at a to\var@@temp at a
-                    \ifvoid\flushend@@tempbox at c
-                        \advance \var@@temp at a 3\p@
-                        \ifdim\var@@temp at a>\flushend@@lastskip at b
-                            \var@@temp at a=-1\p@
-                        \fi
-                    \else
-                        \ifdim\ht\flushend@@tempbox at c<\z@
+                    \setbox\flushend@@tempbox at c\vbox{\unvbox\flushend@@tempbox at c}%
+                    \ifdim\ht\flushend@@tempbox at c>\top@@floatbox at min
+                        %% found float; set height; look for the next
+                        \setbox\flushend@@tempbox at a\vbox{\splitdiscards}%
+                        \ifvoid\flushend@@tempbox at a
                         \else
-                            \var@@temp at a=-1\p@
+                            \advance\flushend@@lastskip at b \ht\flushend@@tempbox at a
+                            \advance\flushend@@lastskip at b \dp\flushend@@tempbox at a
                         \fi
-                    \fi
-                \ifdim \var@@temp at a>\z@
-                \repeat
-                \loop
-                    \setbox\flushend@@varbox at a\vbox{%
-                        \unvbox\flushend@@tempbox at c
-                        \unskip\unkern\unpenalty
-                        \unskip\unkern\unpenalty
-                        \unskip\unkern\unpenalty
-                        \setbox\flushend@@tempbox at c\lastbox
-                        }%
-                    \flushend@@lastskip at b\ht\flushend@@varbox at a
-                    \setbox\flushend@@varbox at a\vbox{%
-                        \unvbox\flushend@@varbox at a
-                        \unskip\unkern\unpenalty
-                        \unskip\unkern\unpenalty
-                        \unskip\unkern\unpenalty
-                        }%
-                    \advance\flushend@@lastskip at b -\ht\flushend@@varbox at a
-                    \ifdim\flushend@@lastskip at b>\topskip
-                        \xdef\top@@section at skip{\the\flushend@@lastskip at b}%
-                    \fi
-                    \ifdim\var@@temp at loop=\ht\flushend@@varbox at a\relax
-                        \advance\var@@loop at iter\@ne
-                    \fi
-                    \var@@temp at loop=\ht\flushend@@varbox at a\relax
-                    \ifnum\var@@loop at iter<3\relax
-                        \wlog at balance@debug{analyze right col: iteration \number\var@@loop at iter; ht \the\var@@temp at loop}%
+                        \advance\flushend@@lastskip at b -\flushend@@lastskip at a
+                        \flushend@@lastskip at b=-\flushend@@lastskip at b 
+                        \xdef\top@@floatbox at ht{\the\flushend@@lastskip at b}%
+                        \var@@temp at a=3\p@
                     \else
-                        \wlog at balance@debug{analyze right col loop limit!}%
-                        \ht\flushend@@varbox at a=\z@
+                        %% break loop
+                        \var@@temp at a=-1\p@
                     \fi
-                \ifdim\ht\flushend@@varbox at a>2\topskip
-                    \setbox\flushend@@tempbox at c\vbox{\unvbox\flushend@@varbox at a}%
-                \repeat
-            \fi
+                \fi
+            \ifdim \var@@temp at a>\z@
+            \repeat
         \fi
     \egroup
     }
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\combine at columns@for at balance}
-%
-% Collects both columns to one box removing left column footnotes
-% and right column top float and adding right skip in between them.
-%
-%    \begin{macrocode}
-\def\combine at columns@for at balance{%
-    \setbox\@outputbox\vbox{\strut
-        \vskip\z@
-        \unvbox\@outputbox
-        }%
-    \set at split@topskip at to\z@
-    \setbox\flushend@@tempbox at c\vsplit\@outputbox to\p@
-    \if at auto@baselineskip
-        %% Trying guess baselineskip value on column break
-        \ifdim\top@@floatbox at skip>\z@
-            \setbox\flushend@@tempbox at c\vsplit\@outputbox to\top@@floatbox at ht
-            \setbox\flushend@@tempbox at c\vbox{\unvbox\flushend@@tempbox at c}%
-        \fi
-        \setbox\@tempboxa\vbox{%
-            \unvbox\flushend@@varbox at a
-            \unskip\unkern\unpenalty
-            \hrule\@height\flushend@@page at rule width\columnwidth
-            \vskip-\flushend@@page at rule
-            \hrule\@height\z@ width\columnwidth
-            \vskip\flushend@@lastskip at c
-            \the\atColsBreak
-            \ifdim\top@@section at skip>\top@@skip@@limit
-                \vskip\top@@section at skip
-            \fi
-            \unvbox\@outputbox
-            \remove at lastbox@at at balancing
-            \the\atColsEnd
-            }%
-        \ifdim\top@@floatbox at skip>\z@
-            \setbox\@outputbox\vbox{\unvbox\flushend@@tempbox at c}%
-        \fi
-    \else
-        %% Ignore baselineskip value on column break
-        \setbox\@tempboxa\vbox{%
-            \unvbox\flushend@@varbox at a
-            \unskip\unkern\unpenalty
-            \hrule\@height\flushend@@page at rule width\columnwidth
-            \vskip-\flushend@@page at rule
-            \hrule\@height\z@ width\columnwidth
-            \the\atColsBreak
-            \unvbox\@outputbox
-            \remove at lastbox@at at balancing
-            \the\atColsEnd
-            }%
-    \fi
-    }
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\set at outputbox@with at footnote}
-%
-% Calculates break position and formats balanced columns in the |\@outputbox|
-% with footnotes. 
-%
-%    \begin{macrocode}
-\def\set at outputbox@with at footnote{%
-    %% footnote in left column
-    \@tempdimb\ht\@tempboxa
-    \ifdim\top@@floatbox at skip>\z@
-        \advance\@tempdimb \top@@floatbox at skip
+
+\def\set at outputbox@with at footnote@and at float{%
+    %%
+    %% The main unit formatting balanced columns. 
+    %%
+    %% \flushend@@tempbox at a - left column
+    %% \flushend@@tempbox at c - left column with natural dimensions
+    %% \flushend@@varbox at a  - right column
+    %% \flushend@@varbox at c  - right column with natural dimensions
+    %% \flushend@@floatbox  - rightcolumn top float
+    %% \@leftcolumn         - void or leftcolumn footnote
+    %%
+    \@tempdimb\ht\flushend@@varbox at lastpage
+    \ifdim\top@@floatbox at ht>\z@
+        \advance\@tempdimb \textfloatsep
         \advance\@tempdimb \top@@floatbox at ht
     \fi
-    \advance\@tempdimb \main at box@skip
-    \advance\@tempdimb \ht\@leftcolumn
-    \@tempdimb .5\@tempdimb
-    \advance\@tempdimb -\main at box@skip
-    \advance\@tempdimb -\ht\@leftcolumn
+    \ifdim\main at box@skip>\z@
+        \advance\@tempdimb \main at box@skip
+        \advance\@tempdimb \ht\@leftcolumn
+    \fi
+    \@tempdimb=.5\@tempdimb
+    \ifdim\@tempdimb>\@colht
+        \@tempdimb=\@colht
+    \fi
+    \ifdim\main at box@skip>\z@
+        \advance\@tempdimb -\main at box@skip
+        \advance\@tempdimb -\ht\@leftcolumn
+    \fi
     \set at split@topskip at to\topskip
     \loop
-        \setbox\flushend@@varbox at a\copy\@tempboxa
+        \xdef\saved at tempdimb{\the\@tempdimb}%
+        \setbox\flushend@@varbox at a\copy\flushend@@varbox at lastpage
         \setbox\flushend@@tempbox at a\vsplit\flushend@@varbox at a to\@tempdimb
-        \setbox\flushend@@tempbox at c\vbox{\unvcopy\flushend@@tempbox at a}%
-        \ifdim\top@@floatbox at skip>\z@
-        \setbox\flushend@@varbox at c\vbox{%
-                \unvcopy\@outputbox
-                \vskip\top@@floatbox at skip
+        \ifdim\main at box@skip>\z@
+            \setbox\flushend@@tempbox at c\vbox{%
+                \unvbox\flushend@@tempbox at a
+                \vskip\main at box@skip
+                \vskip\z@ plus\p@
+                \unvcopy\@leftcolumn
+                }%
+        \else
+            \setbox\flushend@@tempbox at c\vbox{\unvbox\flushend@@tempbox at a}%
+        \fi
+        \setbox\flushend@@tempbox at a\vbox to\@tempdimb{\unvcopy\flushend@@tempbox at c}%
+        \xdef\var@@leftcolumn at badness{\the\badness}%
+        \ifdim\top@@floatbox at ht>\z@
+            \setbox\flushend@@varbox at c\vbox{%
+                \unvcopy\flushend@@floatbox
+                \vskip\textfloatsep
+                \vskip\z@ plus\p@ minus\p@
                 \unvbox\flushend@@varbox at a
                 }%
         \else
             \setbox\flushend@@varbox at c\vbox{\unvbox\flushend@@varbox at a}%
         \fi
+        \setbox\flushend@@varbox at a\vbox to\@tempdimb{\unvcopy\flushend@@varbox at c}%
+        \xdef\var@@rightcolumn at badness{\the\badness}%
         \var@@temp at spread=\ht\flushend@@tempbox at c
         \advance\var@@temp at spread by\dp\flushend@@tempbox at c
-        \advance\var@@temp at spread \main at box@skip
-        \advance\var@@temp at spread \ht\@leftcolumn
         \advance\var@@temp at spread by-\ht\flushend@@varbox at c
         \advance\var@@temp at spread by-\dp\flushend@@varbox at c
-        \wlog at balance@debug{Left x: \the\ht\flushend@@tempbox at a
-                            +\the\dp\flushend@@tempbox at a=\the\ht\flushend@@varbox at a
-                            +\the\dp\flushend@@varbox at a::\the\@tempdimb
-                            ^^JLeft 0: \the\ht\flushend@@tempbox at c
-                            +\the\dp\flushend@@tempbox at c::\the\@tempdimb
-                            ^^JRight x: \the\ht\flushend@@varbox at c
-                            +\the\dp\flushend@@varbox at c=\the\ht\flushend@@varbox at a
-                            +\the\dp\flushend@@varbox at a::\the\@tempdimb
-                            ^^JExtra height:\the\var@@temp at spread\space when \the\@tempdimb
-                            }%
+        \wlog at balance@debug{-----
+                            ^^JLeft: \the\ht\flushend@@tempbox at c
+                            +\the\dp\flushend@@tempbox at c\space / \var@@leftcolumn at badness
+                            ^^JRight: \the\ht\flushend@@varbox at c
+                            +\the\dp\flushend@@varbox at c\space / \var@@rightcolumn at badness
+                            ^^JSplit: \the\@tempdimb
+                            ^^JExtra height: \the\var@@temp at spread
+                           }%
+        \ifdim\main at box@skip>\z@
+            \wlog at balance@debug{Footnote: \the\dimexpr\main at box@skip + \the\ht\@leftcolumn\relax}%
+        \fi
+        \ifdim\top@@floatbox at ht>\z@
+            \wlog at balance@debug{Float: \the\dimexpr\the\ht\flushend@@floatbox + \textfloatsep\relax}%
+        \fi
+        \ifnum\var@@leftcolumn at badness<\flushend@@column at badness
+            \ifnum\var@@rightcolumn at badness<\flushend@@column at badness
+                \ifdim\main at box@skip>\z@
+                    \advance\@tempdimb -\main at box@skip
+                    \advance\@tempdimb -\ht\@leftcolumn
+                \fi
+                \var@@temp at spread=\z@
+            \fi
+        \fi
+        \ifdim\var@@temp at spread<\z@
+            \if at left@column at spread
+                \if at right@column at shrink
+                    \ifdim\dimexpr\var@@temp at spread+\pageshrink>\z@
+                        \var@@temp at a=\dimexpr\ht\flushend@@tempbox at c-0.5\var@@temp at spread\relax
+                    \else
+                        \var@@temp at a=-\dimexpr\var@@temp at spread+.5\pageshrink\relax
+                    \fi
+                    \setbox\flushend@@varbox at a\vbox to\var@@temp at a{\unvcopy\flushend@@tempbox at c}%
+                    \ifnum\badness<\flushend@@column at badness
+                        \@tempdimb=\var@@temp at a
+                        \ifdim\main at box@skip>\z@
+                            \advance\@tempdimb -\main at box@skip
+                            \advance\@tempdimb -\ht\@leftcolumn
+                        \fi
+                        \var@@temp at spread=\z@
+                    \fi
+                    \wlog{[leftcolumn badness]: \number\badness\space on \the\var@@temp at a}%
+                    \setbox\flushend@@varbox at a\vbox to\var@@temp at a{\unvcopy\flushend@@varbox at c}%
+                    \wlog{[rightcolumn badness]: \number\badness\space on \the\var@@temp at a}%
+                \else
+                    \setbox\flushend@@varbox at a\vbox to\ht\flushend@@varbox at c{%
+                        \unvcopy\flushend@@tempbox at c
+                        }%
+                    \ifnum\badness<\flushend@@column at badness
+                        \@tempdimb=\ht\flushend@@varbox at c
+                        \ifdim\main at box@skip>\z@
+                            \advance\@tempdimb -\main at box@skip
+                            \advance\@tempdimb -\ht\@leftcolumn
+                        \fi
+                        \var@@temp at spread=\z@
+                    \fi
+                    \wlog{[leftcolumn badness]: \number\badness on \the\ht\flushend@@varbox at c}%
+                    \setbox\flushend@@varbox at a\vbox to\ht\flushend@@varbox at c{%
+                        \unvcopy\flushend@@varbox at c
+                        }%
+                    \wlog{[rightcolumn badness]: \number\badness on \the\ht\flushend@@varbox at c}%
+                \fi
+            \else
+                \if at right@column at shrink
+                    \ifdim\dimexpr\var@@temp at spread+\pageshrink<\z@
+                    \else
+                        \@tempdimb=\ht\flushend@@tempbox at c
+                        \ifdim\main at box@skip>\z@
+                            \advance\@tempdimb -\main at box@skip
+                            \advance\@tempdimb -\ht\@leftcolumn
+                        \fi
+                        \var@@temp at spread=\z@
+                    \fi
+                \fi 
+            \fi
+        \else
+            \ifdim\var@@temp at spread>\z@
+                \ifdim\dimexpr\@tempdimb+\p@\relax>\@colht
+                    \@tempdimb=\@colht
+                    \ifdim\main at box@skip>\z@
+                        \advance\@tempdimb -\main at box@skip
+                        \advance\@tempdimb -\ht\@leftcolumn
+                    \fi
+                    \var@@temp at spread=\z@
+                \fi
+            \fi
+        \fi
     \ifdim\var@@temp at spread<\z@
         \advance\@tempdimb 1\p@
     \repeat
-    \flushend@@lastskip at a\the\ht\flushend@@tempbox at c
-    \advance\flushend@@lastskip at a \main at box@skip
-    \advance\flushend@@lastskip at a \ht\@leftcolumn
-    \flushend@@lastskip at b\the\@tempdimb
-    \setbox\flushend@@tempbox at a\vsplit\@tempboxa to\@tempdimb
-    \setbox\@leftcolumn\vbox to\@tempdima{%
-        \vbox to \flushend@@lastskip at a{%
-            \unvbox\flushend@@tempbox at a
-            \vskip\main at box@skip
-            \unvbox\@leftcolumn
-            \vss
-            }%
-        \hrule\@height\flushend@@page at rule width\textwidth
-        \vskip-\flushend@@page at rule
-        \hrule\@height\z@ width\columnwidth
-        \vss
-        }%
-    \global\ht\@leftcolumn=\the\@tempdima
+    %% final construction of the lastpage
     \wlog{- LAST -%
           ^^JExtra skip:\the\var@@temp at spread
-          ^^JLeft:\the\ht\@leftcolumn/\the\dp\@leftcolumn
-          ^^JRight:\the\ht\@tempboxa/\the\dp\@tempboxa
+          ^^JLeft:\the\ht\flushend@@tempbox at c/\the\dp\flushend@@tempbox at c
+          ^^JRight:\the\ht\flushend@@varbox at c/\the\dp\flushend@@varbox at c
+          ^^JSplit: \saved at tempdimb
           ^^JOutput:\the\@tempdimb
+          ^^JPageshrink: \the\pageshrink
+          ^^JPagestretch: \the\pagestretch
+          ^^J at colht:\the\@colht
           }%
-    \ifdim\top@@floatbox at skip>\z@
-        \setbox\@outputbox\vbox to\@tempdima{%
-            \if at right@column at spread
-                \vbox spread\var@@temp at spread{%
-                    \unvbox\@outputbox
-                    \vskip\top@@floatbox at skip
-                    \unvbox\@tempboxa
-                    }%
+    \setbox\flushend@@tempbox at c\vsplit\flushend@@varbox at lastpage to\saved at tempdimb
+    \ifdim\main at box@skip>\z@
+        \@tempdimb=\dimexpr\@tempdimb+\main at box@skip+\ht\@leftcolumn\relax
+        \setbox\@leftcolumn\vbox to\@tempdimb{%
+            \flushend@@lastskip at a=\dimexpr
+                \@tempdimb
+                -\ht\flushend@@tempbox at c
+                -\main at box@skip
+                -\ht\@leftcolumn
+                \relax
+            \unvbox\flushend@@tempbox at c
+            \vskip\main at box@skip
+            \vskip\z@ plus\p@
+            \unvbox\@leftcolumn
+            \prevdepth\z@
+            \hrule\@height\flushend@@page at rule width\textwidth
+            \vskip-\flushend@@page at rule
+            \ifdim\flushend@@lastskip at a>\z@
+                \if at left@column at spread
+                \else
+                    \vss
+                \fi
             \else
-                \vbox spread\var@@temp at spread{%
-                    \unvbox\@outputbox
-                    \vskip\top@@floatbox at skip
-                    \unvbox\@tempboxa
-                    \vss
-                    }%
+                \ifdim\flushend@@lastskip at a<\z@
+                    \if at left@column at shrink
+                    \else
+                        \vss
+                    \fi
+                \fi 
             \fi
-            \vss
             }%
     \else
-        \setbox\@outputbox\vbox to\@tempdima{%
-            \if at right@column at spread
-                \vbox spread\var@@temp at spread{%
-                    \unvbox\@tempboxa
-                    }%
+        \setbox\@leftcolumn\vbox to\@tempdimb{%
+            \flushend@@lastskip at a=\dimexpr
+                \@tempdimb-\ht\flushend@@tempbox at c
+                \relax
+            \var@@temp at spread=\dp\flushend@@tempbox at c
+            \unvbox\flushend@@tempbox at c
+            \ifdim\var@@temp at spread>\dp\strutbox
             \else
-                \vbox spread\var@@temp at spread{%
-                    \unvbox\@tempboxa
+                \vskip-\var@@temp at spread
+            \fi
+            \prevdepth\z@
+            \hrule\@height\flushend@@page at rule width\textwidth
+            \vskip-\flushend@@page at rule
+            \ifdim\flushend@@lastskip at a>\z@
+                \if at left@column at spread
+                \else
                     \vss
-                    }%
+                \fi
+            \else
+                \ifdim\flushend@@lastskip at a<\z@
+                    \if at left@column at shrink
+                    \else
+                        \vss
+                    \fi
+                \fi 
             \fi
-            \vss
             }%
     \fi
-    }
-%    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\set at outputbox@without at footnote}
-%
-% Calculates break position and formats balanced columns in the |\@outputbox|
-% without footnotes. 
-%
-%    \begin{macrocode}
-\def\set at outputbox@without at footnote{%
-    %% no footnote in left column
-    \@tempdimb \ht\@tempboxa
-    \ifdim\top@@floatbox at skip>\z@
-        \advance\@tempdimb \top@@floatbox at skip
-        \advance\@tempdimb \top@@floatbox at ht
-    \fi
-    \@tempdimb .5\@tempdimb
-    \set at split@topskip at to\topskip
-    \loop
-        \setbox\flushend@@varbox at a\copy\@tempboxa
-        \setbox\flushend@@tempbox at a\vsplit\flushend@@varbox at a to\@tempdimb
-        \setbox\flushend@@tempbox at c\vbox{\unvcopy\flushend@@tempbox at a}%
-        \ifdim\top@@floatbox at skip>\z@
-            \setbox\flushend@@varbox at c\vbox{%
-                \unvcopy\@outputbox
-                \vskip\top@@floatbox at skip
-                \unvbox\flushend@@varbox at a
-                }%
-        \else
-            \setbox\flushend@@varbox at c\vbox{\unvbox\flushend@@varbox at a}%
-        \fi
-        \var@@temp at spread=\ht\flushend@@tempbox at c
-        \advance\var@@temp at spread by\dp\flushend@@tempbox at c
-        \advance\var@@temp at spread by-\ht\flushend@@varbox at c
-        \advance\var@@temp at spread by-\dp\flushend@@varbox at c
-        \wlog at balance@debug{Left x: \the\ht\flushend@@tempbox at a
-                            +\the\dp\flushend@@tempbox at a=\the\ht\flushend@@varbox at a
-                            +\the\dp\flushend@@varbox at a::\the\@tempdimb
-                            ^^JLeft 0: \the\ht\flushend@@tempbox at c
-                            +\the\dp\flushend@@tempbox at c::\the\@tempdimb
-                            ^^JRight x: \the\ht\flushend@@varbox at c
-                            +\the\dp\flushend@@varbox at c=\the\ht\flushend@@varbox at a
-                            +\the\dp\flushend@@varbox at a::\the\@tempdimb
-                            ^^JExtra height:\the\var@@temp at spread\space when \the\@tempdimb
-                           }%
-    \ifdim\var@@temp at spread<\z@ \advance\@tempdimb 1\p@ \repeat
-    \wlog{- LAST -%
-          ^^JExtra skip:\the\var@@temp at spread
-          ^^JLeft:\the\ht\flushend@@tempbox at c/\the\dp\flushend@@tempbox at c
-          ^^JRight:\the\ht\flushend@@varbox at c/\the\dp\flushend@@varbox at c
-          ^^JOutput:\the\@tempdimb
-          }%
-    \setbox\flushend@@tempbox at c\vsplit\@tempboxa to\@tempdimb
-    \setbox\flushend@@varbox at c\vbox{\unvbox\flushend@@tempbox at c}%
-    \setbox\@leftcolumn\vbox to\@tempdima{%
-        \vbox to\@tempdimb{\unvbox\flushend@@varbox at c\vss}%
-        \hrule\@height\flushend@@page at rule width\textwidth
-        \vskip-\flushend@@page at rule
-        \hrule\@height\z@ width\textwidth
-        \vss
-        }%
+    \wlog{FLUSHEND [output]: \the\@tempdimb
+          ^^JFLUSHEND [leftcolumn badness]: \number\badness
+         }%
     \global\ht\@leftcolumn=\the\@tempdima
-    \ifdim\top@@floatbox at skip>\z@
-        \setbox\@outputbox\vbox to\@tempdima{%
-            \if at right@column at spread
-                \vbox spread\var@@temp at spread{%
-                    \unvbox\@outputbox
-                    \vskip\top@@floatbox at skip
-                    \unvbox\@tempboxa
-                    }%
+    \ifdim\top@@floatbox at ht>\z@
+        \setbox\@outputbox\vbox to\@tempdimb{%
+            \flushend@@lastskip at a=\dimexpr
+                \@tempdimb
+                -\ht\flushend@@floatbox
+                -\textfloatsep
+                -\ht\flushend@@varbox at lastpage
+                \relax
+            \unvbox\flushend@@floatbox
+            \vskip\textfloatsep
+            \vskip\z@ plus\p@ minus\p@
+            \unvbox\flushend@@varbox at lastpage
+            \ifdim\flushend@@lastskip at a>\z@
+                \if at right@column at spread
+                \else
+                    \vss
+                \fi
             \else
-                \vbox spread\var@@temp at spread{%
-                    \unvbox\@outputbox
-                    \vskip\top@@floatbox at skip
-                    \unvbox\@tempboxa
-                    \vss
-                    }%
+                \ifdim\flushend@@lastskip at a<\z@
+                    \if at right@column at shrink
+                    \else
+                        \vss
+                    \fi
+                \fi 
             \fi
-            \vss
             }%
     \else
-        \setbox\@outputbox\vbox to\@tempdima{%
-            \if at right@column at spread
-                \vbox spread\var@@temp at spread{%
-                    \unvbox\@tempboxa
-                    }%
+        \setbox\@outputbox\vbox to\@tempdimb{%
+            \flushend@@lastskip at a=\dimexpr
+                \@tempdimb-\ht\flushend@@varbox at lastpage
+                \relax
+            \unvbox\flushend@@varbox at lastpage
+            \ifdim\flushend@@lastskip at a>\z@
+                \if at right@column at spread
+                \else
+                    \vss
+                \fi
             \else
-                \vbox spread\var@@temp at spread{%
-                    \unvbox\@tempboxa
-                    \vss
-                    }%
+                \ifdim\flushend@@lastskip at a<\z@
+                    \if at right@column at shrink
+                    \else
+                        \vss
+                    \fi
+                \fi 
             \fi
-            \vss
             }%
     \fi
+    \wlog{FUSHEND [rightcolumn badness]: \number\badness}%
+    \global\ht\@outputbox=\the\@tempdima
     }
-%    \end{macrocode}
-% \end{macro}
-% \begin{macro}{\last at outputdblcol@modern}
-%
-% Columns balancing of the twocolumn mode page (modern algorithm).
-% It is maybe not so safe for text moving or missing at all
-% as it uses some heuristic technique to find footnotes, last skip between lines
-% at left column and floats or section like heads at right column top
-% for replacing them (except heads of course) to other places in text.
-%
-%    \begin{macrocode}
-\def\last at outputdblcol@modern{%
+
+\newdimen\oldbreak at skip
+
+\def\combine at columns@for at balance{%
+    %%
+    %% Combines lastpage columns for balancing.
+    %%
+    \setbox\flushend@@tempbox at a\vbox{\pagediscards}%
+    \oldbreak at skip=\ht\flushend@@tempbox at a
+    \advance\oldbreak at skip by\dp\flushend@@tempbox at a
+    \setbox\@outputbox\vbox{\strut
+        \vskip\z@
+        \unvbox\@outputbox
+        }%
+    \set at split@topskip at to\z@
+    %% Removes topskip
+    \setbox\flushend@@tempbox at c\vsplit\@outputbox to\p@
+    \ifdim\top@@floatbox at ht>\z@
+        %% removes top float from right column (if option enabled)
+        \setbox\flushend@@floatbox\vsplit\@outputbox to\top@@floatbox at ht
+        \setbox\flushend@@floatbox\vbox{\unvbox\flushend@@floatbox}%
+    \fi
+    \setbox\flushend@@varbox at lastpage\vbox{%
+        \remove at empty@lastbox at at@balancing\flushend@@varbox at a
+        \unvbox\flushend@@varbox at a
+        \hrule\@height\flushend@@page at rule width\columnwidth
+        \vskip-\flushend@@page at rule
+        \hrule\@height\z@ width\columnwidth
+        \penalty\z@
+        \ifdim\var@@temp at a>\z@
+            \ifdim\var@@temp at a>\dp\strutbox
+            \else
+                \vskip\var@@temp at a
+            \fi
+        \fi
+        \vskip\oldbreak at skip
+        \the\atColsBreak
+        \remove at empty@lastbox at at@balancing\@outputbox
+        \unvbox\@outputbox
+        \the\atColsEnd
+        }%
+    }
+
+\def\last at outputdblcol{%
+    %%
+    %% Redefined \@outputdblcol with columns balancing.
+    %%
     \if at firstcolumn
         \global \@firstcolumnfalse
         \global\setbox\@leftcolumn\copy\@outputbox
@@ -1032,216 +906,57 @@
         \advance\@tempdima by\dp\@leftcolumn
         \set at split@topskip at to\topskip
         \var@@temp at spread=\wd\@outputbox
-        \get@@footnoterule@@box
-        \xdef\main at box@height{\the\ht\@leftcolumn}%
+        \xdef\top@@floatbox at ht{\z@}%
         \xdef\main at box@skip{\z@}%
-        \reset at check@@baselineskip@@skip\relax\relax\flushend@@lastskip at c
-        \setbox\flushend@@varbox at a\vbox{\unvcopy\@leftcolumn}%
-        \var@@loop at iter\z@ \var@@temp at loop\z@
-        \analyze at leftcolumn@box\flushend@@varbox at a
-        \setbox\flushend@@varbox at a\vbox{\unvcopy\@outputbox}%
-        \var@@loop at iter\z@ \var@@temp at loop\z@
-        \analyze at rightcolumn@box\flushend@@varbox at a
-        \ifdim\main at box@skip>\z@
-            %% footnote in left column
-            \set at split@topskip at to\z@
-            \setbox\flushend@@varbox at a\vsplit\@leftcolumn to\main at box@height
-        \else
-            %% no footnote in left column
-            \setbox\flushend@@varbox at a\box\@leftcolumn
-        \fi
         \ifdim\var@@temp at spread>\z@
             %% rightcolumn non empty
-            \combine at columns@for at balance
-       \else
-            %% rightcolumn empty
-            \setbox\@tempboxa\vbox{%
-                \unvbox\flushend@@varbox at a
-                \remove at lastbox@at at balancing
-                \the\atColsEnd
-                }%
-       \fi
-        \ifdim\main at box@skip>\z@
-            %% footnote in left column
-            \set at outputbox@with at footnote
-        \else
-            %% no footnote in left column
-  	        \set at outputbox@without at footnote
-        \fi
-        \setbox\@outputbox \vbox {%
-            \hb at xt@\textwidth {%
-                \hb at xt@\columnwidth {%
-                    \fmt at box@adds{\box\@leftcolumn}\hss}%
-                    \hfil
-                    \vrule \@width\columnseprule
-                    \hfil
-                    \hb at xt@\columnwidth {%
-                        \fmt at box@adds{\box\@outputbox}\hss}%
-                        }%
-                    }%
-        \global\let\@outputdblcol\saved at orig@@outputdblcol
-        \global\atColsEnd{}%
-        \ifvoid\hold at viper
-        \else
-            \setbox\@outputbox\vbox{\box\hold at viper\box\@outputbox}%
-        \fi
-        \@combinedblfloats
-        \csname @setmarks\endcsname
-        \@outputpage
-        \begingroup
-            \@dblfloatplacement
-            \@startdblcolumn
-            \@whilesw\if at fcolmade\fi
-                {\@outputpage\@startdblcolumn}%
-            \ifvoid\@viper
+            \setbox\flushend@@varbox at a\vbox{\unvcopy\@outputbox}%
+            \ifdim\dimexpr\@colht-\ht\flushend@@varbox at a>\z@\relax
+                \if at footnote@check
+                    \get@@footnoterule@@box
+                    \xdef\main at box@height{\the\ht\@leftcolumn}%
+                    \setbox\flushend@@varbox at a\vbox{\unvcopy\@leftcolumn}%
+                    \var@@loop at iter\z@ \var@@temp at loop\z@
+                    \analyze at leftcolumn@box\flushend@@varbox at a
+                \fi
+                \ifdim\top@@floatbox at min<\maxdimen
+                    \setbox\flushend@@varbox at a\vbox{\unvcopy\@outputbox}%
+                    \var@@loop at iter\z@ \var@@temp at loop\z@
+                    \analyze at rightcolumn@box\flushend@@varbox at a
+                \fi
+                \ifdim\main at box@skip>\z@
+                    %% footnote in left column
+                    \set at split@topskip at to\z@
+                    \setbox\flushend@@varbox at a\vsplit\@leftcolumn to\main at box@height
+                \else
+                    %% no footnote in left column
+                    \setbox\flushend@@varbox at a\box\@leftcolumn
+                \fi
+                \combine at columns@for at balance
             \else
-                \global\setbox\@viper\vbox{%
-                    \vskip-\stripsep
-                    \unvbox\@viper
-                    }%
-                \csname @viperoutput\endcsname
+                \xdef\main at box@skip{\maxdimen}%
             \fi
-        \endgroup
-    \fi
-    }
-%    \end{macrocode}
-% \end{macro}
-% \begin{macro}{\last at outputdblcol@old}
-%
-% Columns balancing of the twocolumn mode page (ancient algorithm).
-% It is maybe not so good in some cases but maybe more safe for text
-% moving or missing at all.
-%
-%    \begin{macrocode}
-\def\last at outputdblcol@ancient{%
-    \if at firstcolumn
-        \global\@firstcolumnfalse
-        \global\setbox\@leftcolumn\box\@outputbox
-    \else
-        \global\@firstcolumntrue
-        \@tempdima\ht\@leftcolumn
-        \set at split@topskip at to\topskip
-        \if at auto@baselineskip
-            \setbox\@tempboxa\vbox{%
-                \unvcopy\@leftcolumn
-                \global\flushend@@lastskip at c\lastskip
-                \global\flushend@@lastskip at b\lastskip
-                \loop
-                    \global\flushend@@lastskip at a\flushend@@lastskip at b
-                    \unskip\unpenalty
-                    \global\flushend@@lastskip at b\lastskip
-                    \global\advance\flushend@@lastskip at c by\lastskip
-                \ifdim\flushend@@lastskip at b=-\flushend@@lastskip at a
-                    \global\advance\flushend@@lastskip at c by-\lastskip
-                \else
-                \repeat
-                \ifdim\flushend@@lastskip at b=-\flushend@@lastskip at a
-                    \ifdim\flushend@@lastskip at b=\z@
-                        \setbox\flushend@@varbox at a\lastbox
-                        \global\advance\flushend@@lastskip at c by\ht\flushend@@varbox at a
-                        \global\advance\flushend@@lastskip at c by\lastskip
-                        \unskip\unpenalty
-                        \setbox\flushend@@varbox at a\lastbox
-                        \global\advance\flushend@@lastskip at c by\dp\flushend@@varbox at a
-                    \else
-                        \global\flushend@@lastskip at c\lastskip
-                        \global\advance\flushend@@lastskip at c by\topskip
-                    \fi
-                \fi
-                \global\advance\flushend@@lastskip at c by-\topskip
-                }%
-            \setbox\@tempboxa\vbox{%
-                \unvbox\@leftcolumn
-                \unskip\unpenalty
-                \vskip\flushend@@lastskip at c
-                \hrule\@height\flushend@@page at rule width\columnwidth
-                \vskip-\flushend@@page at rule
-                \hrule\@height\z@ width\textwidth
-                \the\atColsBreak
-                \unvbox\@outputbox
-                \remove at lastbox@at at balancing
-                \the\atColsEnd
-            }%
         \else
-            \setbox\@tempboxa\vbox{%
-                \unvbox\@leftcolumn
-                \setbox\z@\lastbox
-                \unskip
-                \hrule\@height\flushend@@page at rule width\columnwidth
-                \vskip-\flushend@@page at rule
-                \hrule\@height\z@ width\textwidth
-                \the\atColsBreak
-                \unvbox\@outputbox
-                \remove at lastbox@at at balancing
-                \the\atColsEnd
-                }%
+                %% rightcolumn empty
+                \setbox\flushend@@varbox at a\box\@leftcolumn
+                \setbox\flushend@@varbox at lastpage\vbox{%
+                    \remove at empty@lastbox at at@balancing\flushend@@varbox at a
+                    \unvbox\flushend@@varbox at a
+                    \the\atColsEnd
+                    }%
         \fi
-        \@tempdimb .5\ht\@tempboxa
-        \loop
-            \setbox\flushend@@tempbox at a\copy\@tempboxa
-            \setbox\flushend@@tempbox at c\vbox to\@tempdimb{%
-                \vsplit\flushend@@tempbox at a to\@tempdimb
-                \vss
-                \vsplit\flushend@@tempbox at a to\@tempdimb
-                }%
-            \wlog{Extra height:\the\ht\flushend@@tempbox at a\space when \the\@tempdimb}%
-        \ifvoid\flushend@@tempbox at a
-        \else
-            \advance\@tempdimb 1\p@
-        \repeat
-        \loop
-            \setbox\flushend@@tempbox at a\copy\@tempboxa
-            \setbox\flushend@@tempbox at c\vbox to\@tempdimb{%
-                \vsplit\flushend@@tempbox at a to\@tempdimb
-                \vss
-                }%
-            \wlog{(2)Left:\the\ht\flushend@@tempbox at c\space
-                    Right:\the\ht\flushend@@tempbox at a\space
-                   Output:\the\@tempdimb
-                 }%
-        \ifdim\ht\flushend@@tempbox at c<\ht\flushend@@tempbox at a
-            \@tempdimb=\the\ht\flushend@@tempbox at a
-        \repeat
-        \wlog{- LAST -^^JExtra skip: \the\z@
-                      ^^JLeft:\the\ht\flushend@@tempbox at c
-                      ^^JRight:\the\ht\flushend@@tempbox at a
-                      ^^JOutput:\the\@tempdimb
-             }%
-        \setbox\flushend@@tempbox at c\vbox to\@tempdimb{%
-            \vsplit\@tempboxa to\@tempdimb
-            \vss
-            }%
-        \setbox\@leftcolumn\vbox to\@tempdima{%
-            \fmt at vbox@adds[\columnwidth]{%
-                \vbox to\@tempdimb{%
-                    \unvbox
-                    \flushend@@tempbox at c
-                    }%
-                }%
-            \hrule\@height\flushend@@page at rule
-            \vskip-\flushend@@page at rule
-            \hrule\@height\z@ width\textwidth
-            \vss
-            }%
-        \setbox\@outputbox\vbox to\@tempdima{%
-            \fmt at vbox@adds[\columnwidth]{%
-                \vbox to\@tempdimb{%
-                    \unvbox\@tempboxa
-                    \vskip\z@
-                    }%
-                }%
-            \hrule\@height\flushend@@page at rule
-            \vskip-\flushend@@page at rule
-            \hrule\@height\z@ width\textwidth
-            \vss
-            }%
+        \ifdim\main at box@skip<\maxdimen
+            \set at outputbox@with at footnote@and at float
+        \fi
         \setbox\@outputbox\vbox{%
             \hb at xt@\textwidth{%
-                \hb at xt@\columnwidth{\box\@leftcolumn\hss}%
+                \hb at xt@\columnwidth{%
+                    \fmt at box@adds{\box\@leftcolumn}\hss}%
                 \hfil
                 \vrule \@width\columnseprule
                 \hfil
-                \hb at xt@\columnwidth{\box\@outputbox\hss}%
+                \hb at xt@\columnwidth{%
+                    \fmt at box@adds{\box\@outputbox}\hss}%
                 }%
             }%
         \global\let\@outputdblcol\saved at orig@@outputdblcol
@@ -1251,6 +966,7 @@
             \setbox\@outputbox\vbox{\box\hold at viper\box\@outputbox}%
         \fi
         \@combinedblfloats
+        \csname @setmarks\endcsname
         \@outputpage
         \begingroup
             \@dblfloatplacement
@@ -1268,61 +984,29 @@
         \endgroup
     \fi
     }
-%    \end{macrocode}
-% \end{macro}
-%
-% Adds default balancing of the last page at the end of document.
-%
-%    \begin{macrocode}
-\usepackage{etoolbox}
-\AtBeginDocument{%
+
+\def\initialize at flushend{%
+    %%
+    %%  Activates flushend package functionality.
+    %%
     \global\let\saved at orig@@outputdblcol\@outputdblcol
-    \if at ancient@balance at version
-        \global\let\last at outputdblcol\last at outputdblcol@ancient
-    \else
-        \global\let\last at outputdblcol\last at outputdblcol@modern
-    \fi
     \global\let\balanced@@outputdblcol\last at outputdblcol
-    \preto\enddocument{\let\@outputdblcol\balanced@@outputdblcol}%
-    \appto\footnoterule{\vskip\z@}%
+    \edef\enddocument{%
+        \unexpanded{\let\@outputdblcol\balanced@@outputdblcol}%
+        \unexpanded\expandafter{\enddocument}%
+        }%
+    \g at addto@macro\footnoterule{\vskip\z@}%
+    \savingvdiscards=\@ne
     }
-%    \end{macrocode}
-%
-% User interface commands for the balancing pages.
-%
-% \cs{flushcolsend} is used to switch on column balancing on the current page.
-%
-%    \begin{macrocode}
+
 \def\flushcolsend{\global\let\@outputdblcol\last at outputdblcol}
-%    \end{macrocode}
-%
-% \cs{raggedcolsend} is used to switch off column balancing on the current page.
-%
-%    \begin{macrocode}
 \def\raggedcolsend{\global\let\@outputdblcol\saved at orig@@outputdblcol}
-%    \end{macrocode}
-%
-% \cs{flushend} is used to switch on column balancing on the last page.
-% It is used by default.
-%
-%    \begin{macrocode}
 \def\flushend{\global\let\balanced@@outputdblcol\last at outputdblcol}
-%    \end{macrocode}
-%
-% \cs{raggedend} is used to switch off column balancing on the last page.
-%
-%    \begin{macrocode}
 \def\raggedend{\global\let\balanced@@outputdblcol\saved at orig@@outputdblcol}
-%    \end{macrocode}
-%
-% In the case to see some debug information |debug| option is used and it is
-% possible to see how package calculates dimensions of balanced columns by
-% additional rules on balanced page and some log records in log file.
-%
-%    \begin{macrocode}
 \if at balance@debug
     \showcolsendrule
 \fi
+\AtBeginDocument{\initialize at flushend}
 %    \end{macrocode}
 %
 % \iffalse

Modified: trunk/Master/texmf-dist/source/latex/sttools/midfloat.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/sttools/midfloat.dtx	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/source/latex/sttools/midfloat.dtx	2021-10-11 20:25:22 UTC (rev 60736)
@@ -1,6 +1,6 @@
-% \iffalse meta-comment
+% \iffalse meta-comment/*%    \end{macrocode}*/
 %
-% Copyright (C) 2012 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+% Copyright (C) 2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
 % ---------------------------------------------------------------------------
 % This work may be distributed and/or modified under the
 % conditions of the LaTeX Project Public License, either version 1.3
@@ -20,13 +20,35 @@
 % \fi
 %
 % \iffalse
+%<*internal>
+\begingroup
+%</internal>
+%<*batchfile>
+\input docstrip.tex
+\keepsilent\askforoverwritefalse
+\preamble
+%%
+%% This is file `midfoat.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% midfloat.dtx  (with options: `package')
+%% 
+\endpreamble
+\generate{\file{midfloat.sty}{\from{midfloat.dtx}{package}}}
+%</batchfile>
+%<batchfile>\endbatchfile
+%<*internal>
+\generate{\file{midfloat.ins}{\from{midfloat.dtx}{batchfile}}}
+\endgroup
+%</internal>
 %<*driver>
 \ProvidesFile{midfloat.dtx}
 %</driver>
 %<*package>
-%% Copyright (C) 1997-2012 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
-%% VTeX Ltd., Akademijos 4, Vilnius, Lithuania
-%% http://www.vtex.lt/tex/download/macros/
+%% Copyright (C) 1997-2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+%% UAB VTeX, Mokslininkų 2A, LT-08412 Vilnius, Lithuania
 %% --------------------------------------------------------------------------
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3

Modified: trunk/Master/texmf-dist/source/latex/sttools/stabular.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/sttools/stabular.dtx	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/source/latex/sttools/stabular.dtx	2021-10-11 20:25:22 UTC (rev 60736)
@@ -1,6 +1,6 @@
-% \iffalse meta-comment
+% \iffalse meta-comment/*%    \end{macrocode}*/
 %
-% Copyright (C) 2014 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+% Copyright (C) 2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
 % ---------------------------------------------------------------------------
 % This work may be distributed and/or modified under the
 % conditions of the LaTeX Project Public License, either version 1.3
@@ -20,13 +20,35 @@
 % \fi
 %
 % \iffalse
+%<*internal>
+\begingroup
+%</internal>
+%<*batchfile>
+\input docstrip.tex
+\keepsilent\askforoverwritefalse
+\preamble
+%%
+%% This is file `stabular.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% stabular.dtx  (with options: `package')
+%% 
+\endpreamble
+\generate{\file{stabular.sty}{\from{stabular.dtx}{package}}}
+%</batchfile>
+%<batchfile>\endbatchfile
+%<*internal>
+\generate{\file{stabular.ins}{\from{stabular.dtx}{batchfile}}}
+\endgroup
+%</internal>
 %<*driver>
 \ProvidesFile{stabular.dtx}
 %</driver>
 %<*package>
-%% Copyright (C) 1998-2014 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
-%% VTeX Ltd., Akademijos 4, Vilnius, Lithuania
-%% http://www.vtex.lt/tex/download/macros/
+%% Copyright (C) 1998-2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+%% UAB VTeX, Mokslininkų 2A, LT-08412 Vilnius, Lithuania
 %% --------------------------------------------------------------------------
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3
@@ -42,12 +64,12 @@
 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
 %<package>\ProvidesPackage{stabular}
 %<*package>
-    [2014/03/20 v2.0 Improve tabular environment]
+    [2021/10/04 v2.1 Improve tabular environment]
 %</package>
 %
 %<*driver>
 \documentclass{ltxdoc}
-\usepackage{stabular}[2014/03/20]
+\usepackage{stabular}[2021/10/04]
 \EnableCrossrefs
 \CodelineIndex
 \RecordChanges
@@ -81,6 +103,7 @@
 % \changes{v1.1}{2012/05/29}{Converted to DTX file}
 % \changes{v1.2}{2014/01/13}{Fixed bug in the '@sarray' macro}
 % \changes{v2.0}{2014/03/20}{Minimized code and extra functionality}
+% \changes{v2.1}{2021/10/04}{Sync with array bugfix version for tabular}
 %
 % \DoNotIndex{\newcommand,\newenvironment}
 %
@@ -226,10 +249,10 @@
     \@preamble
   }
 \def\pkgarray@@stabarray{\@ifnextchar[{\pkgarray@@sarray}{\pkgarray@@sarray[c]}}
-\def\pkgarray at stabular{\gdef\@halignto{}\pkgarray@@stabular}
+\def\pkgarray at stabular{\def\@halignto{}\pkgarray@@stabular}
 \expandafter\def\csname pkgarray at stabular*\endcsname#1{%
        \setlength\dimen@{#1}%
-       \xdef\@halignto{to\the\dimen@}\pkgarray@@stabular}
+       \edef\@halignto{to\the\dimen@}\pkgarray@@stabular}
 \def\pkgarray@@stabular{%
   \leavevmode
   \bgroup 

Modified: trunk/Master/texmf-dist/source/latex/sttools/stfloats.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/sttools/stfloats.dtx	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/source/latex/sttools/stfloats.dtx	2021-10-11 20:25:22 UTC (rev 60736)
@@ -1,6 +1,6 @@
-% \iffalse meta-comment
+% \iffalse meta-comment/*%    \end{macrocode}*/
 %
-% Copyright (C) 2016 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+% Copyright (C) 2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
 % ---------------------------------------------------------------------------
 % This work may be distributed and/or modified under the
 % conditions of the LaTeX Project Public License, either version 1.3
@@ -20,11 +20,34 @@
 % \fi
 %
 % \iffalse
+%<*internal>
+\begingroup
+%</internal>
+%<*batchfile>
+\input docstrip.tex
+\keepsilent\askforoverwritefalse
+\preamble
+%%
+%% This is file `stfloats.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% stfloats.dtx  (with options: `package')
+%% 
+\endpreamble
+\generate{\file{stfloats.sty}{\from{stfloats.dtx}{package}}}
+%</batchfile>
+%<batchfile>\endbatchfile
+%<*internal>
+\generate{\file{stfloats.ins}{\from{stfloats.dtx}{batchfile}}}
+\endgroup
+%</internal>
 %<*driver>
 \ProvidesFile{stfloats.dtx}
 %</driver>
 %<*package>
-%% Copyright (C) 1997-2017 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+%% Copyright (C) 1997-2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
 %% VTeX UAB, Mokslininku 2a, Vilnius, Lithuania
 %% --------------------------------------------------------------------------
 %% This work may be distributed and/or modified under the

Modified: trunk/Master/texmf-dist/source/latex/sttools/sttools.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/sttools/sttools.dtx	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/source/latex/sttools/sttools.dtx	2021-10-11 20:25:22 UTC (rev 60736)
@@ -1,6 +1,6 @@
 % \iffalse meta-comment
 %
-% Copyright (C) 2016 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+% Copyright (C) 2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
 % ---------------------------------------------------------------------------
 % This work may be distributed and/or modified under the
 % conditions of the LaTeX Project Public License, either version 1.3
@@ -62,7 +62,7 @@
 % \GetFileInfo{sttools.dtx}
 % \title{The \textsf{sttools} collection}
 % \author{Sigitas Tolu\v{s}is \\ \url{sigitas at vtex.lt}}
-% \date{2016.06.28}
+% \date{2021.10.04}
 %
 % \maketitle
 %
@@ -74,12 +74,18 @@
 % \section{Usage}
 %
 % \begin{itemize}
-% \item \textbf{cuted.sty, v1.5 2012/10/04} -- place some material
+%
+% \item \textbf{cuted.sty, v2.0 2021/10/04} -- place some material
 % page width wide at any
 % place on twocolumn page with existing text reformatted under inserted
-% material; \\\texttt{TODO: add optional rules to separate from text};
-% \item \textbf{floatpag.sty, v1.1 2012/05/29} -- set pagestyle for floats page;
-% \item \textbf{flushend.sty, v3.2 2016/06/21} -- balance page in twocolumn mode; 
+% material; \\\texttt{\cs{preCutedStrip}\marg{...} and \cs{postCutedStrip}\marg{...} 
+% can be used to add extra stuff before and after the |strip|};
+% \\\texttt{(2021/10/04): rewrite with new balance algorithm and options}.
+%
+% \item \textbf{floatpag.sty, v2.0 2021/10/04} -- set pagestyle for floats page;
+% \\ \texttt{(2021/10/04): removed latex209 compatibility; added rotated dblfloat support};
+%
+% \item \textbf{flushend.sty, v4.0 2021/10/04} -- balance page in twocolumn mode; 
 % \\\texttt{(2014/03/03): totally rewritten with new algorithm to support footnotes, 
 % top  floats and column break before one line section title.
 % \\(2014/04/24): bugfix version;
@@ -87,15 +93,25 @@
 % \\              - spreaded or fixed right column height;
 % \\              - optional old algorithm for backward compatability;
 % \\(2015/04/14): set debug option off by default; keeplastbox modified;
-% \\(2016/06/21): bugfix compatibility with luatexja package};
+% \\(2016/06/21): bugfix compatibility with luatexja package;
+% \\(2017/03/27): bugfix for get@@footnoterule@@box; options for some checks on/off;
+% \\(2020/10/14): bugfix development and test;
+% \\(2020/10/16): bugfix version: modern with noautobase;
+% \\(2021/10/04): another rewrite with new balance algorithm and options}.
+%
 % \item \textbf{midfloat.sty, v1.1 2012/05/29} -- insert onecolumn stuff in twocolumn
 % page; \\\texttt{TODO: extend to work on both columns};
-% \item \textbf{stabular.sty, v2.0 2014/03/20} -- use modified tabular environment;
+%
+% \item \textbf{stabular.sty, v2.1 2021/10/04} -- use modified tabular environment;
 % \\\texttt{(2014/03/20): removed extra stuff and left only possibility to break 
 %       on page boundary;
-% \\added tabular variant from array package};
-% \item \textbf{stfloats.sty, v3.2 2016/06/28} -- enable enriched floats output mechanism;
-% \\\texttt{(2016/06/28): compatibility bugfix with 2015 latexrelease};
+% \\added tabular variant from array packag;
+% \\(2021/10/04): sync with array bugfix version for tabular}.
+%
+% \item \textbf{stfloats.sty, v3.3 2017/03/27} -- enable enriched floats output mechanism;
+% \\\texttt{(2016/06/28): compatibility bugfix with 2015 latexrelease;
+% \\ (2017/03/27): compatibility bugfix with 2017-05-01 latexrelease}.
+%
 % \item \textbf{texsort.sty, v1.1 2012/05/29} -- sort numerical values; \\\texttt{TODO:
 % extend (rewrite) to support alphnanumerical values for sorting}.
 % \end{itemize}

Modified: trunk/Master/texmf-dist/source/latex/sttools/sttools.ins
===================================================================
--- trunk/Master/texmf-dist/source/latex/sttools/sttools.ins	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/source/latex/sttools/sttools.ins	2021-10-11 20:25:22 UTC (rev 60736)
@@ -1,4 +1,4 @@
-%% Copyright (C) 2016 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+%% Copyright (C) 2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
 %% --------------------------------------------------------------------------
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3

Modified: trunk/Master/texmf-dist/source/latex/sttools/texsort.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/sttools/texsort.dtx	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/source/latex/sttools/texsort.dtx	2021-10-11 20:25:22 UTC (rev 60736)
@@ -1,6 +1,6 @@
-% \iffalse meta-comment
+% \iffalse meta-comment/*%    \end{macrocode}*/
 %
-% Copyright (C) 2012 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+% Copyright (C) 2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
 % ---------------------------------------------------------------------------
 % This work may be distributed and/or modified under the
 % conditions of the LaTeX Project Public License, either version 1.3
@@ -17,19 +17,38 @@
 % This work consists of the files texsort.dtx and texsort.ins
 % and the derived filebase texsort.sty.
 %
-% Also available from:
-%  http://www.vtex.lt/tex/download/macros/
-%
 % \fi
 %
 % \iffalse
+%<*internal>
+\begingroup
+%</internal>
+%<*batchfile>
+\input docstrip.tex
+\keepsilent\askforoverwritefalse
+\preamble
+%%
+%% This is file `texsort.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% texsort.dtx  (with options: `package')
+%% 
+\endpreamble
+\generate{\file{texsort.sty}{\from{texsort.dtx}{package}}}
+%</batchfile>
+%<batchfile>\endbatchfile
+%<*internal>
+\generate{\file{texsort.ins}{\from{texsort.dtx}{batchfile}}}
+\endgroup
+%</internal>
 %<*driver>
 \ProvidesFile{texsort.dtx}
 %</driver>
 %<*package>
-%% Copyright (C) 2000-2012 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
-%% VTeX Ltd., Akademijos 4, Vilnius, Lithuania
-%% http://www.vtex.lt/tex/download/macros/
+%% Copyright (C) 2000-2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+%% UAB VTeX, Mokslininkų 2A, LT-08412 Vilnius, Lithuania
 %% --------------------------------------------------------------------------
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3
@@ -553,4 +572,4 @@
 %</package>
 % \fi
 %
-% \Finale
\ No newline at end of file
+% \Finale

Modified: trunk/Master/texmf-dist/tex/latex/sttools/cuted.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/sttools/cuted.sty	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/tex/latex/sttools/cuted.sty	2021-10-11 20:25:22 UTC (rev 60736)
@@ -6,9 +6,8 @@
 %%
 %% cuted.dtx  (with options: `package')
 %% 
-%% Copyright (C) 1997-2012 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
-%% VTeX Ltd., Akademijos 4, Vilnius, Lithuania
-%% http://www.vtex.lt/tex/download/macros/
+%% Copyright (C) 1997-2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+%% UAB VTeX, Mokslininkų 2A, LT-08412 Vilnius, Lithuania
 %% --------------------------------------------------------------------------
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3
@@ -22,419 +21,527 @@
 %%
 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
 \ProvidesPackage{cuted}
-    [2012/10/04 v1.5 Mixing onecolumn and twocolumn modes]
-\def\on at stripcols@break{\hbox{}}
-\DeclareOption{unskipbreak}{\gdef\on at stripcols@break{\unskip}}
-\newif\if at flushend@auto at baselineskip
-\DeclareOption{autobase}{\global\@flushend at auto@baselineskiptrue}
+    [2021/10/04 v2.0 Mixing onecolumn and twocolumn modes]
+
+\newif\if at right@column at spread \@right at column@spreadtrue
+\newif\if at right@column at shrink \@right at column@shrinktrue
+\newif\if at left@column at spread \@left at column@spreadtrue
+\newif\if at left@column at shrink \@left at column@shrinktrue
+\newif\ifcuted@@debug \cuted@@debugfalse
+
+\DeclareOption{spread}{%
+    \global\@left at column@spreadtrue
+    \global\@right at column@spreadtrue
+    }
+\DeclareOption{nospread}{%
+    \global\@left at column@spreadfalse
+    \global\@right at column@spreadfalse
+    }
+\DeclareOption{lspread}{\global\@left at column@spreadtrue}
+\DeclareOption{nolspread}{\global\@left at column@spreadfalse}
+\DeclareOption{rspread}{\global\@right at column@spreadtrue}
+\DeclareOption{norspread}{\global\@right at column@spreadfalse}
+
+\DeclareOption{shrink}{%
+    \global\@left at column@shrinktrue
+    \global\@right at column@shrinktrue
+    }
+\DeclareOption{noshrink}{%
+    \global\@left at column@shrinkfalse
+    \global\@right at column@shrinkfalse
+    }
+\DeclareOption{lshrink}{\global\@left at column@shrinktrue}
+\DeclareOption{nolshrink}{\global\@left at column@shrinkfalse}
+\DeclareOption{rshrink}{\global\@right at column@shrinktrue}
+\DeclareOption{norshrink}{\global\@right at column@shrinkfalse}
+
+\DeclareOption{debug}{\global\cuted@@debugtrue}
+\DeclareOption{nodebug}{\global\cutted@@debugfalse}
+
 \ProcessOptions
 
+\newif\if at lastviper \@lastviperfalse
 \newtoks\At at ViperColsBreak \At at ViperColsBreak{}
+\newtoks\preCutedStrip \preCutedStrip{}
+\newtoks\postCutedStrip \postCutedStrip{}
+\newbox\cuted@@tempbox at a
+\newbox\cuted@@tempbox at c
+\newbox\cuted@@tempbox at var
+\@ifundefined{hold at viper}
+    {\newbox\hold at viper}{}
+\@ifundefined{@viper}
+    {\newbox\@viper}{}
+\newbox\cuted@@varbox at a
+\newbox\cuted@@varbox at c
+\newdimen\cuted@@tempdim at spread
+\newdimen\cuted@@tempdim at a
+\newdimen\cuted@@tempdim at b
+\newdimen\ht at hold@viper
+\newdimen\ht at viper
+\newdimen\var@@pagediscards at ht \var@@pagediscards at ht=\z@
+\@ifundefined{stripsep}
+    {\newskip\stripsep \stripsep 15\p@ plus 2\p@ minus 2\p@}{}
+\newcount\viper at penalty
+\mathchardef\@Mv=10005
+\def\cuted@@column at badness{101}
+\def\cuted@@page at rule{\z@}
+\savingvdiscards=\@ne
+
+\def\cuted@@wlog at debug#1{\ifcuted@@debug \wlog{#1}\fi}
+
+\def\set at split@topskip at to#1{%
+    \splittopskip=#1\relax
+    \vfuzz=\maxdimen
+    \vbadness=\maxdimen
+    }
+
 \def\oldcolsbreak#1{\global\At at ViperColsBreak{#1}}
-\def\viper at top@hook{\splittopskip0pt plus 2pt}
 
-\newbox\v at aaa
-\newbox\v at ccc
-\@ifundefined{lastskip at a}{\newskip\lastskip at a}{}
-\@ifundefined{lastskip at b}{\newskip\lastskip at b}{}
-\@ifundefined{lastskip at d}{\newskip\lastskip at d}{}
-\@ifundefined{lastbox at a}{\newbox\lastbox at a}{}
-\@ifundefined{stripsep}{\newskip\stripsep \stripsep 15pt plus 2pt minus 2pt}{}
+\def\on at stripcols@break{%
+    %%
+    %% adds original vertical page break skip
+    %%
+    \begingroup
+        \setbox\cuted@@tempbox at var\vbox{\pagediscards}%
+        \ifvoid\cuted@@tempbox at var
+        \else
+            \global\var@@pagediscards at ht=\ht\cuted@@tempbox at var
+            \global\advance\var@@pagediscards at ht by\dp\cuted@@tempbox at var
+        \fi
+    \endgroup
+    \ifdim\var@@pagediscards at ht=\z@
+    \else
+        \vskip\var@@pagediscards at ht
+    \fi
+    }
 
-\@ifundefined{@viper}{\newbox\@viper}{}
-\newif\if at lastviper \@lastviperfalse
 \def\@outputdblcol{%
-  \if at firstcolumn
-    \global \@firstcolumnfalse
-    \global \setbox\@leftcolumn \box\@outputbox
-  \else
-    \global \@firstcolumntrue
-    \setbox\@outputbox \vbox {%
-                         \hb at xt@\textwidth {%
-                           \hb at xt@\columnwidth {%
-                             \box\@leftcolumn \hss}%
-                           \hfil
-                           \vrule \@width\columnseprule
-                           \hfil
-                           \hb at xt@\columnwidth {%
-                             \box\@outputbox \hss}%
-                                             }%
-                              }%
-    \ifvoid\hold at viper
+    \if at firstcolumn
+        \global\@firstcolumnfalse
+        \global\setbox\@leftcolumn\copy\@outputbox
+        \splitmaxdepth\maxdimen
+        \vbadness\maxdimen
+        \setbox\@outputbox\vbox{\unvbox\@outputbox\unskip}%
+        \setbox\@outputbox\vsplit\@outputbox to\maxdimen
+        \toks@\expandafter{\topmark}%
+        \xdef\@firstcoltopmark{\the\toks@}%
+        \toks@\expandafter{\splitfirstmark}%
+        \xdef\@firstcolfirstmark{\the\toks@}%
+        \ifx\@firstcolfirstmark\@empty
+            \global\let\@setmarks\relax
+        \else
+          \gdef\@setmarks{%
+              \let\firstmark\@firstcolfirstmark
+              \let\topmark\@firstcoltopmark
+              }%
+        \fi
     \else
-      \setbox\@outputbox \vbox to\textheight{%
-                             \box\hold at viper
-                             \box\@outputbox
-                             \vss
-                             }%
+        \global\@firstcolumntrue
+        \setbox\@outputbox\vbox{%
+            \hb at xt@\textwidth{%
+                \hb at xt@\columnwidth{\box\@leftcolumn \hss}%
+                \hfil
+                {\normalcolor\vrule \@width\columnseprule}%
+                \hfil
+                \hb at xt@\columnwidth{\box\@outputbox \hss}%
+                }%
+            }%
+        \ifvoid\hold at viper
+        \else
+              \setbox\@outputbox\vbox to\textheight{%
+                  \box\hold at viper
+                  \box\@outputbox
+                  \vss
+                  }%
+        \fi
+        \@combinedblfloats
+        \@setmarks
+        \@outputpage
+        \begingroup
+            \@dblfloatplacement
+            \@startdblcolumn
+            \@whilesw\if at fcolmade \fi
+                {\@outputpage \@startdblcolumn}%
+            \ifvoid\@viper
+            \else
+                \global\setbox\@viper\vbox{%
+                    \vskip-\stripsep
+                    \unvbox\@viper
+                    }%
+                \@viperoutput
+            \fi
+        \endgroup
     \fi
-    \@combinedblfloats
-    \@outputpage
-    \begingroup
-      \@dblfloatplacement
-      \@startdblcolumn
-      \@whilesw\if at fcolmade \fi
-        {\@outputpage
-         \@startdblcolumn}%
-      \ifvoid\@viper
-      \else
-        \global\setbox\@viper\vbox{%
-                   \vskip-\stripsep
-                   \unvbox\@viper
-                   }%
-        \@viperoutput
-      \fi
-    \endgroup
-  \fi
-  }
-\mathchardef\@Mv=10005
-\newcount\viper at penalty
+    }
 \def\strip{%
-  \ifinner
-     \@parmoderr\viper at penalty\z@
-  \else
-     \viper at penalty=-\@Mv\relax
-  \fi
-  \global \setbox\@viper\vbox\bgroup%
+    \ifinner
+        \@parmoderr
+        \viper at penalty\z@
+    \else
+        \viper at penalty=-\@Mv
+    \fi
+    \global\setbox\@viper\vbox\bgroup
         \hsize\textwidth
         \@parboxrestore
-        \col at number \@ne
+        \col at number=\@ne
         \vrule height\topskip width\z@ depth\z@
-  }
+    }
 \def\endstrip{%
     \egroup
-    \ifnum\viper at penalty <-\@Mii
-      \penalty -\@Miv
-      \ifvmode
-        \@tempdima\prevdepth    %% saving and restoring \prevdepth added
-        \vbox{}%                %% 26 May 87 to prevent extra vertical
-        \prevdepth\@tempdima   %% space when used in vertical mode
-        \penalty-\@Mv\relax
-      \else
-        \par
-        \penalty-\@Mv\relax
-        \noindent
-      \fi
+    \ifnum\viper at penalty<-\@Mii
+        \penalty-\@Miv
+        \ifvmode
+            \@tempdima\prevdepth
+            \vbox{}%
+            \prevdepth\@tempdima
+            \penalty-\@Mv\relax
+        \else
+            \par
+            \penalty-\@Mv
+            \noindent
+        \fi
     \fi
     }
 \gdef\@viperoutput{%
-               \global \setbox\@holdpg \vbox{%
-                      \unvbox\@holdpg
-                      \unvbox\@cclv
-                      \setbox\@tempboxa \lastbox
-                      \unskip
-                                     }%
-               \@pagedp \dp\@holdpg
-               \@pageht \ht\@holdpg
-               \ifvoid\@viper\else
-                   \advance \@pageht \@pagedp
-                   \ifvoid\footins \else
-                     \advance \@pageht \ht\footins
-                     \advance \@pageht \skip\footins
-                     \advance \@pageht \dp\footins
-                   \fi
-                   \ifvbox \@kludgeins
-                     \ifdim \wd\@kludgeins=\z@
-                       \advance \@pageht \ht\@kludgeins
-                     \fi
-                   \fi
-                   \@reinserts
-                   \@addviper
-               \fi
-  }
+    \global\setbox\@holdpg\vbox{%
+        \unvbox\@holdpg
+        \unvbox\@cclv
+        \setbox\@tempboxa\lastbox
+        \unskip
+        }%
+    \@pagedp=\dp\@holdpg
+    \@pageht=\ht\@holdpg
+    \ifvoid\@viper
+    \else
+        \advance\@pageht by\@pagedp
+        \ifvoid\footins
+        \else
+            \advance\@pageht by\ht\footins
+            \advance\@pageht by\skip\footins
+            \advance\@pageht by\dp\footins
+        \fi
+        \ifvbox\@kludgeins
+            \ifdim\wd\@kludgeins=\z@
+                \advance\@pageht by\ht\@kludgeins
+            \fi
+        \fi
+        \@reinserts
+        \@addviper
+    \fi
+    }
 \gdef\@specialoutput{%
-   \ifnum \outputpenalty>-\@Mii
-     \@doclearpage
-   \else
-     \ifnum \outputpenalty<-\@Miii
-       \ifnum \outputpenalty<-\@MM \deadcycles \z@ \fi
-       \ifnum \outputpenalty=-\@Mv
-              \@viperoutput
-               \ifnum \outputpenalty<\z@
-                 \if at nobreak
-                 \else
-                   \addpenalty \interlinepenalty
-                 \fi
-               \fi
-       \else
-              \global \setbox\@holdpg \vbox {\unvbox\@cclv}%
-       \fi
-     \else
-       \global \setbox\@holdpg \vbox{%
-                      \unvbox\@holdpg
-                      \unvbox\@cclv
-                      \setbox\@tempboxa \lastbox
-                      \unskip
-                                     }%
-       \@pagedp \dp\@holdpg
-       \@pageht \ht\@holdpg
-       \unvbox \@holdpg
-       \@next\@currbox\@currlist{%
-         \ifnum \count\@currbox>\z@
-           \advance \@pageht \@pagedp
-           \ifvoid\footins \else
-             \advance \@pageht \ht\footins
-             \advance \@pageht \skip\footins
-             \advance \@pageht \dp\footins
-           \fi
-           \ifvbox \@kludgeins
-             \ifdim \wd\@kludgeins=\z@
-               \advance \@pageht \ht\@kludgeins
-             \fi
-           \fi
-           \@reinserts
-           \@addtocurcol
-         \else
-           \@reinserts
-           \@addmarginpar
-         \fi
-         }\@latexbug
-       \ifnum \outputpenalty<\z@
-         \if at nobreak
-         \else
-           \addpenalty \interlinepenalty
-         \fi
-       \fi
-     \fi
+    \ifnum\outputpenalty>-\@Mii
+        \@doclearpage
+    \else
+        \ifnum\outputpenalty<-\@Miii
+            \ifnum\outputpenalty<-\@MM \deadcycles \z@ \fi
+            \ifnum\outputpenalty=-\@Mv
+                \@viperoutput
+                \ifnum\outputpenalty<\z@
+                    \if at nobreak
+                    \else
+                        \addpenalty \interlinepenalty
+                    \fi
+                \fi
+            \else
+                \global\setbox\@holdpg\vbox{\unvbox\@cclv}%
+            \fi
+        \else
+            \global\setbox\@holdpg\vbox{%
+                \unvbox\@holdpg
+                \unvbox\@cclv
+                \setbox\@tempboxa\lastbox
+                \unskip
+                }%
+            \@pagedp=\dp\@holdpg
+            \@pageht=\ht\@holdpg
+            \unvbox\@holdpg
+            \@next\@currbox\@currlist{%
+                \ifnum\count\@currbox>\z@
+                    \advance \@pageht \@pagedp
+                    \ifvoid\footins
+                    \else
+                        \advance\@pageht by\ht\footins
+                        \advance\@pageht by\skip\footins
+                        \advance\@pageht by\dp\footins
+                    \fi
+                    \ifvbox\@kludgeins
+                        \ifdim\wd\@kludgeins=\z@
+                            \advance\@pageht by\ht\@kludgeins
+                        \fi
+                    \fi
+                    \@reinserts
+                    \@addtocurcol
+                \else
+                    \@reinserts
+                    \@addmarginpar
+                \fi
+                }\@latexbug
+            \ifnum\outputpenalty<\z@
+                \if at nobreak
+                \else
+                    \addpenalty \interlinepenalty
+                \fi
+            \fi
+        \fi
    \fi
   }
-\@ifundefined{hold at viper}{\newbox\hold at viper}{}
-\newdimen\ht at viper
-\def \@addviper {%
-   \if at firstcolumn
-     \@insertfalse
-     \@reqcolroom .5\@pageht
-     \ht at viper\@reqcolroom
-     \advance \@reqcolroom \ht\@viper
-     \advance \@reqcolroom \stripsep
-     \ifvoid\hold at viper\@tempdima=\z@\else\@tempdima\ht\hold at viper\fi
-%%
-     \@tempdimb \ht at viper
-     \loop
-     \setbox\v at aaa\copy\@holdpg
-     \setbox\v at ccc\vbox to\@tempdimb{%
-                \vsplit\v at aaa to\@tempdimb\vss\vsplit\v at aaa to\@tempdimb}%
-     \wlog{Extra height:\the\ht\v at aaa\space when \the\@tempdimb}%
-     \ifvoid\v at aaa \else \advance\@tempdimb 1pt \repeat
-     \loop
-     \setbox\v at aaa\copy\@holdpg
-     \setbox\v at ccc\vbox to\@tempdimb{%
-                \vsplit\v at aaa to\@tempdimb\vss}%
-     \wlog{(2)Left:\the\ht\v at ccc\space Right:\the\ht\v at aaa\space Output:\the\@tempdimb}%
-     \ifdim \ht\v at ccc<\ht\v at aaa \@tempdimb \the\ht\v at aaa \repeat
-     \wlog{- LAST -^^JLeft:\the\ht\v at ccc^^JRight:\the\ht\v at aaa^^JOutput:\the\@tempdimb}%
-     \setbox\v at ccc\vbox to\@tempdimb{%
-                \vsplit\@holdpg to\@tempdimb\vss}%
-%%
-     \setbox\@tempboxa \vbox {%
-        \hb at xt@\textwidth {%
-                \hb at xt@\columnwidth {%
-                    \vbox to\ht at viper{\box\v at ccc\vss} \hss}%
-                    \hfil
-                    \vrule \@width\columnseprule
-                    \hfil
-                    \hb at xt@\columnwidth {%
-                    \vbox to\ht at viper{\box\@holdpg\vss} \hss}%
-                          }%
-                       }%
-     \ifvoid\hold at viper
-        \global\setbox\hold at viper \vbox {%
-                \unvbox\@tempboxa
-                \penalty\interlinepenalty
-                \vskip\stripsep
-                \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
-                \outputpenalty \z@
+\def\@addviper{%
+    \@insertfalse
+    \def\var@@thecol at num{2}%
+    \if at firstcolumn
+        \def\var@@thecol at num{1}%
+        \@reqcolroom=.5\@pageht
+        \ht at viper=\@reqcolroom
+        \advance\@reqcolroom by\ht\@viper
+        \advance\@reqcolroom by\stripsep
+    \else
+        \@reqcolroom=\@colht
+        \advance\@reqcolroom by\@pageht
+        \ht at viper.5\@reqcolroom
+        \@reqcolroom=\ht at viper
+        \advance\@reqcolroom by\ht\@viper
+        \advance\@reqcolroom by\stripsep
+        \global\setbox\@holdpg\vbox{%
+            \setbox\cuted@@tempbox at a\vbox{%
+                \aftergroup\unvbox
+                \unvcopy\@leftcolumn
+                \unskip\unkern\unpenalty
+                \setbox\@tempboxa\lastbox
+                \ifdim\dimexpr\ht\@tempboxa+\wd\@tempboxa+\dp\@tempboxa>\z@
+                    %% keeps lastbox
+                    \aftergroup\@leftcolumn
+                \else
+                    %% removes lastbox
+                    \aftergroup\cuted@@tempbox at a
+                \fi
+                }%
+            \unskip\unkern\unpenalty
+            \on at stripcols@break
+            \the\At at ViperColsBreak
+            \unvbox\@holdpg
+            }%
+        \global\At at ViperColsBreak{}%
+        \ht at viper=.5\ht\@holdpg
+        \ifdim\ht at viper>\@colht
+            \ht at viper=\@colht
+        \fi
+    \fi
+    %%
+    %% calculations for breaking
+    %%
+    \ifvoid\hold at viper
+        \ht at hold@viper=\z@
+    \else
+        \ht at hold@viper=\ht\hold at viper
+    \fi
+    \cuted@@tempdim at b\ht at viper
+    \set at split@topskip at to\topskip
+    \loop
+        \xdef\saved at tempdimb{\the\cuted@@tempdim at b}%
+        \setbox\cuted@@varbox at a\copy\@holdpg
+        \setbox\cuted@@tempbox at a\vsplit\cuted@@varbox at a to\cuted@@tempdim at b
+        %% set leftcolumn boxes
+        \setbox\cuted@@tempbox at c\vbox{\unvbox\cuted@@tempbox at a}%
+        \setbox\cuted@@tempbox at a\vbox to\cuted@@tempdim at b{\unvcopy\cuted@@tempbox at c}%
+        \xdef\var@@leftcolumn at badness{\the\badness}%
+        %% set rightcolumn boxes
+        \setbox\cuted@@varbox at c\vbox{\unvbox\cuted@@varbox at a}%
+        \setbox\cuted@@varbox at a\vbox to\cuted@@tempdim at b{\unvcopy\cuted@@varbox at c}%
+        \xdef\var@@rightcolumn at badness{\the\badness}%
+        %% analyzing split goodness
+        \cuted@@tempdim at spread=\ht\cuted@@tempbox at c
+        \advance\cuted@@tempdim at spread by\dp\cuted@@tempbox at c
+        \advance\cuted@@tempdim at spread by-\ht\cuted@@varbox at c
+        \advance\cuted@@tempdim at spread by-\dp\cuted@@varbox at c
+        \cuted@@wlog at debug{CUTED [-----]%
+              ^^JLeft: \the\ht\cuted@@tempbox at c
+              +\the\dp\cuted@@tempbox at c\space/\var@@leftcolumn at badness
+              ^^JRight: \the\ht\cuted@@varbox at c
+              +\the\dp\cuted@@varbox at c\space/\var@@rightcolumn at badness
+              ^^JSplit: \the\cuted@@tempdim at b
+              ^^JExtra height: \the\cuted@@tempdim at spread
+             }%
+        \ifnum\var@@leftcolumn at badness<\cuted@@column at badness
+            \ifnum\var@@rightcolumn at badness<\cuted@@column at badness
+                \cuted@@tempdim at spread=\z@
+            \fi
+        \fi
+        \ifdim\cuted@@tempdim at spread<\z@
+            \if at left@column at spread
+                \if at right@column at shrink
+                    \ifdim\dimexpr\cuted@@tempdim at spread+\pageshrink>\z@
+                        \cuted@@tempdim at a=\dimexpr\ht\cuted@@tempbox at c-0.5\cuted@@tempdim at spread\relax
+                    \else
+                        \cuted@@tempdim at a=-\dimexpr\cuted@@tempdim at spread+.5\pageshrink\relax
+                    \fi
+                    \setbox\cuted@@varbox at a\vbox to\cuted@@tempdim at a{\unvcopy\cuted@@tempbox at c}%
+                    \ifnum\badness<\cuted@@column at badness
+                        \cuted@@tempdim at b=\cuted@@tempdim at a
+                        \cuted@@tempdim at spread=\z@
+                    \fi
+                    \cuted@@wlog at debug{CUTED [leftcolumn badness]: \number\badness\space on \the\cuted@@tempdim at a}%
+                    \setbox\cuted@@varbox at a\vbox to\cuted@@tempdim at a{\unvcopy\cuted@@varbox at c}%
+                    \cuted@@wlog at debug{CUTED [rightcolumn badness]: \number\badness\space on \the\cuted@@tempdim at a}%
+                \else
+                    \setbox\cuted@@varbox at a\vbox to\ht\cuted@@varbox at c{%
+                        \unvcopy\cuted@@tempbox at c
                         }%
-     \else
-        \global\setbox\hold at viper \vbox {%
-                \unvbox\hold at viper
-                \unvbox\@tempboxa
-                \penalty\interlinepenalty
-                \vskip\stripsep
-                \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
-                \outputpenalty \z@
+                    \ifnum\badness<\cuted@@column at badness
+                        \@tempdimb=\ht\cuted@@varbox at c
+                        \cuted@@tempdim at spread=\z@
+                    \fi
+                    \cuted@@wlog at debug{CUTED [leftcolumn badness]: \number\badness on \the\ht\cuted@@varbox at c}%
+                    \setbox\cuted@@varbox at a\vbox to\ht\cuted@@varbox at c{%
+                        \unvcopy\cuted@@varbox at c
                         }%
-     \fi
-     \ifdim \@colroom>\@reqcolroom
-        \global\setbox\hold at viper \vbox {%
-                \unvbox\hold at viper
-                \box\@viper
-                \penalty\interlinepenalty
-                \vskip\stripsep
-                \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
-                \outputpenalty \z@
-                        }%
-        \@inserttrue
-        \advance\@tempdima by-\ht\hold at viper
-        \global \advance \@colht \@tempdima
-        \ifdim \@colht<2.5\baselineskip
-           \@latex at warning@no at line {Optional argument of \noexpand\twocolumn
-                too tall on page \thepage (1 stulpelis)}%
-           \@emptycol
-           \if at firstcolumn
-           \else
-             \@emptycol
-           \fi
-           \global\@lastvipertrue
+                    \cuted@@wlog at debug{CUTED [rightcolumn badness]: \number\badness on \the\ht\cuted@@varbox at c}%
+                \fi
+            \else
+                \if at right@column at shrink
+                    \ifdim\dimexpr\cuted@@tempdim at spread+\pageshrink<\z@
+                    \else
+                        \cuted@@tempdim at b=\ht\cuted@@tempbox at c
+                        \cuted@@tempdim at spread=\z@
+                    \fi
+                \fi
+            \fi
         \else
-           \global \vsize \@colht
-           \global \@colroom \@colht
-           \check at floats
-           \ifdim\@tempdima>\z@
-                   \global\advance\@colroom by-\@tempdima
-           \fi
-           \ifdim\@colroom<\z@
-                   \global\@colroom 1pt
-                   \ifdim\@tempdima>\@colht
-                      \@latex at warning@no at line {TOP ir/ar BOT FLOAT's
-                                 netelpa lape \thepage (1 stulpelis)}%
-                   \fi
-                   \@emptycol
-                   \if at firstcolumn
-                   \else
-                     \@emptycol
-                   \fi
-                   \global\@lastvipertrue
-           \fi
+            \ifdim\cuted@@tempdim at spread>\z@
+                \ifdim\dimexpr\@tempdimb+\p@\relax>\@colht
+                    \cuted@@tempdim at b=\@colht
+                    \cuted@@tempdim at spread=\z@
+                \fi
+            \fi
         \fi
-     \fi
-   \else
-     \@insertfalse
-     \@reqcolroom\@colht
-     \advance\@reqcolroom \@pageht
-     \ht at viper.5\@reqcolroom
-     \@reqcolroom\ht at viper
-     \advance \@reqcolroom \ht\@viper
-     \advance \@reqcolroom \stripsep
-      \if at flushend@auto at baselineskip
-        \setbox\@tempboxa\vbox{\unvcopy\@leftcolumn
-          \global\lastskip at d\lastskip
-          \global\lastskip at b\lastskip
-          \loop
-            \global\lastskip at a\lastskip at b
-            \unskip\unpenalty
-            \global\lastskip at b\lastskip
-            \global\advance\lastskip at d by\lastskip
-          \ifdim\lastskip at b=-\lastskip at a
-            \global\advance\lastskip at d by-\lastskip
-          \else
-          \repeat
-          \ifdim\lastskip at b=-\lastskip at a
-            \ifdim\lastskip at b=\z@
-              \setbox\lastbox at a\lastbox
-              \global\advance\lastskip at d by\ht\lastbox at a
-              \global\advance\lastskip at d by\lastskip
-              \unskip\unpenalty
-              \setbox\lastbox at a\lastbox
-              \global\advance\lastskip at d by\dp\lastbox at a
+    \ifdim\cuted@@tempdim at spread<\z@
+        \advance\cuted@@tempdim at b 1\p@
+    \repeat
+    \wlog{CUTED [- LAST -]%
+          ^^JExtra skip:\the\cuted@@tempdim at spread
+          ^^JLeft:\the\ht\cuted@@tempbox at c/\the\dp\cuted@@tempbox at c
+          ^^JRight:\the\ht\cuted@@varbox at c/\the\dp\cuted@@varbox at c
+          ^^JSplit: \saved at tempdimb
+          ^^JOutput:\the\cuted@@tempdim at b
+          ^^JPageshrink: \the\pageshrink
+          ^^JPagestretch: \the\pagestretch
+          ^^J at colht:\the\@colht
+          }%
+    %%
+    %% final construction of the cuted page above strip
+    %%
+    \setbox\cuted@@tempbox at c\vsplit\@holdpg to\saved at tempdimb
+    \setbox\cuted@@tempbox at a\vbox to\cuted@@tempdim at b{%
+        \cuted@@tempdim at a=\dimexpr
+            \cuted@@tempdim at b-\ht\cuted@@tempbox at c
+            \relax
+        \cuted@@tempdim at spread=\dp\cuted@@tempbox at c
+        \unvbox\cuted@@tempbox at c
+        \ifdim\cuted@@tempdim at spread>\dp\strutbox
+        \else
+            \vskip-\cuted@@tempdim at spread
+        \fi
+        \prevdepth\z@
+        \hrule\@height\cuted@@page at rule width\textwidth
+        \vskip-\cuted@@page at rule
+        \ifdim\cuted@@tempdim at a>\z@
+            \if at left@column at spread
             \else
-              \global\lastskip at d\lastskip
-              \global\advance\lastskip at d by\topskip
+                \vss
             \fi
-          \fi
-          \global\advance\lastskip at d by-\topskip
-          }%
-       \ifdim\ht\@holdpg>\@colht
-         \global\setbox\@holdpg\vbox{\unvbox\@leftcolumn\unskip\unpenalty
-           \par\eject
-           \vbox to \@colht{\unvbox\@holdpg\unskip}%
-           }%
-       \else
-         \global\setbox\@holdpg\vbox{%
-           \unvbox\@leftcolumn\unskip\unpenalty
-           \vskip\lastskip at d
-           \the\At at ViperColsBreak
-           \unvbox\@holdpg
-           \unskip
-           }%
-       \fi
-     \else
-       \global\setbox\@holdpg\vbox{%
-                \unvbox\@leftcolumn
-                \setbox\@tempboxa\lastbox
-                \on at stripcols@break
-                \the\At at ViperColsBreak
-                \unvbox\@holdpg
-                }%
-     \fi
-     \global\At at ViperColsBreak{}%
-     \ht at viper .5\ht\@holdpg
-     \ifdim \ht at viper>\@colht
-        \ht at viper \@colht
-     \fi
-     \ifvoid\hold at viper\@tempdima=\z@\else\@tempdima\ht\hold at viper\fi
-%%
-     \@tempdimb \ht at viper
-     \loop
-       \setbox\v at aaa\copy\@holdpg
-       \setbox\v at ccc\vbox to\@tempdimb{%
-                \vsplit\v at aaa to\@tempdimb
+        \else
+            \ifdim\cuted@@tempdim at a<\z@
+                \if at left@column at shrink
+                \else
+                    \vss
+                \fi
+            \fi
+        \fi
+        }%
+    \wlog{CUTED [output]: \the\cuted@@tempdim at b
+          ^^JCUTED [leftcolumn badness]: \number\badness
+         }%
+    \setbox\cuted@@varbox at a\vbox to\cuted@@tempdim at b{%
+        \cuted@@tempdim at a=\dimexpr
+            \cuted@@tempdim at b-\ht\@holdpg
+            \relax
+        \unvbox\@holdpg
+        \ifdim\cuted@@tempdim at a>\z@
+            \if at right@column at spread
+            \else
                 \vss
-                \vsplit\v at aaa to\@tempdimb
+            \fi
+        \else
+            \ifdim\cuted@@tempdim at a<\z@
+                \if at right@column at shrink
+                \else
+                    \vss
+                \fi
+            \fi
+        \fi
+        }%
+    \wlog{CUTED [rightcolumn badness]: \number\badness}%
+    \setbox\cuted@@tempbox at var\vbox{%
+        \hb at xt@\textwidth{%
+            \hb at xt@\columnwidth{%
+                \vbox to\ht at viper{\box\cuted@@tempbox at a\vss}%
+                \hss
                 }%
-       \wlog{Extra height:\the\ht\v at aaa\space when \the\@tempdimb}%
-     \ifvoid\v at aaa
-     \else
-       \advance\@tempdimb 1\p@
-     \repeat
-     \loop
-       \setbox\v at aaa\copy\@holdpg
-       \setbox\v at ccc\vbox to\@tempdimb{\vsplit\v at aaa to\@tempdimb\vss}%
-       \wlog{(2)Left:\the\ht\v at ccc\space
-               Right:\the\ht\v at aaa\space
-              Output:\the\@tempdimb
-            }%
-     \ifdim\ht\v at ccc<\ht\v at aaa
-       \@tempdimb \the\ht\v at aaa
-     \repeat
-     \wlog{- LAST -^^JLeft:\the\ht\v at ccc
-                  ^^JRight:\the\ht\v at aaa
-                 ^^JOutput:\the\@tempdimb
-          }%
-     \setbox\v at ccc\vbox to\@tempdimb{\vsplit\@holdpg to\@tempdimb\vss}%
-     \setbox\@tempboxa\vbox{%
-        \hb at xt@\textwidth {%
-            \hb at xt@\columnwidth{\vbox to\ht at viper{\box\v at ccc\vss} \hss}%
             \hfil
-            \vrule \@width\columnseprule
+            {\normalcolor\vrule \@width\columnseprule}%
             \hfil
-            \hb at xt@\columnwidth {\vbox to\ht at viper{\box\@holdpg\vss} \hss}%
+            \hb at xt@\columnwidth{%
+                \vbox to\ht at viper{\box\cuted@@varbox at a\vss}%
+                \hss
+                }%
             }%
         }%
-     \ifvoid\hold at viper
-        \global\setbox\hold at viper \vbox {%
-                \unvbox\@tempboxa
-                \penalty\interlinepenalty
-                \vskip\stripsep
-                \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
-                \outputpenalty \z@
-                        }%
-     \else
-        \global\setbox\hold at viper \vbox {%
-                \unvbox\hold at viper
-                \unvbox\@tempboxa
-                \penalty\interlinepenalty
-                \vskip\stripsep
-                \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
-                \outputpenalty \z@
-                        }%
-     \fi
-     \ifdim \@colht>\@reqcolroom
-        \global\setbox\hold at viper \vbox {%
-                \unvbox\hold at viper
-                \box\@viper
-                \penalty\interlinepenalty
-                \vskip\stripsep
-                \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
-                \outputpenalty \z@
-                        }%
+    %%
+    %% finalize cuted page
+    %%
+    \ifvoid\hold at viper
+        \global\setbox\hold at viper\vbox{%
+            \unvbox\cuted@@tempbox at var
+            \penalty\interlinepenalty
+            \vskip\stripsep
+            \the\preCutedStrip
+            \ifnum\outputpenalty<-\@Mii
+                \vskip -\parskip
+            \fi
+            \outputpenalty\z@
+            }%
+    \else
+        \global\setbox\hold at viper\vbox{%
+             \unvbox\hold at viper
+             \cuted@@tempbox at var
+             \penalty\interlinepenalty
+             \vskip\stripsep
+             \the\preCutedStrip
+             \ifnum\outputpenalty<-\@Mii
+                 \vskip -\parskip
+             \fi
+             \outputpenalty\z@
+             }%
+    \fi
+    \ifdim\@colht>\@reqcolroom
+        \global\setbox\hold at viper\vbox{%
+             \unvbox\hold at viper
+             \box\@viper
+             \penalty\interlinepenalty
+             \the\postCutedStrip
+             \vskip\stripsep
+             \ifnum\outputpenalty<-\@Mii
+                 \vskip -\parskip
+             \fi
+             \outputpenalty\z@
+             }%
         \@inserttrue
         \global\@firstcolumntrue
-        \advance\@tempdima by-\ht\hold at viper
-        \global \advance \@colht \@tempdima
-        \ifdim \@colht<2.5\baselineskip
+        \advance\ht at hold@viper by-\ht\hold at viper
+        \global\advance\@colht by\ht at hold@viper
+        \ifdim\@colht<2.5\baselineskip
             \@latex at warning@no at line {Optional argument of \noexpand\twocolumn
-                                     too tall on page \thepage (2 stulpelis)}%
+                                     too tall on page \thepage (\var@@thecol at num column)}%
             \@emptycol
             \if at firstcolumn
             \else
@@ -442,17 +549,17 @@
             \fi
             \global\@lastvipertrue
         \else
-            \global \vsize \@colht
-            \global \@colroom \@colht
-            \check at floats
-            \ifdim\@tempdima>\z@
-                \global\advance\@colroom by-\@tempdima
+            \global\vsize\@colht
+            \global\@colroom\@colht
+            \check at floats\cuted@@tempdim at a
+            \ifdim\cuted@@tempdim at a>\z@
+                \global\advance\@colroom by-\cuted@@tempdim at a
             \fi
             \ifdim\@colroom<\z@
-                \global\@colroom 1pt
-                \ifdim\@tempdima>\@colht
-                \@latex at warning@no at line {TOP ir/ar BOT FLOAT's
-                                 netelpa lape \thepage (2 stulpelis)}%
+                \global\@colroom1\p@
+                \ifdim\cuted@@tempdim at a>\@colht
+                    \@latex at warning@no at line{TOP and/or BOT FLOAT's
+                        to large on \thepage (\var@@thecol at num column)}%
                 \fi
                 \@emptycol
                 \if at firstcolumn
@@ -462,73 +569,80 @@
                 \global\@lastvipertrue
             \fi
         \fi
-      \fi
-  \fi
-  \if at insert
-  \else
-      \advance\@tempdima by-\ht\hold at viper
-      \global \advance \@colht \@tempdima
-      \global\setbox\hold at viper \vbox {%
-                                       \unvbox\hold at viper
-                                       \csname viper at top@hook\endcsname
-                                       \vsplit\@viper to \@colht
-                                       \vss
-                                      }%
-      \vbox{}%
-      \global\@firstcolumnfalse
-      \newpage
-  \fi
-  }
-
-\def\check at floats{%
-    \global\@tempdima\z@
-    \let\@elt\ht at comflelt
-    \ifx\@toplist\@empty \else \@toplist \fi
-    \ifx\@botlist\@empty \else \@botlist \fi
+    \fi
+    \if at insert
+    \else
+        \advance\ht at hold@viper by-\ht\hold at viper
+        \global\advance\@colht by\ht at hold@viper
+        \global\setbox\hold at viper\vbox{%
+            \unvbox\hold at viper
+            \set at split@topskip at to{\z@ plus2\p@}%
+            \vsplit\@viper to\@colht
+            \vss
+            }%
+        \vbox{}%
+        \global\@firstcolumnfalse
+        \newpage
+    \fi
     }
-\def\ht at comflelt#1{%
-  \setbox\@tempboxa\vbox{\copy #1\vskip\floatsep}%
-  \global\advance\@tempdima  by\ht\@tempboxa
-  }
-\output {%
-  \let \par \@@par
-  \ifnum \outputpenalty<-\@M
-    \@specialoutput
-  \else
-    \@makecol
-    \@opcol
-    \@startcolumn
-    \@whilesw \if at fcolmade \fi
-      {%
-       \@opcol\@startcolumn}%
-  \fi
-  \ifnum \outputpenalty>-\@Miv
-    \ifdim \@colroom<1.5\baselineskip
-      \ifdim \@colroom<\textheight
-        \@latex at warning@no at line {Text page \thepage\space
-                               contains only floats}%
-        \if at lastviper\else\@emptycol\fi
-        \if at twocolumn
-          \if at firstcolumn
-          \else
-            \@emptycol
-          \fi
-        \fi
-        \global\@lastviperfalse
-      \else
-        \global \vsize \@colroom
-      \fi
+\def\check at floats#1{%
+    \begingroup
+        \global#1\z@
+        \def\@elt##1{%
+            \setbox\@tempboxa\vbox{\copy #1\vskip\floatsep}%
+            \global\advance##1 by\ht\@tempboxa
+            }%
+        \ifx\@toplist\@empty \else \@toplist \fi
+        \ifx\@botlist\@empty \else \@botlist \fi
+    \endgroup
+    }
+\output{%
+    \let\par\@@par
+    \ifnum\outputpenalty<-\@M
+        \@specialoutput
     \else
-      \global \vsize \@colroom
+        \@makecol
+        \@opcol
+        \@startcolumn
+        \@whilesw\if at fcolmade\fi
+            {\@opcol \@startcolumn}%
     \fi
-  \else
-    \ifnum\outputpenalty<-100005
-      \global \vsize \maxdimen
+    \ifnum\outputpenalty>-\@Miv
+        \ifdim\@colroom<1.5\baselineskip
+            \ifdim\@colroom<\textheight
+                \@latex at warning@no at line{%
+                    Text page \thepage\space contains only floats%
+                    }%
+                \if at lastviper
+                \else
+                    \@emptycol
+                \fi
+                \if at twocolumn
+                    \if at firstcolumn
+                    \else
+                        \@emptycol
+                    \fi
+                \fi
+                \global\@lastviperfalse
+            \else
+                \global\vsize\@colroom
+            \fi
+        \else
+            \global\vsize\@colroom
+        \fi
     \else
-      \global \vsize \@colroom
+        \ifnum\outputpenalty<-\@Mv
+            \global\vsize\maxdimen
+        \else
+            \global\vsize\@colroom
+        \fi
     \fi
-  \fi
-  }
+    }
+\ifcuted@@debug
+    \xdef\cuted@@page at rule{.4\p@}
+\else
+    \xdef\cuted@@page at rule{\z@}
+\fi
 \endinput
 %%
 %% End of file `cuted.sty'.

Modified: trunk/Master/texmf-dist/tex/latex/sttools/floatpag.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/sttools/floatpag.sty	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/tex/latex/sttools/floatpag.sty	2021-10-11 20:25:22 UTC (rev 60736)
@@ -7,8 +7,8 @@
 %% floatpag.dtx  (with options: `package')
 %% 
 %% Copyright (C) 1999-2012 by Vytas Statulevi\v{c}ius <vytas at vtex.lt>
-%% VTeX Ltd., Akademijos 4, Vilnius, Lithuania
-%% http://www.vtex.lt/tex/download/macros/
+%% Copyright (C) 2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+%% UAB VTeX, Mokslininkų 2A, LT-08412 Vilnius, Lithuania
 %% --------------------------------------------------------------------------
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3
@@ -28,21 +28,14 @@
 %%
 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
 \ProvidesPackage{floatpag}
-    [2012/05/29 v1.1 Different pagestyles on float pages]
-\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{floatpag}
-             [1999/04/29
-                 FLOAT PAGESTYLE]
+    [2021/10/04 v2.0 Different pagestyles on float pages]
+
 \def\floatpagestyle#1{\gdef\at at float@page{\thispagestyle{#1}}}
-\def\rotfloatpagestyle#1{%
-  \gdef\@r at f@pagestyle{#1}%
-  \gdef\at at rotfloat@page{\thispagestyle{#1}}%
-  }
+\def\rotfloatpagestyle#1{\gdef\@r at f@pagestyle{#1}}
 \floatpagestyle{headings}
 \rotfloatpagestyle{plain}
 \def\thisfloatpagestyle#1{%
-  \expandafter\expandafter\expandafter\gdef\expandafter
-    \csname\number\@currbox @float\endcsname{\thispagestyle{#1}}\relax
+  \global\@namedef{\number\@currbox @float}{\thispagestyle{#1}}\relax
   }
 %% Modify |\x at float| - ordinary floats
 \def\@xfloat #1[#2]{%
@@ -79,28 +72,27 @@
              \else
                \advance \@tempcnta \@ne
              \fi
-           \fi
-           \if \reserved at a t%
+           \else\if \reserved at a t%
              \@setfpsbit \tw@
-           \fi
-           \if \reserved at a b%
+           \else\if \reserved at a b%
              \@setfpsbit 4%
-           \fi
-           \if \reserved at a p%
+           \else\if \reserved at a p%
              \@setfpsbit 8%
-           \fi
-           \if \reserved at a !%
+           \else\if \reserved at a !%
              \ifnum \@tempcnta>15
                \advance\@tempcnta -\sixt@@n\relax
              \fi
-           \fi
+           \else
+             \@latex at error{Unknown float option `\reserved at a'}%
+             {Option `\reserved at a' ignored and `p' used.}%
+             \@setfpsbit 8%
+           \fi\fi\fi\fi\fi
            }%
        \@tempcntb \csname ftype@\@captype \endcsname
        \multiply \@tempcntb \@xxxii
        \advance \@tempcnta \@tempcntb
        \global \count\@currbox \@tempcnta
-       \expandafter\expandafter\expandafter\gdef\expandafter
-         \csname\number\@currbox @float\endcsname{\at at float@page}\relax
+       \global\@namedef{\number\@currbox @float}{\at at float@page}\relax
        }%
     \@fltovf
   \fi
@@ -112,52 +104,27 @@
         \@parboxrestore
         \@floatboxreset
   }
-%% 2e rotating.sty v. 2.10:
-\def\e at xrotfloat#1[#2]{%
+\def\floatpag@@xrotfloat#1[#2]{%
   \@float{#1}[#2]%
   \thisfloatpagestyle{\@r at f@pagestyle}%
   \begin{lrbox}\rot at float@box
   \begin{minipage}\textheight
   }
-%% 2.09 rotating.sty v. 1.6
-\def\n at xrotfloat#1[#2]{%
-  \ifhmode
-    \@bsphack
-    \@floatpenalty -\@Mii
-  \else
-   \@floatpenalty-\@Miii
-  \fi
-  \def\@captype{#1}%
-  \ifinner
-    \@parmoderr\@floatpenalty\z@
-  \else
-    \@next\@currbox\@freelist{\@tempcnta\csname ftype@#1\endcsname
-      \multiply\@tempcnta\@xxxii\advance\@tempcnta\sixt@@n
-      \@tfor \@tempa :=#2\do{%
-        \if\@tempa h\advance\@tempcnta \@ne\fi
-        \if\@tempa t\advance\@tempcnta \tw@\fi
-        \if\@tempa b\advance\@tempcnta 4\relax\fi
-        \if\@tempa p\advance\@tempcnta 8\relax\fi
-        }%
-      \global\count\@currbox\@tempcnta
-      }%
-    \@fltovf
-  \fi
-  \expandafter\expandafter\expandafter\gdef\expandafter
-    \csname\number\@currbox @float\endcsname{\at at rotfloat@page}\relax
-  \global\setbox\@currbox\vbox\bgroup
-    \hsize\textheight
-    \@parboxrestore
-  }
-%% Check for |rotating| version: 2e ar 209:
-%% 1999.02.08 To be sure check at begin document.
+\def\floatpag@@rotxdblfloat#1[#2]{%
+  \@float{#1}[#2]%
+  \thisfloatpagestyle{\@r at f@pagestyle}%
+  \hsize\textwidth\linewidth\textwidth
+  \begin{lrbox}\rot at float@box
+  \begin{minipage}\textheight
+}
 \AtBeginDocument{%
-\@ifpackageloaded{rotating}%
-{\let\@xrotfloat\e at xrotfloat\let\n at xrotfloat\relax}%
-{\let\@xrotfloat\n at xrotfloat\let\e at xrotfloat\relax}}%
+  \let\@xrotfloat\floatpag@@xrotfloat
+  \let\@rotxdblfloat\floatpag@@rotxdblfloat
+  }%
 %% "Hook" in the output procedure.
-\def\spec at float#1{\expandafter\csname\number#1 at float\endcsname
-  \expandafter\expandafter\expandafter\gdef\expandafter\csname\number#1 at float\endcsname{}%
+\def\spec at float#1{%
+  \@nameuse{\number#1 at float}%
+  \global\@namedef{\number#1 at float}{}%
   }
 \def\@vtryfc#1{%
   \global\setbox\@outputbox\vbox{}%

Modified: trunk/Master/texmf-dist/tex/latex/sttools/flushend.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/sttools/flushend.sty	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/tex/latex/sttools/flushend.sty	2021-10-11 20:25:22 UTC (rev 60736)
@@ -6,8 +6,8 @@
 %%
 %% flushend.dtx  (with options: `package')
 %% 
-%% Copyright (C) 1997-2020 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
-%% VTeX Ltd., Mokslinink\k{u} 2a, Vilnius, Lithuania
+%% Copyright (C) 1997-2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+%% UAB VTeX, Mokslininkų 2A, LT-08412 Vilnius, Lithuania
 %% --------------------------------------------------------------------------
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3
@@ -21,28 +21,49 @@
 %%
 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
 \ProvidesPackage{flushend}
-    [2020/10/16 v3.5 Balancing columns in twocolumn mode]
-\newif\if at auto@baselineskip \@auto at baselineskiptrue
-\newif\if at ancient@balance at version \@ancient at balance@versionfalse
+    [2021/10/04 v4.0 Balancing columns in twocolumn mode]
+
+\newif\if at footnote@check \@footnote at checktrue
 \newif\if at right@column at spread \@right at column@spreadtrue
-\newif\if at remove@lastbox at at@balancing \@remove at lastbox@at at balancingtrue
+\newif\if at right@column at shrink \@right at column@shrinktrue
+\newif\if at left@column at spread \@left at column@spreadtrue
+\newif\if at left@column at shrink \@left at column@shrinktrue
 \newif\if at balance@debug \@balance at debugfalse
-\DeclareOption{autobase}{\global\@auto at baselineskiptrue}
-\DeclareOption{noautobase}{\global\@auto at baselineskipfalse}
-\DeclareOption{ancient}{\global\@ancient at balance@versiontrue}
-\DeclareOption{modern}{\global\@ancient at balance@versionfalse}
-\DeclareOption{spread}{\global\@right at column@spreadtrue}
-\DeclareOption{nospread}{\global\@right at column@spreadfalse}
-\DeclareOption{removelastbox}{\global\@remove at lastbox@at at balancingtrue}
-\DeclareOption{keeplastbox}{\global\@remove at lastbox@at at balancingfalse}
+
+\DeclareOption{spread}{%
+    \global\@left at column@spreadtrue
+    \global\@right at column@spreadtrue
+    }
+\DeclareOption{nospread}{%
+    \global\@left at column@spreadfalse
+    \global\@right at column@spreadfalse
+    }
+\DeclareOption{lspread}{\global\@left at column@spreadtrue}
+\DeclareOption{nolspread}{\global\@left at column@spreadfalse}
+\DeclareOption{rspread}{\global\@right at column@spreadtrue}
+\DeclareOption{norspread}{\global\@right at column@spreadfalse}
+\DeclareOption{shrink}{%
+    \global\@left at column@shrinktrue
+    \global\@right at column@shrinktrue
+    }
+\DeclareOption{noshrink}{%
+    \global\@left at column@shrinkfalse
+    \global\@right at column@shrinkfalse
+    }
+\DeclareOption{lshrink}{\global\@left at column@shrinktrue}
+\DeclareOption{nolshrink}{\global\@left at column@shrinkfalse}
+\DeclareOption{rshrink}{\global\@right at column@shrinktrue}
+\DeclareOption{norshrink}{\global\@right at column@shrinkfalse}
 \DeclareOption{checkfootnote}{%
     \AtEndOfPackage{%
         \let\check@@footnoterule@@box\initial at check@@footnoterule@@box
+        \@footnote at checktrue
         }%
     }
 \DeclareOption{nocheckfootnote}{%
     \AtEndOfPackage{%
         \let\check@@footnoterule@@box\@gobblethree
+        \@footnote at checkfalse
         }%
     }
 \DeclareOption{checkfloat}{%
@@ -57,25 +78,27 @@
     }
 \DeclareOption{debug}{\global\@balance at debugtrue}
 \DeclareOption{nodebug}{\global\@balance at debugfalse}
+
 \ProcessOptions
+
 \newskip\flushend@@lastskip at a
 \newskip\flushend@@lastskip at b
-\newskip\flushend@@lastskip at c
-\newcount\flushend@@penalty at a
+\newcount\flushend@@lastnode
 \newcount\var@@loop at iter
-\newdimen\flushend@@lastkern at a
 \newdimen\var@@temp at spread
 \newdimen\var@@temp at a
 \newdimen\var@@temp at loop
-\def\top@@skip@@limit{.7\topskip}
 \newdimen\flushend@@page at rule \flushend@@page at rule\z@
 \def\showcolsendrule{\global\flushend@@page at rule=.4\p@}
-\gdef\top@@floatbox at min@default{4\topskip}
-\let\top@@floatbox at min\top@@floatbox at min@default
+\gdef\top@@floatbox at min@default{5\topskip}
+\let\top@@floatbox at min\maxdimen
+\def\flushend@@column at badness{101}
+\newbox\flushend@@varbox at lastpage
 \newbox\flushend@@varbox at a
 \newbox\flushend@@varbox at c
 \newbox\flushend@@tempbox at a
 \newbox\flushend@@tempbox at c
+\newbox\flushend@@floatbox
 \@ifundefined{@viper}{\newbox\@viper}{}
 \@ifundefined{hold at viper}{\newbox\hold at viper}{}
 \newtoks\atColsBreak \atColsBreak={}
@@ -82,145 +105,111 @@
 \newtoks\atColsEnd   \atColsEnd={}
 \@ifundefined{fmt at box@adds}{\def\fmt at box@adds#1{#1}}{}
 \@ifundefined{fmt at vbox@adds}{\def\fmt at vbox@adds[#1]#2{#2}}{}
+\def\wlog at balance@debug#1{\if at balance@debug \wlog{#1}\fi}
+\def\log at box@info#1{<box\the#1>(\the\ht#1+\the\dp#1)x\the\wd#1}
+
 \def\unskip at three@kern at penalty{%
     \unskip\unkern\unpenalty
     \unskip\unkern\unpenalty
     \unskip\unkern\unpenalty
     }
-\gdef\remove at lastbox@at at balancing{%
-    \unskip at three@kern at penalty
-    \if at remove@lastbox at at@balancing
-    \else
-        \expandafter\null
-    \fi
-    \bgroup
+
+\gdef\remove at empty@lastbox at at@balancing#1{%
+    %%
+    %% Removes lastbox without dimensions.
+    %% Removes latest skip, kern, penalty.
+    %% Cuts the lastbox's depth bigger then strutbox's depth.
+    %%
+    \var@@temp at a=\z@
+    \setbox\flushend@@tempbox at a\vbox{%
+        \unvcopy#1%
+        \unskip at three@kern at penalty
+        \global\flushend@@lastnode=\lastnodetype
+        }%
+    \setbox#1\vbox{%
+        \unvcopy\flushend@@tempbox at a
         \setbox\z@\lastbox
-        \ifdim\wd\z@>\z@
-            \box\z@
+        \ifdim\dimexpr\ht\z at +\dp\z at +\wd\z@\relax>\z@
+            %% not empty lastbox - store depth of the lastbox
+            \global\var@@temp at a=\dp\z@
         \else
-            \aftergroup\unskip at three@kern at penalty
+            %% empty lastbox
+            \setbox\z@\box\flushend@@tempbox at a
+            \expandafter\unskip at three@kern at penalty
         \fi
-    \egroup
+        }%
+    \ifvoid\flushend@@tempbox at a\else
+        %% not empty lastbox - restore original
+        \setbox#1\box\flushend@@tempbox at a
+    \fi
+    \ifdim\var@@temp at a>\z@
+        %% cut the depth of the lastbox with the negative skip
+        \ifdim\var@@temp at a>\dp\strutbox
+        %% it is something more than single line depth
+        \else
+            \setbox#1\vbox{\unvbox#1\vskip-\var@@temp at a}%
+        \fi
+    \fi
     }
+
 \def\set at split@topskip at to#1{%
-    \splittopskip#1\relax \vfuzz\maxdimen \vbadness\maxdimen
+    \splittopskip=#1\relax
+    \vfuzz=\maxdimen
+    \vbadness=\maxdimen
     }
-\def\show@@box#1{%
-    \bgroup
-        \showboxbreadth=20000\showboxdepth=20000%
-        \showbox#1\relax
-    \egroup
-    }
-\def\wlog at balance@debug#1{\if at balance@debug \wlog{#1}\fi}
-\def\log at box@info#1{<box\the#1>(\the\ht#1+\the\dp#1)x\the\wd#1}
-\let\show@@box at next\@gobble
-\gdef\analyze at lastbox@box#1{%
-    \setbox\flushend@@varbox at a\vbox{%
-        \unvbox#1%
-        \global\flushend@@lastskip at a\lastskip
-        \unskip
-        \global\var@@temp at a\lastkern
-        \unkern
-        \global\flushend@@penalty at a\lastpenalty
-        \unpenalty
-        \ifdim\lastskip>\z@
-            \global\flushend@@lastskip at a\lastskip
-        \fi
-        \unskip
-        \ifdim\lastkern>\z@
-            \global\var@@temp at a\lastkern
-        \fi
-        \unkern
-        \ifnum\lastpenalty>\z@
-            \global\flushend@@penalty at a\lastpenalty
-        \fi
-        \unpenalty
-        \global\setbox\flushend@@tempbox at a\lastbox
-        }%
-    \wlog at balance@debug{^^J::analyze at lastbox@box::\log at box@info{#1}%
-                        ^^J ::unvbox: \log at box@info{\flushend@@varbox at a}%
-                        ^^J::lastbox: \log at box@info{\flushend@@tempbox at a}%
-                        ^^J::lastskip: \the\flushend@@lastskip at a;
-                            lastkern: \the\var@@temp at a;
-                         lastpenalty: \the\flushend@@penalty at a
-                       }%
-    }
+
 \gdef\analyze at leftcolumn@box#1{%
+    %%
+    %% Try to find footnotes on the leftcolumn
+    %%
     \set at split@topskip at to\z@
     \flushend@@lastskip at b\ht#1%
-    \wlog at balance@debug{^^Jmainbox: \log at box@info{#1}}%
+    \advance\flushend@@lastskip at b\dp#1%
     \setbox\flushend@@varbox at a\vbox{%
         \unvbox#1%
         \global\flushend@@lastskip at a\lastskip
-        \unskip
-        \global\flushend@@lastkern at a\lastkern
-        \unkern
-        \global\flushend@@penalty at a\lastpenalty
-        \unpenalty
+        \unskip\unkern\unpenalty
         \global\setbox\flushend@@tempbox at a\lastbox
         }%
     \advance\flushend@@lastskip at b -\ht\flushend@@varbox at a
     \advance\flushend@@lastskip at b -\ht\flushend@@tempbox at a
-    \wlog at balance@debug{.-box: \log at box@info{\flushend@@varbox at a}%
-                 ^^J.-lastbox: \log at box@info{\flushend@@tempbox at a}%
-                ^^J.-lastskip: \the\flushend@@lastskip at a;
-                     lastkern: \the\flushend@@lastkern at a;
-                  lastpenalty: \the\flushend@@penalty at a
-                    ^^J.-diff: \the\flushend@@lastskip at b
-        }%
-    \check@@footnoterule@@box\flushend@@tempbox at a\flushend@@lastskip at b\flushend@@varbox at a
-    \check@@baselineskip@@skip
-        \flushend@@lastskip at a
-        \flushend@@lastskip at b
-        \flushend@@lastskip at c
-    \ifx\check@@footnoterule@@box\check@@baselineskip@@skip
-    \else
-        \ifvoid\flushend@@tempbox at a
-            \ifdim\ht\flushend@@varbox at a>\topskip
-                \flushend@@lastskip at b\ht\flushend@@varbox at a
-                \var@@temp at a\ht\flushend@@varbox at a
-                \loop
-                    \setbox\flushend@@tempbox at c\vsplit\flushend@@varbox at a to\var@@temp at a
-                    \ifvoid\flushend@@varbox at a
-                        \setbox\flushend@@varbox at a\vbox{\unvbox\flushend@@tempbox at c}%
-                        \advance \var@@temp at a -3\p@
-                    \else
-                        \var@@temp at a=-1\p@
-                    \fi
-                \ifdim \var@@temp at a>\z@
-                \repeat
-                \setbox\flushend@@varbox at a\vbox{\unvbox\flushend@@varbox at a}%
-                \setbox\flushend@@tempbox at c\vbox{\unvbox\flushend@@tempbox at c}%
-                \advance\flushend@@lastskip at b -\ht\flushend@@varbox at a
-                \advance\flushend@@lastskip at b -\ht\flushend@@tempbox at c
-                \wlog at balance@debug{..--box: \log at box@info{\flushend@@tempbox at c}%
-                             ^^J..--lastbox: \log at box@info{\flushend@@varbox at a}%
-                                ^^J..--diff: \the\flushend@@lastskip at b
-                    }%
-                \check@@footnoterule@@box\flushend@@varbox at a\flushend@@lastskip at b
-                    \flushend@@tempbox at c
-                \check@@baselineskip@@skip\flushend@@lastskip at a\flushend@@lastskip at b
-                    \flushend@@lastskip at c
-                \ifx\check@@footnoterule@@box\check@@baselineskip@@skip
+    \ifvoid\flushend@@tempbox at a
+        \ifdim\ht\flushend@@varbox at a>\topskip
+            \flushend@@lastskip at b\ht\flushend@@varbox at a
+            \var@@temp at a\ht\flushend@@varbox at a
+            \loop
+                \setbox\flushend@@tempbox at c\vsplit\flushend@@varbox at a to\var@@temp at a
+                \ifvoid\flushend@@varbox at a
+                    \setbox\flushend@@varbox at a\vbox{\unvbox\flushend@@tempbox at c}%
+                    \advance\var@@temp at a -3\p@
                 \else
-                    \ifdim\ht\flushend@@varbox at a>.5\topskip
-                        \analyze at lastbox@box\flushend@@varbox at a
-                    \fi
-                    \setbox\flushend@@varbox at a\vbox{\unvbox\flushend@@tempbox at c}%
+                    \var@@temp at a=-1\p@
                 \fi
-            \else
-                \wlog at balance@debug{lastbox: \log at box@info{\flushend@@varbox at a}}%
-            \fi
+            \ifdim \var@@temp at a>\z@
+            \repeat
+            \setbox\flushend@@varbox at a\vbox{\unvbox\flushend@@varbox at a}%
+            \setbox\flushend@@tempbox at c\vbox{\unvbox\flushend@@tempbox at c}%
+            \advance\flushend@@lastskip at b -\ht\flushend@@varbox at a
+            \advance\flushend@@lastskip at b -\ht\flushend@@tempbox at c
+            \check@@footnoterule@@box\flushend@@varbox at a\flushend@@lastskip at b
+                \flushend@@tempbox at c
+            \setbox\flushend@@varbox at a\vbox{\unvbox\flushend@@tempbox at c}%
+        \else
+            \global\@footnote at checkfalse
         \fi
+    \else
+        \check@@footnoterule@@box\flushend@@tempbox at a\flushend@@lastskip at b\flushend@@varbox at a
+    \fi
+    \if at footnote@check
         \ifdim\var@@temp at loop=\ht\flushend@@varbox at a\relax
-           \global\advance\var@@loop at iter\@ne
+            \global\advance\var@@loop at iter\@ne
         \fi
         \var@@temp at loop=\ht\flushend@@varbox at a\relax
         \ifnum\var@@loop at iter<3\relax
-            \wlog at balance@debug{analyze left col: iteration \number\var@@loop at iter; ht \the\var@@temp at loop}%
+            %% next iteration
         \else
-            \wlog at balance@debug{analyze left col loop limit!}%
-            \ht\flushend@@varbox at a\z@
+            %% loop limit, break loop
+            \ht\flushend@@varbox at a=\z@
         \fi
         \ifdim\ht\flushend@@varbox at a>\topskip
             \expandafter\analyze at leftcolumn@box\expandafter\flushend@@varbox at a
@@ -227,13 +216,13 @@
         \fi
     \fi
     }
+
 \def\get@@footnoterule@@box{%
     \set at split@topskip at to\z@
     \setbox\flushend@@varbox at a\vbox{\strut
         \vskip\z@
         \footnoterule
-        \unskip\unkern\unpenalty
-        \unskip\unkern\unpenalty
+        \unskip at three@kern at penalty
         }%
     \setbox\flushend@@tempbox at c\vsplit\flushend@@varbox at a to\p@
     \xdef\footnoterule@@box@@ht{\the\ht\flushend@@varbox at a}%
@@ -242,7 +231,9 @@
     \wlog at balance@debug{:footnoterule: \log at box@info{\flushend@@varbox at a}}%
     \setbox\flushend@@tempbox at c\vbox{\unvbox\flushend@@varbox at a}%
     }
+
 \long\def\@gobblethree#1#2#3{}
+
 \def\check@@footnoterule@@box#1#2#3{%
     \ifdim\ht#1=\footnoterule@@box@@ht
         \ifdim\dp#1=\footnoterule@@box@@dp
@@ -250,6 +241,7 @@
                 \ifdim#2=\topskip
                 \else
                     \xdef\main at box@height{\the\ht#3}%
+                    \xdef\main at box@depth{\the\dp#3}%
                     \xdef\main at box@skip{\the#2}%
                     \wlog at balance@debug{^^J:footnoterule found:
                                         main at box <ht=\main at box@height,
@@ -256,31 +248,25 @@
                                         skip=\main at box@skip>
                                        }%
                     \global\let\check@@footnoterule@@box\@gobblethree
-                    \global\let\check@@baselineskip@@skip\reset at check@@baselineskip@@skip
+                    \global\@footnote at checkfalse
                 \fi
             \fi
         \fi
     \fi
     }
+
 \let\initial at check@@footnoterule@@box\check@@footnoterule@@box
-\def\check@@baselineskip@@skip#1#2#3{%
-    \ifdim#1>\z@
-        \ifdim#2>\z@
-            \global#3=\the#1%
-            \global\let\check@@baselineskip@@skip\@gobblethree
-        \fi
-    \fi
-    }
-\let\initial at check@@baselineskip@@skip\check@@baselineskip@@skip
-\def\reset at check@@baselineskip@@skip#1#2#3{%
-    \global#3=\z@
-    \global\let\check@@baselineskip@@skip\initial at check@@baselineskip@@skip
-    }
+
 \def\analyze at rightcolumn@box#1{%
+    %%
+    %% Looking for the top floats on the right column.
+    %%
+    %% Top box is considered as float if box's height
+    %% is larger then \top@@floatbox at min.
+    %% So, it is a dangerous feature to be used carefully.
+    %%
     \bgroup
         \xdef\top@@floatbox at ht{\z@}%
-        \xdef\top@@floatbox at skip{\z@}%
-        \xdef\top@@section at skip{\z@}%
         \set at split@topskip at to\z@
         \setbox\flushend@@varbox at a\vbox{\strut
             \vskip\z@
@@ -287,350 +273,368 @@
             \unvcopy#1%
             }%
         \setbox\flushend@@tempbox at c\vsplit\flushend@@varbox at a to\p@
-        \wlog at balance@debug{^^J(R)mainbox: \log at box@info{#1}}%
         \flushend@@lastskip at a\ht\flushend@@varbox at a
         \advance\flushend@@lastskip at a\dp\flushend@@varbox at a
         \ifdim\flushend@@lastskip at a>\z@
-            \analyze at nonempty@rightcolumn at box
-        \fi
-    \egroup
-    }
-\def\analyze at nonempty@rightcolumn at box{%
-    \bgroup
-        \var@@temp at a3\p@
-        \loop
-            \flushend@@lastskip at b\ht\flushend@@varbox at a
-            \advance\flushend@@lastskip at b\dp\flushend@@varbox at a
-            \setbox\flushend@@tempbox at c\vsplit\flushend@@varbox at a to\var@@temp at a
-            \ifvoid\flushend@@tempbox at c
-                \advance \var@@temp at a 3\p@
-                \ifdim\var@@temp at a>\flushend@@lastskip at b
-                    \var@@temp at a=-1\p@
-                \fi
-            \else
-                \setbox\flushend@@tempbox at c\vbox{\unvbox\flushend@@tempbox at c}%
-                \ifdim\ht\flushend@@tempbox at c>\top@@floatbox at min
-                    \advance\flushend@@lastskip at b -\ht\flushend@@tempbox at c
-                    \advance\flushend@@lastskip at b -\dp\flushend@@tempbox at c
-                    \advance\flushend@@lastskip at b -\ht\flushend@@varbox at a
-                    \advance\flushend@@lastskip at b -\dp\flushend@@varbox at a
-                    \xdef\top@@floatbox at skip{\the\flushend@@lastskip at b}%
-                    \flushend@@lastskip at b\flushend@@lastskip at a
-                    \advance\flushend@@lastskip at b -\ht\flushend@@varbox at a
-                    \advance\flushend@@lastskip at b -\top@@floatbox at skip
-                    \xdef\top@@floatbox at ht{\the\flushend@@lastskip at b}%
-                    \var@@temp at a=3\p@
+            %% analyze non empty rightcolumn box
+            \var@@temp at a=3\p@
+            \loop
+                \setbox\flushend@@tempbox at c\vsplit\flushend@@varbox at a to\var@@temp at a
+                \flushend@@lastskip at b\ht\flushend@@varbox at a
+                \advance\flushend@@lastskip at b\dp\flushend@@varbox at a
+                \ifvoid\flushend@@tempbox at c
+                    \advance\var@@temp at a by3\p@
+                    \ifdim\var@@temp at a>\flushend@@lastskip at b
+                        %% reach column end, break loop
+                        \var@@temp at a=-1\p@
+                    \fi
                 \else
-                    \advance\flushend@@lastskip at b -\ht\flushend@@tempbox at c
-                    \advance\flushend@@lastskip at b -\dp\flushend@@tempbox at c
-                    \advance\flushend@@lastskip at b -\ht\flushend@@varbox at a
-                    \advance\flushend@@lastskip at b -\dp\flushend@@varbox at a
-                    \ifdim\ht\flushend@@tempbox at c>\topskip
-                    \else
-                        \xdef\top@@section at skip{\the\flushend@@lastskip at b}%
-                    \fi
-                    \var@@temp at a=-1\p@
-                \fi
-            \fi
-        \ifdim \var@@temp at a>\z@
-        \repeat
-        \ifvoid\flushend@@tempbox at c
-        \else
-            \ifdim\top@@section at skip>\z@
-            \else
-                \ifdim\ht\flushend@@tempbox at c>\z@
-                    \setbox\flushend@@varbox at a\vbox{\unvbox\flushend@@tempbox at c}%
-                \fi
-                \flushend@@lastskip at b\ht\flushend@@varbox at a
-                \var@@temp at a=3\p@
-                \loop
-                    \setbox\flushend@@tempbox at c\vsplit\flushend@@varbox at a to\var@@temp at a
-                    \ifvoid\flushend@@tempbox at c
-                        \advance \var@@temp at a 3\p@
-                        \ifdim\var@@temp at a>\flushend@@lastskip at b
-                            \var@@temp at a=-1\p@
-                        \fi
-                    \else
-                        \ifdim\ht\flushend@@tempbox at c<\z@
+                    \setbox\flushend@@tempbox at c\vbox{\unvbox\flushend@@tempbox at c}%
+                    \ifdim\ht\flushend@@tempbox at c>\top@@floatbox at min
+                        %% found float; set height; look for the next
+                        \setbox\flushend@@tempbox at a\vbox{\splitdiscards}%
+                        \ifvoid\flushend@@tempbox at a
                         \else
-                            \var@@temp at a=-1\p@
+                            \advance\flushend@@lastskip at b \ht\flushend@@tempbox at a
+                            \advance\flushend@@lastskip at b \dp\flushend@@tempbox at a
                         \fi
-                    \fi
-                \ifdim \var@@temp at a>\z@
-                \repeat
-                \loop
-                    \setbox\flushend@@varbox at a\vbox{%
-                        \unvbox\flushend@@tempbox at c
-                        \unskip\unkern\unpenalty
-                        \unskip\unkern\unpenalty
-                        \unskip\unkern\unpenalty
-                        \setbox\flushend@@tempbox at c\lastbox
-                        }%
-                    \flushend@@lastskip at b\ht\flushend@@varbox at a
-                    \setbox\flushend@@varbox at a\vbox{%
-                        \unvbox\flushend@@varbox at a
-                        \unskip\unkern\unpenalty
-                        \unskip\unkern\unpenalty
-                        \unskip\unkern\unpenalty
-                        }%
-                    \advance\flushend@@lastskip at b -\ht\flushend@@varbox at a
-                    \ifdim\flushend@@lastskip at b>\topskip
-                        \xdef\top@@section at skip{\the\flushend@@lastskip at b}%
-                    \fi
-                    \ifdim\var@@temp at loop=\ht\flushend@@varbox at a\relax
-                        \advance\var@@loop at iter\@ne
-                    \fi
-                    \var@@temp at loop=\ht\flushend@@varbox at a\relax
-                    \ifnum\var@@loop at iter<3\relax
-                        \wlog at balance@debug{analyze right col: iteration \number\var@@loop at iter; ht \the\var@@temp at loop}%
+                        \advance\flushend@@lastskip at b -\flushend@@lastskip at a
+                        \flushend@@lastskip at b=-\flushend@@lastskip at b
+                        \xdef\top@@floatbox at ht{\the\flushend@@lastskip at b}%
+                        \var@@temp at a=3\p@
                     \else
-                        \wlog at balance@debug{analyze right col loop limit!}%
-                        \ht\flushend@@varbox at a=\z@
+                        %% break loop
+                        \var@@temp at a=-1\p@
                     \fi
-                \ifdim\ht\flushend@@varbox at a>2\topskip
-                    \setbox\flushend@@tempbox at c\vbox{\unvbox\flushend@@varbox at a}%
-                \repeat
-            \fi
+                \fi
+            \ifdim \var@@temp at a>\z@
+            \repeat
         \fi
     \egroup
     }
-\def\combine at columns@for at balance{%
-    \setbox\@outputbox\vbox{\strut
-        \vskip\z@
-        \unvbox\@outputbox
-        }%
-    \set at split@topskip at to\z@
-    \setbox\flushend@@tempbox at c\vsplit\@outputbox to\p@
-    \if at auto@baselineskip
-        %% Trying guess baselineskip value on column break
-        \ifdim\top@@floatbox at skip>\z@
-            \setbox\flushend@@tempbox at c\vsplit\@outputbox to\top@@floatbox at ht
-            \setbox\flushend@@tempbox at c\vbox{\unvbox\flushend@@tempbox at c}%
-        \fi
-        \setbox\@tempboxa\vbox{%
-            \unvbox\flushend@@varbox at a
-            \unskip\unkern\unpenalty
-            \hrule\@height\flushend@@page at rule width\columnwidth
-            \vskip-\flushend@@page at rule
-            \hrule\@height\z@ width\columnwidth
-            \vskip\flushend@@lastskip at c
-            \the\atColsBreak
-            \ifdim\top@@section at skip>\top@@skip@@limit
-                \vskip\top@@section at skip
-            \fi
-            \unvbox\@outputbox
-            \remove at lastbox@at at balancing
-            \the\atColsEnd
-            }%
-        \ifdim\top@@floatbox at skip>\z@
-            \setbox\@outputbox\vbox{\unvbox\flushend@@tempbox at c}%
-        \fi
-    \else
-        %% Ignore baselineskip value on column break
-        \setbox\@tempboxa\vbox{%
-            \unvbox\flushend@@varbox at a
-            \unskip\unkern\unpenalty
-            \hrule\@height\flushend@@page at rule width\columnwidth
-            \vskip-\flushend@@page at rule
-            \hrule\@height\z@ width\columnwidth
-            \the\atColsBreak
-            \unvbox\@outputbox
-            \remove at lastbox@at at balancing
-            \the\atColsEnd
-            }%
-    \fi
-    }
-\def\set at outputbox@with at footnote{%
-    %% footnote in left column
-    \@tempdimb\ht\@tempboxa
-    \ifdim\top@@floatbox at skip>\z@
-        \advance\@tempdimb \top@@floatbox at skip
+
+\def\set at outputbox@with at footnote@and at float{%
+    %%
+    %% The main unit formatting balanced columns.
+    %%
+    %% \flushend@@tempbox at a - left column
+    %% \flushend@@tempbox at c - left column with natural dimensions
+    %% \flushend@@varbox at a  - right column
+    %% \flushend@@varbox at c  - right column with natural dimensions
+    %% \flushend@@floatbox  - rightcolumn top float
+    %% \@leftcolumn         - void or leftcolumn footnote
+    %%
+    \@tempdimb\ht\flushend@@varbox at lastpage
+    \ifdim\top@@floatbox at ht>\z@
+        \advance\@tempdimb \textfloatsep
         \advance\@tempdimb \top@@floatbox at ht
     \fi
-    \advance\@tempdimb \main at box@skip
-    \advance\@tempdimb \ht\@leftcolumn
-    \@tempdimb .5\@tempdimb
-    \advance\@tempdimb -\main at box@skip
-    \advance\@tempdimb -\ht\@leftcolumn
+    \ifdim\main at box@skip>\z@
+        \advance\@tempdimb \main at box@skip
+        \advance\@tempdimb \ht\@leftcolumn
+    \fi
+    \@tempdimb=.5\@tempdimb
+    \ifdim\@tempdimb>\@colht
+        \@tempdimb=\@colht
+    \fi
+    \ifdim\main at box@skip>\z@
+        \advance\@tempdimb -\main at box@skip
+        \advance\@tempdimb -\ht\@leftcolumn
+    \fi
     \set at split@topskip at to\topskip
     \loop
-        \setbox\flushend@@varbox at a\copy\@tempboxa
+        \xdef\saved at tempdimb{\the\@tempdimb}%
+        \setbox\flushend@@varbox at a\copy\flushend@@varbox at lastpage
         \setbox\flushend@@tempbox at a\vsplit\flushend@@varbox at a to\@tempdimb
-        \setbox\flushend@@tempbox at c\vbox{\unvcopy\flushend@@tempbox at a}%
-        \ifdim\top@@floatbox at skip>\z@
-        \setbox\flushend@@varbox at c\vbox{%
-                \unvcopy\@outputbox
-                \vskip\top@@floatbox at skip
+        \ifdim\main at box@skip>\z@
+            \setbox\flushend@@tempbox at c\vbox{%
+                \unvbox\flushend@@tempbox at a
+                \vskip\main at box@skip
+                \vskip\z@ plus\p@
+                \unvcopy\@leftcolumn
+                }%
+        \else
+            \setbox\flushend@@tempbox at c\vbox{\unvbox\flushend@@tempbox at a}%
+        \fi
+        \setbox\flushend@@tempbox at a\vbox to\@tempdimb{\unvcopy\flushend@@tempbox at c}%
+        \xdef\var@@leftcolumn at badness{\the\badness}%
+        \ifdim\top@@floatbox at ht>\z@
+            \setbox\flushend@@varbox at c\vbox{%
+                \unvcopy\flushend@@floatbox
+                \vskip\textfloatsep
+                \vskip\z@ plus\p@ minus\p@
                 \unvbox\flushend@@varbox at a
                 }%
         \else
             \setbox\flushend@@varbox at c\vbox{\unvbox\flushend@@varbox at a}%
         \fi
+        \setbox\flushend@@varbox at a\vbox to\@tempdimb{\unvcopy\flushend@@varbox at c}%
+        \xdef\var@@rightcolumn at badness{\the\badness}%
         \var@@temp at spread=\ht\flushend@@tempbox at c
         \advance\var@@temp at spread by\dp\flushend@@tempbox at c
-        \advance\var@@temp at spread \main at box@skip
-        \advance\var@@temp at spread \ht\@leftcolumn
         \advance\var@@temp at spread by-\ht\flushend@@varbox at c
         \advance\var@@temp at spread by-\dp\flushend@@varbox at c
-        \wlog at balance@debug{Left x: \the\ht\flushend@@tempbox at a
-                            +\the\dp\flushend@@tempbox at a=\the\ht\flushend@@varbox at a
-                            +\the\dp\flushend@@varbox at a::\the\@tempdimb
-                            ^^JLeft 0: \the\ht\flushend@@tempbox at c
-                            +\the\dp\flushend@@tempbox at c::\the\@tempdimb
-                            ^^JRight x: \the\ht\flushend@@varbox at c
-                            +\the\dp\flushend@@varbox at c=\the\ht\flushend@@varbox at a
-                            +\the\dp\flushend@@varbox at a::\the\@tempdimb
-                            ^^JExtra height:\the\var@@temp at spread\space when \the\@tempdimb
-                            }%
+        \wlog at balance@debug{-----
+                            ^^JLeft: \the\ht\flushend@@tempbox at c
+                            +\the\dp\flushend@@tempbox at c\space / \var@@leftcolumn at badness
+                            ^^JRight: \the\ht\flushend@@varbox at c
+                            +\the\dp\flushend@@varbox at c\space / \var@@rightcolumn at badness
+                            ^^JSplit: \the\@tempdimb
+                            ^^JExtra height: \the\var@@temp at spread
+                           }%
+        \ifdim\main at box@skip>\z@
+            \wlog at balance@debug{Footnote: \the\dimexpr\main at box@skip + \the\ht\@leftcolumn\relax}%
+        \fi
+        \ifdim\top@@floatbox at ht>\z@
+            \wlog at balance@debug{Float: \the\dimexpr\the\ht\flushend@@floatbox + \textfloatsep\relax}%
+        \fi
+        \ifnum\var@@leftcolumn at badness<\flushend@@column at badness
+            \ifnum\var@@rightcolumn at badness<\flushend@@column at badness
+                \ifdim\main at box@skip>\z@
+                    \advance\@tempdimb -\main at box@skip
+                    \advance\@tempdimb -\ht\@leftcolumn
+                \fi
+                \var@@temp at spread=\z@
+            \fi
+        \fi
+        \ifdim\var@@temp at spread<\z@
+            \if at left@column at spread
+                \if at right@column at shrink
+                    \ifdim\dimexpr\var@@temp at spread+\pageshrink>\z@
+                        \var@@temp at a=\dimexpr\ht\flushend@@tempbox at c-0.5\var@@temp at spread\relax
+                    \else
+                        \var@@temp at a=-\dimexpr\var@@temp at spread+.5\pageshrink\relax
+                    \fi
+                    \setbox\flushend@@varbox at a\vbox to\var@@temp at a{\unvcopy\flushend@@tempbox at c}%
+                    \ifnum\badness<\flushend@@column at badness
+                        \@tempdimb=\var@@temp at a
+                        \ifdim\main at box@skip>\z@
+                            \advance\@tempdimb -\main at box@skip
+                            \advance\@tempdimb -\ht\@leftcolumn
+                        \fi
+                        \var@@temp at spread=\z@
+                    \fi
+                    \wlog{[leftcolumn badness]: \number\badness\space on \the\var@@temp at a}%
+                    \setbox\flushend@@varbox at a\vbox to\var@@temp at a{\unvcopy\flushend@@varbox at c}%
+                    \wlog{[rightcolumn badness]: \number\badness\space on \the\var@@temp at a}%
+                \else
+                    \setbox\flushend@@varbox at a\vbox to\ht\flushend@@varbox at c{%
+                        \unvcopy\flushend@@tempbox at c
+                        }%
+                    \ifnum\badness<\flushend@@column at badness
+                        \@tempdimb=\ht\flushend@@varbox at c
+                        \ifdim\main at box@skip>\z@
+                            \advance\@tempdimb -\main at box@skip
+                            \advance\@tempdimb -\ht\@leftcolumn
+                        \fi
+                        \var@@temp at spread=\z@
+                    \fi
+                    \wlog{[leftcolumn badness]: \number\badness on \the\ht\flushend@@varbox at c}%
+                    \setbox\flushend@@varbox at a\vbox to\ht\flushend@@varbox at c{%
+                        \unvcopy\flushend@@varbox at c
+                        }%
+                    \wlog{[rightcolumn badness]: \number\badness on \the\ht\flushend@@varbox at c}%
+                \fi
+            \else
+                \if at right@column at shrink
+                    \ifdim\dimexpr\var@@temp at spread+\pageshrink<\z@
+                    \else
+                        \@tempdimb=\ht\flushend@@tempbox at c
+                        \ifdim\main at box@skip>\z@
+                            \advance\@tempdimb -\main at box@skip
+                            \advance\@tempdimb -\ht\@leftcolumn
+                        \fi
+                        \var@@temp at spread=\z@
+                    \fi
+                \fi
+            \fi
+        \else
+            \ifdim\var@@temp at spread>\z@
+                \ifdim\dimexpr\@tempdimb+\p@\relax>\@colht
+                    \@tempdimb=\@colht
+                    \ifdim\main at box@skip>\z@
+                        \advance\@tempdimb -\main at box@skip
+                        \advance\@tempdimb -\ht\@leftcolumn
+                    \fi
+                    \var@@temp at spread=\z@
+                \fi
+            \fi
+        \fi
     \ifdim\var@@temp at spread<\z@
         \advance\@tempdimb 1\p@
     \repeat
-    \flushend@@lastskip at a\the\ht\flushend@@tempbox at c
-    \advance\flushend@@lastskip at a \main at box@skip
-    \advance\flushend@@lastskip at a \ht\@leftcolumn
-    \flushend@@lastskip at b\the\@tempdimb
-    \setbox\flushend@@tempbox at a\vsplit\@tempboxa to\@tempdimb
-    \setbox\@leftcolumn\vbox to\@tempdima{%
-        \vbox to \flushend@@lastskip at a{%
-            \unvbox\flushend@@tempbox at a
-            \vskip\main at box@skip
-            \unvbox\@leftcolumn
-            \vss
-            }%
-        \hrule\@height\flushend@@page at rule width\textwidth
-        \vskip-\flushend@@page at rule
-        \hrule\@height\z@ width\columnwidth
-        \vss
-        }%
-    \global\ht\@leftcolumn=\the\@tempdima
+    %% final construction of the lastpage
     \wlog{- LAST -%
           ^^JExtra skip:\the\var@@temp at spread
-          ^^JLeft:\the\ht\@leftcolumn/\the\dp\@leftcolumn
-          ^^JRight:\the\ht\@tempboxa/\the\dp\@tempboxa
+          ^^JLeft:\the\ht\flushend@@tempbox at c/\the\dp\flushend@@tempbox at c
+          ^^JRight:\the\ht\flushend@@varbox at c/\the\dp\flushend@@varbox at c
+          ^^JSplit: \saved at tempdimb
           ^^JOutput:\the\@tempdimb
+          ^^JPageshrink: \the\pageshrink
+          ^^JPagestretch: \the\pagestretch
+          ^^J at colht:\the\@colht
           }%
-    \ifdim\top@@floatbox at skip>\z@
-        \setbox\@outputbox\vbox to\@tempdima{%
-            \if at right@column at spread
-                \vbox spread\var@@temp at spread{%
-                    \unvbox\@outputbox
-                    \vskip\top@@floatbox at skip
-                    \unvbox\@tempboxa
-                    }%
+    \setbox\flushend@@tempbox at c\vsplit\flushend@@varbox at lastpage to\saved at tempdimb
+    \ifdim\main at box@skip>\z@
+        \@tempdimb=\dimexpr\@tempdimb+\main at box@skip+\ht\@leftcolumn\relax
+        \setbox\@leftcolumn\vbox to\@tempdimb{%
+            \flushend@@lastskip at a=\dimexpr
+                \@tempdimb
+                -\ht\flushend@@tempbox at c
+                -\main at box@skip
+                -\ht\@leftcolumn
+                \relax
+            \unvbox\flushend@@tempbox at c
+            \vskip\main at box@skip
+            \vskip\z@ plus\p@
+            \unvbox\@leftcolumn
+            \prevdepth\z@
+            \hrule\@height\flushend@@page at rule width\textwidth
+            \vskip-\flushend@@page at rule
+            \ifdim\flushend@@lastskip at a>\z@
+                \if at left@column at spread
+                \else
+                    \vss
+                \fi
             \else
-                \vbox spread\var@@temp at spread{%
-                    \unvbox\@outputbox
-                    \vskip\top@@floatbox at skip
-                    \unvbox\@tempboxa
-                    \vss
-                    }%
+                \ifdim\flushend@@lastskip at a<\z@
+                    \if at left@column at shrink
+                    \else
+                        \vss
+                    \fi
+                \fi
             \fi
-            \vss
             }%
     \else
-        \setbox\@outputbox\vbox to\@tempdima{%
-            \if at right@column at spread
-                \vbox spread\var@@temp at spread{%
-                    \unvbox\@tempboxa
-                    }%
+        \setbox\@leftcolumn\vbox to\@tempdimb{%
+            \flushend@@lastskip at a=\dimexpr
+                \@tempdimb-\ht\flushend@@tempbox at c
+                \relax
+            \var@@temp at spread=\dp\flushend@@tempbox at c
+            \unvbox\flushend@@tempbox at c
+            \ifdim\var@@temp at spread>\dp\strutbox
             \else
-                \vbox spread\var@@temp at spread{%
-                    \unvbox\@tempboxa
+                \vskip-\var@@temp at spread
+            \fi
+            \prevdepth\z@
+            \hrule\@height\flushend@@page at rule width\textwidth
+            \vskip-\flushend@@page at rule
+            \ifdim\flushend@@lastskip at a>\z@
+                \if at left@column at spread
+                \else
                     \vss
-                    }%
+                \fi
+            \else
+                \ifdim\flushend@@lastskip at a<\z@
+                    \if at left@column at shrink
+                    \else
+                        \vss
+                    \fi
+                \fi
             \fi
-            \vss
             }%
     \fi
-    }
-\def\set at outputbox@without at footnote{%
-    %% no footnote in left column
-    \@tempdimb \ht\@tempboxa
-    \ifdim\top@@floatbox at skip>\z@
-        \advance\@tempdimb \top@@floatbox at skip
-        \advance\@tempdimb \top@@floatbox at ht
-    \fi
-    \@tempdimb .5\@tempdimb
-    \set at split@topskip at to\topskip
-    \loop
-        \setbox\flushend@@varbox at a\copy\@tempboxa
-        \setbox\flushend@@tempbox at a\vsplit\flushend@@varbox at a to\@tempdimb
-        \setbox\flushend@@tempbox at c\vbox{\unvcopy\flushend@@tempbox at a}%
-        \ifdim\top@@floatbox at skip>\z@
-            \setbox\flushend@@varbox at c\vbox{%
-                \unvcopy\@outputbox
-                \vskip\top@@floatbox at skip
-                \unvbox\flushend@@varbox at a
-                }%
-        \else
-            \setbox\flushend@@varbox at c\vbox{\unvbox\flushend@@varbox at a}%
-        \fi
-        \var@@temp at spread=\ht\flushend@@tempbox at c
-        \advance\var@@temp at spread by\dp\flushend@@tempbox at c
-        \advance\var@@temp at spread by-\ht\flushend@@varbox at c
-        \advance\var@@temp at spread by-\dp\flushend@@varbox at c
-        \wlog at balance@debug{Left x: \the\ht\flushend@@tempbox at a
-                            +\the\dp\flushend@@tempbox at a=\the\ht\flushend@@varbox at a
-                            +\the\dp\flushend@@varbox at a::\the\@tempdimb
-                            ^^JLeft 0: \the\ht\flushend@@tempbox at c
-                            +\the\dp\flushend@@tempbox at c::\the\@tempdimb
-                            ^^JRight x: \the\ht\flushend@@varbox at c
-                            +\the\dp\flushend@@varbox at c=\the\ht\flushend@@varbox at a
-                            +\the\dp\flushend@@varbox at a::\the\@tempdimb
-                            ^^JExtra height:\the\var@@temp at spread\space when \the\@tempdimb
-                           }%
-    \ifdim\var@@temp at spread<\z@ \advance\@tempdimb 1\p@ \repeat
-    \wlog{- LAST -%
-          ^^JExtra skip:\the\var@@temp at spread
-          ^^JLeft:\the\ht\flushend@@tempbox at c/\the\dp\flushend@@tempbox at c
-          ^^JRight:\the\ht\flushend@@varbox at c/\the\dp\flushend@@varbox at c
-          ^^JOutput:\the\@tempdimb
-          }%
-    \setbox\flushend@@tempbox at c\vsplit\@tempboxa to\@tempdimb
-    \setbox\flushend@@varbox at c\vbox{\unvbox\flushend@@tempbox at c}%
-    \setbox\@leftcolumn\vbox to\@tempdima{%
-        \vbox to\@tempdimb{\unvbox\flushend@@varbox at c\vss}%
-        \hrule\@height\flushend@@page at rule width\textwidth
-        \vskip-\flushend@@page at rule
-        \hrule\@height\z@ width\textwidth
-        \vss
-        }%
+    \wlog{FLUSHEND [output]: \the\@tempdimb
+          ^^JFLUSHEND [leftcolumn badness]: \number\badness
+         }%
     \global\ht\@leftcolumn=\the\@tempdima
-    \ifdim\top@@floatbox at skip>\z@
-        \setbox\@outputbox\vbox to\@tempdima{%
-            \if at right@column at spread
-                \vbox spread\var@@temp at spread{%
-                    \unvbox\@outputbox
-                    \vskip\top@@floatbox at skip
-                    \unvbox\@tempboxa
-                    }%
+    \ifdim\top@@floatbox at ht>\z@
+        \setbox\@outputbox\vbox to\@tempdimb{%
+            \flushend@@lastskip at a=\dimexpr
+                \@tempdimb
+                -\ht\flushend@@floatbox
+                -\textfloatsep
+                -\ht\flushend@@varbox at lastpage
+                \relax
+            \unvbox\flushend@@floatbox
+            \vskip\textfloatsep
+            \vskip\z@ plus\p@ minus\p@
+            \unvbox\flushend@@varbox at lastpage
+            \ifdim\flushend@@lastskip at a>\z@
+                \if at right@column at spread
+                \else
+                    \vss
+                \fi
             \else
-                \vbox spread\var@@temp at spread{%
-                    \unvbox\@outputbox
-                    \vskip\top@@floatbox at skip
-                    \unvbox\@tempboxa
-                    \vss
-                    }%
+                \ifdim\flushend@@lastskip at a<\z@
+                    \if at right@column at shrink
+                    \else
+                        \vss
+                    \fi
+                \fi
             \fi
-            \vss
             }%
     \else
-        \setbox\@outputbox\vbox to\@tempdima{%
-            \if at right@column at spread
-                \vbox spread\var@@temp at spread{%
-                    \unvbox\@tempboxa
-                    }%
+        \setbox\@outputbox\vbox to\@tempdimb{%
+            \flushend@@lastskip at a=\dimexpr
+                \@tempdimb-\ht\flushend@@varbox at lastpage
+                \relax
+            \unvbox\flushend@@varbox at lastpage
+            \ifdim\flushend@@lastskip at a>\z@
+                \if at right@column at spread
+                \else
+                    \vss
+                \fi
             \else
-                \vbox spread\var@@temp at spread{%
-                    \unvbox\@tempboxa
-                    \vss
-                    }%
+                \ifdim\flushend@@lastskip at a<\z@
+                    \if at right@column at shrink
+                    \else
+                        \vss
+                    \fi
+                \fi
             \fi
-            \vss
             }%
     \fi
+    \wlog{FUSHEND [rightcolumn badness]: \number\badness}%
+    \global\ht\@outputbox=\the\@tempdima
     }
-\def\last at outputdblcol@modern{%
+
+\newdimen\oldbreak at skip
+
+\def\combine at columns@for at balance{%
+    %%
+    %% Combines lastpage columns for balancing.
+    %%
+    \setbox\flushend@@tempbox at a\vbox{\pagediscards}%
+    \oldbreak at skip=\ht\flushend@@tempbox at a
+    \advance\oldbreak at skip by\dp\flushend@@tempbox at a
+    \setbox\@outputbox\vbox{\strut
+        \vskip\z@
+        \unvbox\@outputbox
+        }%
+    \set at split@topskip at to\z@
+    %% Removes topskip
+    \setbox\flushend@@tempbox at c\vsplit\@outputbox to\p@
+    \ifdim\top@@floatbox at ht>\z@
+        %% removes top float from right column (if option enabled)
+        \setbox\flushend@@floatbox\vsplit\@outputbox to\top@@floatbox at ht
+        \setbox\flushend@@floatbox\vbox{\unvbox\flushend@@floatbox}%
+    \fi
+    \setbox\flushend@@varbox at lastpage\vbox{%
+        \remove at empty@lastbox at at@balancing\flushend@@varbox at a
+        \unvbox\flushend@@varbox at a
+        \hrule\@height\flushend@@page at rule width\columnwidth
+        \vskip-\flushend@@page at rule
+        \hrule\@height\z@ width\columnwidth
+        \penalty\z@
+        \ifdim\var@@temp at a>\z@
+            \ifdim\var@@temp at a>\dp\strutbox
+            \else
+                \vskip\var@@temp at a
+            \fi
+        \fi
+        \vskip\oldbreak at skip
+        \the\atColsBreak
+        \remove at empty@lastbox at at@balancing\@outputbox
+        \unvbox\@outputbox
+        \the\atColsEnd
+        }%
+    }
+
+\def\last at outputdblcol{%
+    %%
+    %% Redefined \@outputdblcol with columns balancing.
+    %%
     \if at firstcolumn
         \global \@firstcolumnfalse
         \global\setbox\@leftcolumn\copy\@outputbox
@@ -656,207 +660,57 @@
         \advance\@tempdima by\dp\@leftcolumn
         \set at split@topskip at to\topskip
         \var@@temp at spread=\wd\@outputbox
-        \get@@footnoterule@@box
-        \xdef\main at box@height{\the\ht\@leftcolumn}%
+        \xdef\top@@floatbox at ht{\z@}%
         \xdef\main at box@skip{\z@}%
-        \reset at check@@baselineskip@@skip\relax\relax\flushend@@lastskip at c
-        \setbox\flushend@@varbox at a\vbox{\unvcopy\@leftcolumn}%
-        \var@@loop at iter\z@ \var@@temp at loop\z@
-        \analyze at leftcolumn@box\flushend@@varbox at a
-        \setbox\flushend@@varbox at a\vbox{\unvcopy\@outputbox}%
-        \var@@loop at iter\z@ \var@@temp at loop\z@
-        \analyze at rightcolumn@box\flushend@@varbox at a
-        \ifdim\main at box@skip>\z@
-            %% footnote in left column
-            \set at split@topskip at to\z@
-            \setbox\flushend@@varbox at a\vsplit\@leftcolumn to\main at box@height
-        \else
-            %% no footnote in left column
-            \setbox\flushend@@varbox at a\box\@leftcolumn
-        \fi
         \ifdim\var@@temp at spread>\z@
             %% rightcolumn non empty
-            \combine at columns@for at balance
-       \else
-            %% rightcolumn empty
-            \setbox\@tempboxa\vbox{%
-                \unvbox\flushend@@varbox at a
-                \remove at lastbox@at at balancing
-                \the\atColsEnd
-                }%
-       \fi
-        \ifdim\main at box@skip>\z@
-            %% footnote in left column
-            \set at outputbox@with at footnote
-        \else
-            %% no footnote in left column
-           \set at outputbox@without at footnote
-        \fi
-        \setbox\@outputbox \vbox {%
-            \hb at xt@\textwidth {%
-                \hb at xt@\columnwidth {%
-                    \fmt at box@adds{\box\@leftcolumn}\hss}%
-                    \hfil
-                    \vrule \@width\columnseprule
-                    \hfil
-                    \hb at xt@\columnwidth {%
-                        \fmt at box@adds{\box\@outputbox}\hss}%
-                        }%
-                    }%
-        \global\let\@outputdblcol\saved at orig@@outputdblcol
-        \global\atColsEnd{}%
-        \ifvoid\hold at viper
-        \else
-            \setbox\@outputbox\vbox{\box\hold at viper\box\@outputbox}%
-        \fi
-        \@combinedblfloats
-        \csname @setmarks\endcsname
-        \@outputpage
-        \begingroup
-            \@dblfloatplacement
-            \@startdblcolumn
-            \@whilesw\if at fcolmade\fi
-                {\@outputpage\@startdblcolumn}%
-            \ifvoid\@viper
+            \setbox\flushend@@varbox at a\vbox{\unvcopy\@outputbox}%
+            \ifdim\dimexpr\@colht-\ht\flushend@@varbox at a>\z@\relax
+                \if at footnote@check
+                    \get@@footnoterule@@box
+                    \xdef\main at box@height{\the\ht\@leftcolumn}%
+                    \setbox\flushend@@varbox at a\vbox{\unvcopy\@leftcolumn}%
+                    \var@@loop at iter\z@ \var@@temp at loop\z@
+                    \analyze at leftcolumn@box\flushend@@varbox at a
+                \fi
+                \ifdim\top@@floatbox at min<\maxdimen
+                    \setbox\flushend@@varbox at a\vbox{\unvcopy\@outputbox}%
+                    \var@@loop at iter\z@ \var@@temp at loop\z@
+                    \analyze at rightcolumn@box\flushend@@varbox at a
+                \fi
+                \ifdim\main at box@skip>\z@
+                    %% footnote in left column
+                    \set at split@topskip at to\z@
+                    \setbox\flushend@@varbox at a\vsplit\@leftcolumn to\main at box@height
+                \else
+                    %% no footnote in left column
+                    \setbox\flushend@@varbox at a\box\@leftcolumn
+                \fi
+                \combine at columns@for at balance
             \else
-                \global\setbox\@viper\vbox{%
-                    \vskip-\stripsep
-                    \unvbox\@viper
-                    }%
-                \csname @viperoutput\endcsname
+                \xdef\main at box@skip{\maxdimen}%
             \fi
-        \endgroup
-    \fi
-    }
-\def\last at outputdblcol@ancient{%
-    \if at firstcolumn
-        \global\@firstcolumnfalse
-        \global\setbox\@leftcolumn\box\@outputbox
-    \else
-        \global\@firstcolumntrue
-        \@tempdima\ht\@leftcolumn
-        \set at split@topskip at to\topskip
-        \if at auto@baselineskip
-            \setbox\@tempboxa\vbox{%
-                \unvcopy\@leftcolumn
-                \global\flushend@@lastskip at c\lastskip
-                \global\flushend@@lastskip at b\lastskip
-                \loop
-                    \global\flushend@@lastskip at a\flushend@@lastskip at b
-                    \unskip\unpenalty
-                    \global\flushend@@lastskip at b\lastskip
-                    \global\advance\flushend@@lastskip at c by\lastskip
-                \ifdim\flushend@@lastskip at b=-\flushend@@lastskip at a
-                    \global\advance\flushend@@lastskip at c by-\lastskip
-                \else
-                \repeat
-                \ifdim\flushend@@lastskip at b=-\flushend@@lastskip at a
-                    \ifdim\flushend@@lastskip at b=\z@
-                        \setbox\flushend@@varbox at a\lastbox
-                        \global\advance\flushend@@lastskip at c by\ht\flushend@@varbox at a
-                        \global\advance\flushend@@lastskip at c by\lastskip
-                        \unskip\unpenalty
-                        \setbox\flushend@@varbox at a\lastbox
-                        \global\advance\flushend@@lastskip at c by\dp\flushend@@varbox at a
-                    \else
-                        \global\flushend@@lastskip at c\lastskip
-                        \global\advance\flushend@@lastskip at c by\topskip
-                    \fi
-                \fi
-                \global\advance\flushend@@lastskip at c by-\topskip
-                }%
-            \setbox\@tempboxa\vbox{%
-                \unvbox\@leftcolumn
-                \unskip\unpenalty
-                \vskip\flushend@@lastskip at c
-                \hrule\@height\flushend@@page at rule width\columnwidth
-                \vskip-\flushend@@page at rule
-                \hrule\@height\z@ width\textwidth
-                \the\atColsBreak
-                \unvbox\@outputbox
-                \remove at lastbox@at at balancing
-                \the\atColsEnd
-            }%
         \else
-            \setbox\@tempboxa\vbox{%
-                \unvbox\@leftcolumn
-                \setbox\z@\lastbox
-                \unskip
-                \hrule\@height\flushend@@page at rule width\columnwidth
-                \vskip-\flushend@@page at rule
-                \hrule\@height\z@ width\textwidth
-                \the\atColsBreak
-                \unvbox\@outputbox
-                \remove at lastbox@at at balancing
-                \the\atColsEnd
-                }%
+                %% rightcolumn empty
+                \setbox\flushend@@varbox at a\box\@leftcolumn
+                \setbox\flushend@@varbox at lastpage\vbox{%
+                    \remove at empty@lastbox at at@balancing\flushend@@varbox at a
+                    \unvbox\flushend@@varbox at a
+                    \the\atColsEnd
+                    }%
         \fi
-        \@tempdimb .5\ht\@tempboxa
-        \loop
-            \setbox\flushend@@tempbox at a\copy\@tempboxa
-            \setbox\flushend@@tempbox at c\vbox to\@tempdimb{%
-                \vsplit\flushend@@tempbox at a to\@tempdimb
-                \vss
-                \vsplit\flushend@@tempbox at a to\@tempdimb
-                }%
-            \wlog{Extra height:\the\ht\flushend@@tempbox at a\space when \the\@tempdimb}%
-        \ifvoid\flushend@@tempbox at a
-        \else
-            \advance\@tempdimb 1\p@
-        \repeat
-        \loop
-            \setbox\flushend@@tempbox at a\copy\@tempboxa
-            \setbox\flushend@@tempbox at c\vbox to\@tempdimb{%
-                \vsplit\flushend@@tempbox at a to\@tempdimb
-                \vss
-                }%
-            \wlog{(2)Left:\the\ht\flushend@@tempbox at c\space
-                    Right:\the\ht\flushend@@tempbox at a\space
-                   Output:\the\@tempdimb
-                 }%
-        \ifdim\ht\flushend@@tempbox at c<\ht\flushend@@tempbox at a
-            \@tempdimb=\the\ht\flushend@@tempbox at a
-        \repeat
-        \wlog{- LAST -^^JExtra skip: \the\z@
-                      ^^JLeft:\the\ht\flushend@@tempbox at c
-                      ^^JRight:\the\ht\flushend@@tempbox at a
-                      ^^JOutput:\the\@tempdimb
-             }%
-        \setbox\flushend@@tempbox at c\vbox to\@tempdimb{%
-            \vsplit\@tempboxa to\@tempdimb
-            \vss
-            }%
-        \setbox\@leftcolumn\vbox to\@tempdima{%
-            \fmt at vbox@adds[\columnwidth]{%
-                \vbox to\@tempdimb{%
-                    \unvbox
-                    \flushend@@tempbox at c
-                    }%
-                }%
-            \hrule\@height\flushend@@page at rule
-            \vskip-\flushend@@page at rule
-            \hrule\@height\z@ width\textwidth
-            \vss
-            }%
-        \setbox\@outputbox\vbox to\@tempdima{%
-            \fmt at vbox@adds[\columnwidth]{%
-                \vbox to\@tempdimb{%
-                    \unvbox\@tempboxa
-                    \vskip\z@
-                    }%
-                }%
-            \hrule\@height\flushend@@page at rule
-            \vskip-\flushend@@page at rule
-            \hrule\@height\z@ width\textwidth
-            \vss
-            }%
+        \ifdim\main at box@skip<\maxdimen
+            \set at outputbox@with at footnote@and at float
+        \fi
         \setbox\@outputbox\vbox{%
             \hb at xt@\textwidth{%
-                \hb at xt@\columnwidth{\box\@leftcolumn\hss}%
+                \hb at xt@\columnwidth{%
+                    \fmt at box@adds{\box\@leftcolumn}\hss}%
                 \hfil
                 \vrule \@width\columnseprule
                 \hfil
-                \hb at xt@\columnwidth{\box\@outputbox\hss}%
+                \hb at xt@\columnwidth{%
+                    \fmt at box@adds{\box\@outputbox}\hss}%
                 }%
             }%
         \global\let\@outputdblcol\saved at orig@@outputdblcol
@@ -866,6 +720,7 @@
             \setbox\@outputbox\vbox{\box\hold at viper\box\@outputbox}%
         \fi
         \@combinedblfloats
+        \csname @setmarks\endcsname
         \@outputpage
         \begingroup
             \@dblfloatplacement
@@ -883,18 +738,21 @@
         \endgroup
     \fi
     }
-\usepackage{etoolbox}
-\AtBeginDocument{%
+
+\def\initialize at flushend{%
+    %%
+    %%  Activates flushend package functionality.
+    %%
     \global\let\saved at orig@@outputdblcol\@outputdblcol
-    \if at ancient@balance at version
-        \global\let\last at outputdblcol\last at outputdblcol@ancient
-    \else
-        \global\let\last at outputdblcol\last at outputdblcol@modern
-    \fi
     \global\let\balanced@@outputdblcol\last at outputdblcol
-    \preto\enddocument{\let\@outputdblcol\balanced@@outputdblcol}%
-    \appto\footnoterule{\vskip\z@}%
+    \edef\enddocument{%
+        \unexpanded{\let\@outputdblcol\balanced@@outputdblcol}%
+        \unexpanded\expandafter{\enddocument}%
+        }%
+    \g at addto@macro\footnoterule{\vskip\z@}%
+    \savingvdiscards=\@ne
     }
+
 \def\flushcolsend{\global\let\@outputdblcol\last at outputdblcol}
 \def\raggedcolsend{\global\let\@outputdblcol\saved at orig@@outputdblcol}
 \def\flushend{\global\let\balanced@@outputdblcol\last at outputdblcol}
@@ -902,6 +760,7 @@
 \if at balance@debug
     \showcolsendrule
 \fi
+\AtBeginDocument{\initialize at flushend}
 \endinput
 %%
 %% End of file `flushend.sty'.

Modified: trunk/Master/texmf-dist/tex/latex/sttools/midfloat.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/sttools/midfloat.sty	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/tex/latex/sttools/midfloat.sty	2021-10-11 20:25:22 UTC (rev 60736)
@@ -6,9 +6,8 @@
 %%
 %% midfloat.dtx  (with options: `package')
 %% 
-%% Copyright (C) 1997-2012 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
-%% VTeX Ltd., Akademijos 4, Vilnius, Lithuania
-%% http://www.vtex.lt/tex/download/macros/
+%% Copyright (C) 1997-2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+%% UAB VTeX, Mokslininkų 2A, LT-08412 Vilnius, Lithuania
 %% --------------------------------------------------------------------------
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3

Modified: trunk/Master/texmf-dist/tex/latex/sttools/stabular.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/sttools/stabular.sty	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/tex/latex/sttools/stabular.sty	2021-10-11 20:25:22 UTC (rev 60736)
@@ -6,9 +6,8 @@
 %%
 %% stabular.dtx  (with options: `package')
 %% 
-%% Copyright (C) 1998-2014 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
-%% VTeX Ltd., Akademijos 4, Vilnius, Lithuania
-%% http://www.vtex.lt/tex/download/macros/
+%% Copyright (C) 1998-2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+%% UAB VTeX, Mokslininkų 2A, LT-08412 Vilnius, Lithuania
 %% --------------------------------------------------------------------------
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3
@@ -22,7 +21,7 @@
 %%
 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
 \ProvidesPackage{stabular}
-    [2014/03/20 v2.0 Improve tabular environment]
+    [2021/10/04 v2.1 Improve tabular environment]
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesPackage{stabular}[2014/03/20]
 \def\use@@pkg@@array@@variant{0}
@@ -88,10 +87,10 @@
     \@preamble
   }
 \def\pkgarray@@stabarray{\@ifnextchar[{\pkgarray@@sarray}{\pkgarray@@sarray[c]}}
-\def\pkgarray at stabular{\gdef\@halignto{}\pkgarray@@stabular}
+\def\pkgarray at stabular{\def\@halignto{}\pkgarray@@stabular}
 \expandafter\def\csname pkgarray at stabular*\endcsname#1{%
        \setlength\dimen@{#1}%
-       \xdef\@halignto{to\the\dimen@}\pkgarray@@stabular}
+       \edef\@halignto{to\the\dimen@}\pkgarray@@stabular}
 \def\pkgarray@@stabular{%
   \leavevmode
   \bgroup

Modified: trunk/Master/texmf-dist/tex/latex/sttools/stfloats.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/sttools/stfloats.sty	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/tex/latex/sttools/stfloats.sty	2021-10-11 20:25:22 UTC (rev 60736)
@@ -6,7 +6,7 @@
 %%
 %% stfloats.dtx  (with options: `package')
 %% 
-%% Copyright (C) 1997-2017 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+%% Copyright (C) 1997-2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
 %% VTeX UAB, Mokslininku 2a, Vilnius, Lithuania
 %% --------------------------------------------------------------------------
 %% This work may be distributed and/or modified under the

Modified: trunk/Master/texmf-dist/tex/latex/sttools/texsort.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/sttools/texsort.sty	2021-10-11 20:25:04 UTC (rev 60735)
+++ trunk/Master/texmf-dist/tex/latex/sttools/texsort.sty	2021-10-11 20:25:22 UTC (rev 60736)
@@ -6,9 +6,8 @@
 %%
 %% texsort.dtx  (with options: `package')
 %% 
-%% Copyright (C) 2000-2012 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
-%% VTeX Ltd., Akademijos 4, Vilnius, Lithuania
-%% http://www.vtex.lt/tex/download/macros/
+%% Copyright (C) 2000-2021 by Sigitas Tolu\v{s}is <sigitas at vtex.lt>
+%% UAB VTeX, Mokslininkų 2A, LT-08412 Vilnius, Lithuania
 %% --------------------------------------------------------------------------
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3



More information about the tex-live-commits mailing list.