Latest Blog Article >> more articles
How to type a square character in Mac OS X
The founders of the Paderborn Center for Parallel Computing, my current employer, have made the choice to use PC² instead of PCPC as the official acronym for the institute. While this choice bears the advantage of memorability, typing a square character (²) on a Mac is tedious because the standard keyboard layout does not provide a default key combination to directly type a square character. But as Mac OS X is highly customizable, it needless to say that there are solutions for this problem. In the following, I present three solutions to the problem, that are partly complementary.
1. System wide "Text and symbol substitution"
Since version 10.6 (Snow Leopard) Mac OS X provides support for system wide "Text and Symbol substitution" that can be configured in the "Language & Text" system preference pane. This method allows to setup the text input system to automatically replace PC2 with PC², whenever the text PC2 is typed.
To configure this text substitution open the "Language & Text" preference pane in system preferences and navigate to the "Text" tab. Using the plus button you can setup a new replacement rule that replaces "PC2" with "PC²" (see screenshot below). For typing the ² character, you can use the character viewer or copy and paste the string from this article.
This text replacement will become active only, after your applications have been restarted, hence I suggest to log out and log in again. A limitation of this approach is that it works only in applications that have been built using the OS X Cocoa libraries. While this will cover the vast majority of the applications you are likely to use, there is one notable exception: Microsoft Office 2008 for Mac still uses the outdated Carbon libraries, hence the text substitution will not be available. Fortunately there is an easy workaround, which I will describe in the next section.

2. Application-specific text substitution (Microsoft Office 2008)
Since Microsoft Office 2008 is still an application that uses the outdated Carbon libraries, it does not enjoy the system wide text substitution feature of Mac OS X 10.6. However, Word and PowerPoint allow for configuring text substitutions in the application using the "Auto correct" feature.
To setup the substitution select the Option "AutoCorrect" from the "Tools" menu and configure the substitution as shown in the screenshot below. For some reason Microsoft decided that its Office applications do not share the substitutions, hence the substitution has to be setup in every application separately.

3. Configure Cocoa Keybindings
The most flexible way to configure the keyboard layout on OS X is to setup custom key bindings. In fact, keybindings go much beyond simply assigning characters to specific key combinations, but allow to customize the Cocoa text system in a very powerful way. An excellent presentation by Jacob Rus on how to configure the Cocoa Text Input system can be found here.
For the use case of binding the ² character to a specific key combination, the required configuration is however not very difficult. Keybindings are configured using XML property lists. For binding the ² symbol to the key combination ⌃⌥2 (aka Ctrl+Alt+2) simply create a file at ~/Library/KeyBindings/DefaultKeyBinding.dict with the following contents.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>^~2</key>
<array>
<string>insertText:</string>
<string>²</string>
</array>
</dict>
</plist>
It may be necessary to create a KeyBindings directory in the Library sub-directory of your home folder first. In the case that you have already configured your default keybindings, simply merge the relevant parts of the property list above with your DefaultKeyBindings.dict.
As for the system wide text substitutions introduced above, this keybindings affect only Cocoa applications and also require a restart of the applicaitons to become active.
Written April 13th, 2010