Displaying page layout variables

Kent McPherson a.o.^{∗}

1994/09/08

1 Introduction

This L^{A}TEX 2ε package is a reimplementation of layout.sty by Kent McPherson. It defines the command \layout which produces an overview of the layout of the current document.

2 The implementation

This package prints a figure to illustrate the layout that is implemented by the document class. In the figure several words appear. They are stored in control sequences to be able to select a different language. 1 ⟨∗package⟩

 2 \DeclareOption{dutch}{%
 3 \def\Headertext{Kop regel}
 4 \def\Bodytext{Brood tekst}
 5 \def\Footertext{Voet regel}
 6 \def\MarginNotestext{Marge\\Notities}
 7 \def\oneinchtext{een inch}
 8 }
 9 \DeclareOption{english}{%
10 \def\Headertext{Header}
11 \def\Bodytext{Body}
12 \def\Footertext{Footer}
13 \def\MarginNotestext{Margin\\Notes}
14 \def\oneinchtext{one inch}

15 }

This package has an option verbose. Using it will make the command \layout type some of the parameters on the terminal.

16 \DeclareOption{verbose}{\let\type\typeout}
17 \DeclareOption{silent}{\let\type\@gobble}

∗Converted for L^{A}TEX 2ε by Johannes Braams

layout package version v1.1d as of 1994/09/08 2

The default language is English and the default mode is silent.

18 \ExecuteOptions{english,silent}
19 \ProcessOptions

\bs Define \bs if it is undefined, redefine it if it is already defined.

20 \@ifundefined{bs}{\newcommand\bs{\char '134 }}%
21 {\renewcommand\bs{\char '134 }}

\ConvertToCount This macro stores the value of a length register in a count register.

22 \def\ConvertToCount#1#2{%

First copy the value

23 #1=#2

Then divide it by 65536.

24 \divide #1 by 65536}

The result of this is that the count register holds the value of the length register in points.

\SetToHalf \SetToQuart Small macros used in computing positions.

25 \def\SetToHalf#1#2{#1=#2\relax\divide#1by\tw@}
26 \def\SetToQuart#1#2{#1=#2\relax\divide#1by4}

\Identify A small macro used in identifying dimensions.

27 \def\Identify#1{%
28 \put(\PositionX,\PositionY){\circle{20}}
29 \put(\PositionX,\PositionY){\makebox(0,0){\tiny #1}}

30 }

\InsideHArrow This macro is used to produce two horizontal arrows inside a box. The argument gives the width of the box.

31 \def\InsideHArrow#1{{%
32 \ArrowLength = #1
33 \divide\ArrowLength by \tw@
34 \advance\ArrowLength by -10
35 \advance\PositionX by -10
36 \ifnum\ArrowLength<\z@
37  \put(\PositionX,\PositionY){\vector(1,0){-\ArrowLength}}
38  \advance\PositionX by 20
39  \put(\PositionX,\PositionY){\vector(-1,0){-\ArrowLength}}
40 \else
41  \put(\PositionX,\PositionY){\vector(-1,0){\ArrowLength}}
42  \advance\PositionX by 20
43  \put(\PositionX,\PositionY){\vector(+1,0){\ArrowLength}}
44 \fi
45 }}

\InsideVArrow This macro is used to produce two vertical arrows inside a box. The argument gives the height of the box.

46 \def\InsideVArrow#1{{%
47 \ArrowLength = #1
48 \divide\ArrowLength by \tw@
49 \advance\ArrowLength by -10
50 \advance\PositionY by -10
51 \put(\PositionX,\PositionY){\vector(0,-1){\ArrowLength}}
52 \advance\PositionY by 20
53 \put(\PositionX,\PositionY){\vector(0,+1){\ArrowLength}}
54 }}

\OutsideHArrow This macro is used to produce two horizontal arrows to delimit a length. The first argument is the position for the right arrow, the second argument gives the length and the third specifies the length of the arrows.

55 \def\OutsideHArrow#1#2#3{{%
56 \PositionX = #1
57 \advance\PositionX by #3
58 \put(\PositionX,\PositionY){\vector(-1,0){#3}}
59 \PositionX = #1 \advance\PositionX-#2
60 \advance\PositionX by -#3
61 \put(\PositionX,\PositionY){\vector(+1,0){#3}}
62 }}

\OutsideVArrow This macro is used to produce two vertical arrows to delimit a length. The first argument is the position for the lower arrow, the second argument gives the length and the third and fourth specify the lenghts of the lower and upper arrow.

63 \def\OutsideVArrow#1#2#3#4{{%
64 \PositionY = #1
65 \advance\PositionY by -#3
66 \put(\PositionX,\PositionY){\vector(0,+1){#3}}
67 \PositionY = #1
68 \advance\PositionY#2
69 \advance\PositionY#4
70 \put(\PositionX,\PositionY){\vector(0,-1){#4}}
71 }}

\Show Macro used in the table that shows the setting of the parameters.

72 \def\Show#1#2{\bs #2 = \expandafter\number\csname #1@#2\endcsname pt}

\Type Macro used to show a setting of a parameter on the terminal.

73 \def\Type#1#2{%
74 \type{#2 = \expandafter\number\csname #1@#2\endcsname pt}}

\oneinch A constant, giving the length of an inch in points (approximately)

75 \newcount\oneinch
76 \oneinch=72

Because the overview of the layout is produced in a figure environment we need to allocate a number of counters that are used to store the values of various dimensions.

The dimensions of the paper

77 \newcount\cnt@paperwidth
78 \newcount\cnt@paperheight
79 \ConvertToCount\cnt@paperwidth\paperwidth
80 \ConvertToCount\cnt@paperheight\paperheight

the offsets,

81 \newcount\cnt@hoffset
82 \newcount\cnt@voffset
83 \ConvertToCount\cnt@hoffset\hoffset
84 \ConvertToCount\cnt@voffset\voffset

dimensions of the text area,

85 \newcount\cnt@textheight
86 \newcount\cnt@textwidth
87 \ConvertToCount\cnt@textheight\textheight
88 \ConvertToCount\cnt@textwidth\textwidth

margins,

89 \newcount\cnt@topmargin
90 \newcount\cnt@oddsidemargin
91 \newcount\cnt@evensidemargin
92 \ConvertToCount\cnt@topmargin\topmargin
93 \ConvertToCount\cnt@oddsidemargin\oddsidemargin
94 \ConvertToCount\cnt@evensidemargin\evensidemargin

dimensions of the running heads,

95 \newcount\cnt@headheight
96 \newcount\cnt@headsep
97 \ConvertToCount\cnt@headheight\headheight
98 \ConvertToCount\cnt@headsep\headsep

marginal paragraphs,

99 \newcount\cnt@marginparsep
100 \newcount\cnt@marginparwidth
101 \newcount\cnt@marginparpush
102 \ConvertToCount\cnt@marginparsep\marginparsep
103 \ConvertToCount\cnt@marginparwidth\marginparwidth
104 \ConvertToCount\cnt@marginparpush\marginparpush

the distance between the running footers and the text,

105 \newcount\cnt@footskip
106 \ConvertToCount\cnt@footskip\footskip

and the height of the footers, which is needed here to display a box, but which isn’t used by L^{A}TEX.

107 \newcount\fheight
108 \fheight=12

Apart from integer representations of the page layout parameters we also need registers to store reference values in.

The position of the top of the ‘printable area’ is one inch below the top of the paper by default. The value of \ref@top is relative to the lower left corner of the picture environment that will be used.

109 \newcount\ref@top
110 \ref@top=\cnt@paperheight \advance\ref@top by -\oneinch

For the offsets,

111 \newcount\ref@hoffset
112 \newcount\ref@voffset

The \hoffset and \voffset values are added to the default offset of one inch.

113 \ref@hoffset=\cnt@hoffset  \advance\cnt@hoffset by \oneinch
114 \ref@voffset=\cnt@voffset

\cnt@voffset is converted to be relative to the origin of the picture.

115 \cnt@voffset=\ref@top
116 \advance\cnt@voffset by -\ref@voffset

and the text areas, running heads,

117 \newcount\ref@head
118 \ref@head=\ref@top
119 \advance\ref@head by -\ref@voffset
120 \advance\ref@head by -\cnt@topmargin
121 \advance\ref@head by -\cnt@headheight

body of the text

122 \newcount\ref@body
123 \ref@body=\ref@head
124 \advance\ref@body by -\cnt@headsep
125 \advance\ref@body by -\cnt@textheight

and running footers.

126 \newcount\ref@foot
127 \ref@foot=\ref@body
128 \advance\ref@foot by -\cnt@footskip

These are different for even and odd pages, so they are computed by \layout.

129 \newcount\ref@margin
130 \newcount\ref@marginwidth
131 \newcount\ref@marginpar

The following are a number of scratch registers, used in the positioning of the various pices of the picture..

132 \newcount\Interval
133 \newcount\ExtraYPos
134 \newcount\PositionX
135 \newcount\PositionY
136 \newcount\ArrowLength

\layout The command \layout makes the picture and table that display the current settings of the layout parameters.

137 \newcommand\layout{%
138 \@layout
139 \if@twoside
140  \@layout
141 \fi}
142 \newcommand\@layout{%
143 \thispagestyle{empty}

The actions of \layout depend on the pagestyle.

144 \if@twoside
145  \ifodd\count\z@

Here we deal with an odd page in the twosided case.

146  \typeout{Two-sided document style, odd page.}
    So we compute \ref@marginwidth, \ref@marginpar and \ref@margin.
147  \ref@marginwidth=\cnt@oddsidemargin
148  \ref@marginpar=\oneinch
149  \advance\ref@marginpar by \ref@hoffset
150  \advance\ref@marginpar by \cnt@oddsidemargin
151  \ref@margin\ref@marginpar
152  \if@reversemargin
153  \advance\ref@marginpar by -\cnt@marginparsep
154  \advance\ref@marginpar by -\cnt@marginparwidth
155  \else
156  \advance\ref@marginpar by \cnt@textwidth
157  \advance\ref@marginpar by \cnt@marginparsep
158  \fi
159  \else

Here we deal with an even page in the twosided case.

160 \typeout{Two-sided document style, even page.}
    So we compute \ref@marginwidth, \ref@marginpar and \ref@margin.
161  \ref@marginwidth=\cnt@evensidemargin
162  \ref@marginpar=\oneinch
163  \advance\ref@marginpar by \ref@hoffset
164  \advance\ref@marginpar by \cnt@evensidemargin
165  \ref@margin\ref@marginpar
166  \if@reversemargin
167  \advance\ref@marginpar by \cnt@textwidth
168  \advance\ref@marginpar by \cnt@marginparsep
169  \else
170  \advance\ref@marginpar by -\cnt@marginparsep
171  \advance\ref@marginpar by -\cnt@marginparwidth
172  \fi
173  \fi
174 \else

Finally we the case for single sided printing.

175  \typeout{One-sided document style.}
176  \ref@marginwidth=\cnt@oddsidemargin
177  \ref@marginpar=\oneinch
178  \advance\ref@marginpar by \ref@hoffset
179  \advance\ref@marginpar by \cnt@oddsidemargin
180  \ref@margin\ref@marginpar
181  \if@reversemargin
182  \advance\ref@marginpar by -\cnt@marginparsep
183  \advance\ref@marginpar by -\cnt@marginparwidth
184  \else
185  \advance\ref@marginpar by \cnt@textwidth
186  \advance\ref@marginpar by \cnt@marginparsep
187  \fi
188 \fi

Now we begin the picture environment; dividing all the lengths by two is done

 by setting \unitlength to 0.5pt
189 \setlength{\unitlength}{.5pt}
190 \begin{picture}(\cnt@paperwidth,\cnt@paperheight)
191  \centering
192  \thicklines

First we have the pagebox and reference lines,

193  \put(0,0){\framebox(\cnt@paperwidth,\cnt@paperheight){\mbox{}}}
194  \put(0,\cnt@voffset){\dashbox{10}(\cnt@paperwidth,0){\mbox{}}}
195  \put(\cnt@hoffset,0){\dashbox{10}(0,\cnt@paperheight){\mbox{}}}

then the header,

196  \put(\ref@margin,\ref@head){%
197  \framebox(\cnt@textwidth,\cnt@headheight)%
198  {\footnotesize\Headertext}}

the body of the text area,

199  \put(\ref@margin,\ref@body){%
200  \framebox(\cnt@textwidth,\cnt@textheight){\Bodytext}}

the footer

201  \put(\ref@margin,\ref@foot){%
202  \framebox(\cnt@textwidth,\fheight){\footnotesize\Footertext}}

and the space for marginal notes.

203  \put(\ref@marginpar,\ref@body){%
204  \framebox(\cnt@marginparwidth,\cnt@textheight)%
205  {\footnotesize\shortstack{\MarginNotestext}}}

Then we start putting in ‘arrows’ to mark the various parameters. From here

 we use \thinlines.
206  \thinlines

\PositionX and \PositionY will be the coordinates of the center of the arrow displaying \textwidth.

207  \SetToHalf\PositionX\cnt@textwidth
208  \advance\PositionX by \ref@margin

The arrow should be a bit above the bottom of the ‘body box’.

209  \PositionY = \ref@body
210  \advance\PositionY by 50

An identifying number is put here, in a circle.

211  \Identify{8}

Then the arrow is drawn.

212  \InsideHArrow\cnt@textwidth
    Now the \textheight
213  \SetToHalf\PositionY\cnt@textheight
214  \advance\PositionY by \ref@body

The x-psition of the arrow is at 4/5 of the width of the ‘body box’.

215  \PositionX = \cnt@textwidth
216  \divide\PositionX by 5
217  \multiply \PositionX by 4
218  \advance\PositionX by \ref@margin

An identifying number is put here, in a circle.

219  \Identify{7}
220  \InsideVArrow\cnt@textheight
    The \hoffset,
221  \PositionY = \ref@foot
222  \SetToHalf\PositionX\cnt@hoffset
223  \Identify{1}
224  \InsideHArrow\cnt@hoffset

The width of the margin.

225  \SetToQuart\PositionY\cnt@textheight
226  \advance\PositionY by \ref@body
227  \OutsideHArrow\ref@margin\ref@marginwidth{20}
228  \PositionX = \cnt@hoffset
229  \advance\PositionX by -30
230  \Identify{3}
    the \marginparwidth,
231  \SetToQuart\PositionY\cnt@textheight
232  \advance\PositionY by \ref@body

This arrow has to be bit below the one for the \oddsidemargin or

 \evensidemargin.
233  \advance\PositionY by 30
234  \SetToHalf\PositionX\cnt@marginparwidth
235  \advance\PositionX by \ref@marginpar
236  \Identify{10}
237  \InsideHArrow\cnt@marginparwidth

The \marginparsep, this depends on single or double sided printing.

238  \advance\PositionY by 30
239  \if@twoside
240  \ifodd\count\z@

Twosided mode, odd page;

241  \OutsideHArrow\ref@marginpar\cnt@marginparsep{20}
242  \PositionX = \ref@marginpar
243  \else

and even page.

244  \OutsideHArrow\ref@margin\cnt@marginparsep{20}
245  \PositionX = \ref@margin
246  \fi
247  \else

Single sided mode.

248  \OutsideHArrow\ref@marginpar\cnt@marginparsep{20}
249  \PositionX = \ref@marginpar
250  \fi
251  \advance\PositionX by 30
252  \Identify{9}

Identify the \footskip. The arrow will be located on 1/8th of the \textwidth.

253  \PositionX = \cnt@textwidth
254  \divide\PositionX by 8
255  \advance\PositionX by \ref@margin
256  \OutsideVArrow\ref@foot\cnt@footskip{20}{20}
257  \PositionY = \ref@foot
258  \advance\PositionY by -30
259  \Identify{11}

Identify the \voffset. The arrow will be located a bit to the left of the edge of the paper.

260  \PositionX = \cnt@paperwidth
261  \advance\PositionX by -50
262  \PositionY = \cnt@paperheight
263  \ExtraYPos = \PositionY
264  \advance\ExtraYPos by -\cnt@voffset
265  \advance\PositionY by \cnt@voffset
266  \divide\PositionY by \tw@
267  \Identify{2}
268  \InsideVArrow\ExtraYPos
    Identify \topmargin, \headheight and \headsep.

The arrows will be located on 1/8th of the \textwidth, with intervals of the same size, stored in \Interval.

269  \Interval = \cnt@textwidth
270  \divide\Interval by 8
271  \PositionX = \ref@margin
272  \advance\PositionX by \Interval

First the \topmargin. The length of upper arrows for these three parameters dimensions are different. In the computation of these lengths we have to compensate for the diameter of the cirle.

273  \Identify{4}
274  \ExtraYPos = \ref@head
275  \advance\ExtraYPos\cnt@headheight
276  \ArrowLength = \PositionY
277  \advance\ArrowLength-\ExtraYPos
278  \advance\ArrowLength-\cnt@topmargin
279  \advance\ArrowLength-10%
280  \OutsideVArrow\ExtraYPos\cnt@topmargin{20}{\ArrowLength}
281  \advance\PositionX by \Interval
 Then the \headheight
282  \Identify{5}
283  \advance\ArrowLength\cnt@topmargin
284  \OutsideVArrow\ref@head\cnt@headheight{20}{\ArrowLength}
285  \advance\PositionX by \Interval

and finally the \headsep

286  \Identify{6}
287  \advance\ArrowLength\cnt@headheight
288  \ExtraYPos=\ref@body
289  \advance\ExtraYPos\cnt@textheight
290  \OutsideVArrow\ExtraYPos\cnt@headsep{20}{\ArrowLength}

Here we can end the picture environment and insert a little space.

291 \end{picture}

292

293 \medskip

Below the picture we put a table to show the actual values of the parameters. Note that fractional points are truncated, i.e., 72.27pt is displayed as 72pt

The table is typeset inside a box with a depth of 0 to always keep it on the same page as the picture.

294 \vtop to 0pt{%
295  \@minipagerestore\footnotesize\ttfamily
296  \begin{tabular}{@{}rl@{\hspace{20pt}}rl}
297  1 & \oneinchtext\ + \bs\texttt{hoffset}
298  & 2 & \oneinchtext\ + \bs\texttt{voffset} \\
299  3 & \if@twoside
300  \ifodd\count\z@ \Show{cnt}{oddsidemargin}
301  \else \Show{cnt}{evensidemargin}
302  \fi
303  \else
304  \Show{cnt}{oddsidemargin}
305  \fi                    & 4 & \Show{cnt}{topmargin} \\
306  5 & \Show{cnt}{headheight} & 6 & \Show{cnt}{headsep} \\
307  7 & \Show{cnt}{textheight} & 8 & \Show{cnt}{textwidth} \\
308  9 & \Show{cnt}{marginparsep}&10& \Show{cnt}{marginparwidth} \\
309  11& \Show{cnt}{footskip}   &   & \Show{cnt}{marginparpush}

310  \rlap{(not shown)}\\
311  & \Show{ref}{hoffset}    &   & \Show{ref}{voffset} \\
312  & \Show{cnt}{paperwidth} &   & \Show{cnt}{paperheight} \\

313

314 \end{tabular}\vss}

When the option verbose was used the following lines will show dimensions on the terminal.

315 \Type{ref}{hoffset}
316 \Type{ref}{voffset}
317 \Type{cnt}{textheight}
318 \Type{cnt}{textwidth}

Finally we start a new page.

319 \newpage

320 }

321 ⟨/package⟩