% This macro source file is from the four volume series
% "TeX in Practice" by Stephan von Bechtolsheim, published
% 1993 by Springer-Verlag, New York.
% Copyright 1993 Stephan von Bechtolsheim.
% No warranty or liability is assumed.
% This macro may be copied freely if no fees other than
% media cost or shipping charges are charged and as long
% as this copyright and the following source code itself
% is not changed. Please see the series for further information.
%
% Version: 1.0
% Date: May 1, 1993
%
%
% This source code is documented in 35.9.1, p. IV-122.
% Original source in file "o2.TEX", starting line 1834.
\wlog{L: "ts-outpu.tip" ["o2.TEX," l. 1834, p. IV-122]}%
% This file DOES belong to format "texip."
\InputD{namedef.tip}
\InputD{showpll.tip}
\InputD{new-midi.tip}
\InputD{topinfix.tip}
\InputD{nathd.tip}
\InputD{rangetst.tip}
\newif\ifWritePageLog
\WritePageLogfalse
\newwrite\PageLogStream
\def\WritePageLogFile{%
    \immediate\openout\PageLogStream = \jobname.plog
    \WritePageLogtrue
}
\newcount\BadnessSave
\ShowPlainListsfalse
\catcode`\@ = 11
\newcount\@PageLayoutCode
\def\SetPageLayout #1{% 
    \global\@PageLayoutCode = #1
    \CheckRange{\@PageLayoutCode}{0}{5}%
        {\string\SetPageLayout: }
}
\SetPageLayout{0}%
\def\@LeftRunningHead{}
\def\@RightRunningHead{}
\newcount\@SavedPageLayoutCode
\def\NewPageRightHandSpecial{% 
    \vfill
    \supereject
    \ifodd\count0
        \wlog{\string\NewPageRightHandSpecial: no empty
            page to generate (\string\count0 = \the\count0)}%
    \else
        \hbox{}
        \@SavedPageLayoutCode = \@PageLayoutCode
        \SetPageLayout{1}%
        \wlog{\string\NewPageRightHandSpecial: empty page
            generated,
            (\string\count0 = \the\count0).}%
        \vfill
        \eject
        \SetPageLayout{\@SavedPageLayoutCode}%
    \fi
}
\newdimen\OddPagesHorizontalShift
\newdimen\EvenPagesHorizontalShift
\newdimen\CurrentPageShift
\def\plainoutput{% 
    \@ShowPlainLists
    \edef\@LeftRunningHead{\@LeftRunningHead}%
    \edef\@RightRunningHead{\@RightRunningHead}%
    \ifnum\@PageLayoutCode = 0
    \else
        \headline = {}
        \footline = {}
    \fi
    \ifcase\@PageLayoutCode
    \or
    \or
        \global\@PageLayoutCode = 3
    \or
        \@PageLayoutCodeThree
    \or
        \global\@PageLayoutCode = 5
    \or
        \ifodd\count0
            \headline = {% 
                \small\rm
                \hfil
                \botmark
                \hskip 18pt
                \PrintCounter{PageNo}%
            }%
        \else
            \headline = {% 
                \small\rm
                \PrintCounter{PageNo}%
                \hskip 18pt
                \@LeftRunningHead
                \hfil
            }%
        \fi
    \else
        \errmessage{\string\plainoutput: \string\@PageLayoutCode
            out of range.}%
    \fi
    \setbox 4 = \vbox{%
        \pagebody
    }%
    \ifWritePageLog
        \immediate\write\PageLogStream{%
            Part name: \CurrentPartName, Page \the\count0
        }%
        \immediate\write\PageLogStream{%
            Page \the\count0:
            stretch: \the\pagestretch,
            shrink: \the\pageshrink,
            outputpenalty: \the\outputpenalty
        }%
        \immediate\write\PageLogStream{%
            pagefilstretch: \the\pagefilstretch,
            pagefillstretch: \the\pagefillstretch
        }%
        \immediate\write\PageLogStream{%
            ht 255: \the\ht255,
            dp 255: \the\dp255
        }%
        \NaturalHeight{\dimen0}{255}%
        \NaturalDepth{\dimen1}{255}%
        \immediate\write\PageLogStream{%
            Natural height: \the\dimen0,
            Natural depth:  \the\dimen1
        }%
        \dimen2 = \vsize
        \advance\dimen2 by -\dimen0
        \immediate\write\PageLogStream{%
            Ideal height: \the\vsize,
            Difference:  \the\dimen2
        }%
        \immediate\write\PageLogStream{%
            badness: \the\BadnessSave,
            height: \the\ht4,
            depth: \the\dp4
        }%
        \immediate\write\PageLogStream{}%
    \fi
    \setbox 5 = \vbox{%
        \makeheadline
        \box 4
        \makefootline
    }%
    \@MakeRobustMacros
    \ifodd\count0
        \CurrentPageShift = \OddPagesHorizontalShift
    \else
        \CurrentPageShift = \EvenPagesHorizontalShift
    \fi
    \wlog{Redefined \string\plainoutput (ts-outpu.tip):
        Shifting: shift amount is \the\CurrentPageShift\space\space
        (page is \the\pageno).}%
    \setbox 6 = \vbox{%
        \moveright\CurrentPageShift \box5
    }%
    \shipout\box6
    \advancepageno
    \ifnum\outputpenalty > -10000
    \else
        \dosupereject
    \fi
}
\def\@PageLayoutCodeThree{%
    \ifodd\count0
        \headline = {% 
            \small\rm
            \hfil
            \@RightRunningHead
            \hskip 18pt
            \PrintCounter{PageNo}%
        }%
    \else
        \headline = {% 
            \small\rm
            \PrintCounter{PageNo}%
            \hskip 18pt
            \@LeftRunningHead
            \hfil
        }%
    \fi
}
\catcode`\@ = 12
