Whiteboard Diagrams as PDFs
Need a quick diagram for the paper you’re working on? Instead of this:
\begin{figure}
\vspace{0.5in}
Remember to put a diagram here!
\vspace{0.5in}
\caption{The to-be-written awesome caption will go here.}
\label{fig:now-its-all-clear}
\end{figure}
what if you could quickly turn a whiteboard sketch into a diagram suitable for use as a draft — and maybe even for use in a camera-ready, depending upon your drawing skills — in your paper?
I find drafting diagrams on the whiteboard is much faster than trying to do it in PowerPoint, OmniGraffle, or the like. Dan Roam’s non-technical but useful book The Back of the Napkin might help convince you of this, if you aren’t too averse to what I think of as business-targeted self-help books. Randall Munroe’s “what if?” posts are an excellent showcase for the explanatory power of simple line drawings. Who knows? You might like your hand-drawn diagram so much that you use it as-is, and don’t end up recreating it in Powerpoint.
But then how do you get it into a nice vector format for use in LaTeX or the like? Pull out your smartphone, take a picture of the whiteboard, and put it on your computer. You can use various programs to make this easier, like the Camera Upload feature in Dropbox’s phone app.
Smartphones usually produce JPEGs, which aren’t the ideal image format for diagrams, particularly diagrams that should have the feel of vector, rather than raster, graphics. I use several open source tools to quickly convert a JPEG like this:
into a small, scalable vector diagram like this:
It’s a multi-step process. First I crop and threshold the image into a bitmap using Gimp, and then I vectorize it using potrace. Specifically:
- Crop, threshold, and make a bitmap:
- Load the JPEG in Gimp.
- Select the area you want to crop.
- Crop using
Image
→Crop to Selection
. - Convert to a bitmap using
Image
→Mode
→Indexed
. - (Optional) Scale the image using
Image
→Scale Image...
to about 1,000 pixels or so in the shorter dimension, preserving the aspect ratio. This step isn’t necessary, but might help potrace if you have a particularly high-resolution camera on your phone. - I get best results if I use
Generate optimum palette
with two colors, rather than usingUse black and white (1-bit) palette
. You’d think they’d be identical, but in my very limited testing, they’re not. Your results may vary. - Export to a bitmap format that
potrace
can understand. UseFile
→Export...
, and save as a PBM.
- Use potrace to convert from a bitmap to a vector format:
- To make a PDF, try
potrace -b pdf -o file.pdf -t 10 file.pbm
. You may want to play with the potrace algorithm’s options (see the man page); the-t n
option suppresses speckles of up ton
pixels, which I find useful in removing stray whiteboard marks; calibraten
to the size of the image and the dirtiness of your whiteboard. - You can use
-b svg
to create SVG files, which can be rendered by most web browers. That’s where the preceding image came from.
- To make a PDF, try
There are many ways to tweak this process. Use ImageMagick or GraphicsMagick instead of Gimp if you want to do it all at the command line, or try Inkscape’s integrated potrace functionality if you want to do it all in a GUI.
Happy drawing!