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⟩

Change History

v1.0b

\@grid: (DPC) convert ignore

spaces between arguments …. 2

\@grid@i: (DPC) macro intro-

duced . . . . . . . . . . . . . . . . . . . 2 General: (DPC) Remove alloca-

tions. . . . . . . . . . . . . . . . . . . . 1 (DPC) convert to doc format . . 1 v1.0c

                                          \graphpaper:  (DPC)  add

\leavevmode . . . . . . . . . . . . . . 2

Index

Numbers written in italic refer to the page where the corresponding entry is described, the ones underlined to the code line of the definition, the rest to the code lines where the entry is used.

Symbols

\@grid . . . . . . . . . 25, \underline{26} \@grid@i . . . . . . . 26, \underline{27} \@gridx . . . . . . . . . . . 2 \@gridy . . . . . . . . . . . 3 \@hgrid . . . . . . . . 16, 47

\@hgridnumber . . . 19, 20
\@nonumhgrid . . . . 23, 42
\@nonumvgrid . . . . 14, 31
\@tempcnta . . . . . . .

. . 2, 28–35, 38–47

\@tempcntb 3, 36–38, 47

\@vgrid . . . . . . . . . 6, 38

\@vgridnumber . . . . 9, 10

\\ . . . . . . . . . . . . . . 12

A

\addtocounter . . . 13, 22

\advance . 30, 35, 41, 46 \arabic . . . . . . . . 12, 21

C

\c@@grid . . . . . . . . . . 5 \count@ . . . . . . . . . . . 5

D \def . . . . . . 6, 10, 14,

16, 20, 23, 26, 27 \divide . . . . . . . 29,

33, 34, 40, 44, 45

G

                          \graphpaper . . . . . . . \underline{25}

H \hspace . . . . . . . . . . 21

I

                          \ignorespaces . . . . . 48

L

                          \leavevmode . . . . . . . 25

\let . . . . . . . . . . . . . . 5 \line . . . . . 8, 15, 18, 24

M \makebox . . . . . . . 11, 21 \multiply . . . . . . . . 37

                                                   \multiput . . . . . . . .

8, 9, 15, 18, 19, 24

N

                                                   \newcommand . . . . . . . 25

\newcount . . . . . . . 2, 3

                                                   \newcounter . . . . . . . . 4

R \relax … 28–30, 32–

37, 39–41, 43–46 \rule . . . . . . . . . . . . 12

S

                                                   \setcounter . . . . . . 7, 17
                                                   \shortstack . . . . . . . 12

T

                                                   \thicklines . . . . . 38, 47
                                                   \thinlines . . . . . 31, 42