summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/typogrid/typogrid.sty
blob: 67056ea747ed75552b58c272b40a8a8d6cfc15cf (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
%%
%% This is file `typogrid.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% typogrid.dtx  (with options: `package')
%% 
%%   typogrid package
%% 
%%   Copyright  2003, 2011 Harald Harders, Rolf Niepraschk
%% 
%%   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.
%% 
%%   h.harders@tu-bs.de, rolf.niepraschk@ptb.de
%% 
\ProvidesPackage{typogrid}
  [2011/12/31  v0.21  Typographic grid]
\RequirePackage{calc}
\RequirePackage{keyval}
\newlength{\gridwidth}%
\newcount\tpg@blocks%
\newcounter{tpg@blocks@new}%
\setcounter{tpg@blocks@new}{12}%
\newcommand*\typogridsetup[1]{%
  \expandafter\setkeys\expandafter{typogrid}{#1}}
\define@key{typogrid}{columns}{%
  \setcounter{tpg@blocks@new}{#1}%
  \ifnum\the\c@tpg@blocks@new<1\relax
    \PackageError{typogrid}{Less than 1 column given}{You have to
      declare at least 1 column.}%
    \setcounter{tpg@blocks@new}{1}%
  \fi
}
\newif\iftpg@headings
\newif\iftpg@headings@new
\tpg@headings@newtrue
\define@key{typogrid}{headings}[true]{%
  \csname tpg@headings@new#1\endcsname
}
\newif\iftpg@margin
\newif\iftpg@margin@new
\tpg@margin@newtrue
\define@key{typogrid}{margin}[true]{%
  \csname tpg@margin@new#1\endcsname
}
\newif\iftpg@draft
\DeclareOption{draft}{\tpg@drafttrue}
\DeclareOption{final}{\tpg@draftfalse}
\DeclareOption{colorgrid}{\PassOptionsToPackage{\CurrentOption}{eso-pic}}
\DeclareOption{grid}{\PassOptionsToPackage{\CurrentOption}{eso-pic}}
\DeclareOption*{\expandafter\typogridsetup\expandafter{\CurrentOption}}
\ExecuteOptions{final}
\ProcessOptions\relax
\RequirePackage{eso-pic}[2002/11/16]
\newcommand*\typogrid{%
  \begingroup
    \normalcolor
    \thinlines
    \@tempcnta=\tpg@blocks
    \advance\@tempcnta by -1%
    \AtTextLowerLeft{%
      \put(0,0){%
        \framebox(\LenToUnit{\textwidth},\LenToUnit{\textheight}){}}%
      \multiput(\LenToUnit{\gridwidth},0)%
               (\LenToUnit{\gridwidth},0){\the\@tempcnta}{%
        \line(0,1){\LenToUnit{\textheight}}}%
    }%
    \iftpg@headings
      \AtTextUpperLeft{%
        \put(0,\LenToUnit{\headsep}){%
          \framebox(\LenToUnit{\textwidth},\LenToUnit{\headheight}){}}%
        \multiput(\LenToUnit{\gridwidth},\LenToUnit{\headsep})%
                 (\LenToUnit{\gridwidth},0){\the\@tempcnta}{%
          \line(0,1){\LenToUnit{\headheight}}}%
      }%
      \AtTextLowerLeft{%
        \put(0,\LenToUnit{-\footskip}){%
          \line(1,0){\LenToUnit{\textwidth}}}%
        \put(0,\LenToUnit{-\footskip}){%
          \line(0,1){\LenToUnit{\baselineskip}}}%
        \put(\LenToUnit{\textwidth},\LenToUnit{-\footskip}){%
          \line(0,1){\LenToUnit{\baselineskip}}}%
        \multiput(\LenToUnit{\gridwidth},\LenToUnit{-\footskip})%
        (\LenToUnit{\gridwidth},0){\the\@tempcnta}{%
          \line(0,1){\LenToUnit{\baselineskip}}}%
      }%
    \fi
    \iftpg@margin
      \AtTextLowerLeft{%
        \@tempdima=\textwidth\advance\@tempdima\marginparsep%
        \if@twoside%
          \ifodd\c@page
          \else
            \@tempdima=-\marginparsep\advance\@tempdima-\marginparwidth%
          \fi%
        \fi%
        \put(\LenToUnit{\@tempdima},0){%
          \framebox(\LenToUnit{\marginparwidth},%
            \LenToUnit{\textheight}){}}%
      }%
    \fi
  \endgroup
  \setlength\gridwidth{\textwidth/\arabic{tpg@blocks@new}}%
  \global\gridwidth=\gridwidth
  \global\tpg@blocks=\arabic{tpg@blocks@new}%
  \iftpg@headings@new
    \global\tpg@headingstrue
  \else
    \global\tpg@headingsfalse
  \fi
  \iftpg@margin@new
    \global\tpg@margintrue
  \else
    \global\tpg@marginfalse
  \fi
}
\AtBeginDocument{%
  \iftpg@draft
    \typeout{Typographic grid switched on}%
    \AddToShipoutPicture{\typogrid}%
  \else
    \typeout{Typographic grid switched off}%
  \fi
  \setlength\gridwidth{\textwidth/\arabic{tpg@blocks@new}}%
  \global\tpg@blocks=\arabic{tpg@blocks@new}%
  \iftpg@headings@new
    \tpg@headingstrue
  \else
    \tpg@headingsfalse
  \fi
  \iftpg@margin@new
    \tpg@margintrue
  \else
    \tpg@marginfalse
  \fi
}

\endinput
%%
%% End of file `typogrid.sty'.