summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/gridpapers/gridpapers.dtx
blob: b98885c758beea2fcf56494eec239d282b9fe103 (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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
% \iffalse meta-comment
%
% 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.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainers of this work are Robert McNees, Leo C. Stein.
%
% This work consists of the files gridpapers.dtx and gridpapers.ins
% and the derived filebase gridpapers.sty.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{gridpapers.dtx}
%</driver>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage[dvipsnames]{xcolor}
\usepackage[pattern=stdeight, textarea,
  majorcolor=cornflower!30, minorcolor=cornflower!10,
  geometry={margin=1in, left=2in}]{gridpapers}[2021/03/14]
\usepackage{hyperref}
\hypersetup{colorlinks,urlcolor=NavyBlue,citecolor=NavyBlue,linkcolor=NavyBlue,
  pdfauthor={Robert McNees and Leo C. Stein},
  pdftitle={The gridpapers package}}
\usepackage{fontawesome}
\definecolor{twitterblue}{RGB}{64,153,255}
\newcommand{\email}[1]{$\langle$\href{mailto:#1}{#1}$\rangle$}
\newcommand{\twitter}[1]{\href{https://twitter.com/#1}{\textcolor{twitterblue}{\faTwitter}\,\tt\textcolor{twitterblue}{@#1}}}
\usepackage{dtxdescribe}
\usepackage[columns=2]{idxlayout}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{gridpapers.dtx}
  \PrintChanges
\end{document}
%</driver>
% \fi
%
% \CheckSum{405}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v1.0.0}{2021/03/13}{Converted to DTX file}
% \changes{v1.0.1}{2021/03/19}{Hotfix: old installs don't have
% everypage-1x, use everypage}
% \changes{v1.0.2}{2021/03/26}{Replace triangle and hexagon code
% to allow rotated grids, add 'ghostly' colorset}
%
% \DoNotIndex{\newcommand,\newenvironment}
%
% \GetFileInfo{gridpapers.sty}
% \title{The \textsf{gridpapers} package}
% \author{Robert McNees\footnote{\email{rmcnees@luc.edu}; \twitter{mcnees}}
%   \ and
%   Leo C.\ Stein\footnote{\email{leo.stein@gmail.com}; \twitter{duetosymmetry}}}
% \date{\fileversion~from \filedate}
%
% \maketitle
%
% All development happens at the repo:
% \url{https://github.com/mcnees/LaTeX-Graph-Paper}.
%
% \section{Introduction}
%
% Make your own quadrille, graph, hex, etc.\ paper! Uses the PGF/TikZ
% package for \LaTeX, which should be part of any modern \TeX{}
% installation. Lots of preset defaults to get started with ease, yet
% all colors and spacing are customizable.
%
% There are example .tex files in the |examples| directory to
% help get you started with customization. Each tex file has an
% almost-empty body, with a |\usepackage| statement that you can
% customize. For example, engineer-pad.tex looks like this:
% \VerbatimInput[frame=single,
%   numbers=left,
%   xleftmargin=2em,
%   label=engineer-pad.tex]{examples/engineer-pad.tex}
% (The |~| in the body forces a non-empty body, or else latex wouldn't generate a PDF).
%
% \section{Usage}
%
% \subsection{Options}
%
% Your graph paper is configured through a number of key/value options
% to the |\usepackage| command.  Let's go through these options.
%
% \DescribeObject{pattern=\marg{name}}\DescribeDefault{std} Which of
% the predefined patterns to use for the page or textarea background.
% The current list of pattern names is: |std|, |stdeight|, |majmin|,
% |dot|, |hex|, |hexup|, |tri|, |iso|, |lightcone|, |ruled|, |doubleruled|. We
% describe each of these patterns in Sec.~\ref{sec:patterns}.
% Patterns come with default page geometry (size and margins; see
% |geometry|), and default `fullness' (whether they fill the page or
% not; see options |fullpage| and |textarea|).
%
% \DescribeObject{colorset=\marg{name}}\DescribeDefault{std} Color
% presets.  Valid color preset names are: |std|, |precocious|, |ghostly|,
% |brickred|, |engineer|, |plumpad|. A preset determines the
% |majorcolor|, |minorcolor|, and |bgcolor| all at once. But, you can
% start from a preset and then override some colors.
%
% \DescribeObject{majorcolor=\marg{color}} Override the preset
% ``major'' color. This can be a named color, or using the syntax from
% |xcolor| to mix colors together.
%
% \DescribeObject{minorcolor=\marg{color}} Override the preset
% ``minor'' color. As above.
%
% \DescribeObject{bgcolor=\marg{color}} Override the preset background
% color. As above.
%
% \DescribeObject{patternsize=\marg{length}} Override the preset
% pattern size.  The meaning of this length argument is different for
% each pattern; see Sec.~\ref{sec:patterns} for more.
%
% \DescribeObject{dotsize=\marg{length}}\DescribeDefault{.7pt}
% Controls the size of the dots themselves for |pattern=dot|.
%
% \DescribeObject{fullpage} Make the pattern fill the whole page.
%
% \DescribeObject{textarea} Make the pattern fill only the text area
% of the document. At most one of the |fullpage| or |textarea| can be
% specified. If one is specified, it will override the default
% `fullness' setting of the pattern.
%
% \DescribeObject{geometry=\marg{geometry spec}} Page geometry
% specification, using the syntax of the |geometry| package. This
% specification will override the pattern's default page geometry.
% However, if the |geometry| package was loaded before |gridpapers|,
% this option will be ignored.
%
% \subsection{Patterns}
% \label{sec:patterns}
%
% The current set of patterns:
%
% \DescribeObject{std} Quadrille, ten squares per inch.  The
% |patternsize| option controls the side of a square.  Default is
% |patternsize=0.1in|.
%
% \DescribeObject{stdeight} Quadrille, eight squares per inch.  The
% |patternsize| option controls the side of a square.  Default is
% |patternsize=0.125in|.
%
% \DescribeObject{majmin} Graph paper, eight squares per inch with a
% major grid every half-inch.  The |patternsize| option controls the
% side of a small square (the larger squares are four times bigger).
% Default is |patternsize=0.125in|.
%
% \DescribeObject{dot} Grid of dots.  The size of an individual dot is
% set by |dotsize|.  The |patternsize| option controls the distance
% between dots.  Default is |patternsize=0.1in|.
%
% \DescribeObject{hex} Grid of hexagons.  The |patternsize| option
% controls the side length of a hexagon.  Default is
% |patternsize=0.1666in|.
%
% \DescribeObject{hexup} Grid of hexagons, rotated 90 degrees from the
% default orientation.  The |patternsize| option controls the side
% length of a hexagon.  Default is |patternsize=0.1666in|.
%
% \DescribeObject{tri} Triangle grid.  The |patternsize| option
% controls the side length of a triangle.  Default is
% |patternsize=0.25in|.
%
% \DescribeObject{iso} Isometric grid.  The |patternsize| option
% controls the side length of a triangle.  Default is
% |patternsize=0.25in|.
%
% \DescribeObject{lightcone} A grid with light cones (45° lines) on a
% square grid.  The |patternsize| option controls the side of a
% horizontal square (not the tipped squared).  Default is
% |patternsize=0.25in|.
%
% \DescribeObject{ruled} Ruled page with bold lines.  The
% |patternsize| option controls the vertical distance between lines.
% Default is |patternsize=0.2in|.
%
% \DescribeObject{doubleruled} Ruled page with bold lines alternating
% with light lines.  The |patternsize| option controls the vertical
% distance between neighboring lines.  Default is
% |patternsize=0.125in|.
%
% \section{Examples}
%
% \subsection{Plenty of customization}
%
% Let's say you want to use the |tri| pattern, which by default fills
% the page. But you want it to fill just the textarea of an A4 page
% with 2cm margins, and you want the triangles to be .75cm
% long. Finally, you like the colors of the engineer set, but want a
% white background. Then you would write:
% \begin{sourceverb}[frame=single]
% \usepackage[pattern=tri,
%   patternsize=0.75cm,
%   textarea,
%   colorset=engineer,
%   bgcolor=white,
%   geometry={a4paper, margin=2cm}]{gridpapers}
% \end{sourceverb}
%
% \subsection{Custom colors}
%
% Using named or blended custom colors is demonstrated in the example
% file |custom-colors.tex|:
% \VerbatimInput[frame=single,
%   numbers=left,
%   xleftmargin=2em,
%   label=custom-colors.tex]{examples/custom-colors.tex}
%

%
% \StopEventually{}
%
% \section{Implementation}
%
% \iffalse
%<*package>
% \fi
%
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{gridpapers}
    [2021/03/27 v1.0.2 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,ghostly,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
    %% ghostly
    \colorlet{minorcolor}{gray!15}
    \colorlet{majorcolor}{gray!20}
    \colorlet{bgcolor}{white}
  \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}{
\tikzdeclarepattern{
  name=hexagons,
  type=uncolored,
  bounding box={(0,0) and (3*\GP@patternsize,0.866025*2*\GP@patternsize)},
  tile size={(3*\GP@patternsize,0.866025*2*\GP@patternsize)},
  parameters={\tikzhexrotate},
  tile transformation={rotate=\tikzhexrotate},
  defaults={
    rotate/.store in=\tikzhexrotate,rotate=0,
  },
  code={
      \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}{
\tikzdeclarepattern{
  name=triangles,
  type=uncolored,
  bounding box={(0,0) and (\GP@patternsize,2*0.866025*\GP@patternsize)},
  tile size={(\GP@patternsize,2*0.866025*\GP@patternsize)},
  parameters={\tikztrirotate},
  tile transformation={rotate=\tikztrirotate},
  defaults={
    rotate/.store in=\tikztrirotate,rotate=0,
    },
  code={
        \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}
    }
  }
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 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,hexup,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
    %% hexup
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Hex-up grid
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \GP@setpattern{true}{}{0.1666in}{%
    \fill [pattern={hexagons[rotate=90]},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={triangles[rotate=90]}, 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@declarelightconepat
\GP@declaredotpat

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

\endinput
%    \end{macrocode}
%
% \iffalse
%</package>
% \fi
%
% \Finale
\endinput