% \iffalse^^A meta-comment
% ======================================================================
% longtwocolumn.dtx
% Copyright (c) Markus Kohm, 2021–2025
%
% This file is part of the LaTeX2e package `longtwocolumn'.
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, version 1.3c of the license.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 and of this work.
%
% This work has the LPPL maintenance status "author-maintained".
%
% The Current Maintainer and author of this work is Markus Kohm.
%
% This work consists of the files `longtwocolumn.dtx' and
% `README.md'.
% ======================================================================
%
%\changes{v0.3}{2025-01-07}{needs at least \LaTeX{} 2020-10-01}
%<identify>\NeedsTeXFormat{LaTeX2e}[2020/10/01]
%<*dtx>
\ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
\ProvidesFile{longtwocolumn.dtx}
%</dtx>
%<package&identify>\ProvidesPackage{longtwocolumn}
%<*dtx|(package&identify)>
  [2025-07-21 v0.1
%</dtx|(package&identify)>
%<*dtx>              
    source of package scrlayer-scrpage]
%</dtx>
%<*package>
%<identify>    combining fancyhdr with KOMA-Script's scrlayer]
%</package>
%<*dtx>
\ifx\documentclass\undefined
  \input docstrip.tex
  \generate{%
    \file{longtwocolumn.sty}{%
      \from{longtwocolumn.dtx}{package}%
    }%
    \file{longtwocolumn-example.tex}{%
      \from{longtwocolumn.dtx}{example}%
    }%
  }
\else
  \let\endbatchfile\relax
\fi
\endbatchfile
\documentclass{koma-script-source-doc}% KOMA-Script related packages use this.
\usepackage[english]{babel}
\usepackage{graphicx}
\setcounter{StandardModuleDepth}{2}
\GetFileInfo{longtwocolumn.dtx}
\begin{document}
\DocInput{longtwocolumn.dtx}
\end{document}
%</dtx>
%\fi
%
% \changes{v0.1}{2025-06-30}{forum answer converted into package}
% \changes{v0.1}{2025-07-21}{color support added}
%
% \GetFileInfo{longtwocolumn.dtx}
% \title{The \pkg*{longtwocolumn} Package}
% \author{\href{mailto:komascript@gmx.info}{Markus Kohm}\thanks{Repository and
%   bug reports:
%   \url{https://gitlab.com/latex9343737/packages/longtwocolumn}}}
% \date{Version \filedate{} \fileversion}
% \maketitle
% \begin{abstract}
%   Package \pkg*{longtwocolumn} provides \cs{longtwocolumn} as variant of
%   \LaTeX's \cs{twocolumn} that allowes the optional argument to span several
%   pages on one column.
% \end{abstract}
%
% \tableofcontents
%
% \section{How to use \pkg*{longtwocolumn}?}
% \label{sec:usage}
%
% First of all, you need to load the package, so you should add
%\begin{verbatim}
%   \usepackage{longtwocolumn}
%\end{verbatim}
% somewhere in your document preamble. Theoretically you would even be able to
% do a
%\begin{verbatim}
%   \RequirePackage{longtwocolumn}
%\end{verbatim}
% before |\documentclass|. However users should not need to do so and
% therefore it is not recommended unless you know what you are doing.
%
% Now you can use \cs{longtwocolumn}\oarg{single column content}. The command
% works similar to \LaTeX's \cs{twocolumn}, but if the \meta{single column
% content} is higher than one page, it is automatically split to several
% pages. Note, that currently \cs{newpage} or \cs{clearpage} inside
% \meta{single column content} is not supported. In my opinion such a support
% is not needed, because each \cs{longtwocolumn} starts a new page, so instead
% of adding \cs{newpage} inside the optional argument of \cs{longtwocolumn}
% you simply can use several \cs{longtwocolumn}.
%
% \begin{description}
% \item[\textbf{Note:}] This is an early experimental package. So it may fail
%   in all cases except the one shown in the example.
% \end{description}
%
% \section{Example}
% \label{sec:example}
%
% \iffalse
%<*example>
% \fi
%
% Often \cs{longtwocolumn} is used for title + abstract in a two column
% document, if the abstract needs more than one page:
%    \begin{macrocode}
\documentclass[twocolumn,abstract]{scrartcl}
\usepackage{longtwocolumn}
\usepackage{lipsum}
\begin{document}

\title{Long One Column Abstract with Two Column Document}
\author{Markus Kohm}
 
\longtwocolumn[{
  \maketitle
  \begin{abstract}
  \lipsum[1-8]
  \end{abstract}
  \vskip\baselineskip
}]
\section{Here we go}
\lipsum[1-7]
\end{document}
%    \end{macrocode}
% Results in:
% \begin{center}
%   \fbox{\includegraphics[page=1,width=.3\textwidth]{longtwocolumn-example.pdf}}%
%   \fbox{\includegraphics[page=2,width=.3\textwidth]{longtwocolumn-example.pdf}}%
%   \fbox{\includegraphics[page=3,width=.3\textwidth]{longtwocolumn-example.pdf}}
% \end{center}
% It results also in the warning message:
%\begin{verbatim}
%  Package longtwocolumn Warning: \clearpage inside optional argument of
%  (longtwocolumn)                \longtwocolumn ignored on input line 37.
%\end{verbatim}
% because the \cs{maketitle} in the optional argument of \cs{longtwocolumn}
% runs \cs{clearpage} at the very beginning. But in this case this is not
% really a problem, because \cs{longtwocolumn} runs \cs{onecolumn} at the very
% beginning and this also runs \cs{clearpage}.
%
% \iffalse
%</example>
% \fi
%
% \MaybeStop{}^^A\PrintIndex}
%
% \section{Implementation}
% \label{implementation}
%
% \iffalse
%<*package>
% \fi
% \begin{command}{\longtwocolumn}
%
% \begin{macro}{\longtwocolumn@box}
%   Internal box register used by \cs{longtwocolumn}.
%    \begin{macrocode}
\newsavebox\longtwocolumn@box
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
\NewDocumentCommand{\longtwocolumn}{+o}{%
  \IfValueTF{#1}{%
%    \end{macrocode}
% Switch to one column, because everything, which is longer than one page,
% should be output in one column mode.
%    \begin{macrocode}
    \onecolumn
%    \end{macrocode}
% We start a new group to allow local changes, e.g., of \cs{clearpage} and
% \cs{newpage}, while we collect the content.
%    \begin{macrocode}
    \begingroup
      \renewcommand*{\cleardoublepage}{%
        \PackageWarning{longtwocolumn}{\string\cleardoublepage\space inside
          optional argument of\MessageBreak \string\longtwocolumn\space
          ignored}%
      }%
      \renewcommand*{\clearpage}{%
        \PackageWarning{longtwocolumn}{\string\clearpage\space inside optional
          argument of\MessageBreak \string\longtwocolumn\space ignored}%
      }%
      \renewcommand*{\newpage}{%
        \PackageWarning{longtwocolumn}{\string\newpage\space inside optional
          argument of\MessageBreak \string\longtwocolumn\space ignored}%
      }
      \global\setbox\longtwocolumn@box\color@vbox
        \normalcolor
        \@parboxrestore
        #1%
        \par
      \color@endbox
    \endgroup
%    \end{macrocode}
% Now we can split the box using the same parameters that would be used for
% normal page splitting.
%    \begin{macrocode}
%<*trace> 
    \typeout{^^J%
      TRACE: Initial height=\the\ht\longtwocolumn@box, 
             depth=\the\dp\longtwocolumn@box}%
%</trace>
    \@whiledim \textheight<\ht\longtwocolumn@box\do {%
%<*trace>
      \typeout{TRACE: Split of \the\textheight\space from 
        \the\ht\longtwocolumn@box}%
%</trace>
      \splittopskip\topskip
      \splitmaxdepth\maxdepth
      \vsplit\longtwocolumn@box to \textheight\clearpage
    }%
%<*trace>
    \typeout{TRACE: Final height=\the\ht\longtwocolumn@box, 
      depth=\the\dp\longtwocolumn@box}%
%</trace>
%    \end{macrocode}
% Before we run \cs{twocolumn} to output the last part of the box, we need to
% deactivate the \cs{normalcolor} at the beginning of
% \cs{@topnewpage} to avoid resetting the color.
%    \begin{macrocode}
    \let\longtwocolumn@normalcolor\normalcolor
    \def\normalcolor{\let\normalcolor\longtwocolumn@normalcolor}%
    \twocolumn[\unvbox\longtwocolumn@box]%
    \let\normalcolor\longtwocolumn@normalcolor
  }{\twocolumn}%
}
%    \end{macrocode}
% \end{command}
%
% \iffalse
%</package>
% \fi
%
% \Finale
% \PrintChanges
%  
% \endinput
% Local Variables:
% mode: doctex
% ispell-local-dictionary: "en_US"
% eval: (flyspell-mode 1)
% TeX-master: t
% End:
