Drawing with Pic

Published: Thu 03 August 2017

In Blog.

I’ve had this idea knocking around in my head for a while now; how to get everything to be “keyboard-driven”. Ultimately one needs to draw a picture or two, but that invariably involves the mouse, and with the mouse comes the imprecise. There’s something satisfying about knowing that objects in your drawing are precise down to the pixel/pt. The same source of that satisfaction is the source of the frustration associated with painstakingly pixel-adjusting lines and objects on the virtual canvas.

I’ve wanted (and been looking for) a suitable language for drawing construction. Something that has “sized the Lego blocks right” as Hanselman would put it. Recently I came upon something that looks like it fits the bill, well at least in spirit; namely: Pic.

Pic is specifically designed to allow putting together quick, simple technical diagrams (typically with lines and arrows connecting blocks), e.g.,

box "Fear"
box "Anger"
box "Hate"
box "Suffering"

Although Pic is originally something that was written by Brian Kernighan, of The C Programming Language fame (amongst many other things) it’s evolved over time and its best-known implementation is GNU Pic, something that’s bundled with groff, the (once) famous typesetting suite. Coming bundled with Groff, GNU Pic outputs troff format which then needs to be Groffed in order to get PostScript (PS). Since PS format generally isn’t used much anymore, it then needs to be translated into something more useful. If it’s diagrams we’re drawing, that something more useful is a png. Getting a png out of PS means employing the services of GhostScript. All of this ends up being quite a pipeline of commands:

pic f-a-h-s.pic | groff | ps2eps | gs -dBATCH -sOutputFile ...

To avoid this long-winded incantation, Dwight Aplevich has provided us with a modern alternative to pic, namely dpic which can produce a nice, modern vector format (SVG) directly:

dpic -v f-a-h-s.pic > f-a-h-s.svg

In addition, the language supported by dpic is a superset of the original pic language and seems significantly richer. Of course, when it comes to drawing DSLs, the list isn’t short (PGF/TikZ, PSTricks and MetaPost to name a few) but what I like about Pic is the ease with-which one can get simple diagrams going.

Comments !