summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/typogrid/typogrid.dtx
blob: 4fb0af5ed096b19cf0a44db336670244d747240c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
% \iffalse meta comment
% File: typogrid.dtx Copyright (C) 2003 Harald Harders
% \fi
%
% \iffalse
%
%<*package>
\def\fileversion{0.10}
\def\filedate{2003/10/30}
\def\docdate{2003/10/30}
%</package>
%<*driver>
\listfiles
\documentclass[a4paper]{ltxdoc}
\title{The \texttt{typogrid} package\thanks{This file has version 
    \fileversion\ last revised \filedate, documentation dated
    \docdate.}}
\author{Harald Harders\\\texttt{h.harders@tu-bs.de}}
\date{File Date \filedate, Printed \today}
\usepackage[T1]{fontenc}
%\def\meta@font@select{\normalfont\itshape}
\makeatother
%%
\EnableCrossrefs
\CodelineIndex
\DoNotIndex{\def,\edef,\let,\newcommand,\newenvironment,\newcounter}
\DoNotIndex{\setcounter,\space,\if,\else,\fi,\empty,\@empty,\ifx,\fi}
\DoNotIndex{\ifnum,\fi,\expandafter,\csname,\endcsname,\the}
\DoNotIndex{\MessageBreak,\message,\newlength,\newif,\xdef,\newcount}
\DoNotIndex{\begingroup,\endgroup,\,,\@tempcnta,\@tempdima,\advance}
\DoNotIndex{\ensuremath,\filedate,\fileversion,\docdate}
\DoNotIndex{\mathit,\mathrm,\mathsf,\nprt@tmp,\nprt@tmpnum,\relax}
\DoNotIndex{\protect,\renewcommand,\setlength,\settowidth,\stepcounter}
\DoNotIndex{\string}
\CodelineNumbered
\RecordChanges
\CheckSum{111}
\begin{document}
 \DocInput{typogrid.dtx}
\end{document}
%</driver>
% \fi
%
% \changes{0.10}{2003/10/30}{First version}%
%
% \maketitle
% \begin{abstract}
% \noindent
% This package produces a typographic grid on every page of the
% document.
% That grid consists of vertical lines that devide the text block into
% columns.
% This may be useful to get the horizontal measures (distances etc.)
% into good values.
% \end{abstract}
%
% \tableofcontents
%
% \section*{Copyright}
% Copyright 2003 Harald Harders.
%
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or any later version.
%
% \section{Usage}
%
% Load the package using the
% \begin{quote}
% \cs{usepackage}\oarg{options}|{typogrid}|
% \end{quote}
% command.
% Valid options are |final|, |draft|, and
% |columns=|\meta{value}.
% The options |final| and |draft| may be given explicitely or
% implicitely from the document-class options.
%
% When |draft| is given the typographic grid is switched on; if
% |final| or none of the above is given it is switched off.
%
% The |columns| option determines the number of columns printed.
% If it is not given, a default of 12 is used.
%
% \DescribeMacro{\typogridsetup}
% There is a second possibility to change the number of columns.
% You may use the \cs{typogridsetup} command that takes a keyval list
% as argument.
% This version suports only |columns=|\meta{value}, e.g.,
% \begin{quote}
% |\typogridsetup{columns=4}|
% \end{quote}
% You may also change the number of columns within the text.
%
% \StopEventually{\PrintChanges \PrintIndex}
%
% \section{The implementation}
% \iffalse
%<*package>
% \fi
% Heading of the package:
%    \begin{macrocode}
\ProvidesPackage{typogrid}[2003/10/29 v\fileversion\space Typographic grid]
\RequirePackage{eso-pic}[2002/11/16]
\RequirePackage{calc}
\RequirePackage{keyval}
%    \end{macrocode}
% Introduce the used lengths.
%    \begin{macrocode}
\newlength{\tpg@left}%
\newlength{\tpg@top}%
\newlength{\tpg@bottom}%
\newlength{\tpg@gridwidth}%
%    \end{macrocode}
% Introduce the used counters and set the default number of columns.
%    \begin{macrocode}
\newcounter{tpg@bloecke}%
\setcounter{tpg@bloecke}{12}%
%    \end{macrocode}
% \begin{macro}{\typogridsetup}
% Declare a command that can be used to change the appearence of the
% typographic grid.
% The argument takes a list of keyval options.
%    \begin{macrocode}
\newcommand*\typogridsetup[1]{%
  \expandafter\setkeys\expandafter{typogrid}{#1}}
%    \end{macrocode}
% \end{macro}
% Define the key |columns| that takes the number of columns.
%    \begin{macrocode}
\define@key{typogrid}{columns}{%
  \setcounter{tpg@bloecke}{#1}%
  \ifnum\arabic{tpg@bloecke}<1
    \PackageError{typogrid}{Less than 1 column given}{You have to
      declare at least 1 column.}%
    \setcounter{tpg@bloecke}{1}%
  \fi
}
%    \end{macrocode}
% Package options:
%    \begin{macrocode}
\newif\iftpg@draft
\DeclareOption{draft}{\tpg@drafttrue}
\DeclareOption{final}{\tpg@draftfalse}
\DeclareOption*{\expandafter\typogridsetup\expandafter{\CurrentOption}}
%    \end{macrocode}
% 
%    \begin{macrocode}
\ExecuteOptions{final}
\ProcessOptions\relax
%    \end{macrocode}
% Start the grid with the first page (should not be necessary).
%    \begin{macrocode}
\AtBeginDocument{%
%    \end{macrocode}
% Print the grid on any page.
%    \begin{macrocode}
  \iftpg@draft
    \typeout{Typographic grid switched on}%
    \AddToShipoutPicture{%
%    \end{macrocode}
% Set the unit length each time because the use may have changed it.
% Do everything inside a group to prevent the changes to be seen
% outside.
%    \begin{macrocode}
      \begingroup
      \normalcolor
      \setlength{\unitlength}{1pt}%
      \thinlines
%    \end{macrocode}
% Calculate the distance of the text block from the page corner.
%    \begin{macrocode}
      \setlength{\tpg@top}{\paperheight-1in-\topmargin-\headheight-\headsep}%
      \setlength{\tpg@bottom}{\tpg@top-\textheight}%
      \setlength{\tpg@gridwidth}{\textwidth/\thetpg@bloecke}%
%    \end{macrocode}
% Calculate the number of vertical lines to be printed.
%    \begin{macrocode}
      \@tempcnta=\thetpg@bloecke
      \advance\@tempcnta by 1
%    \end{macrocode}
% The left distance varies between odd and even pages.
%    \begin{macrocode}
      \ifodd\arabic{page}%
        \setlength{\tpg@left}{\oddsidemargin+1in}%
      \else
        \setlength{\tpg@left}{\evensidemargin+1in}%
      \fi
%    \end{macrocode}
% Print horizontal lines.
%    \begin{macrocode}
      \put(\strip@pt\tpg@left,\strip@pt\tpg@top){%
        \line(1,0){\strip@pt\textwidth}}%
      \put(\strip@pt\tpg@left,\strip@pt\tpg@bottom){%
        \line(1,0){\strip@pt\textwidth}}%
%    \end{macrocode}
% Print equidistant vertical lines.
%    \begin{macrocode}
      \multiput(\strip@pt\tpg@left,\strip@pt\tpg@bottom)%
               (\strip@pt\tpg@gridwidth,0){\the\@tempcnta}{%
        \line(0,1){\strip@pt\textheight}}%
      \endgroup
    }%
  \else
    \typeout{Typographic grid switched off}%
  \fi
}
%    \end{macrocode}
%
% \iffalse
%</package>
% \fi
% \Finale