% \iffalse meta-comment
%
% Copyright 1994 the LaTeX3 project and the individual authors.
% All rights reserved. For further copyright information see the file
% legal.txt, and any other copyright indicated in this file.
% 
% This file is part of the LaTeX2e system.
% ----------------------------------------
% 
%  This system is distributed in the hope that it will be useful,
%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% 
% 
% IMPORTANT NOTICE:
% 
% For error reports in case of UNCHANGED versions see bugs.txt.
% 
% Please do not request updates from us directly.  Distribution is
% done through Mail-Servers and TeX organizations.
% 
% You are not allowed to change this file.
% 
% You are allowed to distribute this file under the condition that
% it is distributed together with all files mentioned in manifest.txt.
% 
% If you receive only some of these files from someone, complain!
% 
% You are NOT ALLOWED to distribute this file alone.  You are NOT
% ALLOWED to take money for the distribution or use of either this
% file or a changed version, except for a nominal charge for copying
% etc.
% \fi
%
% \iffalse
%%% File: ltspace.dtx
%<*driver>
% \fi
\ProvidesFile{ltspace.dtx}
             [1994/05/16 v1.1a LaTeX Kernel (spacing)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltspace.dtx}
\title{\filename}
\date{\filedate}
 \author{%
  Johannes Braams\and
  David Carlisle\and
  Alan Jeffrey\and
  Leslie Lamport\and
  Frank Mittelbach\and
  Chris Rowley\and
  Rainer Sch\"opf}
\begin{document}
\maketitle
 \DocInput{\filename}
\end{document}
%</driver>
% \fi
%
% \CheckSum{512}
%
% \changes{v1.1a}{1994/05/16}{(ASAJ) Split from ltinit.dtx.}
%
% \section{Spacing}
%
% This section deals with spacing, and line- and page-breaking.
%
% \StopEventually{}
%
% \begin{oldcomments}
%
%    \begin{macrocode}
%<*2ekernel>
\message{spacing,}
%    \end{macrocode}
%
%      **********************************************
%      *     SPACING / LINE AND PAGE BREAKING       *
%      **********************************************
%
%
% USER COMMANDS:
% \nopagebreak[i] : i = 0,...,4.  Default argument = 4.  Puts a penalty
%                 into the vertical list output as follows:
%                   0 : penalty = 0
%                   1 : penalty = \@lowpenalty
%                   2 : penalty = \@medpenalty
%                   3 : penalty = \@highpenalty
%                   4 : penalty = 10000
% \pagebreak[i]   : same as \nopagebreak except negatives of its penalty
% \linebreak[i], \nolinebreak[i] : analogs of the above
% \samepage : inhibits page breaking most places by setting the
%              following penalties to 10000
%                    \interlinepenalty
%                    \postdisplaypenalty
%                    \interdisplaylinepenalty
%                    \@beginparpenalty
%                    \@endparpenalty
%                    \@itempenalty
%                    \@secpenalty
%                    \interfootnotelinepenalty
%
% \obeycr    : defines <CR> == \\.
% \restorecr : restores <CR> to its usual meaning.
%
% \\         : initially defined to be \newline
% \\[LENGTH] : initially defined to be \vspace{LENGTH}\newline
%              Note: \\* adds a \vadjust{\penalty 10000}
%
%    \begin{macrocode}
\def\nopagebreak{\@ifnextchar[\@nopgbk{\@nopgbk[4]}}
\def\@nopgbk[#1]{\ifvmode \penalty \@getpen{#1}\else
\@bsphack\vadjust{\penalty \@getpen{#1}}\@esphack\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\pagebreak{\@ifnextchar[\@pgbk{\@pgbk[4]}}
\def\@pgbk[#1]{\ifvmode \penalty -\@getpen{#1}\else
\@bsphack\vadjust{\penalty -\@getpen{#1}}\@esphack\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\nolinebreak{\@ifnextchar[\@nolnbk{\@nolnbk[4]}}
\def\@nolnbk[#1]{\ifvmode \@nolnerr\else \@tempskipa\lastskip
     \unskip \penalty \@getpen{#1}\ifdim \@tempskipa >\z@
     \hskip\@tempskipa\ignorespaces\fi\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\linebreak{\@ifnextchar[\@lnbk{\@lnbk[4]}}
\def\@lnbk[#1]{\ifvmode \@nolnerr\else
     \unskip\penalty -\@getpen{#1}\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\samepage{\interlinepenalty\@M
   \postdisplaypenalty\@M
   \interdisplaylinepenalty\@M
   \@beginparpenalty\@M
   \@endparpenalty\@M
   \@itempenalty\@M
   \@secpenalty\@M
   \interfootnotelinepenalty\@M}
%    \end{macrocode}
%
% \nobreak added to \newline to prevent null lines when \newline
% ends an overfull line.  Change made 24 May 89 as suggested by
% Frank Mittelbach and Rainer Sch\"opf
%
%    \begin{macrocode}
\def\newline{\ifvmode \@nolnerr \else \unskip\nobreak\hfil
  \penalty -\@M\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\@normalcr{%
  \@ifstar
    {\vadjust{\penalty\@M}\@xnewline}%
    \@xnewline}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\@xnewline{\@ifnextchar[\@newline\newline}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\@newline[#1]{\ifhmode\unskip\fi\vspace{#1}\newline}
%    \end{macrocode}
%
%    \begin{macrocode}
\let\\=\@normalcr
%    \end{macrocode}
%
%    \begin{macrocode}
\def\@getpen#1{\ifcase #1 0 \or \@lowpenalty\or
         \@medpenalty \or \@highpenalty
         \else \@M \fi}
%    \end{macrocode}
% @nobreak : Switch used to avoid page breaks caused by \label after a
%      section heading, etc. It should be GLOBALLY set true after the
%      \nobreak and GLOBALLY set false by the next invocation of
%      \everypar. 
%      Commands that reset \everypar should globally set it false if
%      appropriate.
%
%    \begin{macrocode}
\newif\if@nobreak \@nobreakfalse
%    \end{macrocode}
%
% \@bsphack ... \@esphack
%     used by macros such as \index and \begin{@float} ... \end{@float}
%     that want to be invisible -- i.e.,
%     not leave any extra space when used in the middle of text.  Such
%     a macro should begin with \@bsphack and end with \@esphack
%     The macro in question should not create any text, nor change the
%     mode.
%
% \@Esphack is a variant of \@esphack that sets the @ignore switch to
%     true (as \@esphack used to do previously). This is currently used
%     only for float and similar environments.
%
% \@bsphack ==
%  BEGIN
%   if not mmode then             %% Test for math mode added 18 Dec 89
%         \dimen\@savsk := \lastskip
%       if  hmode  then  \@savsf := \spacefactor  fi
%   fi
%  END
%
% \@esphack ==
%  BEGIN
%   if not mmode then             %% Test for math mode added 18 Dec 89
%    if  hmode
%      then  \spacefactor := \@savsf
%            if \dimen\@savsk > 0pt  then  \ignorespaces fi
%    fi
%   fi
%  END
%
% \@Esphack ==
%  BEGIN
%   if not mmode then
%    if  hmode
%      then  \spacefactor := \@savsf
%            if \dimen\@savsk > 0pt  then  \ignorespaces
%                                          \global\@ignoretrue   fi
%    fi
%   fi
%  END
%
%    \begin{macrocode}
\newdimen\@savsk
\newcount\@savsf
%    \end{macrocode}
%
%    \begin{macrocode}
\def\@Esphack{\relax\ifmmode\else\ifhmode\spacefactor\@savsf
     \ifdim \@savsk >\z@ \global\@ignoretrue \ignorespaces
  \fi \fi\fi}
%    \end{macrocode}
% \end{oldcomments}
%
%  \begin{macro}{\@bsphack}
% \changes{LaTeX2e}{1993/12/08}
%         {Command reimplemented; late birthday present for Chris}
%  \begin{macro}{\@esphack}
% \changes{LaTeX2e}{1993/12/08}{Command reimplemented}
% \changes{LaTeX2e}{1993/12/16}{Corrected optimisation :-)}
% 
%    These are generalised hacks which attempt to do sensible things
%    when `invisible commands' appear in vmode too.
%
%    They need to cope with space in both hmode (plus spacefactor) and
%    vmode, and also cope with breaks etc.  In vmode this means
%    ensuring that any following |\addvspace|, etc sees the correct
%    glue in |\lastskip|.
%
%    In fact, these improved versions should be used for other cases
%    of `whatsits, thingies etc' which should be invisible.  They are
%    only for commands, not environments (see notes on |\@Esphack|).
%
%    BTW, anyone know why the standard hacks are surrounded by
%    |\ifmmode\else| rather than simply |\ifhmode|?
%
%    And are there any cases where saving the spacefactor is
%    essential?  I have some extensions where it is, but it does not
%    appear to be so in the standard uses.
%    \begin{macrocode}
%\def \@bsphack{%
%  \relax \ifvmode
%    \@savsk \lastskip
%    \ifdim \lastskip=\z@
%    \else
%      \vskip -\lastskip
%    \fi
%  \else
%    \ifhmode
%      \@savsk \lastskip
%      \@savsf \spacefactor
%    \fi
%  \fi
%}
%    \end{macrocode}
%    I think that, in vmode, it is the safest to put
%    in a |\nobreak| immediately after such things since writes,
%    inserts etc followed by glue give valid breakpoints and, in
%    general, it is possible to create breaks but impossible to
%    destroy them.
%    \begin{macrocode}
%\def \@esphack{%
%   \relax \ifvmode 
%     \nobreak    
%     \ifdim \@savsk=\z@ 
%     \else 
%       \vskip\@savsk
%     \fi
%   \else 
%     \ifhmode
%       \spacefactor \@savsf
%       \ifdim \@savsk>\z@ 
%         \ignorespaces
%       \fi 
%     \fi
%   \fi
%} 
%    \end{macrocode}
%    For the moment we are going to ignore the vertical versions until
%    they are correct.
% \changes{LaTeX2e}{1993/12/19}{There seem to be problems with selfmade
%                           birthday presents}
%    \begin{macrocode}
\def \@bsphack{%
   \relax \ifhmode
     \@savsk \lastskip
     \@savsf \spacefactor
   \fi
}
\def \@esphack{%
     \relax \ifhmode
       \spacefactor \@savsf
       \ifdim \@savsk>\z@
         \ignorespaces
       \fi
     \fi
}
\def \@Esphack{%
     \relax \ifhmode
       \spacefactor \@savsf
       \ifdim \@savsk>\z@
         \global\@ignoretrue
         \ignorespaces
       \fi
     \fi
}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%
%  \begin{macro}{\@vbsphack}
% \changes{LaTeX2e}{1993/12/08}{Command added}
%    Another variant which is useful for invisible things which should
%    not live in vmode (this is how some people feel about marginals).
%
%    If it occurs in vmode then it enters hmode and ensures that
%    |\@savsk| is nonzero so that the |\ignorespaces| is put in later.  
%    \begin{macrocode}
\def \@vbsphack{ %
   \relax \ifvmode
     \leavevmode    
     \@savsk 1sp
     \@savsf \spacefactor
   \else
     \ifhmode
       \@savsk \lastskip
       \@savsf \spacefactor
     \fi
   \fi
}
%    \end{macrocode}
%  \end{macro}
%
%
% \begin{oldcomments}
% VERTICAL SPACING:
%
% LaTeX supports the PLAIN TeX commands \smallskip, \medskip and
% \bigskip. 
% However, it redefines them using \vspace instead of \vskip.
%
% Extra vertical space is added by the command command \addvspace{SKIP},
% which adds a vertical skip of SKIP to the document.  The sequence
%         \addvspace{S1} \addvspace{S2}
% is equivalent to
%         \addvspace{maximum of S1, S2}.
% \addvspace should be used only in vertical mode, and gives an error if
% it's not.  The \addvspace command does NOT add vertical space if
% @minipage = T. The minipage environment uses this to inhibit
% the addition of extra vertical space at the beginning.
%
% Penalties are put into the vertical list with the \addpenalty{PENALTY}
% command.  It works properly when \addpenalty and \addvspace commands
% are mixed.
%
% The @nobreak switch is set true used when in vertical mode and no page
% break should occur.  (Right now, it is used only by the section
% heading commands to inhibit page breaking after a heading.)
%
%
% \addvspace{SKIP} ==
%  BEGIN
%   if vmode
%     then if @minipage
%            else if \lastskip =0
%                    then  \vskip SKIP
%                    else  if \lastskip < SKIP
%                             then  \vskip -\lastskip
%                                   \vskip SKIP
%                             else if SKIP < 0 and \lastskip >= 0
%                                    then \vskip -\lastskip
%                                         \vskip \lastskip + SKIP
%          fi      fi       fi      fi
%     else 'missing \item' error.
%   fi
%  END
% \end{oldcomments}
%    \begin{macrocode}
\def\addvspace#1{\ifvmode
     \if@minipage\else
          \ifdim \lastskip =\z@ \vskip #1\relax
             \else \@tempskipb#1\relax\@xaddvskip
     \fi\fi
  \else\@noitemerr\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\@xaddvskip{\ifdim \lastskip <\@tempskipb\vskip-\lastskip\vskip
             \@tempskipb
        \else  \ifdim \@tempskipb<\z@
                 \ifdim \lastskip <\z@
                    \else \advance\@tempskipb\lastskip
                           \vskip -\lastskip \vskip \@tempskipb
      \fi\fi\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\addpenalty#1{\ifvmode
   \if@minipage\else\if@nobreak\else
      \ifdim\lastskip=\z@ \penalty#1\relax
         \else \@tempskipb\lastskip
               \vskip -\lastskip \penalty#1\vskip\@tempskipb
      \fi\fi\fi
   \else\@noitemerr\fi}
%    \end{macrocode}
%
% \begin{macro}{\vspace}
%    \begin{macrocode}
\def\vspace{\@ifstar\@vspacer\@vspace}
\def\@vspace#1{\ifvmode
    \dimen@\prevdepth \vskip #1\vskip\z@skip \prevdepth\dimen@
       \else
        \@bsphack\vadjust{\dimen@\prevdepth
            \vskip #1\vskip\z@skip \prevdepth\dimen@}\@esphack\fi}
\def\@vspacer#1{\ifvmode \dimen@\prevdepth
         \hrule \@height\z@ \nobreak \vskip #1\vskip\z@skip
           \prevdepth\dimen@
        \else
         \@bsphack\vadjust{\dimen@\prevdepth \hrule \@height\z@ \nobreak
            \vskip #1\vskip\z@skip \prevdepth\dimen@}\@esphack\fi}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\def\smallskip{\vspace\smallskipamount}
\def\medskip{\vspace\medskipamount}
\def\bigskip{\vspace\bigskipamount}
%    \end{macrocode}
%
% \begin{macro}{\endtrivlist}
% See list environment for explanation of the following macros.
%    \begin{macrocode}
\def\endtrivlist{\if@newlist\@noitemerr\fi
   \if@inlabel\indent\fi
   \ifhmode\unskip \par\fi
   \if@noparlist \else
      \ifdim\lastskip >\z@ \@tempskipa\lastskip \vskip -\lastskip
         \advance\@tempskipa\parskip \advance\@tempskipa -\@outerparskip
         \vskip\@tempskipa
   \fi\@endparenv\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{oldcomments}
% CHANGES TO \@endparenv:
% Changed  \hskip -\parindent  to  \setbox0=\lastbox  so a \noindent
% becomes a no-op when used before a line immediately following a
% list environment.  (Changed 23 Oct 86)
%
% To suppress the paragraph indentation in text immediately following
% a paragraph-making environment, \everypar is changed to remove the
% space, and \par is redefined to restore \everypar.  Instead of
% redefining \par and \everpar, \@endparenv was changed to set the
% @endpe switch, letting \end redefine \par and \everypar.  This allows
% paragraph- making environments work right when called by other
% environments. (Changed 27 Oct 86)
%    \begin{macrocode}
\def\@endparenv{%
  \addpenalty\@endparpenalty\addvspace\@topsepadd\@endpetrue}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\@doendpe{\@endpetrue
     \def\par{\@restorepar\everypar{}\par\@endpefalse}\everypar
               {\setbox\z@\lastbox\everypar{}\@endpefalse}}
%    \end{macrocode}
%
%    \begin{macrocode}
\newif\if@endpe
\@endpefalse
%    \end{macrocode}
%
% HORIZONTAL SPACE
%
% \, : used in paragraph mode produces a \thinspace.  It has the
%   ordinary definition in math mode.  Useful for quotes inside quotes,
%   as in  ``\,`Foo', he said.''
%
% \@ : placed before a '.', makes it a sentence-ending period.  Does the
%     right thing for other punctuation marks as well.  Does this by
%     setting spacefactor to 1000.
%
% \end{oldcomments}
%
% \changes{v1.0o}{1994/05/11}{Use \cmd\DeclareProectedCommand. ASAJ.}
%
%    \begin{macrocode}
\DeclareRobustCommand{\,}{%
   \relax\ifmmode\mskip\thinmuskip\else\thinspace\fi
}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\@{\spacefactor\@m}
%    \end{macrocode}
%
% \changes{v1.0o}{1994/05/11}{Use \cmd\DeclareProectedCommand. ASAJ.}
%
%    \begin{macrocode}
\DeclareRobustCommand{\hspace}{\@ifstar\@hspacer\@hspace}
%    \end{macrocode}
%
% \changes{LaTeX2e}{1993/08/05}
%    {(RmS) Removed superfluous \cs{leavevmode} in \cs{@hspace} and
%               \cs{@hspacer}, as suggested by CAR.}
%    \begin{macrocode}
\def\@hspace#1{\hskip #1\relax}
%    \end{macrocode}
% \begin{oldcomments}
%
%    \begin{macrocode}
\def\@hspacer#1{\vrule \@width\z@\nobreak
                \hskip #1\hskip \z@skip}
                      % extra \hskip 0pt added 12/17/85 to guard
                      % against a following \unskip
                      % \relax added 13 Oct 88 for usual TeX lossage
                      % replaced both changes by \hskip\z@skip 27 Nov 91
%    \end{macrocode}
% define \fill to = 0pt plus 1fill
%    \begin{macrocode}
\newskip\fill \fill = 0pt plus 1fill
%    \end{macrocode}
%
% \stretch{N} == 0pt plus N fill
%    \begin{macrocode}
\def\stretch#1{\z@ \@plus #1fill\relax}
%    \end{macrocode}
%
%    \begin{macrocode}
{\catcode`\^^M=13 \gdef\obeycr{\catcode`\^^M=13 \def^^M{\\}\@gobblecr}%
\gdef\restorecr{\catcode`\^^M=5 }} %} BRACE MATCHING
%</2ekernel>
%    \end{macrocode}
%
% \end{oldcomments}
%
% \Finale
\endinput

