Debian Codegraph @

texmf-dist/source/latex/gridpapers/gridpapers.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2021 by Robert McNees <[email protected]>, Leo C. Stein <[email protected]>
4 % ---------------------------------------------------------------------------
5 % This work may be distributed and/or modified under the
6 % conditions of the LaTeX Project Public License, either version 1.3
7 % of this license or (at your option) any later version.
8 % The latest version of this license is in
9 % http://www.latex-project.org/lppl.txt
10 % and version 1.3 or later is part of all distributions of LaTeX
11 % version 2005/12/01 or later.
12 %
13 % This work has the LPPL maintenance status `maintained'.
14 %
15 % The Current Maintainers of this work are Robert McNees, Leo C. Stein.
16 %
17 % This work consists of the files gridpapers.dtx and gridpapers.ins
18 % and the derived filebase gridpapers.sty.
19 %
20 % \fi
21 %
22 % \iffalse
23 %<*driver>
24 \ProvidesFile{gridpapers.dtx}
25 %</driver>
26 %
27 %<*driver>
28 \documentclass{ltxdoc}
29 \usepackage[dvipsnames]{xcolor}
30 \usepackage[pattern=stdeight, textarea,
31 majorcolor=cornflower!30, minorcolor=cornflower!10,
32 geometry={margin=1in, left=2in}]{gridpapers}[2021/03/14]
33 \usepackage{hyperref}
34 \hypersetup{colorlinks,urlcolor=NavyBlue,citecolor=NavyBlue,linkcolor=NavyBlue,
35 pdfauthor={Robert McNees and Leo C. Stein},
36 pdftitle={The gridpapers package}}
37 \usepackage{fontawesome}
38 \definecolor{twitterblue}{RGB}{64,153,255}
39 \newcommand{\email}[1]{$\langle$\href{mailto:#1}{#1}$\rangle$}
40 \newcommand{\twitter}[1]{\href{https://twitter.com/#1}{\textcolor{twitterblue}{\faTwitter}\,\tt\textcolor{twitterblue}{@#1}}}
41 \usepackage{dtxdescribe}
42 \usepackage[columns=2]{idxlayout}
43 \EnableCrossrefs
44 \CodelineIndex
45 \RecordChanges
46 \begin{document}
47 \DocInput{gridpapers.dtx}
48 \PrintChanges
49 \end{document}
50 %</driver>
51 % \fi
52 %
53 % \CheckSum{405}
54 %
55 % \CharacterTable
56 % {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
57 % 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
58 % Digits \0\1\2\3\4\5\6\7\8\9
59 % Exclamation \! Double quote \" Hash (number) \#
60 % Dollar \$ Percent \% Ampersand \&
61 % Acute accent \' Left paren \( Right paren \)
62 % Asterisk \* Plus \+ Comma \,
63 % Minus \- Point \. Solidus \/
64 % Colon \: Semicolon \; Less than \<
65 % Equals \= Greater than \> Question mark \?
66 % Commercial at \@ Left bracket \[ Backslash \\
67 % Right bracket \] Circumflex \^ Underscore \_
68 % Grave accent \` Left brace \{ Vertical bar \|
69 % Right brace \} Tilde \~}
70 %
71 %
72 % \changes{v1.0.0}{2021/03/13}{Converted to DTX file}
73 % \changes{v1.0.1}{2021/03/19}{Hotfix: old installs don't have
74 % everypage-1x, use everypage}
75 % \changes{v1.0.2}{2021/03/26}{Replace triangle and hexagon code
76 % to allow rotated grids, add 'ghostly' colorset}
77 %
78 % \DoNotIndex{\newcommand,\newenvironment}
79 %
80 % \GetFileInfo{gridpapers.sty}
81 % \title{The \textsf{gridpapers} package}
82 % \author{Robert McNees\footnote{\email{[email protected]}; \twitter{mcnees}}
83 % \ and
84 % Leo C.\ Stein\footnote{\email{[email protected]}; \twitter{duetosymmetry}}}
85 % \date{\fileversion~from \filedate}
86 %
87 % \maketitle
88 %
89 % All development happens at the repo:
90 % \url{https://github.com/mcnees/LaTeX-Graph-Paper}.
91 %
92 % \section{Introduction}
93 %
94 % Make your own quadrille, graph, hex, etc.\ paper! Uses the PGF/TikZ
95 % package for \LaTeX, which should be part of any modern \TeX{}
96 % installation. Lots of preset defaults to get started with ease, yet
97 % all colors and spacing are customizable.
98 %
99 % There are example .tex files in the |examples| directory to
100 % help get you started with customization. Each tex file has an
101 % almost-empty body, with a |\usepackage| statement that you can
102 % customize. For example, engineer-pad.tex looks like this:
103 % \VerbatimInput[frame=single,
104 % numbers=left,
105 % xleftmargin=2em,
106 % label=engineer-pad.tex]{examples/engineer-pad.tex}
107 % (The |~| in the body forces a non-empty body, or else latex wouldn't generate a PDF).
108 %
109 % \section{Usage}
110 %
111 % \subsection{Options}
112 %
113 % Your graph paper is configured through a number of key/value options
114 % to the |\usepackage| command. Let's go through these options.
115 %
116 % \DescribeObject{pattern=\marg{name}}\DescribeDefault{std} Which of
117 % the predefined patterns to use for the page or textarea background.
118 % The current list of pattern names is: |std|, |stdeight|, |majmin|,
119 % |dot|, |hex|, |hexup|, |tri|, |iso|, |lightcone|, |ruled|, |doubleruled|. We
120 % describe each of these patterns in Sec.~\ref{sec:patterns}.
121 % Patterns come with default page geometry (size and margins; see
122 % |geometry|), and default `fullness' (whether they fill the page or
123 % not; see options |fullpage| and |textarea|).
124 %
125 % \DescribeObject{colorset=\marg{name}}\DescribeDefault{std} Color
126 % presets. Valid color preset names are: |std|, |precocious|, |ghostly|,
127 % |brickred|, |engineer|, |plumpad|. A preset determines the
128 % |majorcolor|, |minorcolor|, and |bgcolor| all at once. But, you can
129 % start from a preset and then override some colors.
130 %
131 % \DescribeObject{majorcolor=\marg{color}} Override the preset
132 % ``major'' color. This can be a named color, or using the syntax from
133 % |xcolor| to mix colors together.
134 %
135 % \DescribeObject{minorcolor=\marg{color}} Override the preset
136 % ``minor'' color. As above.
137 %
138 % \DescribeObject{bgcolor=\marg{color}} Override the preset background
139 % color. As above.
140 %
141 % \DescribeObject{patternsize=\marg{length}} Override the preset
142 % pattern size. The meaning of this length argument is different for
143 % each pattern; see Sec.~\ref{sec:patterns} for more.
144 %
145 % \DescribeObject{dotsize=\marg{length}}\DescribeDefault{.7pt}
146 % Controls the size of the dots themselves for |pattern=dot|.
147 %
148 % \DescribeObject{fullpage} Make the pattern fill the whole page.
149 %
150 % \DescribeObject{textarea} Make the pattern fill only the text area
151 % of the document. At most one of the |fullpage| or |textarea| can be
152 % specified. If one is specified, it will override the default
153 % `fullness' setting of the pattern.
154 %
155 % \DescribeObject{geometry=\marg{geometry spec}} Page geometry
156 % specification, using the syntax of the |geometry| package. This
157 % specification will override the pattern's default page geometry.
158 % However, if the |geometry| package was loaded before |gridpapers|,
159 % this option will be ignored.
160 %
161 % \subsection{Patterns}
162 % \label{sec:patterns}
163 %
164 % The current set of patterns:
165 %
166 % \DescribeObject{std} Quadrille, ten squares per inch. The
167 % |patternsize| option controls the side of a square. Default is
168 % |patternsize=0.1in|.
169 %
170 % \DescribeObject{stdeight} Quadrille, eight squares per inch. The
171 % |patternsize| option controls the side of a square. Default is
172 % |patternsize=0.125in|.
173 %
174 % \DescribeObject{majmin} Graph paper, eight squares per inch with a
175 % major grid every half-inch. The |patternsize| option controls the
176 % side of a small square (the larger squares are four times bigger).
177 % Default is |patternsize=0.125in|.
178 %
179 % \DescribeObject{dot} Grid of dots. The size of an individual dot is
180 % set by |dotsize|. The |patternsize| option controls the distance
181 % between dots. Default is |patternsize=0.1in|.
182 %
183 % \DescribeObject{hex} Grid of hexagons. The |patternsize| option
184 % controls the side length of a hexagon. Default is
185 % |patternsize=0.1666in|.
186 %
187 % \DescribeObject{hexup} Grid of hexagons, rotated 90 degrees from the
188 % default orientation. The |patternsize| option controls the side
189 % length of a hexagon. Default is |patternsize=0.1666in|.
190 %
191 % \DescribeObject{tri} Triangle grid. The |patternsize| option
192 % controls the side length of a triangle. Default is
193 % |patternsize=0.25in|.
194 %
195 % \DescribeObject{iso} Isometric grid. The |patternsize| option
196 % controls the side length of a triangle. Default is
197 % |patternsize=0.25in|.
198 %
199 % \DescribeObject{lightcone} A grid with light cones (45° lines) on a
200 % square grid. The |patternsize| option controls the side of a
201 % horizontal square (not the tipped squared). Default is
202 % |patternsize=0.25in|.
203 %
204 % \DescribeObject{ruled} Ruled page with bold lines. The
205 % |patternsize| option controls the vertical distance between lines.
206 % Default is |patternsize=0.2in|.
207 %
208 % \DescribeObject{doubleruled} Ruled page with bold lines alternating
209 % with light lines. The |patternsize| option controls the vertical
210 % distance between neighboring lines. Default is
211 % |patternsize=0.125in|.
212 %
213 % \section{Examples}
214 %
215 % \subsection{Plenty of customization}
216 %
217 % Let's say you want to use the |tri| pattern, which by default fills
218 % the page. But you want it to fill just the textarea of an A4 page
219 % with 2cm margins, and you want the triangles to be .75cm
220 % long. Finally, you like the colors of the engineer set, but want a
221 % white background. Then you would write:
222 % \begin{sourceverb}[frame=single]
223 % \usepackage[pattern=tri,
224 % patternsize=0.75cm,
225 % textarea,
226 % colorset=engineer,
227 % bgcolor=white,
228 % geometry={a4paper, margin=2cm}]{gridpapers}
229 % \end{sourceverb}
230 %
231 % \subsection{Custom colors}
232 %
233 % Using named or blended custom colors is demonstrated in the example
234 % file |custom-colors.tex|:
235 % \VerbatimInput[frame=single,
236 % numbers=left,
237 % xleftmargin=2em,
238 % label=custom-colors.tex]{examples/custom-colors.tex}
239 %
240
241 %
242 % \StopEventually{}
243 %
244 % \section{Implementation}
245 %
246 % \iffalse
247 %<*package>
248 % \fi
249 %
250 % \begin{macrocode}
251 \NeedsTeXFormat{LaTeX2e}[1994/06/01]
252 \ProvidesPackage{gridpapers}
253 [2021/03/27 v1.0.2 Graph paper backgrounds]
254
255 \RequirePackage{xkeyval}
256 \RequirePackage{kvoptions}
257 \RequirePackage{xcolor}
258 \RequirePackage{tikz}
259 \usetikzlibrary{patterns.meta,calc}
260 \RequirePackage{tikzpagenodes}
261 %% everypage has been superseded -- try to use the new builtin
262 %% approach, but fall back to everypage-1x if needed
263 %% This code is roughly taken from the new everypage code
264 \@ifundefined{AddToHook}{%
265 \IfFileExists{everypage-1x.sty}{%
266 %% If everypage is new enough to complain, avoid the complaints
267 \RequirePackage{everypage-1x}
268 }{\RequirePackage{everypage}}
269 }{%
270 \newcommand*{\AddEverypageHook}[1]{%
271 \AddToHook{shipout/background}{\put(1in,-1in){#1}}}
272 }
273 \RequirePackage{pagecolor}
274
275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276 %% Option parsing
277 %% Declare switches for processing the options.
278
279 \newif\ifGP@geometrypreviouslyloaded
280 \newif\ifGP@fullnessset
281 \newif\ifGP@fullpage
282 \newif\ifGP@textarea
283 \GP@geometrypreviouslyloadedfalse
284 \GP@fullnesssetfalse
285 \GP@fullpagefalse
286 \GP@textareafalse
287
288 \SetupKeyvalOptions{%
289 family=GP,%
290 prefix=GPOpt@%
291 }
292
293 \DeclareStringOption[std]{pattern}
294 \DeclareStringOption[std]{colorset}
295
296 \DeclareStringOption{majorcolor}
297 \DeclareStringOption{minorcolor}
298 \DeclareStringOption{bgcolor}
299
300 \DeclareStringOption{patternsize}
301 \DeclareStringOption[.7pt]{dotsize}
302
303 \DeclareVoidOption{fullpage}{\GP@fullpagetrue}
304 \DeclareVoidOption{textarea}{\GP@textareatrue}
305
306 \DeclareStringOption{geometry}
307
308 \ProcessKeyvalOptions*
309
310 %% Can only have one of fullpage or textarea
311 \ifGP@fullpage
312 \ifGP@textarea
313 \PackageError{gridpapers}{%
314 Can not specify both fullpage and textarea, please remove one option}{}
315 \fi
316 \GP@fullnesssettrue
317 \fi
318
319 \ifGP@textarea
320 \GP@fullnesssettrue
321 \fi
322
323 %% We keep track of this to know whether or not we would be overriding
324 %% a previously-set page geometry
325 \@ifpackageloaded{geometry}
326 {\GP@geometrypreviouslyloadedtrue}
327 {\GP@geometrypreviouslyloadedfalse%
328 \PassOptionsToPackage{\GPOpt@geometry}{geometry}%
329 \RequirePackage{geometry}%
330 }
331
332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
333 %% Actual package code
334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 %% Some nice colors.
338 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
339 \definecolor{plum}{rgb}{0.36078, 0.20784, 0.4}
340 \definecolor{chameleon}{rgb}{0.30588, 0.60392, 0.023529}
341 \definecolor{cornflower}{rgb}{0.12549, 0.29020, 0.52941}
342 \definecolor{scarlet}{rgb}{0.8, 0, 0}
343 \definecolor{brick}{rgb}{0.64314, 0, 0}
344 \definecolor{sunrise}{rgb}{0.80784, 0.36078, 0}
345 \definecolor{rosiebg}{RGB}{250,247,232}
346 \definecolor{rosiegrid}{RGB}{186,137,113}
347
348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
349 %% The color to use for the null directions when drawing lightcones.
350 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
351 \colorlet{lightlines}{scarlet!30}
352
353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
354 %% Pre-defined Color schemes
355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
356 %% Here are some pre-defined color schemes for the paper background
357 %% and the major and minor grid lines. These are switched by using
358 %% the option colorset=<name>. The allowed values for colorset are in
359 %% the list below.
360 \define@choicekey*{GP}{colorset}[\val\nr]%
361 %% Allowed values for colorset:
362 {std,precocious,ghostly,brickred,engineer,plumpad}[std]{%
363 \ifcase\nr\relax
364 %% std
365 \colorlet{minorcolor}{cornflower!30}
366 \colorlet{majorcolor}{cornflower!50}
367 \colorlet{bgcolor}{white}
368 \or
369 %% precocious
370 \colorlet{minorcolor}{rosiegrid!50}
371 \colorlet{majorcolor}{rosiegrid}
372 \colorlet{bgcolor}{rosiebg}
373 \or
374 %% ghostly
375 \colorlet{minorcolor}{gray!15}
376 \colorlet{majorcolor}{gray!20}
377 \colorlet{bgcolor}{white}
378 \or
379 %% brickred
380 \colorlet{minorcolor}{brick!35}
381 \colorlet{majorcolor}{brick!60}
382 \colorlet{bgcolor}{scarlet!8}
383 \or
384 %% engineer
385 \colorlet{minorcolor}{chameleon!50}
386 \colorlet{majorcolor}{chameleon!80}
387 \colorlet{bgcolor}{chameleon!10}
388 \or
389 %% plumpad
390 \colorlet{minorcolor}{cornflower!40}
391 \colorlet{majorcolor}{cornflower!70}
392 \colorlet{bgcolor}{plum!10}
393 \fi
394 }
395
396 %% Get the specified color set from the options
397 \def\@setkeyhelper#1#2{%
398 \setkeys{GP}{#2=#1}
399 }
400 \expandafter\@setkeyhelper\expandafter{\GPOpt@colorset}{colorset}
401
402 %% If the user further specified majorcolor, minorcolor, and/or
403 %% bgcolor, we now override the selected colorset
404 \ifx\GPOpt@majorcolor\@empty
405 \else
406 \colorlet{majorcolor}{\GPOpt@majorcolor}
407 \fi
408 \ifx\GPOpt@minorcolor\@empty
409 \else
410 \colorlet{minorcolor}{\GPOpt@minorcolor}
411 \fi
412 \ifx\GPOpt@bgcolor\@empty
413 \else
414 \colorlet{bgcolor}{\GPOpt@bgcolor}
415 \fi
416
417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
418 %% The size parameter -- different meanings for different patterns
419 %% Will be reset by pattern code
420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
421 \newcommand{\GP@patternsize}{0.1in}
422
423 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
424 %% This section sets up a routine for filling a shape with
425 %% hexagons. Uses code from:
426 %% http://tex.stackexchange.com/questions/6019/drawing-hexagons/6128#6128
427 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428
429 %% We have to delay this definition until after \GP@patternsize is
430 %% redefined (by the pattern selection and/or user override)
431 \newcommand{\GP@declarehexpat}{
432 \tikzdeclarepattern{
433 name=hexagons,
434 type=uncolored,
435 bounding box={(0,0) and (3*\GP@patternsize,0.866025*2*\GP@patternsize)},
436 tile size={(3*\GP@patternsize,0.866025*2*\GP@patternsize)},
437 parameters={\tikzhexrotate},
438 tile transformation={rotate=\tikzhexrotate},
439 defaults={
440 rotate/.store in=\tikzhexrotate,rotate=0,
441 },
442 code={
443 \pgfsetlinewidth{0.6pt}
444 \pgftransformshift{\pgfpoint{0mm}{0.866025*\GP@patternsize}}
445 \pgfpathmoveto{\pgfpoint{0mm}{0mm}}
446 \pgfpathlineto{\pgfpoint{0.5*\GP@patternsize}{0mm}}
447 \pgfpathlineto{\pgfpoint{\GP@patternsize}{-0.866025*\GP@patternsize}}
448 \pgfpathlineto{\pgfpoint{2*\GP@patternsize}{-0.866025*\GP@patternsize}}
449 \pgfpathlineto{\pgfpoint{2.5*\GP@patternsize}{0mm}}
450 \pgfpathlineto{\pgfpoint{3*\GP@patternsize}{0mm}}
451 \pgfpathmoveto{\pgfpoint{0.5*\GP@patternsize}{0mm}}
452 \pgfpathlineto{\pgfpoint{\GP@patternsize}{0.866025*\GP@patternsize}}
453 \pgfpathlineto{\pgfpoint{2*\GP@patternsize}{0.866025*\GP@patternsize}}
454 \pgfpathlineto{\pgfpoint{2.5*\GP@patternsize}{0mm}}
455 \pgfusepath{stroke}
456 }
457 }
458 }
459
460
461 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
462 %% This section sets up a routine for filling a shape with
463 %% triangles.
464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
465
466 %% We have to delay this definition until after \GP@patternsize is
467 %% redefined (by the pattern selection and/or user override)
468 \newcommand{\GP@declaretripat}{
469 \tikzdeclarepattern{
470 name=triangles,
471 type=uncolored,
472 bounding box={(0,0) and (\GP@patternsize,2*0.866025*\GP@patternsize)},
473 tile size={(\GP@patternsize,2*0.866025*\GP@patternsize)},
474 parameters={\tikztrirotate},
475 tile transformation={rotate=\tikztrirotate},
476 defaults={
477 rotate/.store in=\tikztrirotate,rotate=0,
478 },
479 code={
480 \pgfsetlinewidth{0.6pt}
481 \pgfpathmoveto{\pgfpoint{0mm}{0mm}}
482 \pgfpathlineto{\pgfpoint{\GP@patternsize}{2*0.8660254*\GP@patternsize}}
483 \pgfpathlineto{\pgfpoint{0mm}{2*0.8660254*\GP@patternsize}}
484 \pgfpathmoveto{\pgfpoint{0mm}{0.8660254*\GP@patternsize}}
485 \pgfpathlineto{\pgfpoint{\GP@patternsize}{0.8660254*\GP@patternsize}}
486 \pgfpathmoveto{\pgfpoint{0mm}{2*0.8660254*\GP@patternsize}}
487 \pgfpathlineto{\pgfpoint{\GP@patternsize}{0mm}}
488 \pgfpathlineto{\pgfpoint{0mm}{0mm}}
489 \pgfusepath{stroke}
490 }
491 }
492 }
493
494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
495 %% This section sets up a routine for filling the squares in a
496 %% grid with null lines.
497 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
498 %% TODO Still can't figure out the correct pattern shift!!
499 \newcommand{\GP@declarelightconepat}{
500 \pgfkeys{
501 /pgf/pattern keys/myshift/.store in=\myshift,
502 /pgf/pattern keys/myshift/.initial={(0,0)},
503 }
504 \tikzdeclarepattern{
505 name=lightcones,
506 type=uncolored,
507 parameters={\myshift},
508 bounding box={(0,0) and (\GP@patternsize,\GP@patternsize)},
509 tile size={(\GP@patternsize, \GP@patternsize)},
510 tile transformation={
511 shift=\myshift,
512 },
513 defaults={
514 myshift/.store in=\myshift,myshift={(0,0)},
515 },
516 code={
517 %% TODO Make the dashing an option
518 \tikzset{lightlines/.style={line width=0.4pt,dash=on 0.05cm off 0.05cm phase 0.025cm}}
519 \draw [lightlines] (0,0) -- (\GP@patternsize,\GP@patternsize);
520 \draw [lightlines] (0,\GP@patternsize) -- (\GP@patternsize,0);
521 },
522 }
523 }
524 %% \pgfdeclarepatternformonly
525 %% {lightcones}% name
526 %% {\pgfpointorigin}% lower left
527 %% {\pgfpoint{\GP@patternsize}{\GP@patternsize}}% upper right
528 %% {\pgfpoint{\GP@patternsize}{\GP@patternsize}}% tile size
529 %% {% shape description
530 %% \pgfsetlinewidth{0.4pt}
531 %% %% TODO Make an option
532 %% %Comment out this line for solid lines on light cones, instead of dashes.
533 %% \pgfsetdash{{0.05cm}{0.05cm}}{0.025cm}
534 %% \pgfpathmoveto{\pgfpoint{0in}{0in}}
535 %% \pgfpathlineto{\pgfpoint{\GP@patternsize}{\GP@patternsize}}
536 %% \pgfpathmoveto{\pgfpoint{0in}{\GP@patternsize}}
537 %% \pgfpathlineto{\pgfpoint{\GP@patternsize}{0in}}
538 %% \pgfusepath{stroke}
539 %% }
540
541 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
542 %% This section sets up a routine for filling a region with dots
543 %% Slightly modified version of code added by Leo
544 %% Stein (@duetosymmetry on Twitter).
545 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
546 %% We have to delay this definition until after \GP@patternsize is
547 %% redefined (by the pattern selection and/or user override)
548 \newcommand{\GP@declaredotpat}{
549 \pgfdeclarepatternformonly
550 {dotgrid}%% name
551 {\pgfpoint{-0.5*\GP@patternsize}{-0.5*\GP@patternsize}}%% lower left
552 {\pgfpoint{0.5*\GP@patternsize}{0.5*\GP@patternsize}}%% upper right
553 {\pgfpoint{\GP@patternsize}{\GP@patternsize}}%% tile size
554 {%% shape description
555 \pgfpathcircle{\pgfqpoint{0pt}{0pt}}{\GPOpt@dotsize}
556 \pgfusepath{fill}
557 }
558 }
559
560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
561 %% Begin pattern execution infrastructure
562 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
563
564 %% This inner code will be set by the choicekey pattern=...
565 \newcommand{\GP@innerpatterncode}{}
566 %% This is the "outer" code to hook into every page
567 \newcommand{\GP@patterncode}{% No blank lines in this code!
568 \begin{tikzpicture}[remember picture, overlay]
569 %%
570 %% Change "thin" to "very thin" if the lines are too thick.
571 \tikzset{
572 minorgrid/.style={minorcolor, thin},
573 majorgrid/.style={majorcolor, thin},
574 }
575 \ifGP@fullpage%
576 \coordinate (a) at (current page.south west);
577 \coordinate (b) at (current page.north east);
578 \else%
579 \coordinate (a) at (current page text area.south west);
580 \coordinate (b) at (current page text area.north east);
581 \fi
582 %%
583 \GP@innerpatterncode%
584 %%
585 \end{tikzpicture}
586 }
587
588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
589 %% Begin pattern definition code
590 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
591
592 \define@boolkey{GP}{patterndefaultfullness}{}
593 \newcommand{\GP@patterndefaultgeometry}{}
594 \newcommand{\GP@patterndefaultsize}{}
595
596 %% Pattern-definer-helper
597 %% The interface is:
598 %% \GP@setpattern
599 %% {<true for default fullpage, false for default textarea>}
600 %% {<default geometry config>}
601 %% {<default pattern size>} %% NOTE, not tile length
602 %% {<contents of inner pattern code>}
603 \newcommand{\GP@setpattern}[4]{%
604 \setkeys{GP}{patterndefaultfullness=#1}
605 \renewcommand{\GP@patterndefaultgeometry}{#2}
606 \renewcommand{\GP@patterndefaultsize}{#3}
607 \renewcommand{\GP@innerpatterncode}{#4}
608 }
609
610 \define@choicekey*{GP}{pattern}[\val\nr]%
611 %% Allowed values for pattern:
612 {std,stdeight,majmin,dot,hex,hexup,tri,iso,lightcone,ruled,doubleruled}{%
613 \ifcase\nr\relax
614 %% std
615 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
616 %% Quadrille, ten squares per inch.
617 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
618 \GP@setpattern{false}{letterpaper, margin=0.2in}{0.1in}{%
619 %% Draw a grid with 10 squares per inch.
620 \draw[style=minorgrid, shift={(a)}] (0,0) grid [step=\GP@patternsize] (b);
621 %%
622 %% Draw a frame around the grid.
623 \draw[style=majorgrid] (a) rectangle (b);
624 }
625 \or
626 %% stdeight
627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
628 %% Quadrille, eight squares per inch.
629 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
630 \GP@setpattern{false}{letterpaper, margin=0.1875in}{0.125in}{%
631 %% Draw a grid with 10 squares per inch.
632 \draw[style=minorgrid, shift={(a)}] (0,0) grid [step=\GP@patternsize] (b);
633 %%
634 %% Draw a frame around the grid.
635 \draw[style=majorgrid] (a) rectangle (b);
636 }
637 \or
638 %% majmin
639 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
640 %% Graph paper, eight squares per inch with a major grid
641 %% every half-inch.
642 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
643 \GP@setpattern{false}{letterpaper, margin=0.25in}{0.125in}{%
644 %% Draw a grid with 10 squares per inch.
645 \draw[style=minorgrid, shift={(a)}] (0,0) grid [step=\GP@patternsize] (b);
646 %%
647 \draw[style=majorgrid, shift={(a)}] (0,0) grid [step=4*\GP@patternsize] (b);
648 %%
649 %% Draw a frame around the grid.
650 \draw[style=majorgrid] (a) rectangle (b);
651 }
652 \or
653 %% dot
654 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
655 %% Dot grid
656 %% Slightly modified version of code added by Leo
657 %% Stein (@duetosymmetry).
658 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
659 \GP@setpattern{true}{}{0.1in}{%
660 \fill [pattern=dotgrid,pattern color=minorcolor] (a) rectangle (b);
661 }
662 \or
663 %% hex
664 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
665 %% Hex grid
666 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
667 \GP@setpattern{true}{}{0.1666in}{%
668 \fill [pattern=hexagons,pattern color=minorcolor] (a) rectangle (b);
669 }
670 \or
671 %% hexup
672 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
673 %% Hex-up grid
674 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
675 \GP@setpattern{true}{}{0.1666in}{%
676 \fill [pattern={hexagons[rotate=90]},pattern color=minorcolor] (a) rectangle (b);
677 }
678 \or
679 %% tri
680 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681 %% Triangle grid, adjust triangle size in the preamble
682 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
683 \GP@setpattern{true}{}{0.25in}{%
684 \fill [pattern=triangles,pattern color=minorcolor] (a) rectangle (b);
685 }
686 \or
687 %% iso
688 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
689 %% Isometric grid
690 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
691 \GP@setpattern{true}{}{0.25in}{%
692 \fill [pattern={triangles[rotate=90]}, pattern color=minorcolor] (a) rectangle (b);
693 }
694 \or
695 %% lightcone
696 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
697 %% A grid with light cones.
698 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
699 \GP@setpattern{false}{letterpaper, margin=.125in}{0.25in}{%
700 %% Draw a grid with 4 squares per inch.
701 \draw[style=minorgrid, shift={(a)}] (0,0) coordinate grid [step=\GP@patternsize] (b);
702 %%
703 %% Draw a border around the grid.
704 \draw[style=majorgrid, pattern={lightcones[myshift={(a)}]}, pattern color=lightlines] (a) rectangle (b);
705 }
706 \or
707 %% ruled
708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
709 %% Ruled page with bold lines every 0.2in or 0.25in
710 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
711 \GP@setpattern{false}{letterpaper, body={8in,10.8in}}{0.2in}{%
712 %% Draw a ruled page with lines every 0.2in
713 \draw[style=majorgrid, shift={(a)}] (0,0) grid [ystep=\GP@patternsize, xstep=\paperwidth] (b);
714 %% Draw a frame around the grid.
715 \draw[style=majorgrid] (a) rectangle (b);
716 }
717 \or
718 %% doubleruled
719 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
720 %% Ruled page with bold lines every 0.25in and light lines
721 %% every 0.125 in.
722 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
723 \GP@setpattern{false}{letterpaper, margin=.25in}{0.125in}{%
724 %% Draw a ruled pattern with thin lines every 0.125 in and bold lines every 0.25 in.
725 \draw[style=minorgrid, shift={(a)}] (0,0) grid [ystep=\GP@patternsize, xstep=\paperwidth] (b);
726 %%
727 \draw[style=majorgrid, shift={(a)}] (0,0) grid [ystep=2*\GP@patternsize, xstep=\paperwidth] (b);
728 %%
729 %% Draw a frame around the grid.
730 \draw[style=majorgrid] (a) rectangle (b);
731 }
732 \fi
733 }
734
735 %% Use the passed package option to set the above key
736 \expandafter\@setkeyhelper\expandafter{\GPOpt@pattern}{pattern}
737
738 %% Determine whether or not to (re)set fullpage vs textarea
739 \ifGP@fullnessset
740 %% Respect their choice
741 \else
742 %% Reset the value of \GP@fullpage based on the pattern's default
743 %% There's probably a more idiomatic way to do this but I can't
744 %% figure it out
745 \ifKV@GP@patterndefaultfullness
746 \GP@fullpagetrue
747 \else
748 \GP@fullpagefalse
749 \fi
750 \fi
751
752 %% Determine whether or not to fiddle with the page geometry
753 \ifGP@geometrypreviouslyloaded
754 %% Respect their previous choice
755 \PackageWarning{gridpapers}{'geometry' package was previously loaded, will not use pattern defaults.}
756 \else
757 %% Use the pattern's defaults,
758 \expandafter\geometry\expandafter{\GP@patterndefaultgeometry}
759 %% And then override with any more specific settings passed by the user
760 \expandafter\geometry\expandafter{\GPOpt@geometry}
761 \fi
762
763 %% Determine the correct pattern length
764 \ifx\GPOpt@patternsize\@empty
765 % Use the pattern's preferred length
766 \renewcommand{\GP@patternsize}{\GP@patterndefaultsize}
767 \else
768 % Override with the user's choice
769 \renewcommand{\GP@patternsize}{\GPOpt@patternsize}
770 \fi
771
772 %% Now that everything has been set up, we can finally define the
773 %% patterns with the correct lengths.
774 \GP@declarehexpat
775 \GP@declaretripat
776 \GP@declarelightconepat
777 \GP@declaredotpat
778
779 %% Set the background color.
780 \AtBeginDocument{\pagecolor{bgcolor}}
781 %% Actually hook it in!
782 \AddEverypageHook{%
783 \GP@patterncode%
784 }
785
786 \endinput
787 % \end{macrocode}
788 %
789 % \iffalse
790 %</package>
791 % \fi
792 %
793 % \Finale
794 \endinput