Measurement bundle for TextMate

My project notes usually include measurements, and I like to see them with typographically correct fractions and units. The correct characters are available through the Character Palette, but I don’t like keeping it open all the time, because

So I created a set of TextMate snippets and macros to insert the fraction and unit characters from the keyboard.

The bundle is called Measurement, and you can get a zipped version of it here. After unzipping it on your hard disk, double click the .tmbundle file to open it in TextMate. TextMate will import it and make it available to you.

Here’s what Measurement’s contents looks like in the TM Bundle Editor:

As you can see, most of the entries are simply snippets for inserting the single-character fractions, ⅛, ¼, ⅜, ½, ⅝, ¾, and ⅞. There are two snippets for each fraction: one for when the fraction is by itself and one for when it’s part of a mixed number. The Tab Triggers for the standalone fractions are their plain ASCII renditions: 1/4 for ¼, 1/2 for ½, etc. The Tab Triggers for the fractional parts of mixed numbers are the plain ASCII renditions preceded by a hyphen: to get 2¾, type 2-3/4, then press the Tab key. That’s a fairly common way to type mixed numbers without using the special fraction characters, so it seemed natural to make the Tab Triggers use that form.

The mixed number versions are necessary because TextMate will expand a snippet only if the Tab Trigger is preceded by a “word boundary.” TextMate considers a word boundary to be any place between an alphanumeric character and a non-alphanumeric character. For example, if you defined a snippet with the expanded text “education” and the Tab Trigger “ed,” pressing the Tab key after typing

So, even with a Tab Trigger for ¾ defined as 3/4, pressing the Tab key after 23/4 would not generate 2¾, because there’s no word boundary between the 2 and the 3. But with a Tab Trigger for ¾ defined as -3/4, pressing Tab after 2-3/4 does generate 2¾.

You could argue that the unhyphened versions of the Tab Triggers are unnecessary, and you’d be correct. But I like having the unhyphened versions because it seems more natural to type 7/8 instead of -7/8 to get the standalone fraction ⅞.

There are two macros in the bundle for units: one for inch marks (″) and one for foot marks (′). These are not the straight quote characters, nor are they closing curly quotes. They are the single- and double-prime characters. Using straight quotes for inch and foot marks is a sign that you don’t care; using curly quotes is a sign that you have no visual taste whatsoever and should be shunned by civilized people everywhere. And you probably use Microsoft Word.

I started by defining the inch and foot marks as snippets, but that didn’t work because:

The solution is to use macros. Then I can type “5 in” and press Tab to launch a macro that deletes the preceding space before inserting the double-prime. The foot mark macro works the same way.

The remaining snippets are only of value if you happen to type things like “the bottom chord members of the roof truss are 2×6s” or “the slab is 15′ × 12′ in plan.” Note that these expand with the actual multiplication sign, not the “x” character, even though the “x” is used in the Tab Trigger for ease of typing.

(If you’re wondering why I don’t have a snippet for the degree symbol [°], it’s because that’s easy to type already: Option-Command-8. If the prime, fraction, and multiplication symbols were as easy to get to as the degree, I wouldn’t have made this bundle in the first place.)

I’ve set the scope for each item in the bundle to “text,” so they should work whether you’re writing in Markdown, HTML, or LaTeX. They should not work when you’re writing code—expanding 1/2 into ½ while programming seemed like a bad idea to me.