summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/gridpapers/gridpapers.sty
blob: e5225a96c2c8e1ea2ada3b11c1f106cdfa890bb4 (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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
%%
%% This is file `gridpapers.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% gridpapers.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2021 by Robert McNees <rmcnees@luc.edu>, Leo C. Stein <leo.stein@gmail.com>
%% --------------------------------------------------------------------------
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 

\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{gridpapers}
    [2021/03/19 v1.0.1 Graph paper backgrounds]

\RequirePackage{xkeyval}
\RequirePackage{kvoptions}
\RequirePackage{xcolor}
\RequirePackage{tikz}
\usetikzlibrary{patterns.meta,calc}
\RequirePackage{tikzpagenodes}
%% everypage has been superseded -- try to use the new builtin
%% approach, but fall back to everypage-1x if needed
%% This code is roughly taken from the new everypage code
\@ifundefined{AddToHook}{%
  \IfFileExists{everypage-1x.sty}{%
    %% If everypage is new enough to complain, avoid the complaints
    \RequirePackage{everypage-1x}
  }{\RequirePackage{everypage}}
}{%
  \newcommand*{\AddEverypageHook}[1]{%
  \AddToHook{shipout/background}{\put(1in,-1in){#1}}}
}
\RequirePackage{pagecolor}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Option parsing
%% Declare switches for processing the options.

\newif\ifGP@geometrypreviouslyloaded
\newif\ifGP@fullnessset
\newif\ifGP@fullpage
\newif\ifGP@textarea
\GP@geometrypreviouslyloadedfalse
\GP@fullnesssetfalse
\GP@fullpagefalse
\GP@textareafalse

\SetupKeyvalOptions{%
  family=GP,%
  prefix=GPOpt@%
}

\DeclareStringOption[std]{pattern}
\DeclareStringOption[std]{colorset}

\DeclareStringOption{majorcolor}
\DeclareStringOption{minorcolor}
\DeclareStringOption{bgcolor}

\DeclareStringOption{patternsize}
\DeclareStringOption[.7pt]{dotsize}

\DeclareVoidOption{fullpage}{\GP@fullpagetrue}
\DeclareVoidOption{textarea}{\GP@textareatrue}

\DeclareStringOption{geometry}

\ProcessKeyvalOptions*

%% Can only have one of fullpage or textarea
\ifGP@fullpage
  \ifGP@textarea
    \PackageError{gridpapers}{%
      Can not specify both fullpage and textarea, please remove one option}{}
    \fi
  \GP@fullnesssettrue
\fi

\ifGP@textarea
  \GP@fullnesssettrue
\fi

%% We keep track of this to know whether or not we would be overriding
%% a previously-set page geometry
\@ifpackageloaded{geometry}
  {\GP@geometrypreviouslyloadedtrue}
  {\GP@geometrypreviouslyloadedfalse%
    \PassOptionsToPackage{\GPOpt@geometry}{geometry}%
    \RequirePackage{geometry}%
  }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Actual package code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Some nice colors.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\definecolor{plum}{rgb}{0.36078, 0.20784, 0.4}
\definecolor{chameleon}{rgb}{0.30588, 0.60392, 0.023529}
\definecolor{cornflower}{rgb}{0.12549, 0.29020, 0.52941}
\definecolor{scarlet}{rgb}{0.8, 0, 0}
\definecolor{brick}{rgb}{0.64314, 0, 0}
\definecolor{sunrise}{rgb}{0.80784, 0.36078, 0}
\definecolor{rosiebg}{RGB}{250,247,232}
\definecolor{rosiegrid}{RGB}{186,137,113}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% The color to use for the null directions when drawing lightcones.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\colorlet{lightlines}{scarlet!30}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Pre-defined Color schemes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Here are some pre-defined color schemes for the paper background
%% and the major and minor grid lines.  These are switched by using
%% the option colorset=<name>.  The allowed values for colorset are in
%% the list below.
\define@choicekey*{GP}{colorset}[\val\nr]%
  %% Allowed values for colorset:
  {std,precocious,brickred,engineer,plumpad}[std]{%
  \ifcase\nr\relax
    %% std
    \colorlet{minorcolor}{cornflower!30}
    \colorlet{majorcolor}{cornflower!50}
    \colorlet{bgcolor}{white}
  \or
    %% precocious
    \colorlet{minorcolor}{rosiegrid!50}
    \colorlet{majorcolor}{rosiegrid}
    \colorlet{bgcolor}{rosiebg}
  \or
    %% brickred
    \colorlet{minorcolor}{brick!35}
    \colorlet{majorcolor}{brick!60}
    \colorlet{bgcolor}{scarlet!8}
  \or
    %% engineer
    \colorlet{minorcolor}{chameleon!50}
    \colorlet{majorcolor}{chameleon!80}
    \colorlet{bgcolor}{chameleon!10}
  \or
    %% plumpad
    \colorlet{minorcolor}{cornflower!40}
    \colorlet{majorcolor}{cornflower!70}
    \colorlet{bgcolor}{plum!10}
  \fi
}

%% Get the specified color set from the options
\def\@setkeyhelper#1#2{%
  \setkeys{GP}{#2=#1}
}
\expandafter\@setkeyhelper\expandafter{\GPOpt@colorset}{colorset}

%% If the user further specified majorcolor, minorcolor, and/or
%% bgcolor, we now override the selected colorset
\ifx\GPOpt@majorcolor\@empty
\else
  \colorlet{majorcolor}{\GPOpt@majorcolor}
\fi
\ifx\GPOpt@minorcolor\@empty
\else
  \colorlet{minorcolor}{\GPOpt@minorcolor}
\fi
\ifx\GPOpt@bgcolor\@empty
\else
  \colorlet{bgcolor}{\GPOpt@bgcolor}
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% The size parameter -- different meanings for different patterns
%% Will be reset by pattern code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\GP@patternsize}{0.1in}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This section sets up a routine for filling a shape with
%% hexagons. Uses code from:
%% http://tex.stackexchange.com/questions/6019/drawing-hexagons/6128#6128
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% We have to delay this definition until after \GP@patternsize is
%% redefined (by the pattern selection and/or user override)
\newcommand{\GP@declarehexpat}{
\pgfdeclarepatternformonly
  {hexagons}%% name
  {\pgfpointorigin}%% lower left
  {\pgfpoint{3*\GP@patternsize}{0.866025*2*\GP@patternsize}}
  {\pgfpoint{3*\GP@patternsize}{0.866025*2*\GP@patternsize}}
  {
    \pgfsetlinewidth{0.6pt}
    \pgftransformshift{\pgfpoint{0mm}{0.866025*\GP@patternsize}}
    \pgfpathmoveto{\pgfpoint{0mm}{0mm}}
    \pgfpathlineto{\pgfpoint{0.5*\GP@patternsize}{0mm}}
    \pgfpathlineto{\pgfpoint{\GP@patternsize}{-0.866025*\GP@patternsize}}
    \pgfpathlineto{\pgfpoint{2*\GP@patternsize}{-0.866025*\GP@patternsize}}
    \pgfpathlineto{\pgfpoint{2.5*\GP@patternsize}{0mm}}
    \pgfpathlineto{\pgfpoint{3*\GP@patternsize}{0mm}}
    \pgfpathmoveto{\pgfpoint{0.5*\GP@patternsize}{0mm}}
    \pgfpathlineto{\pgfpoint{\GP@patternsize}{0.866025*\GP@patternsize}}
    \pgfpathlineto{\pgfpoint{2*\GP@patternsize}{0.866025*\GP@patternsize}}
    \pgfpathlineto{\pgfpoint{2.5*\GP@patternsize}{0mm}}
    \pgfusepath{stroke}
  }
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This section sets up a routine for filling a shape with
%% triangles.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% We have to delay this definition until after \GP@patternsize is
%% redefined (by the pattern selection and/or user override)
\newcommand{\GP@declaretripat}{
\pgfdeclarepatternformonly
  %% Name of the pattern
  {triangles}
  %% Set the lower left corner of the pattern
  {\pgfpointorigin}
  %% Set the upper right corner of the pattern
  {\pgfpoint{\GP@patternsize}{2*0.8660254*\GP@patternsize}}
  %% Declare the size of the pattern blocks
  {\pgfpoint{\GP@patternsize}{2*0.8660254*\GP@patternsize}}
  %% Draw the pattern
  {
    \pgfsetlinewidth{0.6pt}
  \pgfpathmoveto{\pgfpoint{0mm}{0mm}}
  \pgfpathlineto{\pgfpoint{\GP@patternsize}{2*0.8660254*\GP@patternsize}}
  \pgfpathlineto{\pgfpoint{0mm}{2*0.8660254*\GP@patternsize}}
    \pgfpathmoveto{\pgfpoint{0mm}{0.8660254*\GP@patternsize}}
  \pgfpathlineto{\pgfpoint{\GP@patternsize}{0.8660254*\GP@patternsize}}
    \pgfpathmoveto{\pgfpoint{0mm}{2*0.8660254*\GP@patternsize}}
  \pgfpathlineto{\pgfpoint{\GP@patternsize}{0mm}}
  \pgfpathlineto{\pgfpoint{0mm}{0mm}}
    \pgfusepath{stroke}
  }
}
\newcommand{\GP@declareisopat}{
\pgfdeclarepatternformonly
  %% Name of the pattern
  {isometric}
  %% Set the lower left corner of the pattern
  {\pgfpointorigin}
  %% Set the upper right corner of the pattern
  {\pgfpoint{2*0.8660254*\GP@patternsize}{\GP@patternsize}}
  %% Declare the size of the pattern blocks
  {\pgfpoint{2*0.8660254*\GP@patternsize}{\GP@patternsize}}
  %% Draw the pattern
  {
    \pgfsetlinewidth{0.6pt}
  \pgfpathmoveto{\pgfpoint{0mm}{0mm}}
  \pgfpathlineto{\pgfpoint{2*0.8660254*\GP@patternsize}{\GP@patternsize}}
  \pgfpathlineto{\pgfpoint{2*0.8660254*\GP@patternsize}{0mm}}
  \pgfpathlineto{\pgfpoint{0mm}{\GP@patternsize}}
  \pgfpathlineto{\pgfpoint{0mm}{0mm}}
    \pgfpathmoveto{\pgfpoint{0.8660254*\GP@patternsize}{0mm}}
    \pgfpathlineto{\pgfpoint{0.8660254*\GP@patternsize}{\GP@patternsize}}
    \pgfusepath{stroke}
  }
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This section sets up a routine for filling the squares in a
%% grid with null lines.
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TODO Still can't figure out the correct pattern shift!!
\newcommand{\GP@declarelightconepat}{
\pgfkeys{
  /pgf/pattern keys/myshift/.store in=\myshift,
  /pgf/pattern keys/myshift/.initial={(0,0)},
}
\tikzdeclarepattern{
  name=lightcones,
  type=uncolored,
  parameters={\myshift},
  bounding box={(0,0) and (\GP@patternsize,\GP@patternsize)},
  tile size={(\GP@patternsize, \GP@patternsize)},
  tile transformation={
    shift=\myshift,
  },
  defaults={
    myshift/.store in=\myshift,myshift={(0,0)},
  },
  code={
    %% TODO Make the dashing an option
    \tikzset{lightlines/.style={line width=0.4pt,dash=on 0.05cm off 0.05cm phase 0.025cm}}
    \draw [lightlines] (0,0) -- (\GP@patternsize,\GP@patternsize);
    \draw [lightlines] (0,\GP@patternsize) -- (\GP@patternsize,0);
  },
}
}
%% \pgfdeclarepatternformonly
%%   {lightcones}% name
%%   {\pgfpointorigin}% lower left
%%   {\pgfpoint{\GP@patternsize}{\GP@patternsize}}%  upper right
%%   {\pgfpoint{\GP@patternsize}{\GP@patternsize}}%  tile size
%%   {% shape description
%%     \pgfsetlinewidth{0.4pt}
%%     %% TODO Make an option
%%     %Comment out this line for solid lines on light cones, instead of dashes.
%%     \pgfsetdash{{0.05cm}{0.05cm}}{0.025cm}
%%     \pgfpathmoveto{\pgfpoint{0in}{0in}}
%%     \pgfpathlineto{\pgfpoint{\GP@patternsize}{\GP@patternsize}}
%%     \pgfpathmoveto{\pgfpoint{0in}{\GP@patternsize}}
%%     \pgfpathlineto{\pgfpoint{\GP@patternsize}{0in}}
%%     \pgfusepath{stroke}
%%   }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This section sets up a routine for filling a region with dots
%% Slightly modified version of code added by Leo
%% Stein (@duetosymmetry on Twitter).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% We have to delay this definition until after \GP@patternsize is
%% redefined (by the pattern selection and/or user override)
\newcommand{\GP@declaredotpat}{
\pgfdeclarepatternformonly
  {dotgrid}%% name
  {\pgfpoint{-0.5*\GP@patternsize}{-0.5*\GP@patternsize}}%% lower left
  {\pgfpoint{0.5*\GP@patternsize}{0.5*\GP@patternsize}}%%  upper right
  {\pgfpoint{\GP@patternsize}{\GP@patternsize}}%%  tile size
  {%% shape description
    \pgfpathcircle{\pgfqpoint{0pt}{0pt}}{\GPOpt@dotsize}
    \pgfusepath{fill}
  }
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Begin pattern execution infrastructure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% This inner code will be set by the choicekey pattern=...
\newcommand{\GP@innerpatterncode}{}
%% This is the "outer" code to hook into every page
\newcommand{\GP@patterncode}{% No blank lines in this code!
\begin{tikzpicture}[remember picture, overlay]
%%
%% Change "thin" to "very thin" if the lines are too thick.
\tikzset{
  minorgrid/.style={minorcolor, thin},
  majorgrid/.style={majorcolor, thin},
}
\ifGP@fullpage%
\coordinate (a) at (current page.south west);
\coordinate (b) at (current page.north east);
\else%
\coordinate (a) at (current page text area.south west);
\coordinate (b) at (current page text area.north east);
\fi
%%
\GP@innerpatterncode%
%%
\end{tikzpicture}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Begin pattern definition code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\define@boolkey{GP}{patterndefaultfullness}{}
\newcommand{\GP@patterndefaultgeometry}{}
\newcommand{\GP@patterndefaultsize}{}

%% Pattern-definer-helper
%% The interface is:
%% \GP@setpattern
%%   {<true for default fullpage, false for default textarea>}
%%   {<default geometry config>}
%%   {<default pattern size>}  %% NOTE, not tile length
%%   {<contents of inner pattern code>}
\newcommand{\GP@setpattern}[4]{%
\setkeys{GP}{patterndefaultfullness=#1}
\renewcommand{\GP@patterndefaultgeometry}{#2}
\renewcommand{\GP@patterndefaultsize}{#3}
\renewcommand{\GP@innerpatterncode}{#4}
}

\define@choicekey*{GP}{pattern}[\val\nr]%
  %% Allowed values for pattern:
  {std,stdeight,majmin,dot,hex,tri,iso,lightcone,ruled,doubleruled}{%
  \ifcase\nr\relax
    %% std
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Quadrille, ten squares per inch.
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \GP@setpattern{false}{letterpaper, margin=0.2in}{0.1in}{%
%% Draw a grid with 10 squares per inch.
\draw[style=minorgrid, shift={(a)}] (0,0) grid [step=\GP@patternsize] (b);
%%
%% Draw a frame around the grid.
\draw[style=majorgrid] (a) rectangle (b);
    }
  \or
    %% stdeight
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Quadrille, eight squares per inch.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \GP@setpattern{false}{letterpaper, margin=0.1875in}{0.125in}{%
%% Draw a grid with 10 squares per inch.
\draw[style=minorgrid, shift={(a)}] (0,0) grid [step=\GP@patternsize] (b);
%%
%% Draw a frame around the grid.
\draw[style=majorgrid] (a) rectangle (b);
    }
  \or
    %% majmin
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Graph paper, eight squares per inch with a major grid
%% every half-inch.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \GP@setpattern{false}{letterpaper, margin=0.25in}{0.125in}{%
%% Draw a grid with 10 squares per inch.
\draw[style=minorgrid, shift={(a)}] (0,0) grid [step=\GP@patternsize] (b);
%%
\draw[style=majorgrid, shift={(a)}] (0,0) grid [step=4*\GP@patternsize]   (b);
%%
%% Draw a frame around the grid.
\draw[style=majorgrid] (a) rectangle (b);
    }
  \or
    %% dot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Dot grid
%% Slightly modified version of code added by Leo
%% Stein (@duetosymmetry).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \GP@setpattern{true}{}{0.1in}{%
    \fill [pattern=dotgrid,pattern color=minorcolor] (a) rectangle (b);
    }
  \or
    %% hex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Hex grid
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \GP@setpattern{true}{}{0.1666in}{%
    \fill [pattern=hexagons,pattern color=minorcolor] (a) rectangle (b);
    }
  \or
    %% tri
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Triangle grid, adjust triangle size in the preamble
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \GP@setpattern{true}{}{0.25in}{%
      \fill [pattern=triangles,pattern color=minorcolor] (a) rectangle (b);
    }
  \or
    %% iso
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Isometric grid
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \GP@setpattern{true}{}{0.25in}{%
      \fill [pattern=isometric, pattern color=minorcolor] (a) rectangle (b);
    }
  \or
    %% lightcone
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% A grid with light cones.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \GP@setpattern{false}{letterpaper, margin=.125in}{0.25in}{%
%% Draw a grid with 4 squares per inch.
\draw[style=minorgrid, shift={(a)}] (0,0) coordinate grid [step=\GP@patternsize] (b);
%%
%% Draw a border around the grid.
\draw[style=majorgrid, pattern={lightcones[myshift={(a)}]}, pattern color=lightlines] (a) rectangle (b);
    }
  \or
    %% ruled
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Ruled page with bold lines every 0.2in or 0.25in
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \GP@setpattern{false}{letterpaper, body={8in,10.8in}}{0.2in}{%
%% Draw a ruled page with lines every 0.2in
\draw[style=majorgrid, shift={(a)}] (0,0) grid [ystep=\GP@patternsize, xstep=\paperwidth] (b);
%% Draw a frame around the grid.
\draw[style=majorgrid] (a) rectangle (b);
    }
  \or
    %% doubleruled
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Ruled page with bold lines every 0.25in and light lines
%% every 0.125 in.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \GP@setpattern{false}{letterpaper, margin=.25in}{0.125in}{%
%% Draw a ruled pattern with thin lines every 0.125 in and bold lines every 0.25 in.
\draw[style=minorgrid, shift={(a)}] (0,0) grid [ystep=\GP@patternsize, xstep=\paperwidth] (b);
%%
\draw[style=majorgrid, shift={(a)}] (0,0) grid [ystep=2*\GP@patternsize, xstep=\paperwidth] (b);
%%
%% Draw a frame around the grid.
\draw[style=majorgrid] (a) rectangle (b);
    }
  \fi
}

%% Use the passed package option to set the above key
\expandafter\@setkeyhelper\expandafter{\GPOpt@pattern}{pattern}

%% Determine whether or not to (re)set fullpage vs textarea
\ifGP@fullnessset
%% Respect their choice
\else
  %% Reset the value of \GP@fullpage based on the pattern's default
  %% There's probably a more idiomatic way to do this but I can't
  %% figure it out
  \ifKV@GP@patterndefaultfullness
    \GP@fullpagetrue
  \else
    \GP@fullpagefalse
  \fi
\fi

%% Determine whether or not to fiddle with the page geometry
\ifGP@geometrypreviouslyloaded
%% Respect their previous choice
\PackageWarning{gridpapers}{'geometry' package was previously loaded, will not use pattern defaults.}
\else
  %% Use the pattern's defaults,
  \expandafter\geometry\expandafter{\GP@patterndefaultgeometry}
  %% And then override with any more specific settings passed by the user
  \expandafter\geometry\expandafter{\GPOpt@geometry}
\fi

%% Determine the correct pattern length
\ifx\GPOpt@patternsize\@empty
  % Use the pattern's preferred length
  \renewcommand{\GP@patternsize}{\GP@patterndefaultsize}
\else
  % Override with the user's choice
  \renewcommand{\GP@patternsize}{\GPOpt@patternsize}
\fi

%% Now that everything has been set up, we can finally define the
%% patterns with the correct lengths.
\GP@declarehexpat
\GP@declaretripat
\GP@declareisopat
\GP@declarelightconepat
\GP@declaredotpat

%% Set the background color.
\AtBeginDocument{\pagecolor{bgcolor}}
%% Actually hook it in!
\AddEverypageHook{%
\GP@patterncode%
}

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