Displaying page layout variables

Kent McPherson a.o.^{∗}

1995/06/25

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 % \changes{v1.1f}{1995/03/14}{Added \cs{notshown}}
 2 % \changes{v1.1f}{1995/03/14}{Added option french}

3 ⟨∗package⟩

 4 \DeclareOption{dutch}{%
 5 \def\Headertext{Kopregel}
 6 \def\Bodytext{Broodtekst}
 7 \def\Footertext{Voetregel}
 8 \def\MarginNotestext{Marge\\Notities}
 9 \def\oneinchtext{een inch}
10 \def\notshown{niet getoond}

11 }

12 \DeclareOption{english}{%
13 \def\Headertext{Header}
14 \def\Bodytext{Body}
15 \def\Footertext{Footer}
16 \def\MarginNotestext{Margin\\Notes}
17 \def\oneinchtext{one inch}
18 \def\notshown{not shown}

19 }

20 \DeclareOption{french}{%
21 \def\Headertext{Ent\^{e}te}
22 \def\Bodytext{Corps}
23 \def\Footertext{Pied de page}
24 \def\MarginNotestext{Marge\\Notes}
25 \def\oneinchtext{un pouce}
26 \def\notshown{non affich\'{e}}

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

27 }

28 \DeclareOption{francais}{\ExecuteOptions{french}}

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

29 \DeclareOption{verbose}{\let\type\typeout}
30 \DeclareOption{silent}{\let\type\@gobble}

The normal behaviour of this package when showing the values of the parameters is to truncate them. However, if you want to see the real parameter values you can use the option reals to get that effect.

31 \def\lay@value{}
32 \DeclareOption{integers}{%
33 \renewcommand*{\lay@value}[2]{%
34  \expandafter\number\csname #1@#2\endcsname pt}}
35 \DeclareOption{reals}{%
36 \renewcommand*{\lay@value}[2]{\the\csname #2\endcsname}}

The default language is English, the default mode is silent and the default way of showing parameter values is to use integers.

37 \ExecuteOptions{english,silent,integers}
38 \ProcessOptions

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

39 \@ifundefined{bs}{\newcommand\bs{\char '134 }}%
40 {\renewcommand\bs{\char '134 }}

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

41 \def\ConvertToCount#1#2{%

First copy the value

42 #1=#2

Then divide it by 65536.

43 \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.

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

\Identify A small macro used in identifying dimensions.

46 \def\Identify#1{%
47 \put(\PositionX,\PositionY){\circle{20}}
48 \put(\PositionX,\PositionY){\makebox(0,0){\tiny #1}}

49 }

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

50 \def\InsideHArrow#1{{%
51 \ArrowLength = #1
52 \divide\ArrowLength by \tw@
53 \advance\ArrowLength by -10

layout package version v1.1i as of 1995/06/25 3

54 \advance\PositionX by -10
55 \ifnum\ArrowLength<\z@
56  \put(\PositionX,\PositionY){\vector(1,0){-\ArrowLength}}
57  \advance\PositionX by 20
58  \put(\PositionX,\PositionY){\vector(-1,0){-\ArrowLength}}
59 \else
60  \put(\PositionX,\PositionY){\vector(-1,0){\ArrowLength}}
61  \advance\PositionX by 20
62  \put(\PositionX,\PositionY){\vector(+1,0){\ArrowLength}}
63 \fi
64 }}

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

65 \def\InsideVArrow#1{{%
66 \ArrowLength = #1
67 \divide\ArrowLength by \tw@
68 \advance\ArrowLength by -10
69 \advance\PositionY by -10
70 \put(\PositionX,\PositionY){\vector(0,-1){\ArrowLength}}
71 \advance\PositionY by 20
72 \put(\PositionX,\PositionY){\vector(0,+1){\ArrowLength}}
73 }}

\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.

74 \def\OutsideHArrow#1#2#3{{%
75 \PositionX = #1
76 \advance\PositionX by #3
77 \put(\PositionX,\PositionY){\vector(-1,0){#3}}
78 \PositionX = #1 \advance\PositionX-#2
79 \advance\PositionX by -#3
80 \put(\PositionX,\PositionY){\vector(+1,0){#3}}
81 }}

\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.

82 \def\OutsideVArrow#1#2#3#4{{%
83 \PositionY = #1
84 \advance\PositionY by -#3
85 \put(\PositionX,\PositionY){\vector(0,+1){#3}}
86 \PositionY = #1
87 \advance\PositionY#2
88 \advance\PositionY#4
89 \put(\PositionX,\PositionY){\vector(0,-1){#4}}
90 }}

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

91 \def\Show#1#2{\bs #2 = \lay@value{#1}{#2}}

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

 92 \def\Type#1#2{%
 93 \type{#2 = \lay@value{#1}{#2}}}

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

 94 \newcount\oneinch
 95 \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

 96 \newcount\cnt@paperwidth
 97 \newcount\cnt@paperheight
 98 \ConvertToCount\cnt@paperwidth\paperwidth
 99 \ConvertToCount\cnt@paperheight\paperheight

the offsets,

100 \newcount\cnt@hoffset
101 \newcount\cnt@voffset
102 \ConvertToCount\cnt@hoffset\hoffset
103 \ConvertToCount\cnt@voffset\voffset

dimensions of the text area,

104 \newcount\cnt@textheight
105 \newcount\cnt@textwidth
106 \ConvertToCount\cnt@textheight\textheight
107 \ConvertToCount\cnt@textwidth\textwidth

margins,

108 \newcount\cnt@topmargin
109 \newcount\cnt@oddsidemargin
110 \newcount\cnt@evensidemargin
111 \ConvertToCount\cnt@topmargin\topmargin
112 \ConvertToCount\cnt@oddsidemargin\oddsidemargin
113 \ConvertToCount\cnt@evensidemargin\evensidemargin

dimensions of the running heads,

114 \newcount\cnt@headheight
115 \newcount\cnt@headsep
116 \ConvertToCount\cnt@headheight\headheight
117 \ConvertToCount\cnt@headsep\headsep

marginal paragraphs,

118 \newcount\cnt@marginparsep
119 \newcount\cnt@marginparwidth
120 \newcount\cnt@marginparpush
121 \ConvertToCount\cnt@marginparsep\marginparsep
122 \ConvertToCount\cnt@marginparwidth\marginparwidth
123 \ConvertToCount\cnt@marginparpush\marginparpush

the distance between the running footers and the text,

124 \newcount\cnt@footskip
125 \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.

126 \newcount\fheight
127 \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.

128 \newcount\ref@top
129 \ref@top=\cnt@paperheight \advance\ref@top by -\oneinch

For the offsets,

130 \newcount\ref@hoffset
131 \newcount\ref@voffset

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

132 \ref@hoffset=\cnt@hoffset  \advance\cnt@hoffset by \oneinch
133 \ref@voffset=\cnt@voffset

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

134 \cnt@voffset=\ref@top
135 \advance\cnt@voffset by -\ref@voffset

and the text areas, running heads,

136 \newcount\ref@head
137 \ref@head=\ref@top
138 \advance\ref@head by -\ref@voffset
139 \advance\ref@head by -\cnt@topmargin
140 \advance\ref@head by -\cnt@headheight

body of the text

141 \newcount\ref@body
142 \ref@body=\ref@head
143 \advance\ref@body by -\cnt@headsep
144 \advance\ref@body by -\cnt@textheight

and running footers.

145 \newcount\ref@foot
146 \ref@foot=\ref@body
147 \advance\ref@foot by -\cnt@footskip

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

148 \newcount\ref@margin
149 \newcount\ref@marginwidth
150 \newcount\ref@marginpar

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

151 \newcount\Interval
152 \newcount\ExtraYPos
153 \newcount\PositionX
154 \newcount\PositionY
155 \newcount\ArrowLength

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

156 \newcommand\layout{%
157 \@layout
158 \if@twoside
159  \@layout
160 \fi}
161 \newcommand\@layout{%
162 \thispagestyle{empty}

The actions of \layout depend on the pagestyle.

163 \if@twoside
164  \ifodd\count\z@

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

165  \typeout{Two-sided document style, odd page.}
    So we compute \ref@marginwidth, \ref@marginpar and \ref@margin.
166  \ref@marginwidth=\cnt@oddsidemargin
167  \ref@marginpar=\oneinch
168  \advance\ref@marginpar by \ref@hoffset
169  \advance\ref@marginpar by \cnt@oddsidemargin
170  \ref@margin\ref@marginpar
171  \if@reversemargin
172  \advance\ref@marginpar by -\cnt@marginparsep
173  \advance\ref@marginpar by -\cnt@marginparwidth
174  \else
175  \advance\ref@marginpar by \cnt@textwidth
176  \advance\ref@marginpar by \cnt@marginparsep
177  \fi
178  \else

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

179 \typeout{Two-sided document style, even page.}
    So we compute \ref@marginwidth, \ref@marginpar and \ref@margin.
180  \ref@marginwidth=\cnt@evensidemargin
181  \ref@marginpar=\oneinch
182  \advance\ref@marginpar by \ref@hoffset
183  \advance\ref@marginpar by \cnt@evensidemargin
184  \ref@margin\ref@marginpar
185  \if@reversemargin
186  \advance\ref@marginpar by \cnt@textwidth
187  \advance\ref@marginpar by \cnt@marginparsep
188  \else
189  \advance\ref@marginpar by -\cnt@marginparsep
190  \advance\ref@marginpar by -\cnt@marginparwidth
191  \fi
192  \fi
193 \else

Finally we the case for single sided printing.

194  \typeout{One-sided document style.}
195  \ref@marginwidth=\cnt@oddsidemargin
196  \ref@marginpar=\oneinch
197  \advance\ref@marginpar by \ref@hoffset

198  \advance\ref@marginpar by \cnt@oddsidemargin
199  \ref@margin\ref@marginpar
200  \if@reversemargin
201  \advance\ref@marginpar by -\cnt@marginparsep
202  \advance\ref@marginpar by -\cnt@marginparwidth
203  \else
204  \advance\ref@marginpar by \cnt@textwidth
205  \advance\ref@marginpar by \cnt@marginparsep
206  \fi
207 \fi

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

 by setting \unitlength to 0.5pt
208 \setlength{\unitlength}{.5pt}
209 \begin{picture}(\cnt@paperwidth,\cnt@paperheight)
210  \centering
211  \thicklines

First we have the pagebox and reference lines,

212  \put(0,0){\framebox(\cnt@paperwidth,\cnt@paperheight){\mbox{}}}
213  \put(0,\cnt@voffset){\dashbox{10}(\cnt@paperwidth,0){\mbox{}}}
214  \put(\cnt@hoffset,0){\dashbox{10}(0,\cnt@paperheight){\mbox{}}}

then the header,

215  \put(\ref@margin,\ref@head){%
216  \framebox(\cnt@textwidth,\cnt@headheight)%
217  {\footnotesize\Headertext}}

the body of the text area,

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

the footer

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

and the space for marginal notes.

222  \put(\ref@marginpar,\ref@body){%
223  \framebox(\cnt@marginparwidth,\cnt@textheight)%
224  {\footnotesize\shortstack{\MarginNotestext}}}

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

 we use \thinlines.
225  \thinlines

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

226  \SetToHalf\PositionX\cnt@textwidth
227  \advance\PositionX by \ref@margin

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

228  \PositionY = \ref@body
229  \advance\PositionY by 50

An identifying number is put here, in a circle.

230  \Identify{8}

Then the arrow is drawn.

231  \InsideHArrow\cnt@textwidth
    Now the \textheight
232  \SetToHalf\PositionY\cnt@textheight
233  \advance\PositionY by \ref@body

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

234  \PositionX = \cnt@textwidth
235  \divide\PositionX by 5
236  \multiply \PositionX by 4
237  \advance\PositionX by \ref@margin

An identifying number is put here, in a circle.

238  \Identify{7}
239  \InsideVArrow\cnt@textheight
    The \hoffset,
240  \PositionY = \ref@foot
241  \SetToHalf\PositionX\cnt@hoffset
242  \Identify{1}
243  \InsideHArrow\cnt@hoffset

The width of the margin.

244  \SetToQuart\PositionY\cnt@textheight
245  \advance\PositionY by \ref@body
246  \OutsideHArrow\ref@margin\ref@marginwidth{20}
247  \PositionX = \cnt@hoffset
248  \advance\PositionX by -30
249  \Identify{3}
    the \marginparwidth,
250  \SetToQuart\PositionY\cnt@textheight
251  \advance\PositionY by \ref@body

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

 \evensidemargin.
252  \advance\PositionY by 30
253  \SetToHalf\PositionX\cnt@marginparwidth
254  \advance\PositionX by \ref@marginpar
255  \Identify{10}
256  \InsideHArrow\cnt@marginparwidth

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

257  \advance\PositionY by 30
258  \if@twoside
259  \ifodd\count\z@

Twosided mode, odd page;

260  \OutsideHArrow\ref@marginpar\cnt@marginparsep{20}
261  \PositionX = \ref@marginpar
262  \else

and even page.

263  \OutsideHArrow\ref@margin\cnt@marginparsep{20}
264  \PositionX = \ref@margin
265  \fi
266  \else

Single sided mode.

267  \OutsideHArrow\ref@marginpar\cnt@marginparsep{20}
268  \PositionX = \ref@marginpar
269  \fi
270  \advance\PositionX by 30
271  \Identify{9}

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

272  \PositionX = \cnt@textwidth
273  \divide\PositionX by 8
274  \advance\PositionX by \ref@margin
275  \OutsideVArrow\ref@foot\cnt@footskip{20}{20}
276  \PositionY = \ref@foot
277  \advance\PositionY by -30
278  \Identify{11}

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

279  \PositionX = \cnt@paperwidth
280  \advance\PositionX by -50
281  \PositionY = \cnt@paperheight
282  \ExtraYPos = \PositionY
283  \advance\ExtraYPos by -\cnt@voffset
284  \advance\PositionY by \cnt@voffset
285  \divide\PositionY by \tw@
286  \Identify{2}
287  \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.

288  \Interval = \cnt@textwidth
289  \divide\Interval by 8
290  \PositionX = \ref@margin
291  \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.

292  \Identify{4}
293  \ExtraYPos = \ref@head
294  \advance\ExtraYPos\cnt@headheight
295  \ArrowLength = \PositionY
296  \advance\ArrowLength-\ExtraYPos
297  \advance\ArrowLength-\cnt@topmargin
298  \advance\ArrowLength-10%
299  \OutsideVArrow\ExtraYPos\cnt@topmargin{20}{\ArrowLength}
300  \advance\PositionX by \Interval
 Then the \headheight
301  \Identify{5}
302  \advance\ArrowLength\cnt@topmargin
303  \OutsideVArrow\ref@head\cnt@headheight{20}{\ArrowLength}
304  \advance\PositionX by \Interval

and finally the \headsep

305  \Identify{6}
306  \advance\ArrowLength\cnt@headheight
307  \ExtraYPos=\ref@body
308  \advance\ExtraYPos\cnt@textheight
309  \OutsideVArrow\ExtraYPos\cnt@headsep{20}{\ArrowLength}

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

310 \end{picture}

311

312 \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.

313 \vtop to 0pt{%
314  \@minipagerestore\footnotesize\ttfamily
315  \begin{tabular}{@{}rl@{\hspace{20pt}}rl}
316  1 & \oneinchtext\ + \bs\texttt{hoffset}
317  & 2 & \oneinchtext\ + \bs\texttt{voffset} \\
318  3 & \if@twoside
319  \ifodd\count\z@ \Show{cnt}{oddsidemargin}
320  \else \Show{cnt}{evensidemargin}
321  \fi
322  \else
323  \Show{cnt}{oddsidemargin}
324  \fi                    & 4 & \Show{cnt}{topmargin} \\
325  5 & \Show{cnt}{headheight} & 6 & \Show{cnt}{headsep} \\
326  7 & \Show{cnt}{textheight} & 8 & \Show{cnt}{textwidth} \\
327  9 & \Show{cnt}{marginparsep}&10& \Show{cnt}{marginparwidth} \\
328  11& \Show{cnt}{footskip}   &   & \Show{cnt}{marginparpush}
329  \rlap{(\notshown)}\\
330  & \Show{ref}{hoffset}    &   & \Show{ref}{voffset} \\
331  & \Show{cnt}{paperwidth} &   & \Show{cnt}{paperheight} \\

332

333 \end{tabular}\vss}

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

334 \Type{ref}{hoffset}
335 \Type{ref}{voffset}
336 \Type{cnt}{textheight}
337 \Type{cnt}{textwidth}

Finally we start a new page.

338 \newpage

339 } 340 ⟨/package⟩