Hipster PDA currency conversion card

Quite a while ago, I posted an article that showed how to make a Hipster PDA card with Celsius-Fahrenheit conversion scales. At the time, I thought it would be good to combine the scale that dealt with the range of temperatures people normally experience with a currency conversion scale; a single card with a handy reference for people traveling in a foreign country. I thought about it, but I didn’t do it until my wife and daughter were a day or two away from taking off on a spring break vacation to Europe. The card looks like this:

The currency conversion (euros/dollars) is on the left and the temperature conversion is on the right.

The code for the card is written in PostScript and can be easily updated for the current exchange rate. Paste it into a plain text file and give it a “ps” extension.

%!PS-Adobe-3.0
%%Title: Currency and Temperature Scales
%%DocumentFonts: Helvetica
%%DocumentNeededFonts: Helvetica
%%EndComments
%%BeginSetup

% Conversion from inches to points (after the Blue Book).
/inch {72 mul} def

% Show right-justified text.
/rshow {
dup stringwidth pop       % gives the width of the string
0 exch sub                % changes sign of width
0 rmoveto                 % moves 
show} def

% show the number on the stack (after the Blue Book)
/nstr {7 string} def
/prt-n {nstr cvs show} def
/rprt-n {nstr cvs rshow} def

% Draw a set of horizontal hash marks spaced a constant vertical
% distance apart from one another. Uses the current line color and
% thickness. On entry, the stack should have the starting location,
% the spacing between marks, the number of spaces between marks
% (which is one less than the number of marks), and the length of
% each mark (which may be negative to indicate drawing in the
% opposite direction).
/hashmarks {
  3 dict begin
  /length exch def
  /count exch def
  /spacing exch def
  /start exch def
  gsave
    0 1 count {
      newpath
      spacing mul start add 0 exch moveto
      length 0 rlineto stroke } for
  grestore
} def

%%EndSetup

%%%%%%%%%% Left half of card %%%%%%%%%%

% In the left half of the card we'll do a scale with dollars and euros.

% Conversions from dollars and euros to points. 100 Euros will cover
% 4.5 inches.
/euro {4.5 mul 100 div inch} def
/usd {1.3308 div euro} def        % this number is dollars per euro

gsave

% Start 3.50 inches in from the left edge and a 6.25 inches up from
% the bottom of a letter-sized sheet. This will center us in the left
% half of an index card, a quarter-inch up from the bottom.
3.50 inch 6.25 inch translate

%%% The side with euros %%%

% draw the baseline
1 setlinewidth
newpath
0 0 euro moveto
0 100 euro lineto
stroke

% the hashmarks
1 setlinewidth
0 euro 10 euro 10 -18 hashmarks     % 10-euro marks
5 euro 5 euro 19 -14 hashmarks      % 5-euro marks
.5 setlinewidth
1 euro 1 euro 99 -10 hashmarks      % 1-euro marks

% the labels
/Helvetica findfont 9 scalefont setfont
gsave
-22 0 euro translate
0 10 100 {
  dup
  1 euro mul 3 sub 0 exch moveto
  rprt-n
} for
grestore

%%% The side with dollars %%%

% the hashmarks
1 setlinewidth
0 usd 10 usd 13 18 hashmarks      % 10-dollar marks
5 usd 10 usd 12 14 hashmarks      % 5-dollar marks
.5 setlinewidth
1 usd 1 usd 132 10 hashmarks      % 1-dollar marks

% the labels
/Helvetica findfont 9 scalefont setfont
gsave
35 0 usd translate
0 10 130 {
  dup
  1 usd mul 3 sub 0 exch moveto
  rprt-n
} for
grestore

grestore

%%%%%%%%%% Right half of card %%%%%%%%%%

% In the right half of the card we'll do a scale with temperatures.

% Conversions from degrees C and degrees F to points.
% 70 degC will cover 4.5 inches.
/degC {4.5 mul 70 div inch} def
/degF {32 sub 1.8 div degC} def
/Fdeg {1.8 div degC} def          % scaling w/o offset

gsave

% Start 4.90 inches in from the left edge and a 6.25 inches up from the
% bottom of a letter-sized sheet. This will (nearly) center us in the
% right half of an index card, a quarter-inch up from the bottom.
4.90 inch 6.25 inch translate

%%% The side with Celsius %%%

% Since our thermometer will start at -25 degC, we need to move
% the origin up.
0 25 degC translate

% draw the baseline
1 setlinewidth
newpath
0 -25 degC moveto
0 45 degC lineto
stroke

% the hashmarks
1 setlinewidth
-20 degC 10 degC 6 -18 hashmarks      % 10-degC marks
-25 degC 10 degC 7 -14 hashmarks      % 5-degC marks
.5 setlinewidth
-24 degC 1 degC 68 -10 hashmarks      % 1-degC marks

% the labels
/Helvetica findfont 9 scalefont setfont
gsave
-22 0 translate
-20 10 40 {
  dup
  1 degC mul 3 sub 0 exch moveto
  rprt-n
} for
grestore

%%% The side with Fahrenheit %%%

% the hashmarks
1 setlinewidth
-10 degF 10 Fdeg 12 18 hashmarks      % 10-degF marks
-5 degF 10 Fdeg 11 14 hashmarks       % 5-degF marks
.5 setlinewidth
-13 degF 1 Fdeg 126 10 hashmarks      % 1-degF marks

% the labels
/Helvetica findfont 9 scalefont setfont
gsave
35 0 degF translate
-10 10 110 {
  dup
  1 Fdeg mul 3 sub 0 exch moveto
  rprt-n
} for
grestore

grestore

After the boilerplate comments, a few utility functions are defined: one for converting inches to points, one for printing right-justified text, one for printing out series of hashmarks, and a few for manipulating the PostScript stack. (PostScript, like Forth, is a stack-based, postfix language.) The “blue book” mentioned in the comments is Adobe’s PostScript tutorial, which you can download from here.

The next section draws the currency conversion scale in the left half of the card. Although the comments, the variable names, and the current exchange rate are geared to a conversion between dollars and euros, the scale could be used to convert between any two currencies. The only thing that would need to be changed is the exchange rate, which is embedded in this line

/usd {1.3308 div euro} def        % this number is dollars per euro

Just change the number from 1.3308 to whatever the exchange rate is and you’re good to go. Even if you want a euros/dollars scale, you’ll probably want to change that number to the current rate. I got the exchange rate from Google: type “1 euro in usd” into the Google search field, and Sergey and Larry will give you the rate. (I just did it and found that the rate has gone up to 1.3367, so I’ll be paying for an ever-so-slightly more expensive vacation.)

Let’s talk about printing the card. First, you’ll notice some comments about starting so many inches in from the left edge and so many inches up from the bottom. The commands associated with these comments put the scales in an index-card-sized area at the top center of a piece of US letter paper. US letter is the default paper size for my printer, and when I stick an index card into the manual feed tray, these margins put the scales right where I want them.

If the sliding guides in your printer’s manual feed tray set the index card at the left or right edge instead of in the center, you’ll have to change the margins. The comments should be a pretty good guide (ho-ho) to changing the margin command.

If you don’t have a PostScript printer, you’ll probably want to convert the file to a PDF before printing. My favorite tool for this is ps2pdf, which comes with Ghostscript, the free PostScript emulator. I use the MacPorts (née DarwinPorts) Ghostscript package. If you have an Intel Mac, you can do the conversion by opening the PostScript file in Preview. I don’t recommend this approach for PPC Mac owners; I tried converting this file with Preview on my iBook G4 and had to kill it after several minutes of spinning beachball (the Activity Monitor said Preview was taking up about 80% to 90% of the CPU time and was “Not Responding”). I have no idea why Preview works well on an Intel and bogs down on a PPC, but that’s been my experience every time I’ve tried to use it to convert a PostScript file. Don’t fear the command line:

ps2pdf filename.ps

will create a filename.pdf file in the same directory in a couple of seconds.

Linux users that want to convert the file to PDF will almost certainly have Ghostscript and ps2pdf on their machines. I have no idea what will work best for Windows users and have no desire to figure it out.

Happy traveling! Send me an e-postcard if you use this.

Update I’ve rewritten this to generate a PDF directly. The new version is also easier to customize for other currencies and written in a more common language, Ruby. You can see the new version here.

Tags:


Comments are closed.