| 1 |
% \iffalse |
| 2 |
%% |
| 3 |
%% File: tocenter.dtx Copyright (C) 2002--2004 by Alexander I. Rozhenko |
| 4 |
%% |
| 5 |
%<package>\NeedsTeXFormat{LaTeX2e} |
| 6 |
%<package>\ProvidesPackage{tocenter} |
| 7 |
%<package> [2004/12/09 v1.1 Centering Page Layout (NCC)] |
| 8 |
% |
| 9 |
% \changes{v1.0}{2002/01/31}{This version was uploaded to CTAN} |
| 10 |
% \changes{v1.1}{2004/12/09}{Documentation was prepared} |
| 11 |
% |
| 12 |
%<*driver> |
| 13 |
\let\makeindex\relax |
| 14 |
\documentclass{ltxdoc} |
| 15 |
\usepackage{tocenter} |
| 16 |
\GetFileInfo{tocenter.sty} |
| 17 |
\begin{document} |
| 18 |
\title{The \textsf{tocenter} package\thanks{This file |
| 19 |
has version number \fileversion, last |
| 20 |
revised \filedate.}} |
| 21 |
\author{Alexander I. Rozhenko\\[email protected]} |
| 22 |
\date{\filedate} |
| 23 |
\maketitle |
| 24 |
\DocInput{tocenter.dtx} |
| 25 |
\end{document} |
| 26 |
%</driver> |
| 27 |
% \fi |
| 28 |
% |
| 29 |
% The package provides commands |
| 30 |
% customizing the layout parameters of a documents. |
| 31 |
% |
| 32 |
% \section{User Interface} |
| 33 |
% |
| 34 |
% \DescribeMacro{\ToCenter} |
| 35 |
% The |\ToCenter|\oarg{hfm}\marg{text-width}\marg{text-height} command |
| 36 |
% calculates margins in such a way to center the specified text area |
| 37 |
% together with header/footer/marginals areas on a sheet of paper. |
| 38 |
% The optional \meta{hfm} parameter specifies what additional areas take into |
| 39 |
% account while centering. It is a combination of three letters |h| (headers), |
| 40 |
% |f| (footers), and |m| (marginal notes). If this parameters is omitted, |
| 41 |
% additional areas are ignored while calculations. For example, |
| 42 |
% the following command |
| 43 |
% \begin{quote} |
| 44 |
% |\ToCenter[h]{\textwidth}{\textheight}| |
| 45 |
% \end{quote} |
| 46 |
% centers the text+header area on the page. The text height and wight |
| 47 |
% are not changed here. This command is useful in books without marginal |
| 48 |
% notes. |
| 49 |
% |
| 50 |
% \DescribeMacro{\FromMargins} |
| 51 |
% The |\FromMargins|\oarg{hfm}\marg{left}\marg{right}\marg{top}\marg{bottom} |
| 52 |
% command calculates the page layout parameters in the MS Word-like style. |
| 53 |
% It sets page margins to the values specified in the last four |
| 54 |
% parameters and calculates the width and |
| 55 |
% height of the text area in such a way to satisfy the requirements. |
| 56 |
% For example, the command |
| 57 |
% \begin{quote} |
| 58 |
% |\FromMargins[hf]{20mm}{10mm}{25mm}{15mm}| |
| 59 |
% \end{quote} |
| 60 |
% calculates the text area dimensions and margins in such a way to |
| 61 |
% provide 20~mm distance from the left edge of the page, 10~mm |
| 62 |
% distance from the right edge, 25~mm distance from the top edge, and |
| 63 |
% 15~mm distance from the bottom edge in assumption that header and |
| 64 |
% footer are in use. |
| 65 |
% |
| 66 |
% If twoside mode is turned on, the left and right margins specified |
| 67 |
% in the |\FromMargins| command are considered for odd pages. |
| 68 |
% For even pages, their values are swapped. |
| 69 |
% |
| 70 |
% If |m|-letter is specified in the optional parameter, the margins are |
| 71 |
% determined depending on two-side and two-column switches. In two-column mode, |
| 72 |
% marginal notes are posed on both sides of paper, but in one-column mode |
| 73 |
% the marginal notes are posed on the outer side of a page in two-side mode |
| 74 |
% and to the right of the text area in one-side mode. All these specifics |
| 75 |
% is taken into account while calculations of text margins. |
| 76 |
% The reverse margin mode is also supported. |
| 77 |
% |
| 78 |
% \DescribeMacro{\ToCenter*} |
| 79 |
% \DescribeMacro{\FromMargins*} |
| 80 |
% The star-forms of these commands |
| 81 |
% \begin{quote} |
| 82 |
% |\ToCenter*|\marg{text-width}\marg{text-height}\\ |
| 83 |
% |\FromMargins*|\marg{left}\marg{right}\marg{top}\marg{bottom} |
| 84 |
% \end{quote} |
| 85 |
% are intended for positioning of simple documents without headers, |
| 86 |
% footers, marginal notes, cross-references, and table of contents. |
| 87 |
% Additionally, the empty page style is set and the writing to aux-file |
| 88 |
% is suppressed. |
| 89 |
% |
| 90 |
% \textit{All mentioned commands are allowed in the preamble only.} |
| 91 |
% \StopEventually{} |
| 92 |
% |
| 93 |
% \section{The Implementation} |
| 94 |
% |
| 95 |
% \begin{macro}{\NCC@pos} |
| 96 |
% The |\NCC@pos|\marg{hfm} command parses the \meta{hfm} parameter |
| 97 |
% and prepares |\NCC@h|\marg{register}, |\NCC@f|\marg{register}, |
| 98 |
% and |\NCC@m|\marg{register} commands to adjust values of skip |
| 99 |
% registers. The |\NCC@pos| command is also useful in the |cropmark| package. |
| 100 |
% \begin{macrocode} |
| 101 |
%<*package> |
| 102 |
\def\NCC@pos#1{% |
| 103 |
\let\NCC@h\@gobble \let\NCC@f\@gobble \let\NCC@m\@gobble |
| 104 |
\@tfor\@tempa:=#1\do{% |
| 105 |
% \end{macrocode} |
| 106 |
% If |h|-letter appears, the |\NCC@h| hook will adjust the value of register |
| 107 |
% on the header height and separation: |
| 108 |
% \begin{macrocode} |
| 109 |
\if h\@tempa |
| 110 |
\def\NCC@h##1{\advance##1\headsep \advance##1\headheight}% |
| 111 |
\else |
| 112 |
% \end{macrocode} |
| 113 |
% If |f|-letter appears, the |\NCC@f| hook will adjust the value of register |
| 114 |
% on the footer skip distance: |
| 115 |
% \begin{macrocode} |
| 116 |
\if f\@tempa |
| 117 |
\def\NCC@f##1{\advance##1\footskip}% |
| 118 |
\else |
| 119 |
% \end{macrocode} |
| 120 |
% If |m|-letter appears, the |\NCC@m| hook will adjust the value of register |
| 121 |
% on the width and separation of marginal paragraphs: |
| 122 |
% \begin{macrocode} |
| 123 |
\if m\@tempa |
| 124 |
\def\NCC@m##1{\advance##1\marginparwidth |
| 125 |
\advance##1\marginparsep}% |
| 126 |
\fi |
| 127 |
\fi |
| 128 |
\fi |
| 129 |
}% |
| 130 |
} |
| 131 |
% \end{macrocode} |
| 132 |
% \end{macro} |
| 133 |
% |
| 134 |
% \begin{macro}{\ToCenter} |
| 135 |
% The star-form of this command differs in the omitted |
| 136 |
% optional parameter, empty page style, and suppressed |
| 137 |
% writing to external files: |
| 138 |
% \begin{macrocode} |
| 139 |
\newcommand{\ToCenter}{% |
| 140 |
\@ifstar{\pagestyle{empty}\nofiles\NCC@center[]}{\NCC@center}% |
| 141 |
} |
| 142 |
\@onlypreamble\ToCenter |
| 143 |
% \end{macrocode} |
| 144 |
% At the first, we parse the \meta{hfm} parameter: |
| 145 |
% \begin{macrocode} |
| 146 |
\newcommand*{\NCC@center}[3][]{\NCC@pos{#1}% |
| 147 |
% \end{macrocode} |
| 148 |
% Start calculations from horizontal margins and width: |
| 149 |
% set text width and calculate in |\@tempdima| the |
| 150 |
% whole width of area to be centered. |
| 151 |
% \begin{macrocode} |
| 152 |
\setlength\textwidth{#2}% |
| 153 |
\@tempdima\textwidth \NCC@m\@tempdima |
| 154 |
% \end{macrocode} |
| 155 |
% In two-column mode, margins appear on both sides of text. |
| 156 |
% We must add the width of marginal area again to |\@tempdima|: |
| 157 |
% \begin{macrocode} |
| 158 |
\if@twocolumn |
| 159 |
\NCC@m\@tempdima |
| 160 |
% \end{macrocode} |
| 161 |
% In two-column mode, we set the odd and even side margins to |
| 162 |
% \begin{quote} |
| 163 |
% |\NCC@m{(\paperwidth-\@tempdima)/2}|: |
| 164 |
% \end{quote} |
| 165 |
% \begin{macrocode} |
| 166 |
\@tempdimb\paperwidth |
| 167 |
\advance\@tempdimb -\@tempdima |
| 168 |
\@tempdima .5\@tempdimb \NCC@m\@tempdima |
| 169 |
\oddsidemargin\@tempdima |
| 170 |
\evensidemargin\@tempdima |
| 171 |
% \end{macrocode} |
| 172 |
% In one-column mode with reverse margins, we set |
| 173 |
% \begin{quote} |
| 174 |
% |\evensidemargin:=(\paperwidth-\@tempdima)/2|\\ |
| 175 |
% |\oddsidemargin:=\NCC@m{(\paperwidth-\@tempdima)/2}| |
| 176 |
% \end{quote} |
| 177 |
% and, with normal margins, we set |
| 178 |
% \begin{quote} |
| 179 |
% |\oddsidemargin:=(\paperwidth-\@tempdima)/2|\\ |
| 180 |
% |\evensidemargin:=\NCC@m{(\paperwidth-\@tempdima)/2}| |
| 181 |
% \end{quote} |
| 182 |
% \begin{macrocode} |
| 183 |
\else |
| 184 |
\@tempdimb\paperwidth |
| 185 |
\advance\@tempdimb -\@tempdima \@tempdima .5\@tempdimb |
| 186 |
\if@reversemargin |
| 187 |
\evensidemargin\@tempdima |
| 188 |
\NCC@m\@tempdima |
| 189 |
\oddsidemargin\@tempdima |
| 190 |
\else |
| 191 |
\oddsidemargin\@tempdima |
| 192 |
\NCC@m\@tempdima |
| 193 |
\evensidemargin\@tempdima |
| 194 |
\fi |
| 195 |
\fi |
| 196 |
% \end{macrocode} |
| 197 |
% Now we calculate the vertical layout parameters. |
| 198 |
% Again, in the |\@tempdima| we calculate the full |
| 199 |
% height of useful areas and set the top margin to |
| 200 |
% \begin{quote} |
| 201 |
% |(\paperwidth-\@tempdima)/2| |
| 202 |
% \end{quote} |
| 203 |
% if headers are in use. |
| 204 |
% \begin{macrocode} |
| 205 |
\setlength\textheight{#3}% |
| 206 |
\@tempdima\textheight \NCC@h\@tempdima \NCC@f\@tempdima |
| 207 |
\@tempdimb\paperheight |
| 208 |
\advance\@tempdimb -\@tempdima |
| 209 |
\topmargin .5\@tempdimb |
| 210 |
% \end{macrocode} |
| 211 |
% Otherwise, we decrease the value of top margin on the height |
| 212 |
% and separation of header: |
| 213 |
% \begin{macrocode} |
| 214 |
\ifx\NCC@h\@gobble |
| 215 |
\advance\topmargin -\headsep |
| 216 |
\advance\topmargin -\headheight |
| 217 |
\fi |
| 218 |
% \end{macrocode} |
| 219 |
% Do final correction of all margins: decrease their values |
| 220 |
% on 1~inch. This compensates the default adjustment applied by |
| 221 |
% dvi drivers. |
| 222 |
% \begin{macrocode} |
| 223 |
\advance \oddsidemargin -1in |
| 224 |
\advance \evensidemargin -1in |
| 225 |
\advance \topmargin -1in |
| 226 |
} |
| 227 |
\@onlypreamble\NCC@center |
| 228 |
% \end{macrocode} |
| 229 |
% \end{macro} |
| 230 |
% |
| 231 |
% \begin{macro}{\FromMargins} |
| 232 |
% Finally, we implement the |\FromMargins| command. |
| 233 |
% \begin{macrocode} |
| 234 |
\newcommand{\FromMargins}{% |
| 235 |
\@ifstar{\pagestyle{empty}\nofiles\NCC@margin[]}{\NCC@margin}% |
| 236 |
} |
| 237 |
\@onlypreamble\FromMargins |
| 238 |
% \end{macrocode} |
| 239 |
% Again, start from parsing the \meta{hfm} parameter: |
| 240 |
% \begin{macrocode} |
| 241 |
\newcommand*{\NCC@margin}[5][]{\NCC@pos{#1}% |
| 242 |
% \end{macrocode} |
| 243 |
% Calculate horizontal parameters at first. |
| 244 |
% In two-side mode, the left margin is equal to the |
| 245 |
% |\oddsidemargin| and the right margin is equal to the |
| 246 |
% |\evensidemargin|. In one-side mode, the |
| 247 |
% |\oddsidemargin| is calculated in the same manner |
| 248 |
% and the |\evensidemargin| is useless. So, we need |
| 249 |
% not distinguish one-side and two-side modes here |
| 250 |
% and do all things as for two-side mode. |
| 251 |
% \begin{macrocode} |
| 252 |
\setlength\oddsidemargin{#2}% |
| 253 |
\setlength\evensidemargin{#3}% |
| 254 |
% \end{macrocode} |
| 255 |
% Calculate in |\@tempdima| the amount of space occupied |
| 256 |
% by horizontal margins and marginal notes. |
| 257 |
% \begin{macrocode} |
| 258 |
\@tempdima\oddsidemargin \advance\@tempdima\evensidemargin |
| 259 |
\NCC@m\@tempdima |
| 260 |
% \end{macrocode} |
| 261 |
% In two-column mode, marginal notes should be counted twice |
| 262 |
% and the values of odd and even margins must be adjusted |
| 263 |
% on the marginal width. |
| 264 |
% \begin{macrocode} |
| 265 |
\if@twocolumn |
| 266 |
\NCC@m\@tempdima |
| 267 |
\textwidth\paperwidth |
| 268 |
\advance\textwidth -\@tempdima |
| 269 |
\NCC@m\oddsidemargin \NCC@m\evensidemargin |
| 270 |
% \end{macrocode} |
| 271 |
% In one-column mode, we must adjust only one margin |
| 272 |
% depending on placement of marginal notes. |
| 273 |
% \begin{macrocode} |
| 274 |
\else |
| 275 |
\textwidth\paperwidth |
| 276 |
\advance\textwidth -\@tempdima |
| 277 |
\if@reversemargin |
| 278 |
\NCC@m\oddsidemargin |
| 279 |
\else |
| 280 |
\NCC@m\evensidemargin |
| 281 |
\fi |
| 282 |
\fi |
| 283 |
% \end{macrocode} |
| 284 |
% Now we calculate the vertical layout parameters. |
| 285 |
% We set the |\@tempdima| to the sum of |
| 286 |
% top margin, bottom margin, header, and footer. |
| 287 |
% \begin{macrocode} |
| 288 |
\setlength\topmargin{#4}% |
| 289 |
\setlength\@tempdima{#5}\advance\@tempdima\topmargin |
| 290 |
\NCC@h\@tempdima \NCC@f\@tempdima |
| 291 |
% \end{macrocode} |
| 292 |
% The rest of page is the text height: |
| 293 |
% \begin{macrocode} |
| 294 |
\textheight\paperheight |
| 295 |
\advance\textheight -\@tempdima |
| 296 |
% \end{macrocode} |
| 297 |
% We must decrease the |\topmargin| on the header separation |
| 298 |
% and height if headers are useless. |
| 299 |
% \begin{macrocode} |
| 300 |
\ifx\NCC@h\@gobble |
| 301 |
\advance\topmargin -\headsep |
| 302 |
\advance\topmargin -\headheight |
| 303 |
\fi |
| 304 |
% \end{macrocode} |
| 305 |
% Do final correction of all margins: |
| 306 |
% \begin{macrocode} |
| 307 |
\advance \oddsidemargin -1in |
| 308 |
\advance \evensidemargin -1in |
| 309 |
\advance \topmargin -1in |
| 310 |
} |
| 311 |
\@onlypreamble\NCC@margin |
| 312 |
%</package> |
| 313 |
% \end{macrocode} |
| 314 |
% \end{macro} |
| 315 |
\endinput |