% \iffalse meta-comment
%
% Copyright 1993-1995 the LaTeX3 project and any individual authors
% listed elsewhere in this file.  All rights reserved.
% 
% For further copyright information see the file legal.txt, and any
% other copyright notices 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.
% 
%   For error reports concerning UNCHANGED versions of this file no more
%   than one year old, see bugs.txt.
% 
%   Please do not request updates from us directly.  Primary
%   distribution is through the CTAN archives.
% 
% 
% IMPORTANT COPYRIGHT NOTICE:
% 
% You are NOT ALLOWED to distribute this file alone.
% 
% You are allowed to distribute this file under the condition that it is
% distributed together with all the files listed in manifest.txt.
% 
% If you receive only some of these files from someone, complain!
% 
% Permission is granted to copy this file to another file with a clearly
% different name and to customize the declarations in that copy to serve
% the needs of your installation, provided that you comply with
% the conditions in the file legal.txt.
% 
% However, NO PERMISSION is granted to produce or to distribute a
% modified version of this file under its original name.
%  
% You are NOT ALLOWED to change this file.
% 
% 
% \fi
%
% \iffalse
%%% File: ltspace.dtx
%<*driver>
% \fi
\ProvidesFile{ltspace.dtx}
             [1995/06/11 v1.2g 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{484}
%
% \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> == \\\relax.
% \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}
%
% \end{oldcomments}
%
%  \begin{macro}{\nopagebreak}
%  \begin{macro}{\@nopgbk}
%    \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}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\pagebreak}
%  \begin{macro}{\@pgbk}
%    \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}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\nolinebreak}
%  \begin{macro}{\@nolnbk}
%    \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}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\linebreak}
%  \begin{macro}{\@lnbk}
%    \begin{macrocode}
\def\linebreak{\@ifnextchar[\@lnbk{\@lnbk[4]}}
\def\@lnbk[#1]{\ifvmode \@nolnerr\else
     \unskip\penalty -\@getpen{#1}\fi}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\samepage}
%    \begin{macrocode}
\def\samepage{\interlinepenalty\@M
   \postdisplaypenalty\@M
   \interdisplaylinepenalty\@M
   \@beginparpenalty\@M
   \@endparpenalty\@M
   \@itempenalty\@M
   \@secpenalty\@M
   \interfootnotelinepenalty\@M}
%    \end{macrocode}
%  \end{macro}
%
%
%  \begin{macro}{\newline}
% |\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}
%  \end{macro}
%
%  \begin{macro}{\\}
% \changes{v1.2a}{1994/11/11}{(DPC) Make robust}
% \changes{v1.2d}{1994/11/14}{(DPC) macro modified}
%  \begin{macro}{\@normalcr}
% The internal definition of the `normal' definition of |\\|.
%    \begin{macrocode}
\DeclareRobustCommand\\{%
  \@ifstar
    {\vadjust{\penalty\@M}\@xnewline}%
    \@xnewline}
\expandafter\let\expandafter\@normalcr
     \csname\expandafter\@gobble\string\\ \endcsname
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\@xnewline}
%    \begin{macrocode}
\def\@xnewline{\@ifnextchar[\@newline\newline}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\@newline}
%    \begin{macrocode}
\def\@newline[#1]{\ifhmode\unskip\fi\vspace{#1}\newline}
%    \end{macrocode}
%  \end{macro}
%
% \begin{oldcomments}
%    \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.  
%    It is not used at present.
% \changes{v1.2f}{1995/05/25}{(CAR) not used so `removed'.}
%    \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 useful error message (CAR).
%   fi
%  END
%
%    \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}
%
% \end{oldcomments}
% 
%  \begin{macro}{\addvspace}
% \changes{v1.2b}{1994/11/12}{Corrected error message}
% \changes{v1.2c}{1994/11/13}{Recorrected error message}
%    
%    \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}
%  \end{macro}
%
%  \begin{macro}{\addpenalty}
% \changes{v1.2b}{1994/11/12}{Corrected error message}
% \changes{v1.2c}{1994/11/13}{Recorrected error message}
%    
%    \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}
%  \end{macro}
%
% \begin{macro}{\vspace}
% \begin{macro}{\@vspace}
% \begin{macro}{\@vspacer}
% \changes{v1.2f}{1995/05/25}
%         {(CAR) macros modified to be more efficient}
% \changes{v1.2f}{1995/05/25}{(CAR) \cs{@restorepar} added to avoid 
%   possible infinite tail recursion caused by a typo in the argument.}
%    The new code for these commands depends on the following facts:
%    \begin{itemize}
%      \item The value of prevdepth is changed only when a box or rule 
%        is created and added to a vertical list;
%      \item The value of prevdepth is used only when a box is created 
%        and added to a vertical list;
%      \item The value of prevdepth is always local to the building of 
%        one vertical list. 
%    \end{itemize}
%    \begin{macrocode}
\def\vspace{\@ifstar\@vspacer\@vspace}
\def\@vspace #1{%
  \ifvmode
    \vskip #1
    \vskip\z@skip
   \else
     \@bsphack
     \vadjust{\@restorepar
              \vskip #1
              \vskip\z@skip
              }%
     \@esphack
   \fi
}
\def\@vspacer #1{%
  \ifvmode
    \dimen@\prevdepth
    \hrule \@height\z@
    \nobreak
    \vskip #1
    \vskip\z@skip
    \prevdepth\dimen@
  \else
    \@bsphack
    \vadjust{\@restorepar
             \hrule \@height\z@
             \nobreak
             \vskip #1
             \vskip\z@skip
             }%
    \@esphack
  \fi
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
\def\smallskip{\vspace\smallskipamount}
\def\medskip{\vspace\medskipamount}
\def\bigskip{\vspace\bigskipamount}
%    \end{macrocode}
%    
%    \begin{macrocode}
\newskip\smallskipamount \smallskipamount=3pt plus 1pt minus 1pt
\newskip\medskipamount   \medskipamount  =6pt plus 2pt minus 2pt
\newskip\bigskipamount   \bigskipamount =12pt plus 4pt minus 4pt
%    \end{macrocode}
%
% \begin{macro}{\endtrivlist}
% \begin{macro}{\@endparenv}
% \begin{macro}{\@doendpe}
% \changes{v1.2b}{1994/11/12}{Changed order of tests to make
% \cs{@noitemerror} correct: end of an era!}
% \changes{v1.2f}{1995/05/25}{Macros moved to ltlists.dtx}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{oldcomments}
%
% 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}
\def\thinspace{\kern .16667em }
\def\negthinspace{\kern-.16667em }
\def\enspace{\kern.5em }
%    \end{macrocode}
%
%    \begin{macrocode}
\def\enskip{\hskip.5em\relax}
\def\quad{\hskip1em\relax}
\def\qquad{\hskip2em\relax}
%    \end{macrocode}
%
% 
%
% \changes{v1.2g}{1995/06/11}
%                {(CAR) \cs{relax} added to stop silent eating of *.}
%    \begin{macrocode}
{\catcode`\^^M=13 \gdef\obeycr{\catcode`\^^M13 \def^^M{\\\relax}%
    \@gobblecr}%
\gdef\restorecr{\catcode`\^^M5 }} 
%</2ekernel>
%    \end{macrocode}
%
% \end{oldcomments}
%
% \Finale
\endinput

