summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/sttools/cuted.dtx
blob: 3f927c1046b370d71d81c5e4b4a80f198de8b267 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
% \iffalse meta-comment/*%    \end{macrocode}*/
%
% Copyright (C) 2021 by Sigitas Tolu\v{s}is <sigitas@vtex.lt>
% ---------------------------------------------------------------------------
% 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.
% The latest version of this license is in
%   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.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Sigitas Tolu\v{s}is.
%
% This work consists of the files cuted.dtx and cuted.ins
% and the derived filebase cuted.sty.
%
% \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-2021 by Sigitas Tolu\v{s}is <sigitas@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
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   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.
%%
%% PURPOSE:   Insert some onecolumn material in full-width on double-column page.
%%
%</package>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{cuted}
%<*package>
    [2021/10/04 v2.0 Mixing onecolumn and twocolumn modes]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{cuted}[2021/10/04]
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\OnlyDescription
\begin{document}
  \DocInput{cuted.dtx}
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{1136}
%
% \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
%   Lower-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
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{}{1997/09/02}{improved column balancing}
% \changes{}{1997/09/03}{float control for \cs{@colroom} setting}
% \changes{}{1997/09/04}{improved \cs{@colroom} setting}
% \changes{}{1997/09/05}{checking for \cs{@viper} and \cs{hold@viper}}
% \changes{}{1997/09/09}{compatibility with flushend.sty}
% \changes{}{1997/09/22}{improved \cs{output} ir \cs{@specialoutput}}
% \changes{}{1997/10/01}{improved \cs{output} ir \cs{@addviper}}
% \changes{}{1998/10/23}{pakeistas koloneliu sujungimas}
% \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}
%
% \providecommand*{\url}{\texttt}
% \GetFileInfo{cuted.dtx}
% \title{The \textsf{cuted} package}
% \author{Sigitas Tolu\v{s}is\\ \url{sigitas@vtex.lt}}
% \date{\fileversion~from \filedate}
%
% \maketitle
%
% \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).
%
% 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.
%
% \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{preCutedStrip}\marg{tokens}
% \\\noindent Before the strip |\stripsep| glue and |\the\preCutedStrip| token list \meta{tokens} are added.   
%
% \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
% \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.
%
% \subsection{Package options}
%
% \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
%   \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}
%
% \iffalse
%<*package>
% \fi
%
%/*%    \begin{macrocode}*/
%    \begin{macrocode}
%

\newif\if@right@column@spread \@right@column@spreadtrue
\newif\if@right@column@shrink \@right@column@shrinktrue
\newif\if@left@column@spread \@left@column@spreadtrue
\newif\if@left@column@shrink \@left@column@shrinktrue
\newif\ifcuted@@debug \cuted@@debugfalse

\DeclareOption{spread}{%
    \global\@left@column@spreadtrue
    \global\@right@column@spreadtrue
    }
\DeclareOption{nospread}{%
    \global\@left@column@spreadfalse
    \global\@right@column@spreadfalse
    }
\DeclareOption{lspread}{\global\@left@column@spreadtrue}
\DeclareOption{nolspread}{\global\@left@column@spreadfalse}
\DeclareOption{rspread}{\global\@right@column@spreadtrue}
\DeclareOption{norspread}{\global\@right@column@spreadfalse}

\DeclareOption{shrink}{%
    \global\@left@column@shrinktrue
    \global\@right@column@shrinktrue
    }
\DeclareOption{noshrink}{%
    \global\@left@column@shrinkfalse
    \global\@right@column@shrinkfalse
    }
\DeclareOption{lshrink}{\global\@left@column@shrinktrue}
\DeclareOption{nolshrink}{\global\@left@column@shrinkfalse}
\DeclareOption{rshrink}{\global\@right@column@shrinktrue}
\DeclareOption{norshrink}{\global\@right@column@shrinkfalse}

\DeclareOption{debug}{\global\cuted@@debugtrue}
\DeclareOption{nodebug}{\global\cutted@@debugfalse}

\ProcessOptions

\newif\if@lastviper \@lastviperfalse
\newtoks\At@ViperColsBreak \At@ViperColsBreak{}
\newtoks\preCutedStrip \preCutedStrip{}
\newtoks\postCutedStrip \postCutedStrip{}
\newbox\cuted@@tempbox@a
\newbox\cuted@@tempbox@c
\newbox\cuted@@tempbox@var
\@ifundefined{hold@viper}
    {\newbox\hold@viper}{}
\@ifundefined{@viper}
    {\newbox\@viper}{}
\newbox\cuted@@varbox@a
\newbox\cuted@@varbox@c
\newdimen\cuted@@tempdim@spread
\newdimen\cuted@@tempdim@a
\newdimen\cuted@@tempdim@b
\newdimen\ht@hold@viper
\newdimen\ht@viper
\newdimen\var@@pagediscards@ht \var@@pagediscards@ht=\z@
\@ifundefined{stripsep}
    {\newskip\stripsep \stripsep 15\p@ plus 2\p@ minus 2\p@}{}
\newcount\viper@penalty
\mathchardef\@Mv=10005
\def\cuted@@column@badness{101}
\def\cuted@@page@rule{\z@}
\savingvdiscards=\@ne

\def\cuted@@wlog@debug#1{\ifcuted@@debug \wlog{#1}\fi}

\def\set@split@topskip@to#1{%
    \splittopskip=#1\relax
    \vfuzz=\maxdimen
    \vbadness=\maxdimen
    }

\def\oldcolsbreak#1{\global\At@ViperColsBreak{#1}}

\def\on@stripcols@break{%
    %%
    %% adds original vertical page break skip
    %%
    \begingroup
        \setbox\cuted@@tempbox@var\vbox{\pagediscards}%
        \ifvoid\cuted@@tempbox@var
        \else
            \global\var@@pagediscards@ht=\ht\cuted@@tempbox@var
            \global\advance\var@@pagediscards@ht by\dp\cuted@@tempbox@var
        \fi
    \endgroup
    \ifdim\var@@pagediscards@ht=\z@
    \else
        \vskip\var@@pagediscards@ht
    \fi
    }

\def\@outputdblcol{%
    \if@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
        \global\@firstcolumntrue
        \setbox\@outputbox\vbox{%
            \hb@xt@\textwidth{%
                \hb@xt@\columnwidth{\box\@leftcolumn \hss}%
                \hfil
                {\normalcolor\vrule \@width\columnseprule}%
                \hfil
                \hb@xt@\columnwidth{\box\@outputbox \hss}%
                }%
            }%
        \ifvoid\hold@viper
        \else
              \setbox\@outputbox\vbox to\textheight{%
                  \box\hold@viper
                  \box\@outputbox
                  \vss
                  }%
        \fi
        \@combinedblfloats
        \@setmarks
        \@outputpage
        \begingroup
            \@dblfloatplacement
            \@startdblcolumn
            \@whilesw\if@fcolmade \fi
                {\@outputpage \@startdblcolumn}%
            \ifvoid\@viper
            \else
                \global\setbox\@viper\vbox{%
                    \vskip-\stripsep
                    \unvbox\@viper
                    }%
                \@viperoutput
            \fi
        \endgroup
    \fi
    }
\def\strip{%
    \ifinner
        \@parmoderr
        \viper@penalty\z@
    \else
        \viper@penalty=-\@Mv
    \fi
    \global\setbox\@viper\vbox\bgroup
        \hsize\textwidth
        \@parboxrestore
        \col@number=\@ne
        \vrule height\topskip width\z@ depth\z@
    }
\def\endstrip{%
    \egroup
    \ifnum\viper@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 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@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@nobreak
                \else
                    \addpenalty \interlinepenalty
                \fi
            \fi
        \fi
   \fi
  }
\def\@addviper{%
    \@insertfalse
    \def\var@@thecol@num{2}%
    \if@firstcolumn
        \def\var@@thecol@num{1}%
        \@reqcolroom=.5\@pageht
        \ht@viper=\@reqcolroom
        \advance\@reqcolroom by\ht\@viper
        \advance\@reqcolroom by\stripsep
    \else
        \@reqcolroom=\@colht
        \advance\@reqcolroom by\@pageht
        \ht@viper.5\@reqcolroom
        \@reqcolroom=\ht@viper
        \advance\@reqcolroom by\ht\@viper
        \advance\@reqcolroom by\stripsep
        \global\setbox\@holdpg\vbox{%
            \setbox\cuted@@tempbox@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@a
                \fi
                }%
            \unskip\unkern\unpenalty
            \on@stripcols@break
            \the\At@ViperColsBreak
            \unvbox\@holdpg
            }%
        \global\At@ViperColsBreak{}%
        \ht@viper=.5\ht\@holdpg
        \ifdim\ht@viper>\@colht
            \ht@viper=\@colht
        \fi
    \fi
    %%
    %% calculations for breaking
    %%
    \ifvoid\hold@viper
        \ht@hold@viper=\z@
    \else
        \ht@hold@viper=\ht\hold@viper
    \fi
    \cuted@@tempdim@b\ht@viper
    \set@split@topskip@to\topskip
    \loop
        \xdef\saved@tempdimb{\the\cuted@@tempdim@b}%
        \setbox\cuted@@varbox@a\copy\@holdpg
        \setbox\cuted@@tempbox@a\vsplit\cuted@@varbox@a to\cuted@@tempdim@b
        %% set leftcolumn boxes
        \setbox\cuted@@tempbox@c\vbox{\unvbox\cuted@@tempbox@a}%
        \setbox\cuted@@tempbox@a\vbox to\cuted@@tempdim@b{\unvcopy\cuted@@tempbox@c}%
        \xdef\var@@leftcolumn@badness{\the\badness}%
        %% set rightcolumn boxes
        \setbox\cuted@@varbox@c\vbox{\unvbox\cuted@@varbox@a}%
        \setbox\cuted@@varbox@a\vbox to\cuted@@tempdim@b{\unvcopy\cuted@@varbox@c}%
        \xdef\var@@rightcolumn@badness{\the\badness}%
        %% analyzing split goodness
        \cuted@@tempdim@spread=\ht\cuted@@tempbox@c
        \advance\cuted@@tempdim@spread by\dp\cuted@@tempbox@c
        \advance\cuted@@tempdim@spread by-\ht\cuted@@varbox@c
        \advance\cuted@@tempdim@spread by-\dp\cuted@@varbox@c
        \cuted@@wlog@debug{CUTED [-----]%
              ^^JLeft: \the\ht\cuted@@tempbox@c
              +\the\dp\cuted@@tempbox@c\space/\var@@leftcolumn@badness
              ^^JRight: \the\ht\cuted@@varbox@c
              +\the\dp\cuted@@varbox@c\space/\var@@rightcolumn@badness
              ^^JSplit: \the\cuted@@tempdim@b
              ^^JExtra height: \the\cuted@@tempdim@spread
             }%
        \ifnum\var@@leftcolumn@badness<\cuted@@column@badness
            \ifnum\var@@rightcolumn@badness<\cuted@@column@badness
                \cuted@@tempdim@spread=\z@
            \fi
        \fi
        \ifdim\cuted@@tempdim@spread<\z@
            \if@left@column@spread
                \if@right@column@shrink
                    \ifdim\dimexpr\cuted@@tempdim@spread+\pageshrink>\z@
                        \cuted@@tempdim@a=\dimexpr\ht\cuted@@tempbox@c-0.5\cuted@@tempdim@spread\relax
                    \else
                        \cuted@@tempdim@a=-\dimexpr\cuted@@tempdim@spread+.5\pageshrink\relax
                    \fi
                    \setbox\cuted@@varbox@a\vbox to\cuted@@tempdim@a{\unvcopy\cuted@@tempbox@c}%
                    \ifnum\badness<\cuted@@column@badness
                        \cuted@@tempdim@b=\cuted@@tempdim@a
                        \cuted@@tempdim@spread=\z@
                    \fi
                    \cuted@@wlog@debug{CUTED [leftcolumn badness]: \number\badness\space on \the\cuted@@tempdim@a}%
                    \setbox\cuted@@varbox@a\vbox to\cuted@@tempdim@a{\unvcopy\cuted@@varbox@c}%
                    \cuted@@wlog@debug{CUTED [rightcolumn badness]: \number\badness\space on \the\cuted@@tempdim@a}%
                \else
                    \setbox\cuted@@varbox@a\vbox to\ht\cuted@@varbox@c{%
                        \unvcopy\cuted@@tempbox@c
                        }%
                    \ifnum\badness<\cuted@@column@badness
                        \@tempdimb=\ht\cuted@@varbox@c
                        \cuted@@tempdim@spread=\z@
                    \fi
                    \cuted@@wlog@debug{CUTED [leftcolumn badness]: \number\badness on \the\ht\cuted@@varbox@c}%
                    \setbox\cuted@@varbox@a\vbox to\ht\cuted@@varbox@c{%
                        \unvcopy\cuted@@varbox@c
                        }%
                    \cuted@@wlog@debug{CUTED [rightcolumn badness]: \number\badness on \the\ht\cuted@@varbox@c}%
                \fi
            \else
                \if@right@column@shrink
                    \ifdim\dimexpr\cuted@@tempdim@spread+\pageshrink<\z@
                    \else
                        \cuted@@tempdim@b=\ht\cuted@@tempbox@c
                        \cuted@@tempdim@spread=\z@
                    \fi
                \fi
            \fi
        \else
            \ifdim\cuted@@tempdim@spread>\z@
                \ifdim\dimexpr\@tempdimb+\p@\relax>\@colht
                    \cuted@@tempdim@b=\@colht
                    \cuted@@tempdim@spread=\z@
                \fi
            \fi
        \fi
    \ifdim\cuted@@tempdim@spread<\z@
        \advance\cuted@@tempdim@b 1\p@
    \repeat
    \wlog{CUTED [- LAST -]%
          ^^JExtra skip:\the\cuted@@tempdim@spread
          ^^JLeft:\the\ht\cuted@@tempbox@c/\the\dp\cuted@@tempbox@c
          ^^JRight:\the\ht\cuted@@varbox@c/\the\dp\cuted@@varbox@c
          ^^JSplit: \saved@tempdimb
          ^^JOutput:\the\cuted@@tempdim@b
          ^^JPageshrink: \the\pageshrink
          ^^JPagestretch: \the\pagestretch
          ^^J@colht:\the\@colht
          }%
    %%
    %% final construction of the cuted page above strip
    %%
    \setbox\cuted@@tempbox@c\vsplit\@holdpg to\saved@tempdimb
    \setbox\cuted@@tempbox@a\vbox to\cuted@@tempdim@b{%
        \cuted@@tempdim@a=\dimexpr
            \cuted@@tempdim@b-\ht\cuted@@tempbox@c
            \relax
        \cuted@@tempdim@spread=\dp\cuted@@tempbox@c
        \unvbox\cuted@@tempbox@c
        \ifdim\cuted@@tempdim@spread>\dp\strutbox
        \else
            \vskip-\cuted@@tempdim@spread
        \fi
        \prevdepth\z@
        \hrule\@height\cuted@@page@rule width\textwidth
        \vskip-\cuted@@page@rule
        \ifdim\cuted@@tempdim@a>\z@
            \if@left@column@spread
            \else
                \vss
            \fi
        \else
            \ifdim\cuted@@tempdim@a<\z@
                \if@left@column@shrink
                \else
                    \vss
                \fi
            \fi
        \fi
        }%
    \wlog{CUTED [output]: \the\cuted@@tempdim@b
          ^^JCUTED [leftcolumn badness]: \number\badness
         }%
    \setbox\cuted@@varbox@a\vbox to\cuted@@tempdim@b{%
        \cuted@@tempdim@a=\dimexpr
            \cuted@@tempdim@b-\ht\@holdpg
            \relax
        \unvbox\@holdpg
        \ifdim\cuted@@tempdim@a>\z@
            \if@right@column@spread
            \else
                \vss
            \fi
        \else
            \ifdim\cuted@@tempdim@a<\z@
                \if@right@column@shrink
                \else
                    \vss
                \fi
            \fi
        \fi
        }%
    \wlog{CUTED [rightcolumn badness]: \number\badness}%
    \setbox\cuted@@tempbox@var\vbox{%
        \hb@xt@\textwidth{%
            \hb@xt@\columnwidth{%
                \vbox to\ht@viper{\box\cuted@@tempbox@a\vss}%
                \hss
                }%
            \hfil
            {\normalcolor\vrule \@width\columnseprule}%
            \hfil
            \hb@xt@\columnwidth{%
                \vbox to\ht@viper{\box\cuted@@varbox@a\vss}%
                \hss
                }%
            }%
        }%
    %%
    %% finalize cuted page
    %%
    \ifvoid\hold@viper
        \global\setbox\hold@viper\vbox{%
            \unvbox\cuted@@tempbox@var
            \penalty\interlinepenalty
            \vskip\stripsep
            \the\preCutedStrip
            \ifnum\outputpenalty<-\@Mii
                \vskip -\parskip
            \fi
            \outputpenalty\z@
            }%
    \else
        \global\setbox\hold@viper\vbox{%
             \unvbox\hold@viper
             \cuted@@tempbox@var
             \penalty\interlinepenalty
             \vskip\stripsep
             \the\preCutedStrip
             \ifnum\outputpenalty<-\@Mii
                 \vskip -\parskip
             \fi
             \outputpenalty\z@
             }%
    \fi
    \ifdim\@colht>\@reqcolroom
        \global\setbox\hold@viper\vbox{%
             \unvbox\hold@viper
             \box\@viper
             \penalty\interlinepenalty
             \the\postCutedStrip
             \vskip\stripsep
             \ifnum\outputpenalty<-\@Mii
                 \vskip -\parskip
             \fi
             \outputpenalty\z@
             }%
        \@inserttrue
        \global\@firstcolumntrue
        \advance\ht@hold@viper by-\ht\hold@viper
        \global\advance\@colht by\ht@hold@viper
        \ifdim\@colht<2.5\baselineskip
            \@latex@warning@no@line {Optional argument of \noexpand\twocolumn
                                     too tall on page \thepage (\var@@thecol@num column)}%
            \@emptycol
            \if@firstcolumn
            \else
                \@emptycol
            \fi
            \global\@lastvipertrue
        \else
            \global\vsize\@colht
            \global\@colroom\@colht
            \check@floats\cuted@@tempdim@a
            \ifdim\cuted@@tempdim@a>\z@
                \global\advance\@colroom by-\cuted@@tempdim@a
            \fi
            \ifdim\@colroom<\z@
                \global\@colroom1\p@
                \ifdim\cuted@@tempdim@a>\@colht
                    \@latex@warning@no@line{TOP and/or BOT FLOAT's
                        to large on \thepage (\var@@thecol@num column)}%
                \fi
                \@emptycol
                \if@firstcolumn
                \else
                    \@emptycol
                \fi
                \global\@lastvipertrue
            \fi
        \fi
    \fi
    \if@insert
    \else
        \advance\ht@hold@viper by-\ht\hold@viper
        \global\advance\@colht by\ht@hold@viper
        \global\setbox\hold@viper\vbox{%
            \unvbox\hold@viper
            \set@split@topskip@to{\z@ plus2\p@}%
            \vsplit\@viper to\@colht
            \vss
            }%
        \vbox{}%
        \global\@firstcolumnfalse
        \newpage
    \fi
    }
\def\check@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
        \@makecol
        \@opcol
        \@startcolumn
        \@whilesw\if@fcolmade\fi
            {\@opcol \@startcolumn}%
    \fi
    \ifnum\outputpenalty>-\@Miv
        \ifdim\@colroom<1.5\baselineskip
            \ifdim\@colroom<\textheight
                \@latex@warning@no@line{%
                    Text page \thepage\space contains only floats%
                    }%
                \if@lastviper
                \else
                    \@emptycol
                \fi
                \if@twocolumn
                    \if@firstcolumn
                    \else
                        \@emptycol
                    \fi
                \fi
                \global\@lastviperfalse
            \else
                \global\vsize\@colroom
            \fi
        \else
            \global\vsize\@colroom
        \fi
    \else
        \ifnum\outputpenalty<-\@Mv
            \global\vsize\maxdimen
        \else
            \global\vsize\@colroom
        \fi
    \fi
    }
\ifcuted@@debug
    \xdef\cuted@@page@rule{.4\p@}
\else
    \xdef\cuted@@page@rule{\z@}
\fi
%    \end{macrocode}
%
% \iffalse
%</package>
% \fi
%
% \Finale