% \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 midfloat.dtx and midfloat.ins
% and the derived filebase midfloat.sty.
%
% \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-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 material in full-width on double-column page.
%%
%</package>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{midfloat}
%<*package>
    [2012/05/29 v1.1 Insert some material in full-width on double-column page]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{midfloat}[2012/05/29]
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{midfloat.dtx}
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{439}
%
% \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{v1.0}{1997/10/01}{some names}
% \changes{v1.1}{2012/05/29}{Converted to DTX file}
%
% \DoNotIndex{\newcommand,\newenvironment}
%
% \providecommand*{\url}{\texttt}
% \GetFileInfo{midfloat.dtx}
% \title{The \textsf{midfloat} 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 (from the left column)
%   in full-width at any place (but not at the top) on double-column 
%   page (|\twocolumn| mode). Existing text remains as it was before 
%   insert. Placement is restricted to one page. (It is some kind of
%   dbfloat intext).
%
% \section{Usage}
%
% \DescribeMacro{strip}
% Provides new environment:
%
%  \begin{verbatim}
%    \begin{strip}[<top strip stretch skip>/<bottom strip skip>] 
%      <wide onecolumn material> 
%    \end{strip}
%  \end{verbatim}
%
%   Puts |\vbox|\marg{wide onecolumn material} in full-width on
%   double-column page.
%
%   \medskip
%   Adds |\stripsep| glue before and after (by default: |15pt|).
%
%   \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
%   Parameters \meta{top strip stretch skip} and \meta{bottom strip skip} are optional. 
%   By default \meta{top strip stretch skip}|=0pt| and \meta{bottom strip skip}|=0pt|.
%   The material on the right column under strip is stretched down 
%   by \meta{top strip stretch skip} and below strip is moved down by \meta{bottom strip skip}.
%
%
% \StopEventually{}
%
% \section{Implementation}
%
% \iffalse
%<*package>
% \fi
%
%
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{midfloat}[1997/10/01]
%    \end{macrocode}
%
%    \begin{macrocode}
\newif\if@vihproof \@vihprooftrue
\newtoks\juo@sar   \juo@sar={}
\@ifundefined{stripsep}{\newskip\stripsep \stripsep 15\p@}{}
\newskip\m@addvipersep \m@addvipersep\z@
\newskip\c@addvipersep \c@addvipersep\z@
\newdimen\ht@strip
\newdimen\right@cor
\newdimen\cor@height \cor@height=\z@
\newdimen\juo@pr
\newdimen\juo@ht
\newdimen\c@colht
\newbox\@viper
\newbox\@rightcolumn
\newcount\juo@sk
\def\@ca#1#2#3#4{}
%    \end{macrocode}
%
% \begin{macro}{\add@strip}
%    \begin{macrocode}
\def\add@strip#1#2#3#4{%
  \begingroup
    \xdef\ex@{\global\noexpand\juo@sar{\the\juo@sar\noexpand\@ca{#1}{#2}{#3}{#4}}}%
    \ex@
  \endgroup
  }
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\remove@strip}
%    \begin{macrocode}
\def\remove@strip#1{\ifx#1\@empty\global\juo@sk=0\else
   \global\advance\juo@sk by-1\expandafter\next@item\the #1\@@#1\fi}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\next@item}
%    \begin{macrocode}
\def\next@item \@ca #1#2#3#4#5\@@#6{\global #6={#5}\global\juo@pr=#1\global\juo@ht=#2%
\global\cor@height=#3\global\m@addvipersep=#4}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\strip}
%    \begin{macrocode}
\def\strip{\@ifnextsymb[{\@strip}{\@strip[0pt/0pt]}}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@strip}
%    \begin{macrocode}
\def\@strip[#1/#2]{\global\@tempdima=#1\global\@tempdimb=#2%
  \global \setbox\@viper\vbox\bgroup%
        \hsize\textwidth
        \@parboxrestore
        \col@number \@ne
        \vrule height\topskip width0pt depth0pt
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\endstrip}
%    \begin{macrocode}
\def\endstrip{%
        \egroup
        \if@firstcolumn
                \ifdim\pagetotal>\z@
                        \vskip\stripsep
                        \global\ht@strip\pagegoal
                        \global\advance\ht@strip by-\pagetotal
                        \global\advance\ht@strip by-\stripsep
                        \global\advance\ht@strip by-\ht\@viper
                        \global\advance\ht@strip by-\stripsep
                        \global\juo@ht=\ht\@viper
                \else
                        \global\ht@strip\z@
                \fi
                \ifdim\ht@strip>\z@
                  \unvbox\@viper
                  \vskip\stripsep
                  \add@strip{\the\pagetotal}{\the\juo@ht}{\the\@tempdima}{\the\@tempdimb}%
                  \global\advance\juo@sk by1
                \else
                  \@latex@error{Strip needs more place!}\@ehc
                  \if@vihproof
                    \framebox[\columnwidth]{??? Strip ???}%
                  \fi
                \fi
        \else
          \@latex@error{Strip is used only on left column!}\@ehc
          \if@vihproof
            \framebox[\columnwidth]{??? Strip ???}%
          \fi
        \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@outputdblcol}
%    \begin{macrocode}
\def\@outputdblcol{%
  \if@firstcolumn
    \global \@firstcolumnfalse
    \global \setbox\@leftcolumn \box\@outputbox
    \global\c@colht\@colht\global\c@addvipersep\z@
    \ifnum\juo@sk>0
        \remove@strip\juo@sar
        \global\@colht\the\juo@pr
        \ifdim\right@cor>\z@
                \global\advance\@colht by\right@cor
        \fi
        \global\advance\@colht by\cor@height
        \global\cor@height=0pt
    \fi
    \global \setbox\@rightcolumn \vbox{}%
  \else
    \ifdim\c@colht>\@colht
            \@tempdima\@colht
            \ifdim\@colht>\z@
            \global\setbox\@rightcolumn \vbox{%
                        \unvbox\@rightcolumn
                        \vbox to\@tempdima{%
                                \vskip\c@addvipersep\unvbox\@outputbox}%
                        \vskip\stripsep
                        \vrule height\the\juo@ht width 0pt depth 0pt
                        \vskip\stripsep
                        }%
            \global\c@addvipersep\m@addvipersep
            \else
            \global\setbox\@rightcolumn \vbox{%
                        \unvbox\@rightcolumn
                        \vrule height\the\juo@ht width 0pt depth 0pt
                        \vskip\stripsep
                        }%
            \fi
            \ifnum\juo@sk>0
                \remove@strip\juo@sar
                \global\@colht\the\juo@pr
                \global\advance\@colht by -\ht\@rightcolumn
                \global\advance\@colht by\cor@height
                \global\cor@height=0pt
            \else                             
                \global\advance\c@colht by-\ht\@rightcolumn
                \global\@colht\c@colht
            \fi
    \else
    \global \@firstcolumntrue
    \global\setbox\@outputbox\vbox to\ht\@leftcolumn{%
                        \unvbox\@rightcolumn
                        \vskip\c@addvipersep
                        \unvbox\@outputbox
                        }%
    \setbox\@outputbox \vbox {%
                         \hb@xt@\textwidth {%
                           \hb@xt@\columnwidth {%
                             \box\@leftcolumn \hss}%
                           \hfil
                           \vrule \@width\columnseprule
                           \hfil
                           \hb@xt@\columnwidth {%
                             \box\@outputbox \hss}%
                                             }%
                              }%
    \@combinedblfloats
    \@outputpage
    \begingroup
      \@dblfloatplacement
      \@startdblcolumn
      \@whilesw\if@fcolmade \fi
        {\@outputpage
         \@startdblcolumn}%
    \endgroup
    \global\juo@sk=0\global\juo@sar={}%
    \global\cor@height\z@\global\c@addvipersep\z@
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@cflt}
%    \begin{macrocode}
\def \@cflt{%
    \let \@elt \@comflelt
    \setbox\@tempboxa \vbox{}%
    \@toplist
    \global\right@cor\ht\@tempboxa
    \ifdim\right@cor>\z@
            \global\advance\right@cor by-\floatsep
            \global\advance\right@cor by\textfloatsep
    \fi
    \setbox\@outputbox \vbox{%
                             \boxmaxdepth \maxdepth
                             \unvbox\@tempboxa
                             \vskip -\floatsep
                             \topfigrule
                             \vskip \textfloatsep
                             \unvbox\@outputbox
                             }%
    \let\@elt\relax
    \xdef\@freelist{\@freelist\@toplist}%
    \global\let\@toplist\@empty
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@ifnextsymb}
%    \begin{macrocode}
\def\@ifnextsymb#1#2#3{%
  \let\reserved@d=#1%
  \def\reserved@a{#2}\def\reserved@b{#3}%
  \futurelet\@let@token\@ifnsymb}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@ifnsymb}
%    \begin{macrocode}
\def\@ifnsymb{%
  \ifx\@let@token\@sptoken
    \let\reserved@c\reserved@b
  \else
    \ifx\@let@token\reserved@d
      \let\reserved@c\reserved@a
    \else
      \let\reserved@c\reserved@b
    \fi
  \fi
  \reserved@c}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode} 
%\endinput 
%    \end{macrocode} 
%%
% \iffalse
%</package>
% \fi
%
% \Finale
