%%----------------------------------------------------------------------
%% Vpage.sty
%%
%% Page size / layout macros. For use with LaTeX.
%%
%% (C) Volker Kuhlmann, 1993
%%
%% Explanation after (last) \endinput. Do not alter this file!
%%----------------------------------------------------------------------

\immediate\typeout{Style `Vpage', V2.2, 18 June 1993}


% so that Vpage can be loaded more than once
\@ifundefined{@@@Vpage}{\def\@@@Vpage{l}}{\endinput}


% Pre-defined paper sizes:
%
\def\paper@Azero        {\PaperWidth 841mm \PaperHeight1189mm\@po@}
\def\paper@Aone         {\PaperWidth 595mm \PaperHeight 841mm\@po@}
\def\paper@Atwo         {\PaperWidth 420mm \PaperHeight 595mm\@po@}
\def\paper@Athree       {\PaperWidth 297mm \PaperHeight 420mm\@po@}
\def\paper@Afour        {\PaperWidth 210mm \PaperHeight 297mm\@po@}
\def\paper@Afive        {\PaperWidth 149mm \PaperHeight 210mm\@po@}
\def\paper@Asix         {\PaperWidth 105mm \PaperHeight 149mm\@po@}
\def\paper@Aseven       {\PaperWidth  74mm \PaperHeight 105mm\@po@}
\def\paper@Aeight       {\PaperWidth  53mm \PaperHeight  74mm\@po@}
\def\paper@Bzero        {\PaperWidth1000mm \PaperHeight1414mm\@po@}
\def\paper@Bone         {\PaperWidth 707mm \PaperHeight1000mm\@po@}
\def\paper@Btwo         {\PaperWidth 500mm \PaperHeight 707mm\@po@}
\def\paper@Bthree       {\PaperWidth 353mm \PaperHeight 500mm\@po@}
\def\paper@Bfour        {\PaperWidth 250mm \PaperHeight 353mm\@po@}
\def\paper@Bfive        {\PaperWidth 176mm \PaperHeight 250mm\@po@}
\def\paper@Czero        {\PaperWidth 917mm \PaperHeight1297mm\@po@}
\def\paper@Cone         {\PaperWidth 648mm \PaperHeight 917mm\@po@}
\def\paper@Ctwo         {\PaperWidth 458mm \PaperHeight 648mm\@po@}
\def\paper@Cthree       {\PaperWidth 324mm \PaperHeight 458mm\@po@}
\def\paper@Cfour        {\PaperWidth 229mm \PaperHeight 324mm\@po@}
\def\paper@Cfive        {\PaperWidth 162mm \PaperHeight 229mm\@po@}
\def\paper@Csix         {\PaperWidth 114mm \PaperHeight 162mm\@po@}
\def\paper@Cseven       {\PaperWidth  81mm \PaperHeight 114mm\@po@}
\def\paper@Ceight       {\PaperWidth  57mm \PaperHeight  81mm\@po@}
\def\paper@USletter     {\PaperWidth 8.5in \PaperHeight 11in \@po@}
\def\paper@USlegal      {\PaperWidth 8.5in \PaperHeight 14in \@po@}
\def\paper@USexecutive  {\PaperWidth 7.25in\PaperHeight 10.5in\@po@}
\def\paper@custom#1#2{   \PaperWidth #1    \PaperHeight #2\@po@}

%%----------------------------------------------------------------------

% new lengths: \PaperWidth, \PaperHeight
% new if: \ifLandscape

\newdimen\PaperWidth
\newdimen\PaperHeight

\newif\ifLandscape


% macros

\def\setpapersize{\@ifnextchar[{\@@setps}{\@@setps[portrait]}}
\def\@@setps[#1]#2{\csname po@#1\endcsname\csname paper@#2\endcsname}
\def\po@portrait{\Landscapefalse}
\def\po@landscape{\Landscapetrue}
\def\@po@{\ifLandscape\dimen0\PaperWidth
  \PaperWidth\PaperHeight\PaperHeight\dimen0\fi\relax}

\@ifundefined{margin@offset}{
\def\margin@offset{
        \oddsidemargin  0in
        \evensidemargin 0in
        \topmargin      0in
        \hoffset        -1in    % to compensate for the
        \voffset        -1in    %   +1in/+1in top/left corner
}}{}

% leftmargin, topmargin, textwidth, textheight, 
%   headheight, headsep, footheight, footskip
\def\setmargins#1#2#3#4#5#6#7#8{%
        \margin@offset
        \advance\oddsidemargin  #1
        \advance\evensidemargin \PaperWidth     % = paperwidth - left
        \advance\evensidemargin -#1             %       - width
        \advance\evensidemargin -#3
        \advance\topmargin      #2
        \textwidth      #3
        \textheight     #4
        \headheight     #5
        \headsep        #6
        \footheight     #7
        \footskip       #8
        \chk@dimen{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}
}

% leftmargin, topmargin, rightmargin, bottommargin, 
%   headheight, headsep, footheight, footskip
\def\setmarginsrb#1#2#3#4#5#6#7#8{%
        \margin@offset
        \textwidth              \PaperWidth     % = paperwidth
        \advance\textwidth      -#1             %  - left - right
        \advance\textwidth      -#3
        \textheight             \PaperHeight    % = paperheight - top
        \advance\textheight     -#2             %  - headheight
        \advance\textheight     -#5             %  - headsep
        \advance\textheight     -#6             %  - footskip - bottom
        \advance\textheight     -#8
        \advance\textheight     -#4
        \advance\oddsidemargin  #1
        \advance\evensidemargin \PaperWidth     % = paperwidth
        \advance\evensidemargin -#1             %  - left - width
        \advance\evensidemargin -\textwidth
        \advance\topmargin      #2
        \headheight     #5
        \headsep        #6
        \footheight     #7
        \footskip       #8
        \chk@dimen{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}
}

\def\chk@dimen#1#2#3#4#5#6#7#8{%
        \dimen0=#1
        \advance\dimen0 by#3
        \advance\dimen0 by-\PaperWidth
        \dimen1=#2
        \advance\dimen1 by#5
        \advance\dimen1 by#6
        \advance\dimen1 by#4
        \advance\dimen1 by#8
        \advance\dimen1 by-\PaperHeight
        \ifnum\dimen0>\z@\typeout{Vpage Warning: Horizontal dimensions
          exceed paper width by \the\dimen0}\fi\relax
        \ifnum\dimen1>\z@\typeout{Vpage Warning: Vertical dimensions
          exceed paper height by \the\dimen1}\fi\relax
}


%
% DEFAULTS:
%
\setpapersize{Afour}
%\setmarginsrb{25mm}{20mm}{20mm}{10mm}{12pt}{0mm}{0pt}{10mm}
\setmarginsrb{35mm}{20mm}{25mm}{15mm}{12pt}{11mm}{0pt}{11mm}
\parskip                2ex plus 0.5ex minus 0.5ex
\parindent              0em
\clubpenalty            500             % 150 by plain
\widowpenalty           500             % 150 by plain
\displaywidowpenalty    100             %  50 by plain
\brokenpenalty          250             % 100 by plain
\marginparwidth         15mm
\marginparsep           3.5mm
\skip\footins           1.3\skip\footins
\footnotesep            1.2\footnotesep
\def\baselinestretch{1.0}
\def\arraystretch{1.0}
\def\textfraction{.2}
%\def\topfraction{.8}
%\def\bottomfraction{.2}
\flushbottom


\endinput

%%----------------------------------------------------------------------

Page Size and Margins
=====================

These macros make it easy to set page margins for a chosen paper size.
Actual dimensions of the most common paper sizes are stored and need
not be remembered.

Two sided printing is supported, meaning if on odd pages the left
margin is, say, 30mm and the right margin is 20mm, it will be vice
versa on even pages. This gives equal margins on the outer and the
inner edge of the paper, as expected e.g. for a book.

The size of the paper can be set with 

        \setpapersize{<size>}

<size> can be Afour, Bfive, USletter, ... A list of the pre-defined
paper sizes appears at the beginning of this file. 

Landscape format is selected by using the optional argument

        \setpapersize[landscape]{<size>}

which swaps the width and height dimensions of the paper.
\setpapersize[portrait]{<size>} is allowed but is the default.

If you have a size which is not pre-defined use

        \setpapersize{custom}{<width>}{<height>}

For <width> and <height> insert the respective dimensions of your
paper.

\setpapersize stores the actual dimensions of the paper in the length
variables

        \PaperWidth
        \PaperHeight

which can be used further, if desired.

        \ifLandscape

yields true if a landscape format is selected. Do not write
\PaperWidth, \PaperHeight, or call \Landscapetrue or \Landscapefalse,
it will not work!!

The margins can be set with

        \setmargins{leftmargin}{topmargin}{textwidth}{textheight}%
                   {headheight}{headsep}{footheight}{footskip}

or with

        \setmarginsrb{leftmargin}{topmargin}{rightmargin}{bottommargin}%
                     {headheight}{headsep}{footheight}{footskip}

In the latter case \textwidth and \textheight are calculated. The first
four parameters of the above two commands are used to set
\oddsidemargin, \evensidemargin, \textwidth, \topmargin, and
\textheight.

Example:

        A4 paper, left margin 30mm, top, right, and bottom margin 20mm
        each, no headers or footers:

        \setpapersize{Afour}
        \setmarginsrb{30mm}{20mm}{20mm}{20mm}{0pt}{0mm}{0pt}{0mm}
        \pagestyle{empty}

For the default settings please see the part after "DEFAULTS:" (last
part before \endinput).  This style also sets several other paragraph
parameters to new values.

The default top and left margins of TeX are +1in. \setmargins
or \setmarginsrb call

        \margin@offset

which sets \hoffset, \voffset to -1in before \setmargins or
\setmarginsrb add the values specified to \topmargin, \oddsidemargin,
\evensidemargin. If \margin@offset is already defined at the time Vpage
is loaded it is NOT redefined! Therefore if \margin@offset is defined
before Vpage is loaded the above mentioned margins can be set to other
values than -1in before the values specified with \setmargin or
\setmarginsrb are added.  \margin@offset should be defined in a
separate file which is included BEFORE Vpage, i.e. appears in the list
of document-substyles of the \documentstyle command before Vpage.

Example:  \documentstyle[...,margins,Vpage,...]{...} 
          if \margin@offset is defined in a file called margins.sty.


Hints for using pageframe.sty
-----------------------------

Vpage.sty and pageframe.sty can be used together if the following
points are considered:

Vpage uses \hoffset and \voffset and writes negative values into it,
pageframe expects them to be zero to give a 1in space on the left and
the top where it prints additional information. Initially, set both to
0mm (in the pre-amble of your text) and adjust them later on.

pageframe needs to know the trimmed height of the paper (= the height
of the "page frame"). Unless the trimmed(!) size of the paper is
equivalent to one of the standard paper sizes (unlikely...) the size
should be specified with

        \setpapersize{custom}{<width>}{<height>}

The correct height of the trimmed page can then be given to pageframe
using

        \paperheight{\PaperHeight}

and the margins of the final product (inside the page frame) can be
specified using \setmargins or \setmarginsrb.

Warning: if \setmarginsrb is used the 3rd parameter (right margin) is
ignored. Instead, the dimension of the right margin has to be assigned
to \evensidemargin. This is because pageframe.sty re-defines the meaning
of \evensidemargin to be the right margin of your text.

All these assignments and macro calls have to be done in the pre-amble
of your document.



SUMMARY:
--------

new lengths:
  \PaperWidth
  \PaperHeight

new ifs:
  \ifLandscape

new macros:
  \setpapersize[<orientation>]{<size>}, 
  \setpapersize[<orientation>]{custom}{<width>}{<height>}
        <orientation> (optional) = landscape or portrait (default)
        <size> = Afour, Bfive, ...
        <width>, <height> = actual dimensions of the paper
  \setmargins{leftmargin}{topmargin}{textwidth}{textheight}%
             {headheight}{headsep}{footheight}{footskip}
  \setmarginsrb{leftmargin}{topmargin}{rightmargin}{bottommargin}%
               {headheight}{headsep}{footheight}{footskip}
%
  \margin@offset


If you have any comments (positive or negative) please let me know!


Copyright (C) Volker Kuhlmann

Use of these macros is granted free of charge provided that this file
is left intact and that no charge is made for its distribution.

Currently: 26 Woodford Tce, Christchurch, New Zealand.
           KUHLMAV@elec.canterbury.ac.nz
%
%% EOF Vpage.sty
%%----------------------------------------------------------------------

