0% found this document useful (0 votes)
25K views

The Geometry Package: Hideo Umeki Hideo - Umeki@toshiba - Co.jp 2000/06/28 (v2.3)

The geometry package provides an easy interface for customizing page layout in LaTeX. It implements automatic centering and balancing mechanisms so that users only need to provide minimal descriptions for page layout. The package defines dimensions for paper size, text area, margins and headers/footers. It can automatically determine unspecified dimensions based on completion rules to achieve balancing or centering of elements on the page.

Uploaded by

Ajuchán Eliezer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25K views

The Geometry Package: Hideo Umeki Hideo - Umeki@toshiba - Co.jp 2000/06/28 (v2.3)

The geometry package provides an easy interface for customizing page layout in LaTeX. It implements automatic centering and balancing mechanisms so that users only need to provide minimal descriptions for page layout. The package defines dimensions for paper size, text area, margins and headers/footers. It can automatically determine unspecified dimensions based on completion rules to achieve balancing or centering of elements on the page.

Uploaded by

Ajuchán Eliezer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

The geometry package

Hideo Umeki
[email protected]
2000/06/28 (v2.3)
Abstract
This package provides an easy and exible user interface to customize page layout. It
implements auto-centering and auto-balancing mechanisms so that the users have only to
give the least description for the page layout.
Contents
1 Preface to Version 2 1
2 Preface to Version 2.3 2
3 Introduction 2
4 Page Geometry 3
4.1 Layout Dimensions . . . . . . 3
4.2 Completion Algorithm . . . . 4
5 User Interface 4
5.1 General Features . . . . . . . 4
5.2 Option Types . . . . . . . . . 6
6 Option List 7
6.1 Boolean Options . . . . . . . 7
6.2 Single-Valued Options . . . . 8
6.3 Two-Valued Options . . . . . 9
6.4 Three-Valued Options . . . . 9
7 Relations Between Options 10
7.1 Option Priority . . . . . . . . 10
7.2 Order Dependence . . . . . . 10
7.3 dvips and pdftex . . . . . . . . 10
8 Default Settings 11
8.1 Default Option . . . . . . . . 11
8.2 Conguration File . . . . . . 11
9 Examples 11
10 Acknowledgements 12
11 The Code 12
1 Preface to Version 2
This new release contains three major changes:
The geometry options using the keyval scheme can be set in the optional argument to the
\usepackage command as well as in the (mandatory) argument of the \geometry macro.
Therefore, you can go
\usepackage[scale={0.7,0.8},nohead]{geometry}
instead of
\usepackage{geometry}
\geometry{scale={0.7,0.8}, nohead}.
Multiple use of \geometry macro is allowed. In the previous version \geometry command
initialized layout dimensions before reading its options. In this release, however, \geometry
just appends its options to the previously specied ones. Therefore,
\usepackage[width=10cm, left=3cm]{geometry}
\geometry{left=5cm}
\geometry{vscale=0.8,nohead}
is equivalent to
\usepackage[width=10cm, left=5cm, vscale=0.8, nohead]{geometry}.
1
If you want to reset layout dimensions and modes, you can use reset option.
The shortened control sequences for \paperwidth and \paperheight, \w and \h respec-
tively, were removed.
2 Preface to Version 2.3
This release contains the following changes:
columnsep and footnotesep options are added. footnotesep controls \skip\footins,
the separation between the bottom of text body and the top of footnote text.
vtex option is added to support VT
E
X.
Magnication setting is sophisticated. mag option becomes order-independent. In addition,
truedimen option is introduced to add true before all internal explicit dimension values.
Then one can use, for example,
\usepackage[a4paper,mag=1440,truedimen]{geometry}
or \usepackage[a4paper,mag=\magstep2,truedimen]{geometry}.
They will have an eect that the paper size will be really A4, while all the fonts in the
document will be magnied by 1.440.
3 Introduction
To set dimensions for page layout in L
A
T
E
X is not straightforward. You need to adjust several
L
A
T
E
X dimensions to place a text area where you want. If you want to center the text area in
the paper you use, for example, you have to specify L
A
T
E
X dimensions as follows:
\usepackage{calc}
\setlength\textwidth{8in}
\setlength\textheight{11in}
\setlength\oddsidemargin{(\paperwidth-\textwidth)/2 - 1in}
\setlength\topmargin{(\paperheight-\textheight
-\headheight-\headsep-\footskip)/2 - 1in}.
Without calc package, the above example would need more tedious settings. The geometry
package provides an easy way to set page layout parameters. In this case, what you have to do
is just
\usepackage[body={8in,11in}]{geometry}.
In addition to this centering problem, setting margins from each edge of the paper is also trou-
blesome. However, with geometry package, you can go
\usepackage[margin=1.5in]{geometry}
if you want to set each margin 1.5in from each edge of the paper. In both cases, the remnant
dimensions to be specied will be automatically determined. The package will be also useful
when you have to set page layout obeying the following strict instructions: for example,
The total allowable width of the text area is 6.5 inches wide by 8.75 inches high. The
rst line on each page should begin 1.2 inches from the top edge of the page. The
left margin should be 0.4 inch from the left edge.
In this case, using geometry package you can go
\usepackage[body={6.5in,8.75in},
top=1.2in, left=0.4in, nohead]{geometry}.
Setting a text area on the paper in document preparation system has some analogy to placing
a window on the background in the window system. The name geometry comes from the
-geometry option used for specifying a size and location of a window in X Window System.
2
Dimension names used in this package
Parts Horizontal Vertical
paper paperwidth paperheight
total-body width or totalwidth height or totalheight
body textwidth textheight
left margin left or lmargin
right margin right or rmargin
top margin top or tmargin
bottom margin bottom or bmargin
head headheight and
headsep
foot footskip
marginal notes marginparwidth and
marginparsep

Table 1: Page geometry parts and dimension names used in this package.
paper
total body
height
width
paperwidth
paperheight
top
bottom
left right


total body
textwidth
headheight
headsep
textheight
footskip
head
body
foot
Figure 1: Dimension names for page geometry. If includemp is false (default),
width=textwidth.
4 Page Geometry
4.1 Layout Dimensions
To realize a straightforward setting for page layout, the following page structure is introduced:
A paper contains a total body (printable area) and margins. The total body consists of a body
(text area), a header, a footer and a marginal note which is optional. There are four margins:
left-, right-, top- and bottom-margin.
paper : total-body (printable area) and margins
total-body : head, body(text area), foot and marginal notes (option)
margins : left-, right-, top- and bottom-margin
Each margin is measured from the corresponding edge of a paper. For example, left-margin
means a horizontal distance between the left edge of the paper and that of the total body.
Therefore the left-margin and top-margin dened in the geometry package are dierent from the
ordinary L
A
T
E
X dimensions \leftmargin and \topmargin. The size of a body (text area) can
be modied by \textwidth and \textheight.
The layout parts and the corresponding dimension names used in this package are listed in
Table 1 and showed schematically in Figure 1. The dimensions for paper, total body and
margins have the following relations.
paperwidth = left + width + right (1)
paperheight = top + height + bottom (2)
The dimensions of the total body, width and height, are dened as follows:
width := textwidth (+marginparsep + marginparwidth) (3)
height := textheight + headheight + headsep + footskip (4)
3
Modes Eects
nohead sets headheight=0pt, headsep=0pt.
nofoot sets footskip=0pt.
noheadfoot equals nohead and nofoot
includemp takes account of the dimensions for marginal notes
when determining width:
width := textwidth + marginparsep + marginparwidth
reversemp makes the marginal notes appear in the left margin
and sets includemp unless includemp=false exists.
reversemarginpar results in the same eect.
Table 2: Layout modes dened in this package and their eects.
Settings Results
left width right left width right
top height bottom top height bottom
* * * m m Default
A * * A R
1
A Balancing
* * A A R
1
A Balancing
* A * = R
2
A R
2
Centering
A B * A B R
3
A * B A R
3
B
* A B R
3
A B
A C B A R
3
B Margins win.
Table 3: Dimension completion rules. The mark * denotes the dimensions not
specied. Each unspecied dimension will be given a proper value ac-
cording the completion rule. See text for explanation of other symbols.
Each of the seven dimensions in the right-hand side of Equations (3) and (4) corresponds to the
ordinary L
A
T
E
X control sequence with the same name.
Table 2 shows layout modes dened in the geometry package, which are used to control layout
dimensions and change relations between them. Figure 2 illustrates various layouts of total body
with dierent layout modes. For example, when includemp mode is on, width takes account
of lengths for marginal notes (marginparsep and marginparwidth) in the Equation (3) (See
Figure 2(b)). The dimensions for a header and a footer can be controlled by nohead or nofoot
mode, as well as direct specication. The geometry package can also deal with standard layout
modes (options), i.e., landscape, portrait, twoside and paper size.
4.2 Completion Algorithm
The automatic completion of layout dimension is a distinguishing feature of this package. Sup-
pose that the paper size is pre-dened in Equation (1) or (2), if two dimensions out of three
in the right-hand side of each equation are given, the remnant dimension will be determined
automatically. In addition, even when only one of three is given, the rest of dimensions will
be determined using auto-balancing or auto-centering scheme. The completion rules are shown
in Table 3 and Equation (5). In Table 3, R
n
(n=1, 2, 3) are the remnant lengths which can be
determined by A, B and L (paperwidth or paperheight) according the following relations.
R
1
= L 2A auto-balancing
R
2
= (L A)/2 auto-centering
R
3
= L A B obvious completion
(5)
If none of three dimensions is specied in each direction, the default setting is used: and m in
horizontal direction are 80% and 10% of paperwidth respectively, 90% and 5% of paperheight
vertically.
5 User Interface
5.1 General Features
The geometry options using the keyval interface key=value can be set either in the optional
argument to the \usepackage command, or in the argument of the \geometry macro. This
4
(a) default
total body
textwidth
headheight
headsep
textheight
footskip
head
body
foot
(b) includemp
total body
head
body
marginal
note
foot
textwidth
marginparwidth
marginparsep
(c) nohead
total body
textheight
footskip
body
foot
textwidth
(d) nohead,includemp
total body
body
marginal
note
foot
textwidth
marginparwidth
marginparsep
Figure 2: Sample layouts of total body with dierent layout modes. (a) default, (b)
includemp, (c) nohead, and (d) nohead and includemp. Marginal note can be
changed its placement from the right-hand to the left-hand side of the total body
by reversemp. If both twoside and includemp are eective, marginal note will
appear on the left (odd pages) and the right (even pages) by turns. Note that
marginal notes can be printed even by default or includemp=false, but then the
width of total body will not include that of marginal notes.
5
macro, if necessary, should be placed in the preamble, i.e., before \begin{document}. In either
case, the argument consists of a list of comma-separated keyval options. The main features of
setting options are listed below.
Multiple lines are allowed. (But blank lines are not allowed.)
Any spaces between words are ignored.
Options are basically order-independent.
(There are some exceptions. See Section 7.2 for details.)
For example,
\usepackage[ a5paper , hmargin = { 3cm,
.8in } , height
= 10in ]{geometry}
is equivalent to
\usepackage[height=10in,a5paper,hmargin={3cm,0.8in}]{geometry}
Note that the order of values in the sub-list (e.g., hmargin={3cm,0.8in}) is signicant. The
above setting is equivalent to the followings:
\usepackage{geometry}
\geometry{height=10in,a5paper,hmargin={3cm,0.8in}}
or
\usepackage[a5paper]{geometry}
\geometry{hmargin={3cm,0.8in},height=8in}
\geometry{height=10in}.
Thus, multiple use of \geometry just appends options.
The geometry package supports the calc package
1
. For example,
\usepackage{calc}
\usepackage[textheight=20\baselineskip+10pt]{geometry}
5.2 Option Types
There are ve types of options:
1. Boolean type
takes a boolean value (true or false). If no value, true is set for default.
key=true false.
key with no value is equivalent to key=true.
Examples: verbose=true, nohead, twoside=false.
Paper name is the exception. The preferred paper name should be set with no values.
Whatever value is given, it is ignored. For instance, a4paper=XXX is equivalent to a4paper.
2. Single-valued type
takes a mandatory value.
key=value.
Examples: width=8in, left=1.25in, footskip=1cm, height=.86\paperheight.
3. Two-valued type
takes a pair of comma-separated values in braces. The two values can be shortened to one
value if they are identical.
key= {value1,value2}.
key=value is equivalent to key= {value,value}.
Examples: hmargin={1.5in,1in}, scale=0.8, body={7in,10in}.
1
CTAN:macros/latex/contrib/support/calc
6
4. Three-valued type
takes three mandatory, comma-separated values in braces.
key= {value1,value2,value3}
Each value must be a dimension or null. When you give an empty value or *, it means null
and leaves the appropriate value to the auto-calculation mechanism. One needs to specify
at least one dimension, typically two dimensions. You can set nulls for all the values, but
it makes no sense. Examples:
hdivide={2cm,*,1cm}, vdivide={3cm,19cm, }, divide={1in,*,1in}.
6 Option List
6.1 Boolean Options
Boolean options are also called modes. One can change various modes for page geometry.
The boolean options are listed below.
verbose typeouts warnings and a list of resulted page parameters.
landscape switches the paper orientation to landscape mode.
portrait switches the paper orientation to portrait mode. This is equivalent to
landscape=false.
twoside switches on two-sided printing. In this mode, specied left and right margins are
switched over in each odd-numbered page.
includemp takes account of spaces for margin notes (\marginparwidth and
\marginparsep) when adjusting horizontal partition.
reversemp reversemarginpar
makes the marginal notes appear in the left margin and sets includemp=true
unless includemp=false has been set explicitly.
nohead eliminates spaces for the head of page, which is equivalent to \headheight=0pt
and \headsep=0pt.
nofoot eliminates spaces for the foot of page, which is equivalent to \footskip=0pt.
noheadfoot eliminates spaces for the head and foot of page, which is equivalent to nohead
and nofoot, i.e., \headheight=0pt, \headsep=0pt and \footskip=0pt.
dvips writes the paper size in the PostScript output with the \special macro. If you
use dvips as a DVI-to-PS driver, this option is very useful. For example, to print
a document with \geometry{a3paper,landscape} on A3 paper in landscape
mode, you dont need options -t a3 -t landscape to dvips. This option is
ineective and forced false if pdftex is true.
pdftex sets \pdfoutput=1 and sets \pdfpagewidth and \pdfpageheight properly in
the \begin{document} if pdatex command is used for typeset. When you use
latex command with pdftex=true, this option is ineective and forced to be
false. If \pdfoutput=1 is already specied, this option is initialized to be true.
You can set pdftex=false explicitly to output DVI, not PDF, when pdatex is
used. This option has priority over dvips.
vtex sets vtex modes.
truedimen adds true before all internal explicit dimension values (e.g., cm and in).
Typically this option will be used with mag option. Note that this is ineective
against externally specied dimensions. For example, when you set mag=1440,
margin=10pt, truedimen, margins are not true but magnied. If you want to
set exact margins, you should set like mag=1440, margin=10truept,
truedimen instead.
a0paper, a1paper, a2paper, a3paper, a4paper, a5paper, a6paper
b0paper, b1paper, b2paper, b3paper, b4paper, b5paper, b6paper
letterpaper, executivepaper, legalpaper
species paper name. They must be used with no values. Note that whatever
value (even false) is given to this option, the value will be ignored and the
paper name is used. For example, the followings have the same eect: a5paper,
a5paper=true, a5paper=false and a5paper=XXXX.
7
reset initializes modes and layout dimensions to their defaults. Note that this is
ineective against paper size (e.g., a4paper) and lengths for header, footer and
marginal notes (e.g., head, footskip, marginparwidth). reset=false has no
eect and cannot cancel the previous reset(=true) if any.
Some of the above options may be given as document class options. For example, you can set
\documentclass[a4paper,landscape]{article}, then a4paper and landscape are processed
in the geometry package as well. Some options may be implicitly given by \ExecuteOptions
in a document class. The standard book document class has twoside. So when you have
\documentclass{book}, then geometry can nd twoside without any explicit setting for
twoside.
6.2 Single-Valued Options
The single-valued options with a mandatory value are listed below.
paper papername
species a paper name. The available paper names are dened in the geometry
package. paper=paper name. For example paper=a4paper, which is equivalent
to just a4paper (see above).
paperwidth width of the paper. paperwidth=paper width.
paperheight height of the paper. paperheight=paper height.
width totalwidth
width of the total body. width=width or totalwidth=width. This dimension
should not be confused with textwidth. Generally, width textwidth because
width includes the width of marginal notes when includemp or dimensions for
marginal notes is set. If textwidth and width are specied at the same time,
width is ignored.
height totalheight
height of the total body (including header and footer). height=height or
totalheight=height . If both textheight and height are specied, height
will be ignored.
left lmargin
left margin of the total body. In other words, the distance between the left edge
of the paper and that of the total body. left=left margin.
right rmargin
right margin of the total body. right=right margin.
top tmargin
top margin of the total body. top=top margin.
bottom bmargin
bottom margin of the total body. bottom=bottom margin.
hscale ratio of width of the total body to \paperwidth. hscale=h-ratio. hscale=0.8
is equivalent to width=0.8\paperwidth.
vscale ratio of height of the total body to \paperheight. vscale=v-ratio.
vscale=0.9 is equivalent to height=0.9\paperheight.
textwidth modies \textwidth, width of text (body). textwidth=width.
textheight modies \textheight, height of text (body). textheight=height .
marginparwidth marginpar
modies \marginparwidth, width of the marginal notes. When this option is
set, includemp is also set true automatically. marginparwidth=length.
marginparsep
modies \marginparsep, separation between body and marginal notes.
includemp is also set true automatically. marginparsep=length.
headheight head
modies \headheight, height of header. headheight=length or head=length.
headsep modies \headsep, separation between header and text (body).
headsep=length.
footskip foot
modies \footskip, distance separation between baseline of last line of text and
baseline of footer. footskip=length or foot=length.
8
paper
total body

-twosideshift

twosideshift

even pages

odd pages
Figure 3: twosideshift option.
hoffset modies \hoffset. hoffset=length.
voffset modies \voffset. voffset=length.
twosideshift
species extra space which is added to left-margin of odd-numbered pages and
subtracted from that of even-numbered pages. twoside mode is also set.
twosideshift=length. The default is 20pt. See Figure 3.
mag sets magnication value (\mag) and automatically modies \hoffset and
\voffset according to the magnication. mag=magnication. Note that
magnication should be an integer value with 1000 as a normal size. For
example, mag=1414 with a4paper provides an enlarged print tting in a3paper,
which is 1.414(=

2) times larger than a4paper. Font enlargement needs extra


disk space. See also truedimen option.
columnsep modies \columnsep, the separation between two columns in twocolumn mode.
footnotesep changes the dimension \skip\footins, separation between the bottom of text
body and the top of footnote text.
6.3 Two-Valued Options
The following list shows keys taking two values in braces or one value for short.
papersize width and height of the paper.
papersize= {width,height} or papersize=length.
total width and height of the total body.
total= {width,height} or total=length.
body text textwidth and textheight of the body of page.
body= {width,height} or body=length.
scale ratio of the total body length to the papers.
scale= {h-ratio,v-ratio} or scale=ratio.
hmargin left and right margin.
hmargin= {left margin,right margin} or hmargin=length.
vmargin top and bottom margin.
vmargin= {top margin,bottom margin} or vmargin=length.
margin margin= {A,B} is equivalent to hmargin= {A,B} and vmargin= {A,B}.
margin=A is automatically expanded to hmargin=A and vmargin=A.
offset horizontal and vertical oset.
offset= {hoset,voset} or offset=length.
6.4 Three-Valued Options
The keys taking three comma-separated values in braces are listed below.
9
hdivide horizontal partitions (left,width,right).
hdivide= {left margin,width,right margin}.
Note that you should not specify all of the three parameters. The best way of
using this option is to specify two of three and leave the rest with null(nothing)
or *. For example, when you set hdivide={2cm,15cm, }, the margin from the
rightside edge of page will be determined calculating paperwidth-2cm-15cm.
vdivide vertical partitions (top,height,bottom).
vdivide= {top margin,height,bottom margin}.
divide divide= {A,B,C} is interpreted as hdivide= {A,B,C} and vdivide=
{A,B,C}.
7 Relations Between Options
7.1 Option Priority
low high (priority)

hscale
vscale

<

width
height

<

textwidth
textheight

head(height)
headsep
foot(skip)

<

nohead
nofoot
noheadfoot

,
dvips < pdftex.
For example,
\usepackage[hscale=0.8, textwidth=7in, width=18cm]{geometry}
is the same as
\usepackage[textwidth=7in]{geometry}.
7.2 Order Dependence
The options dened in the geometry package are basically order-independent, but there are some
exceptions. When redundant, overlap specication is given, the last setting is adopted. For
example,
verbose=true, verbose=false
obviously results in verbose=false. If you set
hmargin={3cm,2cm}, left=1cm
the left-margin is overwritten by left=1cm. As a result, it is equivalent to hmargin={1cm,2cm}.
The reset option initializes all the modes and settings for page layout. If you set
\documentclass[a4paper,landscape]{article}
\usepackage[margins=1cm,nohead]{geometry}
\geometry{reset, head=20pt}
then landscape, margins=1cm and nohead are ignored and head=20pt is set. Note that reset
cant initialize paper size (a4paper in this case).
7.3 dvips and pdftex
The options dvips and pdftex are provided for driver support. They may be used for other
packages that support them. In the geometry package, the pdftex option has priority over dvips.
The table below shows relations between the typeset command, \pdfoutput and eective values
for each driver option.
command pdftex dvips
latex false any
pdatex true false
false any
10
where any means that one can choose true or false. When pdatex command is used for
typeset, the default value of the pdftex option is dependent upon the value of \pdfoutput:
true if \pdfoutput=1, and false otherwise.
8 Default Settings
8.1 Default Option
The default option is
scale={0.8,0.9}.
Other layout parameters, such as paper size, orientation and lengths for header and footer, are
set as dened in the documentclass you use. If you just go \usepackage{geometry} in the
preamble, the package will set the default layout. Additional options will overwrite the layout
dimensions. For example,
\usepackage[ hmargin=2cm ]{geometry}
will overwrite horizontal dimensions, but use the default for vertical layout.
8.2 Conguration File
You can set up a conguration le to make default options. To do this, produce a le
geometry.cfg containing an \ExecuteOptions macro, for example,
\ExecuteOptions{a4paper,dvips}
and install it somewhere T
E
X can nd it.
9 Examples
Set the width of the total body to be 70% that of the paper. The total body is then
centered horizontally. The following settings (each line) result in the same eect.
hscale=0.7,
width=0.7\paperwidth,
hdivide={*,0.7\paperwidth,*},
hmargin=0.15\paperwidth,
left=0.15\paperwidth,
left = .15\paperwidth, right= 0.15\paperwidth,
rmargin= .15\paperwidth.
For vertical layout, in this case, the default is used: vscale=0.9.
Set the height of the total body to be 10in, the bottom-margin 3cm, and the width default.
Then the top-margin will be calculated in the package.
height=10in,bottom=2cm,
bmargin = 2cm ,totalheight= 10in,
vdivide = { *, 10in ,2cm },
and so on.
Set the left-, right-, and top-margin 3cm, 2cm and 2.5in respectively. The page header is
not used. The body is 40 lines of text in height.
left=3cm,right=2cm, nohead,
top=2.5in, textheight=40\baselineskip,
hmargin={3cm, 2cm}, head=0pt, headsep=0pt
tmargin=2.5in, textheight=40\baselineskip,
and so on.
Modify the width of marginal notes to 3cm and include marginal notes when adjusting
horizontal partition
11
marginpar=3cm,
marginparwidth=3cm.
In this case, includemp is not necessary because it is set automatically when
dimension(s) for marginal note are specied.
marginpar=3cm, reversemp
makes the marginal notes appear in the left margin.
Use A5 paper in landscape mode and a full scale of the paper as the body.
a5paper, landscape, scale=1.0 , noheadfoot,
landscape = TRUE, paper=a5paper, noheadfoot,
total={\paperwidth,\paperheight},
and so on.
Get PDF output using pdatex command for typeset.
% pdflatex foo
with
\documentclass[pdftex]{article}
\usepackage{geometry}
or
\documentclass{article}
\usepackage[pdftex]{geometry}
is equivalent to
% pdflatex \pdfoutput=1 \input{foo}
with
\documentclass{article}
\usepackage{geometry}.
Enlarge A4 to A3 with fonts and spaces also enlarged.
a4paper, mag=1414.
To enlarge all the fonts in the document by 2.0 without changing paper size, you can go
letterpaper, mag=2000, truedimen.
10 Acknowledgements
I would like to thank the following people for their pointing out bugs and suggesting, and for
many helpful comments: Friedrich Flender, Piet van Oostrum, Keith Reckdahl, Peter Riocreux,
James Kilger, Jean-Marc Lasgouttes Frank Bennett, Vladimir Volovich, Wlodzimierz Macewicz,
Jean-Bernard Addor, and Michael Vulis(MicroPress).
11 The Code
1 package
This package requires David Carlisles keyval package.
2 \RequirePackage{keyval}%
Internal switches are declared here.
3 \newif\ifGeom@verbose
4 \newif\ifGeom@landscape
5 \newif\ifGeom@nohead
6 \newif\ifGeom@nofoot
7 \newif\ifGeom@includemp
8 \newif\ifGeom@passincmp
9 \newif\ifGeom@hbody
10 \newif\ifGeom@vbody
11 \newif\ifGeom@dvips
12 \newif\ifGeom@pdftex
13 \newif\ifGeom@vtex
12
\Geom@cnth
\Geom@cntv
Counters for horizontal and vertical partitioning patterns.
14 \newcount\Geom@cnth
15 \newcount\Geom@cntv
\geom@warning Macor for printing warning messages.
16 \def\geom@warning#1{%
17 \ifGeom@verbose\PackageWarningNoLine{geometry}{#1}\fi}%
\Geom@Dhscale
\Geom@Dvscale
\Geom@Dtwosideshift
The default values for the horizontal and vertical scale, and twosideshift are dened.
18 \def\Geom@Dhscale{0.8}%
19 \def\Geom@Dvscale{0.9}%
20 \def\Geom@Dtwosideshift{20\Geom@truedimen pt}%
\geom@init The macro for initializing modes and ags is dened here. This macro is called when geometry
package is loaded and when reset option is specied.
21 \def\geom@init{%
22 \Geom@hbodyfalse
23 \Geom@vbodyfalse
24 \let\Geom@truedimen\@empty
25 \let\Geom@width\@undefined
26 \let\Geom@height\@undefined
27 \let\Geom@textwidth\@undefined
28 \let\Geom@textheight\@undefined
29 \let\Geom@hscale\@undefined
30 \let\Geom@vscale\@undefined
31 \let\Geom@lmargin\@undefined
32 \let\Geom@rmargin\@undefined
33 \let\Geom@tmargin\@undefined
34 \let\Geom@bmargin\@undefined
35 \let\Geom@twosideshift\@undefined
36 \Geom@verbosefalse
37 \Geom@landscapefalse
38 \Geom@noheadfalse
39 \Geom@nofootfalse
40 \Geom@includempfalse
41 \Geom@passincmpfalse
42 \Geom@dvipsfalse
43 \geom@initpdftex
44 \geom@initvtex}%
\geom@initpdftex This macro initializes Geom@pdftex switch, which appears in \geom@init macro.
45 \def\geom@initpdftex{%
46 \ifx\pdfpagewidth\@undefined
47 \Geom@pdftexfalse
48 \else
49 \ifnum\pdfoutput=1\relax\Geom@pdftextrue\else\Geom@pdftexfalse\fi
50 \fi}%
\geom@initvtex This macro initializes vtex mode, which appears in \geom@init macro.
51 \def\geom@initvtex{%
52 \ifx\VTeXversion\@undefined
53 \Geom@vtexfalse
54 \else
55 \ifnum\OpMode=\@ne
56 \Geom@vtextrue
57 \else
58 \ifnum\OpMode=\tw@
59 \Geom@vtextrue
60 \else
61 \Geom@vtexfalse
62 \fi
63 \fi
64 \fi}%
\geom@setbool Macro for setting boolean options.
65 \def\geom@setbool#1#2{%
66 \csname #2\ifx\relax#1\relax true\else#1\fi\endcsname}%
13
\geom@checkbool Macro used in \geom@showparams to print true or nothing.
67 \def\geom@checkbool#1{%
68 \csname ifGeom@#1\endcsname #1\space\else\fi}%
\geom@detiv This macro determines the fourth length(#4) from #1(paperwidth or paperheight), #2 and #3. It
is used in \geom@detall macro.
69 \def\geom@detiv#1#2#3#4{% determine #4.
70 \setlength\@tempdima{\@nameuse{paper#1}}%
71 \setlength\@tempdimb{\@nameuse{Geom@#2}}%
72 \addtolength\@tempdima{-\@tempdimb}%
73 \setlength\@tempdimb{\@nameuse{Geom@#3}}%
74 \addtolength\@tempdima{-\@tempdimb}%
75 \ifdim\@tempdima<\z@
76 \geom@warning{#4 results in NEGATIVE (\the\@tempdima).%
77 ^^J\@spaces Parameters of #2 and #3 should be shortened}%
78 \fi
79 \expandafter\edef\csname Geom@#4\endcsname{\the\@tempdima}}%
\geom@detiiandiii This macro determines #2 and #3 from #1. The rst argument can be width or height, which
is expanded into dimensions of paper and total body. It is used in \geom@detall macro.
80 \def\geom@detiiandiii#1#2#3{% determine #2 and #3.
81 \setlength\@tempdima{\@nameuse{paper#1}}%
82 \setlength\@tempdimb{\@nameuse{Geom@#1}}%
83 \addtolength\@tempdima{-\@tempdimb}%
84 \divide\@tempdima\tw@
85 \ifdim\@tempdima<\z@
86 \geom@warning{#2 and #3 result in NEGATIVE (\the\@tempdima).%
87 ^^J\@spaces Parameter for #1 should be shortened}%
88 \fi
89 \expandafter\edef\csname Geom@#2\endcsname{\the\@tempdima}%
90 \expandafter\edef\csname Geom@#3\endcsname{\the\@tempdima}}%
\geom@detall This macro determines partition of each direction. The rst argument is h or v.
91 \def\geom@detall#1#2#3#4{%
92 \@tempcnta\z@
93 \if#1h
94 \ifx\Geom@lmargin\@undefined\else\advance\@tempcnta4\relax\fi
95 \ifGeom@hbody\advance\@tempcnta2\relax\fi
96 \ifx\Geom@rmargin\@undefined\else\advance\@tempcnta1\relax\fi
97 \Geom@cnth\@tempcnta
98 \else
99 \ifx\Geom@tmargin\@undefined\else\advance\@tempcnta4\relax\fi
100 \ifGeom@vbody\advance\@tempcnta2\relax\fi
101 \ifx\Geom@bmargin\@undefined\else\advance\@tempcnta1\relax\fi
102 \Geom@cntv\@tempcnta
103 \fi
104 \ifcase\@tempcnta % 0:(*,*,*)
105 \if#1h
106 \edef\Geom@width{\Geom@Dhscale\paperwidth}%
107 \else
108 \edef\Geom@height{\Geom@Dvscale\paperheight}%
109 \fi
110 \geom@detiiandiii{#2}{#3}{#4}%
111 \or % 1:(*,*,S) goto (5)
112 \geom@warning{#3 was forced to equal #4}%
113 \expandafter\edef\csname Geom@#3\endcsname{\@nameuse{Geom@#4}}%
114 \geom@detiv{#2}{#3}{#4}{#2}%
115 \or\geom@detiiandiii{#2}{#3}{#4}% 2:(*,S,*)
116 \or\geom@detiv{#2}{#2}{#4}{#3} % 3:(*,S,S)
117 \or % 4:(S,*,*) goto (5)
118 \geom@warning{#4 was forced to equal #3}%
119 \expandafter\edef\csname Geom@#4\endcsname{\@nameuse{Geom@#3}}%
120 \geom@detiv{#2}{#3}{#4}{#2}%
121 \or\geom@detiv{#2}{#3}{#4}{#2} % 5:(S,*,S)
122 \or\geom@detiv{#2}{#2}{#3}{#4} % 6:(S,S,*)
123 \or % 7:(S,S,S) goto (5)
124 \geom@warning{Redundant specification in #1-direction.%
14
125 ^^J\@spaces #2 (\@nameuse{Geom@#2}) is ignored}%
126 \geom@detiv{#2}{#3}{#4}{#2}%
127 \else\fi}%
\geom@clean Macro for setting unspecied dimensions to be \@undefined. This is used by \geometry macros.
128 \def\geom@clean{%
129 \ifnum\Geom@cnth<4\let\Geom@lmargin\@undefined\fi
130 \ifodd\Geom@cnth\else\let\Geom@rmargin\@undefined\fi
131 \ifnum\Geom@cntv<4\let\Geom@tmargin\@undefined\fi
132 \ifodd\Geom@cntv\else\let\Geom@bmargin\@undefined\fi
133 \ifGeom@hbody\else
134 \let\Geom@hscale\@undefined
135 \let\Geom@width\@undefined
136 \let\Geom@textwidth\@undefined
137 \fi
138 \ifGeom@vbody\else
139 \let\Geom@vscale\@undefined
140 \let\Geom@height\@undefined
141 \let\Geom@textheight\@undefined
142 \fi}%
\geom@parse@divide Macro for parsing (h,v)divide options.
143 \def\geom@parse@divide#1#2#3#4{%
144 \def\Geom@star{*}%
145 \@tempcnta\z@
146 \@for\Geom@tmp:=#1\do{%
147 \expandafter\KV@@sp@def\expandafter\Geom@frag\expandafter{\Geom@tmp}%
148 \edef\Geom@value{\Geom@frag}%
149 \ifcase\@tempcnta\relax% cnta == 0
150 \edef\Geom@key{#2}%
151 \or \edef\Geom@key{#3}%
152 \else \edef\Geom@key{#4}%
153 \fi
154 \@nameuse{Geom@set\Geom@key false}%
155 \ifx\empty\Geom@value\else
156 \ifx\Geom@star\Geom@value\else
157 \setkeys{Geom}{\Geom@key=\Geom@value}%
158 \fi\fi
159 \advance\@tempcnta\@ne}%
160 \let\Geom@star\relax}%
\geom@branch Macro for branching an options value into the same two values.
161 \def\geom@branch#1#2#3{%
162 \@tempcnta\z@
163 \@for\Geom@tmp:=#1\do{%
164 \KV@@sp@def\Geom@frag{\Geom@tmp}%
165 \edef\Geom@value{\Geom@frag}%
166 \ifcase\@tempcnta\relax% cnta == 0
167 \setkeys{Geom}{#2=\Geom@value}%
168 \or% cnta == 1
169 \setkeys{Geom}{#3=\Geom@value}%
170 \else\fi
171 \advance\@tempcnta\@ne}%
172 \ifnum\@tempcnta=\@ne
173 \setkeys{Geom}{#2=\Geom@value}%
174 \setkeys{Geom}{#3=\Geom@value}%
175 \fi}%
\geom@magtooffset This macro is used to adjust osets by \mag.
176 \def\geom@magtooffset{%
177 \@tempdima=\mag\Geom@truedimen sp%
178 \@tempdimb=1\Geom@truedimen in%
179 \divide\@tempdimb\@tempdima
180 \multiply\@tempdimb\@m
181 \addtolength{\hoffset}{1\Geom@truedimen in}%
182 \addtolength{\voffset}{1\Geom@truedimen in}%
183 \addtolength{\hoffset}{-\@tempdimb}%
184 \addtolength{\voffset}{-\@tempdimb}}%
15
\geom@setpaper
185 \def\geom@setpaper(#1,#2){%
186 \setlength\paperwidth{#1}%
187 \setlength\paperheight{#2}}%
Various paper size are dened here.
188 \@namedef{Geom@a0paper}{%
189 \geom@setpaper(841\Geom@truedimen mm,1189\Geom@truedimen mm)}%
190 \@namedef{Geom@a1paper}{%
191 \geom@setpaper(595\Geom@truedimen mm,841\Geom@truedimen mm)}%
192 \@namedef{Geom@a2paper}{%
193 \geom@setpaper(420\Geom@truedimen mm,595\Geom@truedimen mm)}%
194 \@namedef{Geom@a3paper}{%
195 \geom@setpaper(297\Geom@truedimen mm,420\Geom@truedimen mm)}%
196 \@namedef{Geom@a4paper}{%
197 \geom@setpaper(210\Geom@truedimen mm,297\Geom@truedimen mm)}%
198 \@namedef{Geom@a5paper}{%
199 \geom@setpaper(149\Geom@truedimen mm,210\Geom@truedimen mm)}%
200 \@namedef{Geom@a6paper}{%
201 \geom@setpaper(105\Geom@truedimen mm,149\Geom@truedimen mm)}%
202 \@namedef{Geom@b0paper}{%
203 \geom@setpaper(1000\Geom@truedimen mm,1414\Geom@truedimen mm)}%
204 \@namedef{Geom@b1paper}{%
205 \geom@setpaper(707\Geom@truedimen mm,1000\Geom@truedimen mm)}%
206 \@namedef{Geom@b2paper}{%
207 \geom@setpaper(500\Geom@truedimen mm,707\Geom@truedimen mm)}%
208 \@namedef{Geom@b3paper}{%
209 \geom@setpaper(353\Geom@truedimen mm,500\Geom@truedimen mm)}%
210 \@namedef{Geom@b4paper}{%
211 \geom@setpaper(250\Geom@truedimen mm,353\Geom@truedimen mm)}%
212 \@namedef{Geom@b5paper}{%
213 \geom@setpaper(176\Geom@truedimen mm,250\Geom@truedimen mm)}%
214 \@namedef{Geom@b6paper}{%
215 \geom@setpaper(125\Geom@truedimen mm,176\Geom@truedimen mm)}%
216 \@namedef{Geom@letterpaper}{%
217 \geom@setpaper(8.5\Geom@truedimen in,11\Geom@truedimen in)}%
218 \@namedef{Geom@legalpaper}{%
219 \geom@setpaper(8.5\Geom@truedimen in,14\Geom@truedimen in)}%
220 \@namedef{Geom@executivepaper}{%
221 \geom@setpaper(7.25\Geom@truedimen in,10.5\Geom@truedimen in)}%
The option keys are dened below.
paper paper takes paper name as its value. Available paper names are listed below.
222 \define@key{Geom}{paper}{\setkeys{Geom}{#1}}%
a[0-6]paper
b[0-6]paper
letterpaper
legalpaper
executivepaper
Thirteen standard paper names are available.
223 \define@key{Geom}{a0paper}[true]{\def\Geom@paper{a0paper}}%
224 \define@key{Geom}{a1paper}[true]{\def\Geom@paper{a1paper}}%
225 \define@key{Geom}{a2paper}[true]{\def\Geom@paper{a2paper}}%
226 \define@key{Geom}{a3paper}[true]{\def\Geom@paper{a3paper}}%
227 \define@key{Geom}{a4paper}[true]{\def\Geom@paper{a4paper}}%
228 \define@key{Geom}{a5paper}[true]{\def\Geom@paper{a5paper}}%
229 \define@key{Geom}{a6paper}[true]{\def\Geom@paper{a6paper}}%
230 \define@key{Geom}{b0paper}[true]{\def\Geom@paper{b0paper}}%
231 \define@key{Geom}{b1paper}[true]{\def\Geom@paper{b1paper}}%
232 \define@key{Geom}{b2paper}[true]{\def\Geom@paper{b2paper}}%
233 \define@key{Geom}{b3paper}[true]{\def\Geom@paper{b3paper}}%
234 \define@key{Geom}{b4paper}[true]{\def\Geom@paper{b4paper}}%
235 \define@key{Geom}{b5paper}[true]{\def\Geom@paper{b5paper}}%
236 \define@key{Geom}{b6paper}[true]{\def\Geom@paper{b6paper}}%
237 \define@key{Geom}{letterpaper}[true]{\def\Geom@paper{letterpaper}}%
238 \define@key{Geom}{legalpaper}[true]{\def\Geom@paper{legalpaper}}%
239 \define@key{Geom}{executivepaper}[true]{\def\Geom@paper{executivepaper}}%
papersize
paperwidth
paperheight
240 \define@key{Geom}{papersize}{\geom@branch{#1}{paperwidth}{paperheight}}%
16
241 \define@key{Geom}{paperwidth}{\setlength\paperwidth{#1}%
242 \let\Geom@paper\@undefined}%
243 \define@key{Geom}{paperheight}{\setlength\paperheight{#1}%
244 \let\Geom@paper\@undefined}%
total
width
height
245 \define@key{Geom}{total}{\geom@branch{#1}{width}{height}}%
246 \define@key{Geom}{width}{\Geom@hbodytrue\edef\Geom@width{#1}}%
247 \define@key{Geom}{height}{\Geom@vbodytrue\edef\Geom@height{#1}}%
body
textwidth
textheight
248 \define@key{Geom}{body}{\geom@branch{#1}{textwidth}{textheight}}%
249 \define@key{Geom}{textwidth}{\Geom@hbodytrue\edef\Geom@textwidth{#1}}%
250 \define@key{Geom}{textheight}{\Geom@vbodytrue\edef\Geom@textheight{#1}}%
scale
hscale
vscale
251 \define@key{Geom}{scale}{\geom@branch{#1}{hscale}{vscale}}%
252 \define@key{Geom}{hscale}{\Geom@hbodytrue\edef\Geom@hscale{#1}}%
253 \define@key{Geom}{vscale}{\Geom@vbodytrue\edef\Geom@vscale{#1}}%
margin
hmargin
vmargin
lmargin
rmargin
tmargin
bmargin
254 \define@key{Geom}{margin}{\geom@branch{#1}{lmargin}{tmargin}%
255 \geom@branch{#1}{rmargin}{bmargin}}%
256 \define@key{Geom}{hmargin}{\geom@branch{#1}{lmargin}{rmargin}}%
257 \define@key{Geom}{vmargin}{\geom@branch{#1}{tmargin}{bmargin}}%
258 \define@key{Geom}{lmargin}{\edef\Geom@lmargin{#1}}%
259 \define@key{Geom}{rmargin}{\edef\Geom@rmargin{#1}}%
260 \define@key{Geom}{tmargin}{\edef\Geom@tmargin{#1}}%
261 \define@key{Geom}{bmargin}{\edef\Geom@bmargin{#1}}%
divide
hdivide
vdivide
Provide useful ways to partition each direction of paper.
262 \define@key{Geom}{divide}{\geom@parse@divide{#1}{lmargin}{width}{rmargin}%
263 \geom@parse@divide{#1}{tmargin}{height}{bmargin}}%
264 \define@key{Geom}{hdivide}{\geom@parse@divide{#1}{lmargin}{width}{rmargin}}%
265 \define@key{Geom}{vdivide}{\geom@parse@divide{#1}{tmargin}{height}{bmargin}}%
offset
hoffset
voffset
266 \define@key{Geom}{offset}{\geom@branch{#1}{hoffset}{voffset}}%
267 \define@key{Geom}{hoffset}{\setlength\hoffset{#1}}%
268 \define@key{Geom}{voffset}{\setlength\voffset{#1}}%
headheight
headsep
footskip
269 \define@key{Geom}{headheight}{\Geom@noheadfalse\setlength\headheight{#1}}%
270 \define@key{Geom}{headsep}{\Geom@noheadfalse\setlength\headsep{#1}}%
271 \define@key{Geom}{footskip}{\Geom@nofootfalse\setlength\footskip{#1}}%
marginparwidth
marginparsep
272 \define@key{Geom}{marginparwidth}%
273 {\ifGeom@passincmp\else\Geom@includemptrue\fi%
274 \setlength\marginparwidth{#1}}%
275 \define@key{Geom}{marginparsep}%
276 {\ifGeom@passincmp\else\Geom@includemptrue\fi%
277 \setlength\marginparsep{#1}}%
columnsep
footnotesep
278 \define@key{Geom}{columnsep}{\setlength\columnsep{#1}}%
279 \define@key{Geom}{footnotesep}{\setlength{\skip\footins}{#1}}%
verbose
reset
Note that reset executes \geom@init and sets oneside.
280 \define@key{Geom}{verbose}[true]{%
281 \lowercase{\geom@setbool{#1}}{Geom@verbose}}%
282 \define@key{Geom}{reset}[true]{%
283 \lowercase{\expandafter\csname if#1\endcsname\geom@init
284 \@twosidefalse\@mparswitchfalse\fi}}%
17
includemp
reversemp
reversemarginpar
285 \define@key{Geom}{includemp}[true]{%
286 \Geom@passincmptrue
287 \lowercase{\geom@setbool{#1}}{Geom@includemp}}%
288 \define@key{Geom}{reversemp}[true]{%
289 \ifGeom@passincmp\else\Geom@includemptrue\fi%
290 \lowercase{\geom@setbool{#1}}{@reversemargin}}%
291 \define@key{Geom}{reversemarginpar}[true]{%
292 \ifGeom@passincmp\else\Geom@includemptrue\fi%
293 \lowercase{\geom@setbool{#1}}{@reversemargin}}%
twoside
twosideshift
294 \define@key{Geom}{twoside}[true]{%
295 \lowercase{\geom@setbool{#1}}{@twoside}%
296 \lowercase{\geom@setbool{#1}}{@mparswitch}}%
297 \define@key{Geom}{twosideshift}{\@twosidetrue\@mparswitchtrue
298 \def\Geom@twosideshift{#1}}%
nohead
nofoot
noheadfoot
299 \define@key{Geom}{nohead}[true]{%
300 \lowercase{\geom@setbool{#1}}{Geom@nohead}}%
301 \define@key{Geom}{nofoot}[true]{%
302 \lowercase{\geom@setbool{#1}}{Geom@nofoot}}%
303 \define@key{Geom}{noheadfoot}[true]{%
304 \lowercase{\geom@setbool{#1}}{Geom@nohead}%
305 \lowercase{\geom@setbool{#1}}{Geom@nofoot}}%
landscape
portrait
306 \define@key{Geom}{landscape}[true]{%
307 \lowercase{\geom@setbool{#1}}{Geom@landscape}}%
308 \define@key{Geom}{portrait}[true]{%
309 \lowercase{\expandafter\csname if#1\endcsname
310 \Geom@landscapefalse\else\Geom@landscapetrue\fi}}%
dvips
pdftex
vtex
311 \define@key{Geom}{dvips}[true]{%
312 \lowercase{\geom@setbool{#1}}{Geom@dvips}}%
313 \define@key{Geom}{pdftex}[true]{%
314 \lowercase{\geom@setbool{#1}}{Geom@pdftex}}%
315 \define@key{Geom}{vtex}[true]{%
316 \lowercase{\geom@setbool{#1}}{Geom@vtex}}%
mag
truedimen
Provides an interface to \mag with oset auto-justication.
317 \define@key{Geom}{truedimen}[true]{%
318 \lowercase{\expandafter\csname if#1\endcsname
319 \def\Geom@truedimen{true}\else
320 \let\Geom@truedimen\@empty\fi}}%
321 \define@key{Geom}{mag}{\mag#1}%
papername
totalwidth
totalheight
text
left
right
top
bottom
head
foot
marginpar
The key aliases are dened.
322 \let\KV@Geom@papername\KV@Geom@paper
323 \let\KV@Geom@totalwidth\KV@Geom@width
324 \let\KV@Geom@totalheight\KV@Geom@height
325 \let\KV@Geom@text\KV@Geom@body
326 \let\KV@Geom@left\KV@Geom@lmargin
327 \let\KV@Geom@right\KV@Geom@rmargin
328 \let\KV@Geom@top\KV@Geom@tmargin
329 \let\KV@Geom@bottom\KV@Geom@bmargin
330 \let\KV@Geom@head\KV@Geom@headheight
331 \let\KV@Geom@foot\KV@Geom@footskip
332 \let\KV@Geom@marginpar\KV@Geom@marginparwidth
\geom@process The main macro processing specied layout dimensions is dened.
333 \def\geom@process{%
334 \ifx\Geom@paper\@undefined\else\@nameuse{Geom@\Geom@paper}\fi
335 \ifdim\paperwidth<\p@
18
336 \PackageError{geometry}{%
337 You must set \string\paperwidth\space properly}{%
338 Set your paper type (e.g., a4paper for A4) as a class option^^J%
339 or as a geometry package option.}%
340 \fi
341 \ifdim\paperheight<\p@
342 \PackageError{geometry}{%
343 You must set \string\paperheight\space properly}{%
344 Set your paper type (e.g., a4paper for A4) as a class option^^J%
345 or as a geometry package option.}%
346 \fi
347 \ifnum\@m=\mag\else\geom@magtooffset\fi
348 \ifGeom@landscape
349 \setlength\@tempdima{\paperwidth}%
350 \setlength\paperwidth{\paperheight}%
351 \setlength\paperheight{\@tempdima}%
352 \fi
353 \ifGeom@nohead
354 \setlength\headheight{0pt}%
355 \setlength\headsep{0pt}%
356 \fi
357 \ifGeom@nofoot
358 \setlength\footskip{0pt}%
359 \fi
360 \ifGeom@hbody
361 \ifx\Geom@width\@undefined
362 \ifx\Geom@hscale\@undefined
363 \edef\Geom@width{\Geom@Dhscale\paperwidth}%
364 \else
365 \edef\Geom@width{\Geom@hscale\paperwidth}%
366 \fi
367 \fi
368 \ifx\Geom@textwidth\@undefined\else
369 \setlength\@tempdima{\Geom@textwidth}%
370 \ifGeom@includemp
371 \addtolength\@tempdima{\marginparwidth}%
372 \addtolength\@tempdima{\marginparsep}%
373 \fi
374 \edef\Geom@width{\the\@tempdima}%
375 \fi
376 \fi
377 \ifGeom@vbody
378 \ifx\Geom@height\@undefined
379 \ifx\Geom@vscale\@undefined
380 \edef\Geom@height{\Geom@Dvscale\paperheight}%
381 \else
382 \edef\Geom@height{\Geom@vscale\paperheight}%
383 \fi
384 \fi
385 \ifx\Geom@textheight\@undefined\else
386 \setlength\@tempdima{\Geom@textheight}%
387 \addtolength\@tempdima{\headheight}%
388 \addtolength\@tempdima{\headsep}%
389 \addtolength\@tempdima{\footskip}%
390 \edef\Geom@height{\the\@tempdima}%
391 \fi
392 \fi
393 \geom@detall{h}{width}{lmargin}{rmargin}%
394 \geom@detall{v}{height}{tmargin}{bmargin}%
395 \setlength\textwidth{\Geom@width}%
396 \setlength\textheight{\Geom@height}%
397 \setlength\topmargin{\Geom@tmargin}%
398 \setlength\oddsidemargin{\Geom@lmargin}%
399 \ifGeom@includemp
400 \addtolength\textwidth{-\marginparwidth}%
401 \addtolength\textwidth{-\marginparsep}%
402 \if@reversemargin
19
403 \addtolength\oddsidemargin{\marginparwidth}%
404 \addtolength\oddsidemargin{\marginparsep}%
405 \fi
406 \fi
407 \addtolength\textheight{-\headheight}%
408 \addtolength\textheight{-\headsep}%
409 \addtolength\textheight{-\footskip}%
410 \addtolength\topmargin{-1\Geom@truedimen in}%
411 \addtolength\oddsidemargin{-1\Geom@truedimen in}%
412 \if@twoside
413 \ifx\Geom@twosideshift\@undefined
414 \def\Geom@twosideshift{\Geom@Dtwosideshift}%
415 \fi
416 \setlength\evensidemargin{\Geom@rmargin}%
417 \addtolength\evensidemargin{-1\Geom@truedimen in}%
418 \setlength\@tempdima{\Geom@twosideshift}%
419 \addtolength\oddsidemargin{\@tempdima}%
420 \addtolength\evensidemargin{-\@tempdima}%
421 \ifGeom@includemp
422 \if@mparswitch
423 \setlength\@tempdima{\marginparwidth}%
424 \addtolength\@tempdima{\marginparsep}%
425 \addtolength\evensidemargin{\@tempdima}%
426 \if@reversemargin
427 \addtolength\evensidemargin{-\marginparwidth}%
428 \addtolength\evensidemargin{-\marginparsep}%
429 \fi
430 \fi
431 \fi
432 \else
433 \setlength\evensidemargin{\oddsidemargin}%
434 \fi}
\geom@showparam The macro for typeout of geometry status and L
A
T
E
X layout dimensions.
435 \def\geom@showparams{%
436 \typeout{----------------------- Geometry parameters^^J%
437 mode: %
438 \ifx\Geom@paper\@undefined
439 (default papersize)\space
440 \else
441 \Geom@paper\space
442 \fi
443 \geom@checkbool{landscape}%
444 \geom@checkbool{nohead}%
445 \geom@checkbool{nofoot}%
446 \geom@checkbool{includemp}%
447 \if@reversemargin reversemp\space\fi%
448 \if@twoside twoside\space\fi%
449 \geom@checkbool{dvips}%
450 \geom@checkbool{pdftex}%
451 \geom@checkbool{vtex}%
452 \ifx\Geom@truedimen\@empty\else
453 truedimen
454 \fi^^J%
455 h-parts: \Geom@lmargin, \Geom@width, \Geom@rmargin%
456 \ifnum\Geom@cnth=\z@\space(default)\fi^^J%
457 v-parts: \Geom@tmargin, \Geom@height, \Geom@bmargin%
458 \ifnum\Geom@cntv=\z@\space(default)\fi^^J%
459 \if@twoside
460 twosideshift: \Geom@twosideshift^^J%
461 \fi
462 ----------------------- Page layout dimensions^^J%
463 \string\paperwidth\space\space\the\paperwidth^^J%
464 \string\paperheight\space\the\paperheight^^J%
465 \string\textwidth\space\space\the\textwidth^^J%
466 \string\textheight\space\the\textheight^^J%
467 \string\oddsidemargin\space\space\the\oddsidemargin^^J%
20
468 \string\evensidemargin\space\the\evensidemargin^^J%
469 \string\topmargin\space\space\the\topmargin^^J%
470 \string\headheight\space\the\headheight^^J%
471 \string\headsep\@spaces\the\headsep^^J%
472 \string\footskip\space\space\space\the\footskip^^J%
473 \if@twocolumn
474 \string\columnsep\space\space\the\columnsep^^J%
475 \fi
476 \ifGeom@includemp
477 \string\marginparwidth\space\the\marginparwidth^^J%
478 \string\marginparsep\space\space\space\the\marginparsep^^J%
479 \fi
480 \string\hoffset\space\the\hoffset^^J%
481 \string\voffset\space\the\voffset^^J%
482 \string\mag\space\the\mag^^J%
483 (1in=72.27pt, 1cm=28.45pt)^^J%
484 -----------------------}}%
Paper size is initialized only once here.
485 \let\Geom@paper\@undefined
\geom@setkey \ExecuteOptions is replaced with \geom@setkey to make it possible to deal with key=value
as its argument.
486 \def\geom@setkey{\setkeys{Geom}}%
487 \let\geom@origExecuteOptions\ExecuteOptions
488 \let\ExecuteOptions\geom@setkey
\geom@init is executed. Note that \@twoside, \@mparswitch and \mag are not changed.
489 \geom@init
A local conguration le may dene more options. To set A4 paper as default, geometry.cfg
needs to contain \ExecuteOptions{a4paper}.
490 \InputIfFileExists{geometry.cfg}{}{}%
The original denition for \ExecuteOptions macro is restored.
491 \let\ExecuteOptions\geom@origExecuteOptions
\ProcessOptionsWithKV This macros can process package options using key=value scheme. The code was borrowed
from the hyperref package written by Sebastian Rahtz.
492 \def\ProcessOptionsWithKV#1{%
493 \let\@tempa\@empty
494 \@for\CurrentOption:=\@classoptionslist\do{%
495 \@ifundefined{KV@#1@\CurrentOption}%
496 {}{\edef\@tempa{\@tempa,\CurrentOption,}}}%
497 \edef\@tempa{%
498 \noexpand\setkeys{#1}{\@tempa\@ptionlist{\@currname.\@currext}}}%
499 \@tempa
500 \AtEndOfPackage{\let\@unprocessedoptions\relax}}%
The optional arguments to \usepackage and \documentclass macros are processed here.
501 \ProcessOptionsWithKV{Geom}%
Actual setting and calculation of layout dimensions are here.
502 \geom@process
The verbose, pdftex and dvips options are checked in \AtBeginDocument.
503 \AtBeginDocument{%
504 \ifx\pdfpagewidth\@undefined % latex command is used.
505 \Geom@pdftexfalse
506 \ifx\VTeXversion\@undefined % not VTeX
507 \Geom@vtexfalse
508 \fi
509 \else % pdflatex command is used
510 \ifGeom@pdftex\Geom@dvipsfalse\fi
511 \fi
21
Paper size is temporally adjusted according to \mag for printing devices.
512 \edef\org@pw{\the\paperwidth}
513 \edef\org@ph{\the\paperheight}
514 \divide\paperwidth\@m
515 \multiply\paperwidth\the\mag
516 \divide\paperheight\@m
517 \multiply\paperheight\the\mag
For dvips,
518 \ifGeom@dvips
519 \AtBeginDvi{\special{%
520 papersize=\the\paperwidth,\the\paperheight}}%
521 \fi
For pdftex,
522 \ifGeom@pdftex
523 \pdfoutput=1\relax
524 \pdfpagewidth=\the\paperwidth
525 \pdfpageheight=\the\paperheight
526 \fi
For vtex,
527 \ifGeom@vtex % vtex environment
528 \mediawidth=\the\paperwidth
529 \mediaheight=\the\paperheight
530 \fi
To put back the paper size to the original one,
531 \setlength\paperwidth{\org@pw}
532 \setlength\paperheight{\org@ph}
533 \let\org@pw\relax
534 \let\org@ph\relax
If verbose is set, the page geometry parameters and options are displayed.
535 \ifGeom@verbose
536 \geom@showparams
537 \fi}%
\geometry The user-interface macro \geometry is dened, which sets unspecied dimensions to be
\@undefined by \geom@clean, appends specied options to themselves, and determines lay-
out dimensions by \geom@process.
538 \def\geometry#1{%
539 \geom@clean
540 \setkeys{Geom}{#1}%
541 \geom@process}%
542 /package
543 cong
544
545 %% Uncomment and edit the line below to set default options.
546 %%\ExecuteOptions{a4paper,dvips}
547
548 /cong
22

You might also like