www.eamoncaddigan.net

Content and configuration for https://www.eamoncaddigan.net
git clone https://git.eamoncaddigan.net/www.eamoncaddigan.net.git
Log | Files | Refs | Submodules | README

commit 3bcc10cb7a579f8ba1531ae2eda7f1671a4d6629
parent a5bf76555b24f319675d49cbcc45d3a622174d8d
Author: Eamon Caddigan <eamon.caddigan@gmail.com>
Date:   Wed,  8 Nov 2023 21:16:13 -0800

Links to other designs and some resources

Diffstat:
Mcontent/posts/postscript-graph-paper/index.md | 89++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 56 insertions(+), 33 deletions(-)

diff --git a/content/posts/postscript-graph-paper/index.md b/content/posts/postscript-graph-paper/index.md @@ -1,35 +1,45 @@ --- title: "PostScript Graph Paper" date: 2023-10-22T05:52:41-07:00 +lastmod: 2023-11-08T21:12:00-08:00 draft: false categories: - Programming --- -I needed some graph paper, and for my needs it seemed easier and more -economical to print some at home than buy a whole pad of it. I turned to the -web and found plenty of sites offering PDF files with grids on them, but I -didn't like what I found[^pdfs] and decided to make my own. +I needed a few pages of graph paper, and it seemed easier and more +economical to print some at home than to buy a whole pad of it. There are +plenty of websites offering PDF files with grids on them, but I didn't like +what I found[^pdfs] and decided to make my own. I thought that the process +was fun enough that I have since made a few different kinds: -[Here's a PDF for a US Letter page with a 5 mm × 5 mm grid](grid.pdf). +* [5 mm × 5 mm grid (pdf)](grid.pdf) ([postscript](grid.ps)) +* [5 mm × 5 mm dot grid (pdf)](dotgrid.pdf) ([postscript](dotgrid.ps)) +* [1 inch width hex grid (pdf)](hexgrid.pdf) ([postscript](hexgrid.ps)) -Drawing a grid is not difficult to do with a computer. The SVG format is -pretty straightforward, so I considered writing a simple program to create a -grid in SVG, and then using a second program to print it. But then I -remembered: PostScript is a bona fide programming language! I could -conceivably write the code to generate a graph paper grid in a file which -could be printed directly. So I spent an afternoon familiarizing myself with -PostScript and did that. +All files are meant for US Letter paper but could easily be adapted to other +dimensions. They are also "full bleed" because I decided to allow my printer +to impose its own margins; just be sure that you turn off any "autoscale" or +"fit to page" option before printing these. -I learned that PostScript is a stack based ("concatenative") language, like -Forth or [UXNTAL](https://wiki.xxiivv.com/site/uxntal.html). I was playing -with the latter last fall[^uxntal], so I have some familiarity with the -paradigm. Stack programming seems strange when you're used to other -paradigms, but I find it's not too hard to shift into the right mindset to -write code this way once I get started. +## Why PostScript? -The complete PostScript program, which produced the PDF linked above, -follows: +Drawing a grid is not difficult to do with a computer. I considered writing +code to programmatically generate an SVG file, but then I recalled that +PostScript, the precursor to the PDF format, is a bona fide programming +language! It only took an afternoon of familiarizing myself with the +language to make the grid, and I kept going from there. + +It turns out that PostScript is a stack-based ("concatenative") language, +like Forth or [UXNTAL](https://wiki.xxiivv.com/site/uxntal.html). I was +playing with the latter last fall[^uxntal], so I have some familiarity with +this type of language. Stack programming seems strange when you're used to +other paradigms, but once you get started you may find it easy to shift into +the right mindset for structuring programs this way. + + +The complete PostScript program, which produced the 5 mm × 5 mm grid linked +above, follows: ```PostScript %!PS @@ -72,18 +82,15 @@ stroke ``` This code is probably not idiomatic or efficient, and I welcome feedback on -writing better PostScript. But it worked for me and shouldn't be too hard to -adapt to other page or grid sizes. Some might want to add margins to the -page, but I decided that I would rather let my printer print as much grid as -it was able; I just made sure to disable "print scaling". +writing better PostScript. But it worked for me and won't be hard to adapt +to your own needs. ## Programming with PostScript If you're interested in playing with PostScript programming, -[Ghostscript](https://www.ghostscript.com/) (which I used to convert the -PostScript file to PDF) has an interactive interpreter that allows you to -manipulate and view the stack (just type `stack`), and draw on a page. I -just [came +[Ghostscript](https://www.ghostscript.com/)[^gs] has an interactive +interpreter that allows you to manipulate and view the stack (just type +`stack`), and draw on a page. I just [came across](https://social.tchncs.de/@daveliepmann/111274696437077402) this relevant [quote from Peter Norvig](http://www.norvig.com/21-days.html): @@ -94,14 +101,30 @@ relevant [quote from Peter Norvig](http://www.norvig.com/21-days.html): > also for programming. Insist on a language with an interactive mode and > use it. -If you're like me and tend to open a calculator whenever you're faced with -trivial arithmetic, I invite you to launch `ghostscript` and perform your -calculations on the stack. +Interest in PostScript peaked during an era where books were the easily the +best way to learn about a computing technology[^books]; I've seen the +following recommended and found them fairly easily online: -[^pdfs]: For starters, these sites all branded their downloads—which may be - their right, but I didn't want an advertisement on my paper. +* _Thinking in PostScript_ by Glenn Reid +* _PostScript Language Tutorial & Cookbook_ ("the Blue Book") by Adobe + Systems Incorporated +* _PostScript Language Program Design_ ("the Green Book") by Adobe Systems + Incorporated +* _PostScript Language Reference_ ("the Red Book") by Adobe Systems + Incorporated + +[^pdfs]: For starters, these sites all branded their downloads—which is + certainly their right, but I didn't want an advertisement on my paper. [^uxntal]: I started learning it for a project I ought to pick back up. I followed [compudanzas' _introduction to uxn programming_](https://compudanzas.net/introduction_to_uxn_programming_book.html) and recommend it! + +[^gs]: I used Ghostscript to convert these PS files to PDF, and have been + using it to tweak PDFs from the command line for years without realizing + it was a whole interactive programming language interpreter. + +[^books]: This may well still be true today, but speaking for myself, I + rarely begin learning new tools with a trip to the library, as I once + had for C and Perl.