[comp.text.tex] \midinsert, etc.

bed_gdg@SHSU.BITNET ("George D. Greenwade") (04/27/91)

This is being forwarded to INFO-TeX on behalf of Walter Neumann
<neumann@mps.ohio-state.edu>.  The mailer which drives INFO-TeX and the
mailer from which Walter submitted this (unfortunately) just don't want to
discuss things.  I thank him for his patience and perseverence on getting
this to me so I can get it to you.  His post follows.
 
--GDG
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This is an update to the corrections I posted a while ago to TeX's
default insert macros (\midinsert, \topinsert).  I am editing a
topology proceedings with lots of included figures and have found the
default macros seriously deficient.  The changes to the previous
posting are an improved test (suggested by L. Siebenmann) for a split
insertion on the current page, and protection of \lastskip (item 5
below).  The macros are also useful with AMSTeX.  I do not know if
similar problems exist in Latex.  Latex has its own fairly
sophisticated insert macros.
 
Comments appreciated.  -walter neumann
 
%% newinsert.tex (4/2/91) by walter neumann (neumann@mps.ohio-state.edu)
%
% Include with "\input newinsert.tex" to fix following problems
% with plain TeX's handling of \midinsert and \topinsert:
%
% 1. An insert that falls at the top of the page is too high: it's
%    top is at top-of-page rather than top-of-ink.
% 2. Plain uses \bigskip for space around inserts and assumes \bigskip
%    is 12pt plus stretch, so \midinsert misbehaves if \bigskipamount
%    is changed. This space should be an independent quantity.
% 3. Consecutive midinserts that did not float are spaced twice
%    as far apart as consecutive topinserts or floated midinserts.
% 4. Midinserts can get out of order (see Exercise 15.5 of TeXbook).
% 5. \removelastskip fails after a floated insert. This is relevant for
%    an insertion before any construction (such as a proclamation in
%    plain TeX) that does an explicit or implicit \removelastskip.
%
% Remaining problem: TeX uses \topskip instead of \baselineskip for the
% first line of a page after any topinserts. With the default values
% of 10pt and 12pt respectively, this gives 2pt less space between a
% topinsert or floated midinsert and following text than between a
% middle insertion and following text. To avoid this use:
%
% \topskip=\baselineskip
%
% PARAMETERS:
% Plain.tex puts \bigskipamount of space before and after inserts.
% We provide \insertskipamount for this purpose (default \medskipamount).
% In addition, \inserthardskipamount of glue is added at the top of EVERY
% insert; it remains even at top of page (default 6pt; it should be at
% least \topskipamount-(text height)).
%   These defaults give good balance for insertions of the form:
%       \midinsert
%       [Text or commands to include a graphics file]
%       \medskip \centerline{Figure Title or Table Title}
%       \endinsert.
%
\chardef\OldCatAt\the\catcode `\@
\catcode `\@=11
%
%%%%%%%%%%%% Corrected insert macros for plain.tex %%%%%%%%%%%%%%%%%
%
%  New skipamounts:
%
\newskip\insertskipamount\newskip\inserthardskipamount
\insertskipamount\medskipamount         % Change as desired.
\inserthardskipamount 6pt               % Change as desired (see above)
\def\insertskip{\vskip\insertskipamount}
%
%  Save and restore \lastskip:
%
\newskip\LastSkip
\def\SaveLastSkip{\LastSkip\lastskip}
\def\RestoreLastSkip{\nobreak\vskip-\LastSkip\vskip\LastSkip}
%
%  Larry Siebenmann's test for split topinserts:
%
\newcount\SplitTest%        will be set to -1 if a topinsert has split
\def\SetSplitTest{\SplitTest\insertpenalties
  \SaveLastSkip\insert\topins{\floatingpenalty1}\RestoreLastSkip
  \advance\SplitTest-\insertpenalties}
%
%  From here on we modify definitions in plain.tex.
%
% Redefine \midinsert to convert to \topinsert if a topinsert has been
% split, to prevent midinserts getting out of order (cf. TeXbook Exercise
% 15.5). As in plain.tex, a \midinsert still converts to a \topinsert
% (which then splits) if the insert is too big for current page.
%   Was:    \def\midinsert{\@midtrue\@ins}
\def\midinsert{\par\SetSplitTest\ifnum\SplitTest=-1
  \@midfalse\else\@midtrue\fi\@ins}
% Redefine \@ins to add \inserthardskipamount of glue above.
%   Was:  \def\@ins{\par\begingroup\setbox\z@\vbox\bgroup}
\def\@ins{\par\begingroup\setbox\z@\vbox\bgroup%
  \vglue\inserthardskipamount}
% Changes to \endinsert of plain.tex 3.0:
% - Use \insertskipamount instead of \bigskipamount throughout.
% - Use larger of previous skip and insertskip before middle insert.
% - Add \nointerlineskip to avoid unwanted extra 1pt skip.
% - Save and restore lastskip when an insert floats.
\def\endinsert{\egroup % finish the \vbox
  \if@mid \dimen@\ht\z@ \advance\dimen@\dp\z@
    \advance\dimen@\insertskipamount%            was 12pt (wn)
    \advance\dimen@\pagetotal\advance\dimen@-\pageshrink
    \ifdim\dimen@>\pagegoal\@midfalse\p@gefalse\fi\fi
% Next 3 lines replace:  \if@mid \bigskip\box\z@\bigbreak (wn)
  \if@mid%
    \ifdim\lastskip<\insertskipamount\removelastskip\insertskip\fi
    \nointerlineskip\box\z@\penalty-200\insertskip
  \else%
    \SaveLastSkip%                                  added (wn)
    \insert\topins{\penalty100 % floating insertion
    \splittopskip\z@skip
    \splitmaxdepth\maxdimen \floatingpenalty\z@
    \ifp@ge \dimen@\dp\z@
    \vbox to\vsize{\unvbox\z@\kern-\dimen@}% depth is zero
    \else \box\z@\nobreak\insertskip\fi}% was \bigskip\fi (wn)
    \RestoreLastSkip%                               added (wn)
   \fi\endgroup}
%%%%%%%%%%%%%%%%%% Done correcting insert macros %%%%%%%%%%%%%%%%%%%
%
\catcode `\@=\OldCatAt
\endinput
%% end newinsert.tex
 
--
 Walter Neumann              Email:    neumann@mps.ohio-state.edu
 Department of Mathematics                  neumann@ohstpy.bitnet
 Ohio State University       Tel: 614-292-4886 (office)
 Columbus, OH 43210           -292-4975(Math. Dept.) -292-1479 (Dept. Fax)