[comp.text.tex] A sophisticated double column macro

smith@zeus.harvard.edu (Steven Smith) (09/06/90)

I occasionally submit the following problem in TeX circles in hopes
that someone has solved it so that I will have both a useful new
TeX macro and an excellent example of column manipulation within TeX.
Has anyone information or suggestions?

% I am looking for a sophisticated TeX or LaTeX double column macro capable
% of the following:
% 
%       i) Double/Single column capability on the same page (LaTeX
%          starts a new page each time its format is switched from
%          \doublecolumn to \singlecolumn).
% 
%      ii) The ability to split the opposing column of a large displayed
%          equation.  I.e.,
% 
%            The right column will be split   played equation  that  appears
%            when the equation                within it.   These  rules  are
%                                             ------------------------------
%               a^n = b^n + c^n +d^n + e^n + f^n + ... + z^n
%                                             ______________________________
%            appears  in  the left  column.   affected if the split  appears
%            Splitting  must   occur   with   on the top or bottom of a page.
%            horizontal  rules  to separate   The columns  must be  balanced
%            a split  column  from the dis-   and  may include single column
% 
%            material that spans the entire page.
% 
% 
% This format mimics that of many IEEE journals.  Is there an IEEE.sty
% LaTeX style file anywhere?  Have any TeX hackers attacked this problem?
% I currently use double column macros cannibalized from a Knuth paper on
% literate programming (included in TeX releases).  These provide
% balanced double columns with single column text on the same page,
% but have no fancy large displayed equation/split column capability.
% I must admit, examination of the TeX macros performing only i) proves
% a daunting experience for those wishing to embellish them with ii).


Steven Smith
smith@sandalphon.harvard.edu

smith@zeus.harvard.edu (Steven Smith) (09/10/90)

Several people have asked me for the ``unsophisticated'' double column
macros I mentioned above.  I therefore include them here (in an old
submission to TeXhax).  Perhaps this would make an interesting problem
for those TUG TeX classes one reads about.  Who runs these?  Might
they be receptive to posing such a problem?  

Steven Smith
smith@sandalphon.harvard.edu


% Date: Fri, 28 Apr 89 14:40:22 EST
% From: smith@sandalphon.harvard.edu (Steven Smith)
% Subject: Simple Double Column Macros
% Keywords: Macros
% 
% In Issue 27, I mentioned some macros that provide balanced double column
% capability.  As I received several e-mail requests for these macros,
% I will provide them here.
% 
% My previous letter stated:
% 
%% I am looking for a sophisticated TeX or LaTeX double column macro capable
%% of the following:
%% 
%%       i) Double/Single column capability on the same page (LaTeX
%%          starts a new page each time its format is switched from
%%          \doublecolumn to \singlecolumn).
%% 
%%      ii) The ability to split the opposing column of a large displayed
%%          equation.  I.e.,
%% 
%%            The right column will be split   played equation  that  appears
%%            when the equation                within it.   These  rules  are
%%                                             ------------------------------
%%               a^n = b^n + c^n +d^n + e^n + f^n + ... + z^n
%%                                             ______________________________
%%            appears  in  the left  column.   affected if the split  appears
%%            Splitting  must   occur   with   on the top or bottom of a page.
%%            horizontal  rules  to separate   The columns  must be  balanced
%%            a split  column  from the dis-   and  may include single column
%% 
%%            material that spans the entire page.
%% 
%% 
%% This format mimics that of many IEEE journals.  Is there an IEEE.sty
%% LaTeX style file anywhere?  Have any TeX hackers attacked this problem?
%% I currently use double column macros cannibalized from a Knuth paper on
%% literate programming (included in VMS TeX releases).  These provide
%% balanced double columns with single column text on the same page,
%% but have no fancy large displayed equation/split column capability.
%% I must admit, examination of the TeX macros performing only i) proves
%% a daunting experience for those wishing to embellish them with ii).
% 
% My reasons for including this letter are, of course, surreptitious, but I
% will nevertheless reveal them: it is my hope that some motivated hacker
% take these macros and mold them into the utility described above.  As they
% stand they are robust and useful, but limited.  For example, footnoting
% is NOT supported (although I believe that this could be a simple addition
% if one read Chapter 23 of the TeXbook carefully enough).
% 
% I have a few reservations about releasing these macros because i) I didn't
% write them (I altered them from some Knuth macros), ii) I don't know how
% they work (But they do. Honest.), iii) people will undoubtedly attempt
% to encorporate them within LaTeX, an application they are NOT written for.
% They redefine TeX's \output routine---the equivalent of lobotomizing
% LaTeX.  A LaTeX application for local balanced double columns is possible,
% but it must retrench all \ouput routine dependencies.  The rewritten macros
% would exploit the \vsplit primitive of TeX and could use these double column
% macros as an example.  If you are a LaTeXer who desires balanced double
% columns, your best strategy is to either learn TeX or learn to write a LaTeX
% style file that performs the task. (I submit that the latter proposition is
% Sisyphean while the former is merely Herculean.)
% 
% Here are the macros.  Their syntax is
% 
% <Single Column Text>
% 
% \begindoublecolumns
% <Double Column Text>
% \enddoublecolumns
% 
% <More Single Column Text>
% 
% Note that \leftfloat and \rightfloat are defined for floating figures.
% Their syntax is exactly that of floating figures in plain TeX:
% 
% \leftfloat
% \vbox{}
% \endfloat
% 
% Good Luck!
% 
% 
% Steven Smith
% smith@sandalphon.harvard.edu
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Cut Here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newdimen\pagewidth \newdimen\pageheight \newdimen\ruleht

\newinsert\lefttop \newinsert\righttop
\count\lefttop=1000 \count\righttop=1000
\dimen\lefttop=\maxdimen \dimen\righttop=\maxdimen
\skip\lefttop=25pt plus 3pt minus 3pt
\skip\righttop=\skip\lefttop
\def\leftfloat{\insert\lefttop\bgroup
  \floatingpenalty=0
  \penalty0
  \vbox\bgroup}
\def\rightfloat{\insert\righttop\bgroup
  \floatingpenalty=0
  \penalty0
  \vbox\bgroup}
\def\endfloat{\egroup\egroup}

\def\doublefloatspace #1{
\leftfloat
\vbox to#1{\vfil}
\endfloat
\rightfloat
\vbox to#1{\vfil}
\endfloat}

\newbox\partialpage
\def\begindoublecolumns{\begingroup
  \output={\global\setbox\partialpage=\vbox{\unvbox255}}\eject
  \output={\doublecolumnout} \hsize=3.5in \vsize=19in}
\def\enddoublecolumns{\output={\balancecolumns}\eject
  \endgroup \pagegoal=\vsize}

\def\doublecolumnout{\dimen0=\pageheight
  \advance\dimen0 by-\ht\partialpage \splittopskip=\topskip
  \ifdim\ht\lefttop>0pt \setbox255=\vbox{\unvbox\lefttop
    \setbox0=\lastbox\unvbox0\vskip\skip\lefttop\unvbox255}\fi
  \setbox0=\vsplit255 to\dimen0
  \ifdim\ht\righttop>0pt \setbox255=\vbox{\unvbox\righttop
    \setbox0=\lastbox\unvbox0\vskip\skip\righttop\unvbox255}\fi
  \setbox2=\vsplit255 to\dimen0
  \onepageout\pagesofar
  \unvbox255 \penalty\outputpenalty}
\def\pagesofar{\unvbox\partialpage
  \wd0=\hsize \wd2=\hsize \hbox to\pagewidth{\box0\hfil\box2}}
\def\balancecolumns{\setbox0=\vbox{\unvbox255} \dimen0=\ht0
  \advance\dimen0 by\topskip \advance\dimen0 by-\baselineskip
  \divide\dimen0 by2 \splittopskip=\topskip
  {\vbadness=10000 \loop \global\setbox3=\copy0
    \global\setbox1=\vsplit3 to\dimen0
    \ifdim\ht3>\dimen0 \global\advance\dimen0 by1pt \repeat}
  \setbox0=\vbox to\dimen0{\unvbox1}
  \setbox2=\vbox to\dimen0{\unvbox3}
  \pagesofar}

\def\onepageout#1{\shipout\vbox{
\vbox to0pt{\vskip-22.5pt
  \hbox to\pagewidth{\vbox to8.5pt{\vss}\the\headline}\vss}
\nointerlineskip
\vbox to\pageheight{#1\boxmaxdepth=\maxdepth}
\baselineskip=24pt
\hbox to\pagewidth{\the\footline}}
\advancepageno}

\output{\onepageout{\unvbox255}}

\hsize=7.25in  \vsize=10in
\hoffset=.625in \voffset=.5in
\pagewidth=\hsize \pageheight=\vsize \ruleht=1pt
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Cut Here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

karl@rice-chex.ai.mit.edu (Karl Berry) (09/20/90)

The eplain macros also include double column macros.
I don't know if they qualify as sophisticated or simple.
You can get eplain from ics.uci.edu, in the directory TeX/eplain.

karl@cs.umb.edu
harvard!umb!karl