| 1 |
% \iffalse meta comment |
| 2 |
% File: typogrid.dtx Copyright (C) 2003, 2011 Harald Harders, Rolf Niepraschk |
| 3 |
% \fi |
| 4 |
% |
| 5 |
% \iffalse |
| 6 |
%<*driver> |
| 7 |
\listfiles |
| 8 |
\documentclass[a4paper]{ltxdoc} |
| 9 |
\usepackage[T1]{fontenc} |
| 10 |
\IfFileExists{typogrid.sty}{% |
| 11 |
\usepackage[draft,columns=4,margin=false,headings=true]{typogrid} |
| 12 |
}{% |
| 13 |
\GenericWarning{typogrid.dtx}{Package file typogrid.sty not found |
| 14 |
(Documentation will be messed up!^^J^^A |
| 15 |
Generate typogrid.sty by (La)TeXing typogrid.ins, process |
| 16 |
typogrid.dtx again)^^J}\stop |
| 17 |
} |
| 18 |
%% |
| 19 |
\GetFileInfo{typogrid.sty} |
| 20 |
\title{The \texttt{typogrid} package} |
| 21 |
\author{% |
| 22 |
Harald Harders (\texttt{[email protected]}),\\ |
| 23 |
Rolf Niepraschk (\texttt{[email protected]})} |
| 24 |
\date{File Version \fileversion, \filedate, printed \today} |
| 25 |
%% |
| 26 |
\EnableCrossrefs |
| 27 |
\CodelineIndex |
| 28 |
\DoNotIndex{\def,\edef,\let,\newcommand,\newenvironment,\newcounter} |
| 29 |
\DoNotIndex{\setcounter,\space,\if,\else,\fi,\empty,\@empty,\ifx,\fi} |
| 30 |
\DoNotIndex{\ifnum,\fi,\expandafter,\csname,\endcsname,\the} |
| 31 |
\DoNotIndex{\MessageBreak,\message,\newlength,\newif,\xdef,\newcount} |
| 32 |
\DoNotIndex{\begingroup,\endgroup,\,,\@tempcnta,\@tempdima,\advance} |
| 33 |
\DoNotIndex{\ensuremath,\filedate,\fileversion,\docdate} |
| 34 |
\DoNotIndex{\mathit,\mathrm,\mathsf,\nprt@tmp,\nprt@tmpnum,\relax} |
| 35 |
\DoNotIndex{\protect,\renewcommand,\setlength,\settowidth,\stepcounter} |
| 36 |
\DoNotIndex{\string,\put,\multiput} |
| 37 |
\CodelineNumbered |
| 38 |
\RecordChanges |
| 39 |
\CheckSum{219} |
| 40 |
\begin{document} |
| 41 |
\DocInput{typogrid.dtx} |
| 42 |
\end{document} |
| 43 |
%</driver> |
| 44 |
% \fi |
| 45 |
% |
| 46 |
% \changes{0.21}{2011/12/31}{Update Makefile}% |
| 47 |
% \changes{0.21}{2011/12/31}{Set date and version explicitly in |
| 48 |
% \cs{ProvidesPackage}}% |
| 49 |
% \changes{0.20}{2003/11/09}{Reimplementation with respect to |
| 50 |
% \texttt{showframe.sty} by Rolf Niepraschk}% |
| 51 |
% \changes{0.10}{2003/10/30}{First version}% |
| 52 |
% |
| 53 |
% \maketitle |
| 54 |
% \begin{abstract} |
| 55 |
% \noindent |
| 56 |
% This package produces a typographic grid on every page of the |
| 57 |
% document. |
| 58 |
% That grid consists of vertical lines that devide the text block into |
| 59 |
% columns. |
| 60 |
% This may be useful to get the horizontal measures (distances etc.) |
| 61 |
% into good values. |
| 62 |
% \end{abstract} |
| 63 |
% |
| 64 |
% \tableofcontents |
| 65 |
% |
| 66 |
% \section*{Copyright} |
| 67 |
% Copyright 2003, 2011 Harald Harders, Rolf Niepraschk. |
| 68 |
% |
| 69 |
% This program can be redistributed and/or modified under the terms |
| 70 |
% of the LaTeX Project Public License Distributed from CTAN |
| 71 |
% archives in directory macros/latex/base/lppl.txt; either |
| 72 |
% version 1 of the License, or any later version. |
| 73 |
% |
| 74 |
% \section{Usage} |
| 75 |
% |
| 76 |
% Load the package using the |
| 77 |
% \begin{quote} |
| 78 |
% \cs{usepackage}\oarg{options}|{typogrid}| |
| 79 |
% \end{quote} |
| 80 |
% command. |
| 81 |
% Valid options are |final|, |draft|, |
| 82 |
% |columns=|\meta{value}, |headings=|\meta{true,false}, and |
| 83 |
% |margin=|\meta{true,false}. |
| 84 |
% The options |final| and |draft| may be given explicitely or |
| 85 |
% implicitely from the document-class options. |
| 86 |
% |
| 87 |
% When |draft| is given the typographic grid is switched on; if |
| 88 |
% |final| or none of the above is given it is switched off. |
| 89 |
% |
| 90 |
% The |columns| option determines the number of columns printed. |
| 91 |
% If it is not given, a default of 12 is used. |
| 92 |
% |
| 93 |
% If |headings=true| is given, a grid is printed for the head line and |
| 94 |
% the foot line, too (this is the default, you may also omit it). |
| 95 |
% If |headings=false| is given, no grid is printed for the headings. |
| 96 |
% |
| 97 |
% With |margin=false|, you can switch off printing a frame around the |
| 98 |
% area for margin notes (default is to print the frame). |
| 99 |
% |
| 100 |
% \DescribeMacro{\typogridsetup} |
| 101 |
% There is a second possibility to change the typographic grid. |
| 102 |
% You may use the \cs{typogridsetup} command that takes a keyval list |
| 103 |
% as argument. |
| 104 |
% The same keywords are allowed as in the \cs{usepackage} line, e.g., |
| 105 |
% \begin{quote} |
| 106 |
% |\typogridsetup{columns=4}| |
| 107 |
% \end{quote} |
| 108 |
% You may use this command within the text in order to change the grid |
| 109 |
% at arbitrary position of the document. |
| 110 |
% The change takes effect on the next page. |
| 111 |
% |
| 112 |
% \DescribeMacro{\typogrid} |
| 113 |
% If you have switched off printing of the grid, you may get a grid |
| 114 |
% for single pages using |
| 115 |
% \begin{quote} |
| 116 |
% |\AddToShipoutPicture*{\typogrid}| |
| 117 |
% \end{quote} |
| 118 |
% |
| 119 |
% The package defines the length \cs{gridwidth} which is as long as |
| 120 |
% the space between too grid lines. |
| 121 |
% You may use it to scale pictures to fit to the grid, for instance. |
| 122 |
% |
| 123 |
% |
| 124 |
% \section{Shortcomings} |
| 125 |
% |
| 126 |
% \begin{itemize} |
| 127 |
% \item Calculation of position and size of the headings and the |
| 128 |
% margin works for standard cases, only. |
| 129 |
% \item If the text width changes from one page to the next, the grid |
| 130 |
% width is wrong on the first page after the change. |
| 131 |
% \end{itemize} |
| 132 |
% |
| 133 |
% |
| 134 |
% \StopEventually{\PrintChanges \PrintIndex} |
| 135 |
% |
| 136 |
% |
| 137 |
% \section{The implementation} |
| 138 |
% \iffalse |
| 139 |
%<*package> |
| 140 |
% \fi |
| 141 |
% Heading of the package: |
| 142 |
% \begin{macrocode} |
| 143 |
\ProvidesPackage{typogrid} |
| 144 |
[2011/12/31 v0.21 Typographic grid] |
| 145 |
\RequirePackage{calc} |
| 146 |
\RequirePackage{keyval} |
| 147 |
% \end{macrocode} |
| 148 |
% Introduce the used lengths. |
| 149 |
% \begin{macrocode} |
| 150 |
\newlength{\gridwidth}% |
| 151 |
% \end{macrocode} |
| 152 |
% Introduce the used counters and set the default number of columns. |
| 153 |
% \begin{macrocode} |
| 154 |
\newcount\tpg@blocks% |
| 155 |
\newcounter{tpg@blocks@new}% |
| 156 |
\setcounter{tpg@blocks@new}{12}% |
| 157 |
% \end{macrocode} |
| 158 |
% \begin{macro}{\typogridsetup} |
| 159 |
% Declare a command that can be used to change the appearence of the |
| 160 |
% typographic grid. |
| 161 |
% The argument takes a list of keyval options. |
| 162 |
% \begin{macrocode} |
| 163 |
\newcommand*\typogridsetup[1]{% |
| 164 |
\expandafter\setkeys\expandafter{typogrid}{#1}} |
| 165 |
% \end{macrocode} |
| 166 |
% \end{macro} |
| 167 |
% Define the key |columns| that takes the number of columns. |
| 168 |
% \begin{macrocode} |
| 169 |
\define@key{typogrid}{columns}{% |
| 170 |
\setcounter{tpg@blocks@new}{#1}% |
| 171 |
\ifnum\the\c@tpg@blocks@new<1\relax |
| 172 |
\PackageError{typogrid}{Less than 1 column given}{You have to |
| 173 |
declare at least 1 column.}% |
| 174 |
\setcounter{tpg@blocks@new}{1}% |
| 175 |
\fi |
| 176 |
} |
| 177 |
% \end{macrocode} |
| 178 |
% Define the key |headings| to switch on or off a frame around the |
| 179 |
% headings. |
| 180 |
% \begin{macrocode} |
| 181 |
\newif\iftpg@headings |
| 182 |
\newif\iftpg@headings@new |
| 183 |
\tpg@headings@newtrue |
| 184 |
\define@key{typogrid}{headings}[true]{% |
| 185 |
\csname tpg@headings@new#1\endcsname |
| 186 |
} |
| 187 |
% \end{macrocode} |
| 188 |
% Define the key |margin| to switch on or off a frame around the |
| 189 |
% margin. |
| 190 |
% \begin{macrocode} |
| 191 |
\newif\iftpg@margin |
| 192 |
\newif\iftpg@margin@new |
| 193 |
\tpg@margin@newtrue |
| 194 |
\define@key{typogrid}{margin}[true]{% |
| 195 |
\csname tpg@margin@new#1\endcsname |
| 196 |
} |
| 197 |
% \end{macrocode} |
| 198 |
% Package options: |
| 199 |
% \begin{macrocode} |
| 200 |
\newif\iftpg@draft |
| 201 |
\DeclareOption{draft}{\tpg@drafttrue} |
| 202 |
\DeclareOption{final}{\tpg@draftfalse} |
| 203 |
\DeclareOption{colorgrid}{\PassOptionsToPackage{\CurrentOption}{eso-pic}} |
| 204 |
\DeclareOption{grid}{\PassOptionsToPackage{\CurrentOption}{eso-pic}} |
| 205 |
\DeclareOption*{\expandafter\typogridsetup\expandafter{\CurrentOption}} |
| 206 |
% \end{macrocode} |
| 207 |
% Default is no grid. |
| 208 |
% \begin{macrocode} |
| 209 |
\ExecuteOptions{final} |
| 210 |
\ProcessOptions\relax |
| 211 |
% \end{macrocode} |
| 212 |
% Load this package after processing the options. |
| 213 |
% \begin{macrocode} |
| 214 |
\RequirePackage{eso-pic}[2002/11/16] |
| 215 |
% \end{macrocode} |
| 216 |
% \begin{macro}{\typogrid} |
| 217 |
% Define the command that produces the grid. |
| 218 |
% \begin{macrocode} |
| 219 |
\newcommand*\typogrid{% |
| 220 |
% \end{macrocode} |
| 221 |
% Switch to black and thin lines. |
| 222 |
% \begin{macrocode} |
| 223 |
\begingroup |
| 224 |
\normalcolor |
| 225 |
\thinlines |
| 226 |
% \end{macrocode} |
| 227 |
% Calculate the number of lines to be printed. |
| 228 |
% \begin{macrocode} |
| 229 |
\@tempcnta=\tpg@blocks |
| 230 |
\advance\@tempcnta by -1% |
| 231 |
% \end{macrocode} |
| 232 |
% Print a frame around the text block. |
| 233 |
% \begin{macrocode} |
| 234 |
\AtTextLowerLeft{% |
| 235 |
\put(0,0){% |
| 236 |
\framebox(\LenToUnit{\textwidth},\LenToUnit{\textheight}){}}% |
| 237 |
% \end{macrocode} |
| 238 |
% Print the vertical lines for the grid. |
| 239 |
% \begin{macrocode} |
| 240 |
\multiput(\LenToUnit{\gridwidth},0)% |
| 241 |
(\LenToUnit{\gridwidth},0){\the\@tempcnta}{% |
| 242 |
\line(0,1){\LenToUnit{\textheight}}}% |
| 243 |
}% |
| 244 |
% \end{macrocode} |
| 245 |
% Print a frame around the head line if wanted. |
| 246 |
% \begin{macrocode} |
| 247 |
\iftpg@headings |
| 248 |
\AtTextUpperLeft{% |
| 249 |
\put(0,\LenToUnit{\headsep}){% |
| 250 |
\framebox(\LenToUnit{\textwidth},\LenToUnit{\headheight}){}}% |
| 251 |
% \end{macrocode} |
| 252 |
% Print the grid. |
| 253 |
% \begin{macrocode} |
| 254 |
\multiput(\LenToUnit{\gridwidth},\LenToUnit{\headsep})% |
| 255 |
(\LenToUnit{\gridwidth},0){\the\@tempcnta}{% |
| 256 |
\line(0,1){\LenToUnit{\headheight}}}% |
| 257 |
}% |
| 258 |
% \end{macrocode} |
| 259 |
% Print a line below the foot line if wanted (the height of the foot |
| 260 |
% line is not available). |
| 261 |
% \begin{macrocode} |
| 262 |
\AtTextLowerLeft{% |
| 263 |
\put(0,\LenToUnit{-\footskip}){% |
| 264 |
\line(1,0){\LenToUnit{\textwidth}}}% |
| 265 |
% \end{macrocode} |
| 266 |
% Print the grid. |
| 267 |
% \begin{macrocode} |
| 268 |
\put(0,\LenToUnit{-\footskip}){% |
| 269 |
\line(0,1){\LenToUnit{\baselineskip}}}% |
| 270 |
\put(\LenToUnit{\textwidth},\LenToUnit{-\footskip}){% |
| 271 |
\line(0,1){\LenToUnit{\baselineskip}}}% |
| 272 |
\multiput(\LenToUnit{\gridwidth},\LenToUnit{-\footskip})% |
| 273 |
(\LenToUnit{\gridwidth},0){\the\@tempcnta}{% |
| 274 |
\line(0,1){\LenToUnit{\baselineskip}}}% |
| 275 |
}% |
| 276 |
\fi |
| 277 |
% \end{macrocode} |
| 278 |
% Print a frame around the margin if wanted. |
| 279 |
% \begin{macrocode} |
| 280 |
\iftpg@margin |
| 281 |
\AtTextLowerLeft{% |
| 282 |
\@tempdima=\textwidth\advance\@tempdima\marginparsep% |
| 283 |
\if@twoside% |
| 284 |
\ifodd\c@page |
| 285 |
\else |
| 286 |
\@tempdima=-\marginparsep\advance\@tempdima-\marginparwidth% |
| 287 |
\fi% |
| 288 |
\fi% |
| 289 |
\put(\LenToUnit{\@tempdima},0){% |
| 290 |
\framebox(\LenToUnit{\marginparwidth},% |
| 291 |
\LenToUnit{\textheight}){}}% |
| 292 |
}% |
| 293 |
\fi |
| 294 |
\endgroup |
| 295 |
% \end{macrocode} |
| 296 |
% Calculate the width of each grid. |
| 297 |
% Store it globally to be able to use it inside the document. |
| 298 |
% \begin{macrocode} |
| 299 |
\setlength\gridwidth{\textwidth/\arabic{tpg@blocks@new}}% |
| 300 |
\global\gridwidth=\gridwidth |
| 301 |
\global\tpg@blocks=\arabic{tpg@blocks@new}% |
| 302 |
\iftpg@headings@new |
| 303 |
\global\tpg@headingstrue |
| 304 |
\else |
| 305 |
\global\tpg@headingsfalse |
| 306 |
\fi |
| 307 |
\iftpg@margin@new |
| 308 |
\global\tpg@margintrue |
| 309 |
\else |
| 310 |
\global\tpg@marginfalse |
| 311 |
\fi |
| 312 |
} |
| 313 |
% \end{macrocode} |
| 314 |
% \end{macro} |
| 315 |
% Start the grid at \cs{begin\{document\}}. |
| 316 |
% Do it that late to enable the author to switch between |draft| and |
| 317 |
% |final| before that position. |
| 318 |
% \begin{macrocode} |
| 319 |
\AtBeginDocument{% |
| 320 |
% \end{macrocode} |
| 321 |
% Print the grid on any page if wanted. |
| 322 |
% \begin{macrocode} |
| 323 |
\iftpg@draft |
| 324 |
\typeout{Typographic grid switched on}% |
| 325 |
\AddToShipoutPicture{\typogrid}% |
| 326 |
\else |
| 327 |
\typeout{Typographic grid switched off}% |
| 328 |
\fi |
| 329 |
% \end{macrocode} |
| 330 |
% Declare width of grid for first page of document. |
| 331 |
% \begin{macrocode} |
| 332 |
\setlength\gridwidth{\textwidth/\arabic{tpg@blocks@new}}% |
| 333 |
\global\tpg@blocks=\arabic{tpg@blocks@new}% |
| 334 |
\iftpg@headings@new |
| 335 |
\tpg@headingstrue |
| 336 |
\else |
| 337 |
\tpg@headingsfalse |
| 338 |
\fi |
| 339 |
\iftpg@margin@new |
| 340 |
\tpg@margintrue |
| 341 |
\else |
| 342 |
\tpg@marginfalse |
| 343 |
\fi |
| 344 |
} |
| 345 |
% \end{macrocode} |
| 346 |
% |
| 347 |
% \iffalse |
| 348 |
%</package> |
| 349 |
% \fi |
| 350 |
% \Finale |
| 351 |
|