The graphpap package^{∗}

Leslie Lamport

1994/08/09

\graphpaper[⟨N ⟩](⟨X,Y ⟩)(⟨DX,DY ⟩) Makes a grid with left-hand corner at (⟨X,Y ⟩), extending (⟨DX,DY ⟩) units in the X and Y directions, where the lines are N units apart. Every fifth line is thick and is numbered. The default value of N is 10. The arguments must all be integers.

First, we define three counters. The first two are defined as raw TeX counters since multiplication and division must be performed in them.

1 ⟨∗package⟩

 2 % \newcount\@gridx% now  (\@tempcnta)
 3 % \newcount\@gridy% now  (\@tempcntb)
 4 % \newcounter{@grid}
 5 \let\c@@grid\count@

Next we define the following commands to draw vertical and horizontal grids. The “nonum” commands just draw the grids; the other commands also print numbers. All the arguments must be integers.

VERTICAL GRIDS

\@vgrid(⟨xpos,ypos⟩){⟨xincrement⟩}{⟨number-of-lines⟩}{⟨length-of-lines⟩} \@nonumvgrid(⟨xpos,ypos⟩){⟨xincrement⟩}{⟨number-of-lines⟩}{⟨length-of-lines⟩}

HORIZONTAL GRIDS

\@hgrid(⟨xpos,ypos⟩){⟨yincrement⟩}{⟨number-of-lines⟩}{⟨length-of-lines⟩} \@nonumhgrid same as \@hgrid but no numbers drawn

 6 \def\@vgrid(#1,#2)#3#4#5{%
 7 \setcounter{@grid}{#1}%
 8 \multiput(#1,#2)(#3,0){#4}{\line(0,1){#5}}%
 9 \multiput(#1,#2)(#3,0){#4}{\@vgridnumber{#3}}}
10 \def\@vgridnumber#1{%
11 \makebox(0,0)[t]{%
12  \shortstack{\rule{0pt}{10pt}\\\arabic{@grid}}}%
13 \addtocounter{@grid}{#1}}
14 \def\@nonumvgrid(#1,#2)#3#4#5{%
15 \multiput(#1,#2)(#3,0){#4}{\line(0,1){#5}}}
16 \def\@hgrid(#1,#2)#3#4#5{%
17 \setcounter{@grid}{#2}%

∗This file has version number v1.0c, last revised 1994/08/09.

18 \multiput(#1,#2)(0,#3){#4}{\line(1,0){#5}}%
19 \multiput(#1,#2)(0,#3){#4}{\@hgridnumber{#3}}}
20 \def\@hgridnumber#1{%
21 \makebox(0,0)[r]{\arabic{@grid}\hspace{10pt}}%
22 \addtocounter{@grid}{#1}}
23 \def\@nonumhgrid(#1,#2)#3#4#5{%
24 \multiput(#1,#2)(0,#3){#4}{\line(1,0){#5}}}

Finally, \graphpaper is defined in a straightforward way in terms of the commands above.

\graphpaper
25 \newcommand\graphpaper[1][10]{\leavevmode\@grid{#1}}
\@grid
26 \def\@grid#1(#2,#3)#4{\@grid@i{#1}{#2}{#3}(}
\@grid@i
27 \def\@grid@i#1#2#3(#4,#5){%
28 \@tempcnta=#4\relax
29 \divide\@tempcnta#1\relax
30 \advance\@tempcnta1\relax
31 {\thinlines\@nonumvgrid(#2,#3){#1}{\@tempcnta}{#5}
32  \@tempcnta#4\relax
33  \divide\@tempcnta5\relax
34  \divide\@tempcnta#1\relax
35  \advance\@tempcnta1\relax
36  \@tempcntb5\relax
37  \multiply\@tempcntb#1\relax
38  \thicklines\@vgrid(#2,#3){\@tempcntb}{\@tempcnta}{#5}
39  \@tempcnta#5\relax
40  \divide\@tempcnta #1\relax
41  \advance\@tempcnta1\relax
42  \thinlines\@nonumhgrid(#2,#3){#1}{\@tempcnta}{#4}
43  \@tempcnta#5\relax
44  \divide\@tempcnta5\relax
45  \divide\@tempcnta#1\relax
46  \advance\@tempcnta1\relax
47  \thicklines\@hgrid(#2,#3){\@tempcntb}{\@tempcnta}{#4}}%
48 \ignorespaces}

49 ⟨/package⟩